From e207c106ba7eaffcb521140baccc7795664a4d53 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Sat, 16 Dec 2023 05:29:26 +0900 Subject: [PATCH] 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 --- base/compiler/abstractinterpretation.jl | 4 +++- test/compiler/effects.jl | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 0541aa9e64278..bae7bad238318 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -2306,7 +2306,9 @@ end function abstract_eval_special_value(interp::AbstractInterpreter, @nospecialize(e), vtypes::Union{VarTable,Nothing}, sv::AbsIntState) if isa(e, QuoteNode) - return RTEffects(Const(e.value), Union{}, EFFECTS_TOTAL) + 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) return RTEffects(abstract_eval_ssavalue(e, sv), Union{}, EFFECTS_TOTAL) elseif isa(e, SlotNumber) diff --git a/test/compiler/effects.jl b/test/compiler/effects.jl index 9df29a19c5e28..2160a716af689 100644 --- a/test/compiler/effects.jl +++ b/test/compiler/effects.jl @@ -1340,3 +1340,19 @@ end end return res end |> Core.Compiler.is_terminates + +# https://github.com/JuliaLang/julia/issues/52531 +const a52531 = Core.Ref(1) +@eval getref52531() = $(QuoteNode(a52531)).x +@test !Core.Compiler.is_consistent(Base.infer_effects(getref52531)) +let + global set_a52531!, get_a52531 + _a::Int = -1 + set_a52531!(a::Int) = (_a = a; return get_a52531()) + get_a52531() = _a +end +@test !Core.Compiler.is_consistent(Base.infer_effects(set_a52531!, (Int,))) +@test !Core.Compiler.is_consistent(Base.infer_effects(get_a52531, ())) +@test get_a52531() == -1 +@test set_a52531!(1) == 1 +@test get_a52531() == 1