Skip to content

Commit 99b8a2c

Browse files
committed
effects: improve idempotency of effects derived by post-opt analysis
Since now effects can be refined by post-opt analysis, `typeinf_edge` should propagate `frame.result.ipo_effects` instead of `frame.ipo_effects`.
1 parent d4c3891 commit 99b8a2c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

base/compiler/typeinfer.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ function finish(me::InferenceState, interp::AbstractInterpreter)
537537
end
538538
me.result.valid_worlds = me.valid_worlds
539539
me.result.result = bestguess
540-
me.ipo_effects = me.result.ipo_effects = adjust_effects(me)
540+
me.result.ipo_effects = me.ipo_effects = adjust_effects(me)
541541

542542
if limited_ret
543543
# a parent may be cached still, but not this intermediate work:
@@ -856,7 +856,7 @@ function typeinf_edge(interp::AbstractInterpreter, method::Method, @nospecialize
856856
update_valid_age!(caller, frame.valid_worlds)
857857
isinferred = is_inferred(frame)
858858
edge = isinferred ? mi : nothing
859-
effects = isinferred ? frame.ipo_effects : adjust_effects(Effects(), method) # effects are adjusted already within `finish` for ipo_effects
859+
effects = isinferred ? frame.result.ipo_effects : adjust_effects(Effects(), method) # effects are adjusted already within `finish` for ipo_effects
860860
# propagate newly inferred source to the inliner, allowing efficient inlining w/o deserialization:
861861
# note that this result is cached globally exclusively, we can use this local result destructively
862862
volatile_inf_result = isinferred && let inferred_src = result.src

test/compiler/effects.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,3 +1158,17 @@ end
11581158
issue51837(; openquotechar, newlinechar)
11591159
end |> !Core.Compiler.is_nothrow
11601160
@test_throws ArgumentError issue51837(; openquotechar='α', newlinechar='\n')
1161+
1162+
# idempotency of effects derived by post-opt analysis
1163+
callgetfield(x, f) = getfield(x, f, Base.@_boundscheck)
1164+
@test Base.infer_effects(callgetfield, (Some{Any},Symbol)).noub === Core.Compiler.NOUB_IF_NOINBOUNDS
1165+
callgetfield1(x, f) = getfield(x, f, Base.@_boundscheck)
1166+
callgetfield_simple(x, f) = callgetfield1(x, f)
1167+
@test Base.infer_effects(callgetfield_simple, (Some{Any},Symbol)).noub ===
1168+
Base.infer_effects(callgetfield_simple, (Some{Any},Symbol)).noub ===
1169+
Core.Compiler.ALWAYS_TRUE
1170+
callgetfield2(x, f) = getfield(x, f, Base.@_boundscheck)
1171+
callgetfield_inbounds(x, f) = @inbounds callgetfield2(x, f)
1172+
@test Base.infer_effects(callgetfield_inbounds, (Some{Any},Symbol)).noub ===
1173+
Base.infer_effects(callgetfield_inbounds, (Some{Any},Symbol)).noub ===
1174+
Core.Compiler.ALWAYS_FALSE

0 commit comments

Comments
 (0)