Skip to content

Commit

Permalink
effects: fix #52843, account for mutable values directly embedded to IR
Browse files Browse the repository at this point in the history
Fixes another variant of #52531.
  • Loading branch information
aviatesk committed Jan 11, 2024
1 parent 73cdfd8 commit 3dcc07c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 7 additions & 7 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2310,11 +2310,7 @@ function abstract_eval_cfunction(interp::AbstractInterpreter, e::Expr, vtypes::U
end

function abstract_eval_special_value(interp::AbstractInterpreter, @nospecialize(e), vtypes::Union{VarTable,Nothing}, sv::AbsIntState)
if isa(e, QuoteNode)
effects = Effects(EFFECTS_TOTAL;
inaccessiblememonly = is_mutation_free_argtype(typeof(e.value)) ? ALWAYS_TRUE : ALWAYS_FALSE)
return RTEffects(Const(e.value), Union{}, effects)
elseif isa(e, SSAValue)
if isa(e, SSAValue)
return RTEffects(abstract_eval_ssavalue(e, sv), Union{}, EFFECTS_TOTAL)
elseif isa(e, SlotNumber)
if vtypes !== nothing
Expand All @@ -2335,8 +2331,12 @@ function abstract_eval_special_value(interp::AbstractInterpreter, @nospecialize(
elseif isa(e, GlobalRef)
return abstract_eval_globalref(interp, e, sv)
end

return RTEffects(Const(e), Union{}, EFFECTS_TOTAL)
if isa(e, QuoteNode)
e = e.value
end
effects = Effects(EFFECTS_TOTAL;
inaccessiblememonly = is_mutation_free_argtype(typeof(e)) ? ALWAYS_TRUE : ALWAYS_FALSE)
return RTEffects(Const(e), Union{}, effects)
end

function abstract_eval_value_expr(interp::AbstractInterpreter, e::Expr, sv::AbsIntState)
Expand Down
6 changes: 6 additions & 0 deletions test/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,12 @@ top_52531(_) = (set_initialized52531!(true); nothing)
top_52531(0)
@test is_initialized52531()

const ref52843 = Ref{Int}()
@eval func52843() = ($ref52843[] = 1; nothing)
@test !Core.Compiler.is_foldable(Base.infer_effects(func52843))
let; Base.Experimental.@force_compile; func52843(); end
@test ref52843[] == 1

@test Core.Compiler.is_inaccessiblememonly(Base.infer_effects(identityidentity, Tuple{Any}))
@test Core.Compiler.is_inaccessiblememonly(Base.infer_effects(()->Vararg, Tuple{}))

Expand Down

0 comments on commit 3dcc07c

Please sign in to comment.