Skip to content

Commit

Permalink
effects: improve idempotency of effects derived by post-opt analysis
Browse files Browse the repository at this point in the history
Since now effects can be refined by post-opt analysis, `typeinf_edge`
should propagate `frame.result.ipo_effects` instead of
`frame.ipo_effects`.
  • Loading branch information
aviatesk committed Nov 9, 2023
1 parent 81ef12a commit 358540c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ function finish(me::InferenceState, interp::AbstractInterpreter)
end
me.result.valid_worlds = me.valid_worlds
me.result.result = bestguess
me.ipo_effects = me.result.ipo_effects = adjust_effects(me)
me.result.ipo_effects = me.ipo_effects = adjust_effects(me)

if limited_ret
# a parent may be cached still, but not this intermediate work:
Expand Down Expand Up @@ -856,7 +856,7 @@ function typeinf_edge(interp::AbstractInterpreter, method::Method, @nospecialize
update_valid_age!(caller, frame.valid_worlds)
isinferred = is_inferred(frame)
edge = isinferred ? mi : nothing
effects = isinferred ? frame.ipo_effects : adjust_effects(Effects(), method) # effects are adjusted already within `finish` for ipo_effects
effects = isinferred ? frame.result.ipo_effects : adjust_effects(Effects(), method) # effects are adjusted already within `finish` for ipo_effects
# propagate newly inferred source to the inliner, allowing efficient inlining w/o deserialization:
# note that this result is cached globally exclusively, we can use this local result destructively
volatile_inf_result = isinferred && let inferred_src = result.src
Expand Down
14 changes: 14 additions & 0 deletions test/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1158,3 +1158,17 @@ end
issue51837(; openquotechar, newlinechar)
end |> !Core.Compiler.is_nothrow
@test_throws ArgumentError issue51837(; openquotechar='α', newlinechar='\n')

# idempotency of effects derived by post-opt analysis
callgetfield(x, f) = getfield(x, f, Base.@_boundscheck)
@test Base.infer_effects(callgetfield, (Some{Any},Symbol)).noub === Core.Compiler.NOUB_IF_NOINBOUNDS
callgetfield1(x, f) = getfield(x, f, Base.@_boundscheck)
callgetfield_simple(x, f) = callgetfield1(x, f)
@test Base.infer_effects(callgetfield_simple, (Some{Any},Symbol)).noub ===
Base.infer_effects(callgetfield_simple, (Some{Any},Symbol)).noub ===
Core.Compiler.ALWAYS_TRUE
callgetfield2(x, f) = getfield(x, f, Base.@_boundscheck)
callgetfield_inbounds(x, f) = @inbounds callgetfield2(x, f)
@test Base.infer_effects(callgetfield_inbounds, (Some{Any},Symbol)).noub ===
Base.infer_effects(callgetfield_inbounds, (Some{Any},Symbol)).noub ===
Core.Compiler.ALWAYS_FALSE

0 comments on commit 358540c

Please sign in to comment.