Skip to content

Commit 7f0aa0e

Browse files
mlechuaviatesk
authored andcommitted
Add isdefinedglobal builtin
JuliaLang/julia#54999, JuliaLang/julia#56985
1 parent 1661546 commit 7f0aa0e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
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 kind(var) == K"globalref"
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
@@ -3409,7 +3409,11 @@ function expand_abstract_or_primitive_type(ctx, ex)
34093409
[K"global" name]
34103410
[K"if"
34113411
[K"&&"
3412-
[K"isdefined" name]
3412+
[K"call"
3413+
"isdefinedglobal"::K"core"
3414+
ctx.mod::K"Value"
3415+
name=>K"Symbol"
3416+
false::K"Bool"]
34133417
[K"call" "_equiv_typedef"::K"core" name newtype_var]
34143418
]
34153419
nothing_(ctx, ex)
@@ -3936,7 +3940,10 @@ function expand_struct_def(ctx, ex, docs)
39363940
[K"=" struct_name newtype_var]
39373941
[K"call"(supertype) "_setsuper!"::K"core" newtype_var supertype]
39383942
[K"if"
3939-
[K"isdefined" global_struct_name]
3943+
[K"call" "isdefinedglobal"::K"core"
3944+
ctx.mod::K"Value"
3945+
struct_name=>K"Symbol"
3946+
false::K"Bool"]
39403947
[K"if"
39413948
[K"call" "_equiv_typedef"::K"core" global_struct_name newtype_var]
39423949
[K"block"

0 commit comments

Comments
 (0)