Skip to content

Commit 2a8eca3

Browse files
authored
irinterp: refine :nothrow only when it is not proved yet (#50764)
This makes irinterp not override `:nothrow=true` that are assumed by `Base.@assume_effects`.
1 parent cbc72d5 commit 2a8eca3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,8 +1153,11 @@ function semi_concrete_eval_call(interp::AbstractInterpreter,
11531153
# that are newly resovled by irinterp
11541154
# state = InliningState(interp)
11551155
# ir = ssa_inlining_pass!(irsv.ir, state, propagate_inbounds(irsv))
1156-
new_effects = Effects(result.effects; nothrow)
1157-
return ConstCallResults(rt, SemiConcreteResult(mi, ir, new_effects), new_effects, mi)
1156+
effects = result.effects
1157+
if !is_nothrow(effects)
1158+
effects = Effects(effects; nothrow)
1159+
end
1160+
return ConstCallResults(rt, SemiConcreteResult(mi, ir, effects), effects, mi)
11581161
end
11591162
end
11601163
end

test/compiler/effects.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,3 +1010,16 @@ end |> !Core.Compiler.is_nothrow
10101010
@test Base.infer_effects() do
10111011
getglobal(@__MODULE__, :my_defined_var, :foo, nothing)
10121012
end |> !Core.Compiler.is_nothrow
1013+
1014+
# irinterp should refine `:nothrow` information only if profitable
1015+
Base.@assume_effects :nothrow function irinterp_nothrow_override(x, y)
1016+
z = sin(y)
1017+
if x
1018+
return "julia"
1019+
end
1020+
return z
1021+
end
1022+
@test Base.infer_effects((Float64,)) do y
1023+
isinf(y) && return zero(y)
1024+
irinterp_nothrow_override(true, y)
1025+
end |> Core.Compiler.is_nothrow

0 commit comments

Comments
 (0)