Skip to content

Commit 7c5e953

Browse files
committed
Don't attempt to const prop call cycles
Even if the result is unused. Fixes #31974.
1 parent e813f0d commit 7c5e953

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function abstract_call_method(method::Method, @nospecialize(sig), sparams::Simpl
258258
# we have a self-cycle in the call-graph, but not in the inference graph (typically):
259259
# break this edge now (before we record it) by returning early
260260
# (non-typically, this means that we lose the ability to detect a guaranteed StackOverflow in some cases)
261-
return Any, false, nothing
261+
return Any, true, nothing
262262
end
263263
topmost = nothing
264264
edgecycle = true
@@ -339,7 +339,7 @@ function abstract_call_method(method::Method, @nospecialize(sig), sparams::Simpl
339339
# since it's very unlikely that we'll try to inline this,
340340
# or want make an invoke edge to its calling convention return type.
341341
# (non-typically, this means that we lose the ability to detect a guaranteed StackOverflow in some cases)
342-
return Any, false, nothing
342+
return Any, true, nothing
343343
end
344344
poison_callstack(sv, topmost::InferenceState, true)
345345
sig = newsig

test/compiler/inference.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,3 +2414,10 @@ let
24142414
f = MixedKeyDict((Dict(2 => 7), Dict(5. => 11)))
24152415
@test merge(+, d, e, f).dicts == (Dict(1 => 10, 2 => 7), Dict(4.0 => 2, 5.0 => 20))
24162416
end
2417+
2418+
# Issue #31974
2419+
f31974(a::UnitRange) = (if first(a) <= last(a); f31974((first(a)+1):last(a)); end; a)
2420+
f31974(n::Int) = f31974(1:n)
2421+
# This query hangs if type inference improperly attempts to const prop
2422+
# call cycles.
2423+
@test code_typed(f31974, Tuple{Int}) !== nothing

0 commit comments

Comments
 (0)