From 1eb876c482e03243841331e49320266ea5d14923 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 20 Dec 2023 16:01:50 -0500 Subject: [PATCH 1/3] Lowering: Insert QuoteNode for captured boxed value --- src/julia-syntax.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index e7899688453c7..4f91c6fc5b023 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -3586,7 +3586,7 @@ f(x) = yt(x) (rhs (convert-for-type-decl rhs1 (cl-convert vt fname lam #f #f #f interp opaq (table) locals) #t lam)) (ex (cond (closed `(call (core setfield!) ,(if interp - `($ ,var) + `($ (call (core QuoteNode) ,var)) (capt-var-access var fname opaq)) (inert contents) ,rhs)) From 07ab2f0fe21bc57ac4c088e4a0aae6c29afe217c Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Wed, 20 Dec 2023 23:33:45 -0300 Subject: [PATCH 2/3] Add tests --- test/compiler/effects.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/compiler/effects.jl b/test/compiler/effects.jl index 0c95ca0a29aab..5f3594840fc46 100644 --- a/test/compiler/effects.jl +++ b/test/compiler/effects.jl @@ -1357,9 +1357,24 @@ end @test set_a52531!(1) == 1 @test get_a52531() == 1 +let + global is_initialized52531, set_initialized52531 + _is_initialized = false + set_initialized52531(flag::Bool) = (_is_initialized = flag) + is_initialized52531() = _is_initialized +end +@test !is_initialized52531() +@test set_initialized52531(true) +@test is_initialized52531() +@test !set_initialized52531(false) +@test !is_initialized52531() +foo52531(4) +@test is_initialized52531() + @test Core.Compiler.is_inaccessiblememonly(Base.infer_effects(identity∘identity, Tuple{Any})) @test Core.Compiler.is_inaccessiblememonly(Base.infer_effects(()->Vararg, Tuple{})) # pointerref nothrow for invalid pointer @test !Core.Compiler.intrinsic_nothrow(Core.Intrinsics.pointerref, Any[Type{Ptr{Vector{Int64}}}, Int, Int]) @test !Core.Compiler.intrinsic_nothrow(Core.Intrinsics.pointerref, Any[Type{Ptr{T}} where T, Int, Int]) +foo52531(x) = (set_initialized52531(true); nothing) From 4f950667e72bf1a685ffc1045268f853e37147be Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 21 Dec 2023 06:03:58 +0100 Subject: [PATCH 3/3] Update test/compiler/effects.jl Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> --- test/compiler/effects.jl | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/test/compiler/effects.jl b/test/compiler/effects.jl index 5f3594840fc46..2c303f5335633 100644 --- a/test/compiler/effects.jl +++ b/test/compiler/effects.jl @@ -1347,9 +1347,9 @@ const a52531 = Core.Ref(1) @test !Core.Compiler.is_consistent(Base.infer_effects(getref52531)) let global set_a52531!, get_a52531 - _a::Int = -1 + _a::Int = -1 set_a52531!(a::Int) = (_a = a; return get_a52531()) - get_a52531() = _a + 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, ())) @@ -1358,17 +1358,16 @@ end @test get_a52531() == 1 let - global is_initialized52531, set_initialized52531 - _is_initialized = false - set_initialized52531(flag::Bool) = (_is_initialized = flag) - is_initialized52531() = _is_initialized -end -@test !is_initialized52531() -@test set_initialized52531(true) -@test is_initialized52531() -@test !set_initialized52531(false) + global is_initialized52531, set_initialized52531! + _is_initialized = false + set_initialized52531!(flag::Bool) = (_is_initialized = flag) + is_initialized52531() = _is_initialized +end +top_52531(_) = (set_initialized52531!(true); nothing) +@test !Core.Compiler.is_consistent(Base.infer_effects(is_initialized52531)) +@test !Core.Compiler.is_removable_if_unused(Base.infer_effects(set_initialized52531!, (Bool,))) @test !is_initialized52531() -foo52531(4) +top_52531(0) @test is_initialized52531() @test Core.Compiler.is_inaccessiblememonly(Base.infer_effects(identity∘identity, Tuple{Any})) @@ -1377,4 +1376,3 @@ foo52531(4) # pointerref nothrow for invalid pointer @test !Core.Compiler.intrinsic_nothrow(Core.Intrinsics.pointerref, Any[Type{Ptr{Vector{Int64}}}, Int, Int]) @test !Core.Compiler.intrinsic_nothrow(Core.Intrinsics.pointerref, Any[Type{Ptr{T}} where T, Int, Int]) -foo52531(x) = (set_initialized52531(true); nothing)