Skip to content

Commit 32aab4f

Browse files
mlechuc42f
andcommitted
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 (missing world age increments). Co-authored-by: Claire Foster <[email protected]>
1 parent 7194d9b commit 32aab4f

File tree

6 files changed

+42
-2
lines changed

6 files changed

+42
-2
lines changed

src/closure_conversion.jl

Lines changed: 2 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")
@@ -389,6 +388,7 @@ function _convert_closures(ctx::ClosureConversionCtx, ex)
389388
type_for_closure(ctx, ex, name_str, field_syms, field_is_box)
390389
if !ctx.is_toplevel_seq_point
391390
push!(ctx.toplevel_stmts, closure_type_def)
391+
push!(ctx.toplevel_stmts, @ast ctx ex [K"latestworld_if_toplevel"])
392392
closure_type_def = nothing
393393
end
394394
closure_info = ClosureInfo(closure_type_, field_syms, field_inds)
@@ -413,6 +413,7 @@ function _convert_closures(ctx::ClosureConversionCtx, ex)
413413
end
414414
@ast ctx ex [K"block"
415415
closure_type_def
416+
[K"latestworld_if_toplevel"]
416417
closure_type := if isempty(type_params)
417418
closure_type_
418419
else

src/desugaring.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ function expand_unionall_def(ctx, srcref, lhs, rhs, is_const=true)
11771177
K"block"
11781178
[K"=" rr [K"where" rhs lhs[2:end]...]]
11791179
[is_const ? K"constdecl" : K"assign_const_if_global" name rr]
1180+
[K"latestworld_if_toplevel"]
11801181
rr
11811182
]
11821183
)
@@ -1233,6 +1234,7 @@ function expand_assignment(ctx, ex, is_const=false)
12331234
K"block"
12341235
sink_assignment(ctx, ex, rr, expand_forms_2(ctx, rhs))
12351236
[K"constdecl" lhs rr]
1237+
[K"latestworld"]
12361238
[K"removable" rr]
12371239
]
12381240
else
@@ -1849,6 +1851,17 @@ function expand_call(ctx, ex)
18491851
expand_forms_2(ctx, farg)
18501852
expand_forms_2(ctx, _wrap_unsplatted_args(ctx, ex, args))...
18511853
]
1854+
elseif kind(farg) == K"Identifier" && farg.name_val == "include"
1855+
# world age special case
1856+
r = ssavar(ctx, ex)
1857+
@ast ctx ex [K"block"
1858+
[K"=" r [K"call"
1859+
expand_forms_2(ctx, farg)
1860+
expand_forms_2(ctx, args)...
1861+
]]
1862+
[K"latestworld_if_toplevel"]
1863+
r
1864+
]
18521865
else
18531866
@ast ctx ex [K"call"
18541867
expand_forms_2(ctx, farg)
@@ -2321,6 +2334,7 @@ function method_def_expr(ctx, srcref, callex_srcref, method_table,
23212334
ret_var # might be `nothing` and hence removed
23222335
]
23232336
]
2337+
[K"latestworld"]
23242338
[K"removable" method_metadata]
23252339
]
23262340
end
@@ -2449,10 +2463,12 @@ function expand_function_generator(ctx, srcref, callex_srcref, func_name, func_n
24492463
# Code generator definition
24502464
gen_func_method_defs = @ast ctx srcref [K"block"
24512465
[K"function_decl" gen_name]
2466+
[K"latestworld_if_toplevel"]
24522467
[K"scope_block"(scope_type=:hard)
24532468
[K"method_defs"
24542469
gen_name
24552470
[K"block"
2471+
[K"latestworld_if_toplevel"]
24562472
method_def_expr(ctx, srcref, callex_srcref, nothing, SyntaxList(ctx),
24572473
gen_arg_names, gen_arg_types, gen_body, nothing)
24582474
]
@@ -2786,6 +2802,7 @@ function keyword_function_defs(ctx, srcref, callex_srcref, name_str, typevar_nam
27862802

27872803
kw_func_method_defs = @ast ctx srcref [K"block"
27882804
[K"function_decl" body_func_name]
2805+
[K"latestworld"]
27892806
[K"scope_block"(scope_type=:hard)
27902807
[K"method_defs"
27912808
body_func_name
@@ -2855,6 +2872,7 @@ function expand_function_def(ctx, ex, docs, rewrite_call=identity, rewrite_body=
28552872
end
28562873
return @ast ctx ex [K"block"
28572874
[K"function_decl" name]
2875+
[K"latestworld"]
28582876
name
28592877
]
28602878
end
@@ -3091,6 +3109,7 @@ function expand_function_def(ctx, ex, docs, rewrite_call=identity, rewrite_body=
30913109
end
30923110
gen_func_method_defs
30933111
kw_func_method_defs
3112+
[K"latestworld_if_toplevel"]
30943113
[K"scope_block"(scope_type=:hard)
30953114
[K"method_defs"
30963115
isnothing(bare_func_name) ? "nothing"::K"core" : bare_func_name
@@ -3408,6 +3427,7 @@ function expand_abstract_or_primitive_type(ctx, ex)
34083427
nothing_(ctx, ex)
34093428
[K"constdecl" name newtype_var]
34103429
]
3430+
[K"latestworld"]
34113431
nothing_(ctx, ex)
34123432
]
34133433
end
@@ -3981,6 +4001,7 @@ function expand_struct_def(ctx, ex, docs)
39814001
global_struct_name
39824002
newtype_var
39834003
]
4004+
[K"latestworld"]
39844005
# Default constructors
39854006
if isempty(inner_defs)
39864007
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
@@ -313,6 +313,7 @@ function to_lowered_expr(mod, ex, ssa_offset=0)
313313
k == K"constdecl" ? :const :
314314
k == K"leave" ? :leave :
315315
k == K"isdefined" ? :isdefined :
316+
k == K"latestworld" ? :latestworld :
316317
k == K"globaldecl" ? :globaldecl :
317318
k == K"pop_exception" ? :pop_exception :
318319
k == K"captured_local" ? :captured_local :

src/kinds.jl

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

116118
# The following kinds are emitted by lowering and used in Julia's untyped IR
@@ -147,6 +149,8 @@ function _register_kinds()
147149
"new_opaque_closure"
148150
# Wrapper for the lambda of around opaque closure methods
149151
"opaque_closure_method"
152+
# World age increment
153+
"latestworld"
150154
"END_IR_KINDS"
151155
])
152156
end

src/linear_ir.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,19 @@ function compile(ctx::LinearIRContext, ex, needs_value, in_tail_pos)
819819
end
820820
elseif k == K"gc_preserve_begin"
821821
makenode(ctx, ex, k, compile_args(ctx, children(ex)))
822-
elseif k == K"gc_preserve_end" || k == K"global"
822+
elseif k == K"gc_preserve_end"
823823
if needs_value
824824
throw(LoweringError(ex, "misplaced kind $k in value position"))
825825
end
826826
emit(ctx, ex)
827827
nothing
828+
elseif k == K"global"
829+
if needs_value
830+
throw(LoweringError(ex, "misplaced kind $k in value position"))
831+
end
832+
emit(ctx, ex)
833+
ctx.is_toplevel_thunk && emit(ctx, makenode(ctx, ex, K"latestworld"))
834+
nothing
828835
elseif k == K"meta"
829836
emit(ctx, ex)
830837
if needs_value
@@ -881,6 +888,11 @@ function compile(ctx::LinearIRContext, ex, needs_value, in_tail_pos)
881888
emit(ctx, @ast ctx ex [K"=" rr ex[2]])
882889
emit(ctx, @ast ctx ex [K"globaldecl" ex[1] rr])
883890
end
891+
ctx.is_toplevel_thunk && emit(ctx, makenode(ctx, ex, K"latestworld"))
892+
elseif k == K"latestworld"
893+
emit(ctx, ex)
894+
elseif k == K"latestworld_if_toplevel"
895+
ctx.is_toplevel_thunk && emit(ctx, makeleaf(ctx, ex, K"latestworld"))
884896
else
885897
throw(LoweringError(ex, "Invalid syntax; $(repr(k))"))
886898
end

src/syntax_graph.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ function _value_string(ex)
431431
k == K"Symbol" ? ":$(ex.name_val)" :
432432
k == K"globalref" ? "$(ex.mod).$(ex.name_val)" :
433433
k == K"slot" ? "slot" :
434+
k == K"latestworld" ? "(latestworld)" :
434435
k == K"static_parameter" ? "static_parameter" :
435436
k == K"symbolic_label" ? "label:$(ex.name_val)" :
436437
k == K"symbolic_goto" ? "goto:$(ex.name_val)" :

0 commit comments

Comments
 (0)