Skip to content

Commit 1f3c424

Browse files
vchuravygbaraldiaviatesk
authored andcommitted
Lowering: Insert QuoteNode for captured boxed value (#52596)
`Core.Box` is not self-quoting so it should be captured in a QuoteNode. This has been benign until the improved effect system, we handle `QuoteNode` of a mutable value as a global access, whereas a direct reference to a value is treated as inaccessible memory. Fixes #52531 --------- Co-authored-by: Gabriel Baraldi <[email protected]> Co-authored-by: Shuhei Kadowaki <[email protected]> (cherry picked from commit 1290b51)
1 parent 24b525d commit 1f3c424

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/julia-syntax.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3580,7 +3580,7 @@ f(x) = yt(x)
35803580
(rhs (convert-for-type-decl rhs1 (cl-convert vt fname lam #f #f #f interp opaq (table) locals) #t lam))
35813581
(ex (cond (closed `(call (core setfield!)
35823582
,(if interp
3583-
`($ ,var)
3583+
`($ (call (core QuoteNode) ,var))
35843584
(capt-var-access var fname opaq))
35853585
(inert contents)
35863586
,rhs))

test/compiler/effects.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,12 +1030,25 @@ const a52531 = Core.Ref(1)
10301030
@test !Core.Compiler.is_consistent(Base.infer_effects(getref52531))
10311031
let
10321032
global set_a52531!, get_a52531
1033-
_a::Int = -1
1033+
_a::Int = -1
10341034
set_a52531!(a::Int) = (_a = a; return get_a52531())
1035-
get_a52531() = _a
1035+
get_a52531() = _a
10361036
end
10371037
@test !Core.Compiler.is_consistent(Base.infer_effects(set_a52531!, (Int,)))
10381038
@test !Core.Compiler.is_consistent(Base.infer_effects(get_a52531, ()))
10391039
@test get_a52531() == -1
10401040
@test set_a52531!(1) == 1
10411041
@test get_a52531() == 1
1042+
1043+
let
1044+
global is_initialized52531, set_initialized52531!
1045+
_is_initialized = false
1046+
set_initialized52531!(flag::Bool) = (_is_initialized = flag)
1047+
is_initialized52531() = _is_initialized
1048+
end
1049+
top_52531(_) = (set_initialized52531!(true); nothing)
1050+
@test !Core.Compiler.is_consistent(Base.infer_effects(is_initialized52531))
1051+
@test !Core.Compiler.is_removable_if_unused(Base.infer_effects(set_initialized52531!, (Bool,)))
1052+
@test !is_initialized52531()
1053+
top_52531(0)
1054+
@test is_initialized52531()

0 commit comments

Comments
 (0)