Skip to content

Commit 7878843

Browse files
committed
irinterp: refine :nothrow only when it is not proved yet
This makes irinterp not override `:nothrow=true` that are assumed by `Base.@assume_effects`.
1 parent 3eddd17 commit 7878843

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

base/compiler/abstractinterpretation.jl

+5-2
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

+13
Original file line numberDiff line numberDiff line change
@@ -998,3 +998,16 @@ f50198() = (hf50198(Ref(:x)[]); nothing)
998998
f50311(x, s) = Symbol(s)
999999
g50311(x) = Val{f50311((1.0, x), "foo")}()
10001000
@test fully_eliminated(g50311, Tuple{Float64})
1001+
1002+
# irinterp should refine `:nothrow` information only if profitable
1003+
Base.@assume_effects :nothrow function irinterp_nothrow_override(x, y)
1004+
z = sin(y)
1005+
if x
1006+
return "julia"
1007+
end
1008+
return z
1009+
end
1010+
@test Base.infer_effects((Float64,)) do y
1011+
isinf(y) && return zero(y)
1012+
irinterp_nothrow_override(true, y)
1013+
end |> Core.Compiler.is_nothrow

0 commit comments

Comments
 (0)