Skip to content

Commit

Permalink
irinterp: refine :nothrow only when it is not proved yet
Browse files Browse the repository at this point in the history
This makes irinterp not override `:nothrow=true` that are assumed by
`Base.@assume_effects`.
  • Loading branch information
aviatesk committed Aug 3, 2023
1 parent cbc72d5 commit e3ae49a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,11 @@ function semi_concrete_eval_call(interp::AbstractInterpreter,
# that are newly resovled by irinterp
# state = InliningState(interp)
# ir = ssa_inlining_pass!(irsv.ir, state, propagate_inbounds(irsv))
new_effects = Effects(result.effects; nothrow)
return ConstCallResults(rt, SemiConcreteResult(mi, ir, new_effects), new_effects, mi)
effects = result.effects
if !is_nothrow(effects)
effects = Effects(effects; nothrow)
end
return ConstCallResults(rt, SemiConcreteResult(mi, ir, effects), effects, mi)
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions test/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1010,3 +1010,16 @@ end |> !Core.Compiler.is_nothrow
@test Base.infer_effects() do
getglobal(@__MODULE__, :my_defined_var, :foo, nothing)
end |> !Core.Compiler.is_nothrow

# irinterp should refine `:nothrow` information only if profitable
Base.@assume_effects :nothrow function irinterp_nothrow_override(x, y)
z = sin(y)
if x
return "julia"
end
return z
end
@test Base.infer_effects((Float64,)) do y
isinf(y) && return zero(y)
irinterp_nothrow_override(true, y)
end |> Core.Compiler.is_nothrow

0 comments on commit e3ae49a

Please sign in to comment.