Skip to content

Commit 5282b45

Browse files
committed
Emit latestworld world age increments
For method defs, `latestworld` is produced in desugaring rather than closure conversion for now (our closure conversion doesn't seem to cover the same cases as lisp lowering yet). Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299. Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing min_world for global variable definitions) since the lowering changes from those appear to be amendments to the changes above.
1 parent 51f9124 commit 5282b45

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

src/closure_conversion.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ function _convert_closures(ctx::ClosureConversionCtx, ex)
355355
K"globaldecl"
356356
ex[1]
357357
_convert_closures(ctx, ex[2])
358-
# TODO (null)?
359358
]
360359
else
361360
makeleaf(ctx, ex, K"TOMBSTONE")

src/desugaring.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ function expand_unionall_def(ctx, srcref, lhs, rhs, is_const=true)
11881188
K"block"
11891189
[K"=" rr [K"where" rhs lhs[2:end]...]]
11901190
[is_const ? K"const" : K"assign_const_if_global" name rr]
1191+
[K"latestworld_if_toplevel"]
11911192
rr
11921193
]
11931194
)
@@ -1246,7 +1247,7 @@ function expand_assignment(ctx, ex, is_const=false)
12461247
K"block"
12471248
sink_assignment(ctx, ex, rr, expand_forms_2(ctx, rhs))
12481249
[K"const" lhs rr]
1249-
# todo latestworld
1250+
[K"latestworld"]
12501251
[K"removable" rr]
12511252
]
12521253
else
@@ -1863,6 +1864,17 @@ function expand_call(ctx, ex)
18631864
expand_forms_2(ctx, farg)
18641865
expand_forms_2(ctx, _wrap_unsplatted_args(ctx, ex, args))...
18651866
]
1867+
elseif kind(farg) == K"Identifier" && farg.name_val == "include"
1868+
# world age special case
1869+
r = ssavar(ctx, ex)
1870+
@ast ctx ex [K"block"
1871+
[K"=" r [K"call"
1872+
expand_forms_2(ctx, farg)
1873+
expand_forms_2(ctx, args)...
1874+
]]
1875+
[K"latestworld_if_toplevel"]
1876+
r
1877+
]
18661878
else
18671879
@ast ctx ex [K"call"
18681880
expand_forms_2(ctx, farg)
@@ -2332,6 +2344,7 @@ function method_def_expr(ctx, srcref, callex_srcref, method_table,
23322344
ret_var # might be `nothing` and hence removed
23332345
]
23342346
]
2347+
[K"latestworld"]
23352348
[K"removable" method_metadata]
23362349
]
23372350
end
@@ -2464,6 +2477,7 @@ function expand_function_generator(ctx, srcref, callex_srcref, func_name, func_n
24642477
[K"method_defs"
24652478
gen_name
24662479
[K"block"
2480+
[K"latestworld_if_toplevel"]
24672481
method_def_expr(ctx, srcref, callex_srcref, nothing, SyntaxList(ctx),
24682482
gen_arg_names, gen_arg_types, gen_body, nothing)
24692483
]
@@ -3102,6 +3116,7 @@ function expand_function_def(ctx, ex, docs, rewrite_call=identity, rewrite_body=
31023116
end
31033117
gen_func_method_defs
31043118
kw_func_method_defs
3119+
[K"latestworld_if_toplevel"]
31053120
[K"scope_block"(scope_type=:hard)
31063121
[K"method_defs"
31073122
isnothing(bare_func_name) ? "nothing"::K"core" : bare_func_name
@@ -3419,6 +3434,7 @@ function expand_abstract_or_primitive_type(ctx, ex)
34193434
nothing_(ctx, ex)
34203435
[K"const" name newtype_var]
34213436
]
3437+
[K"latestworld"]
34223438
nothing_(ctx, ex)
34233439
]
34243440
end
@@ -3972,6 +3988,7 @@ function expand_struct_def(ctx, ex, docs)
39723988
global_struct_name
39733989
newtype_var
39743990
]
3991+
[K"latestworld"]
39753992
# Default constructors
39763993
if isempty(inner_defs)
39773994
default_inner_constructors(ctx, ex, global_struct_name,

src/eval.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ function to_lowered_expr(mod, ex, ssa_offset=0)
302302
k == K"const" ? :const :
303303
k == K"leave" ? :leave :
304304
k == K"isdefined" ? :isdefined :
305+
k == K"latestworld" ? :latestworld :
305306
k == K"globaldecl" ? :globaldecl :
306307
k == K"pop_exception" ? :pop_exception :
307308
k == K"captured_local" ? :captured_local :

src/kinds.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ function _register_kinds()
109109
# A local variable captured into a global method. Contains the
110110
# `index` of the associated `Box` in the rewrite list.
111111
"captured_local"
112+
# Causes the linearization pass to conditionally emit a world age increment
113+
"latestworld_if_toplevel"
112114
"END_LOWERING_KINDS"
113115

114116
# The following kinds are emitted by lowering and used in Julia's untyped IR
@@ -142,6 +144,8 @@ function _register_kinds()
142144
"new_opaque_closure"
143145
# Wrapper for the lambda of around opaque closure methods
144146
"opaque_closure_method"
147+
# World age increment
148+
"latestworld"
145149
"END_IR_KINDS"
146150
])
147151
end

src/linear_ir.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,7 @@ function compile(ctx::LinearIRContext, ex, needs_value, in_tail_pos)
651651
elseif k == K"=" || k == K"const"
652652
if k == K"const"
653653
check_no_local_bindings(ctx, ex[1], "unsupported `const` declaration on local variable")
654-
# if !at_top_level(ctx)
655-
# TODO: How do we determine this?
656-
# Lisp does this by checking that the current lambda takes no arguments
657-
# throw(LoweringError(ex, "`global const` declaration not allowed inside function"))
658-
# end
654+
# other errors (probably this one too) should be handled in previous passes
659655
end
660656
lhs = ex[1]
661657
if kind(lhs) == K"Placeholder"
@@ -827,12 +823,19 @@ function compile(ctx::LinearIRContext, ex, needs_value, in_tail_pos)
827823
end
828824
elseif k == K"gc_preserve_begin"
829825
makenode(ctx, ex, k, compile_args(ctx, children(ex)))
830-
elseif k == K"gc_preserve_end" || k == K"global"
826+
elseif k == K"gc_preserve_end"
831827
if needs_value
832828
throw(LoweringError(ex, "misplaced kind $k in value position"))
833829
end
834830
emit(ctx, ex)
835831
nothing
832+
elseif k == K"global"
833+
if needs_value
834+
throw(LoweringError(ex, "misplaced kind $k in value position"))
835+
end
836+
emit(ctx, ex)
837+
ctx.is_toplevel_thunk && emit(ctx, makenode(ctx, ex, K"latestworld"))
838+
nothing
836839
elseif k == K"meta"
837840
emit(ctx, ex)
838841
if needs_value
@@ -889,6 +892,11 @@ function compile(ctx::LinearIRContext, ex, needs_value, in_tail_pos)
889892
emit(ctx, @ast ctx ex [K"=" rr ex[2]])
890893
emit(ctx, @ast ctx ex [K"globaldecl" ex[1] rr])
891894
end
895+
ctx.is_toplevel_thunk && emit(ctx, makenode(ctx, ex, K"latestworld"))
896+
elseif k == K"latestworld"
897+
emit(ctx, makeleaf(ctx, ex, K"latestworld"))
898+
elseif k == K"latestworld_if_toplevel"
899+
ctx.is_toplevel_thunk && emit(ctx, makeleaf(ctx, ex, K"latestworld"))
892900
else
893901
throw(LoweringError(ex, "Invalid syntax; $(repr(k))"))
894902
end

0 commit comments

Comments
 (0)