From 7c5e9533e69e53c249b24140908bdd6a9f5bbb8d Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Fri, 10 May 2019 11:12:14 -0400 Subject: [PATCH] Don't attempt to const prop call cycles Even if the result is unused. Fixes #31974. --- base/compiler/abstractinterpretation.jl | 4 ++-- test/compiler/inference.jl | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index a6d28c14762a3..f4e888e39750a 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -258,7 +258,7 @@ function abstract_call_method(method::Method, @nospecialize(sig), sparams::Simpl # we have a self-cycle in the call-graph, but not in the inference graph (typically): # break this edge now (before we record it) by returning early # (non-typically, this means that we lose the ability to detect a guaranteed StackOverflow in some cases) - return Any, false, nothing + return Any, true, nothing end topmost = nothing edgecycle = true @@ -339,7 +339,7 @@ function abstract_call_method(method::Method, @nospecialize(sig), sparams::Simpl # since it's very unlikely that we'll try to inline this, # or want make an invoke edge to its calling convention return type. # (non-typically, this means that we lose the ability to detect a guaranteed StackOverflow in some cases) - return Any, false, nothing + return Any, true, nothing end poison_callstack(sv, topmost::InferenceState, true) sig = newsig diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 21e80639ab657..5f1e0a7bb282e 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -2414,3 +2414,10 @@ let f = MixedKeyDict((Dict(2 => 7), Dict(5. => 11))) @test merge(+, d, e, f).dicts == (Dict(1 => 10, 2 => 7), Dict(4.0 => 2, 5.0 => 20)) end + +# Issue #31974 +f31974(a::UnitRange) = (if first(a) <= last(a); f31974((first(a)+1):last(a)); end; a) +f31974(n::Int) = f31974(1:n) +# This query hangs if type inference improperly attempts to const prop +# call cycles. +@test code_typed(f31974, Tuple{Int}) !== nothing