Skip to content

Commit e207c10

Browse files
authored
fix #52531, fix the effects modeling of QuoteNode (#52548)
What observed in #52531 is that `QuoteNode` can embed global variables that users can modify. Therefore, when dealing with `QuoteNode`, it's necessary to taint its `:inaccessiblememonly` just like we do for `GlobalRef`. - fixes #52531 - replaces #52536
1 parent e8576fc commit e207c10

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,9 @@ end
23062306

23072307
function abstract_eval_special_value(interp::AbstractInterpreter, @nospecialize(e), vtypes::Union{VarTable,Nothing}, sv::AbsIntState)
23082308
if isa(e, QuoteNode)
2309-
return RTEffects(Const(e.value), Union{}, EFFECTS_TOTAL)
2309+
effects = Effects(EFFECTS_TOTAL;
2310+
inaccessiblememonly = is_mutation_free_argtype(typeof(e.value)) ? ALWAYS_TRUE : ALWAYS_FALSE)
2311+
return RTEffects(Const(e.value), Union{}, effects)
23102312
elseif isa(e, SSAValue)
23112313
return RTEffects(abstract_eval_ssavalue(e, sv), Union{}, EFFECTS_TOTAL)
23122314
elseif isa(e, SlotNumber)

test/compiler/effects.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,3 +1340,19 @@ end
13401340
end
13411341
return res
13421342
end |> Core.Compiler.is_terminates
1343+
1344+
# https://github.com/JuliaLang/julia/issues/52531
1345+
const a52531 = Core.Ref(1)
1346+
@eval getref52531() = $(QuoteNode(a52531)).x
1347+
@test !Core.Compiler.is_consistent(Base.infer_effects(getref52531))
1348+
let
1349+
global set_a52531!, get_a52531
1350+
_a::Int = -1
1351+
set_a52531!(a::Int) = (_a = a; return get_a52531())
1352+
get_a52531() = _a
1353+
end
1354+
@test !Core.Compiler.is_consistent(Base.infer_effects(set_a52531!, (Int,)))
1355+
@test !Core.Compiler.is_consistent(Base.infer_effects(get_a52531, ()))
1356+
@test get_a52531() == -1
1357+
@test set_a52531!(1) == 1
1358+
@test get_a52531() == 1

0 commit comments

Comments
 (0)