Skip to content

Commit 8dec2f6

Browse files
committed
Add isdefinedglobal builtin
JuliaLang/julia#54999, JuliaLang/julia#56985
1 parent a60c0f3 commit 8dec2f6

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/closure_conversion.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,13 @@ function _convert_closures(ctx::ClosureConversionCtx, ex)
337337
elseif binfo.is_always_defined || is_self_captured(ctx, var)
338338
# Captured but unboxed vars are always defined
339339
@ast ctx ex true::K"Bool"
340+
elseif binfo.kind == :global
341+
# Normal isdefined won't work for globals (#56985)
342+
@ast ctx ex [K"call"
343+
"isdefinedglobal"::K"core"
344+
ctx.mod::K"Value"
345+
binfo.name::K"Symbol"
346+
false::K"Bool"]
340347
else
341348
ex
342349
end

src/desugaring.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,7 +3398,11 @@ function expand_abstract_or_primitive_type(ctx, ex)
33983398
[K"global" name]
33993399
[K"if"
34003400
[K"&&"
3401-
[K"isdefined" name]
3401+
[K"call"
3402+
"isdefinedglobal"::K"core"
3403+
ctx.mod::K"Value"
3404+
name=>K"Symbol"
3405+
false::K"Bool"]
34023406
[K"call" "_equiv_typedef"::K"core" name newtype_var]
34033407
]
34043408
nothing_(ctx, ex)
@@ -3927,7 +3931,10 @@ function expand_struct_def(ctx, ex, docs)
39273931
[K"=" struct_name newtype_var]
39283932
[K"call"(supertype) "_setsuper!"::K"core" newtype_var supertype]
39293933
[K"if"
3930-
[K"isdefined" global_struct_name]
3934+
[K"call" "isdefinedglobal"::K"core"
3935+
ctx.mod::K"Value"
3936+
struct_name=>K"Symbol"
3937+
false::K"Bool"]
39313938
[K"if"
39323939
[K"call" "_equiv_typedef"::K"core" global_struct_name newtype_var]
39333940
[K"block"

test/scopes_ir.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,6 @@ end
418418
#---------------------
419419
1 1
420420
2 (= slot₁/x %₁)
421-
3 (isdefined TestMod.y)
421+
3 (call core.isdefinedglobal TestMod :y false)
422422
4 (return %₃)
423423

0 commit comments

Comments
 (0)