Skip to content

Commit 5a0bda4

Browse files
committed
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 c61b27f commit 5a0bda4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,6 +2268,8 @@ end
22682268

22692269
function abstract_eval_special_value(interp::AbstractInterpreter, @nospecialize(e), vtypes::Union{VarTable,Nothing}, sv::AbsIntState)
22702270
if isa(e, QuoteNode)
2271+
merge_effects!(interp, sv, Effects(EFFECTS_TOTAL;
2272+
inaccessiblememonly = is_mutation_free_argtype(typeof(e.value)) ? ALWAYS_TRUE : ALWAYS_FALSE))
22712273
return Const(e.value)
22722274
elseif isa(e, SSAValue)
22732275
return abstract_eval_ssavalue(e, sv)

test/compiler/effects.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,3 +1023,19 @@ end
10231023
isinf(y) && return zero(y)
10241024
irinterp_nothrow_override(true, y)
10251025
end |> Core.Compiler.is_nothrow
1026+
1027+
# https://github.com/JuliaLang/julia/issues/52531
1028+
const a52531 = Core.Ref(1)
1029+
@eval getref52531() = $(QuoteNode(a52531)).x
1030+
@test !Core.Compiler.is_consistent(Base.infer_effects(getref52531))
1031+
let
1032+
global set_a52531!, get_a52531
1033+
_a::Int = -1
1034+
set_a52531!(a::Int) = (_a = a; return get_a52531())
1035+
get_a52531() = _a
1036+
end
1037+
@test !Core.Compiler.is_consistent(Base.infer_effects(set_a52531!, (Int,)))
1038+
@test !Core.Compiler.is_consistent(Base.infer_effects(get_a52531, ()))
1039+
@test get_a52531() == -1
1040+
@test set_a52531!(1) == 1
1041+
@test get_a52531() == 1

0 commit comments

Comments
 (0)