From 47f0d6155d08fc9bc876fb59d7d32d44c896c9f9 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Mon, 11 Nov 2024 01:34:03 +0000 Subject: [PATCH 1/2] Add lowering and interpreter support for `:worldinc` Split out from #56509 to facilitate adjusting downstream packages. --- base/boot.jl | 2 ++ src/ast.c | 2 ++ src/interpreter.c | 3 +++ src/julia-syntax.scm | 8 +++++++- src/julia_internal.h | 1 + src/toplevel.c | 3 ++- 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/base/boot.jl b/base/boot.jl index 88a4e7438671e..63cc1e39b3a59 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -271,6 +271,8 @@ macro nospecialize(x) end Expr(@nospecialize args...) = _expr(args...) +macro worldinc() Expr(:worldinc) end + _is_internal(__module__) = __module__ === Core # can be used in place of `@assume_effects :total` (supposed to be used for bootstrapping) macro _total_meta() diff --git a/src/ast.c b/src/ast.c index ea1de429a946c..51dc6d4680c8c 100644 --- a/src/ast.c +++ b/src/ast.c @@ -119,6 +119,7 @@ JL_DLLEXPORT jl_sym_t *jl_release_sym; JL_DLLEXPORT jl_sym_t *jl_acquire_release_sym; JL_DLLEXPORT jl_sym_t *jl_sequentially_consistent_sym; JL_DLLEXPORT jl_sym_t *jl_uninferred_sym; +JL_DLLEXPORT jl_sym_t *jl_worldinc_sym; static const uint8_t flisp_system_image[] = { #include @@ -461,6 +462,7 @@ void jl_init_common_symbols(void) jl_acquire_release_sym = jl_symbol("acquire_release"); jl_sequentially_consistent_sym = jl_symbol("sequentially_consistent"); jl_uninferred_sym = jl_symbol("uninferred"); + jl_worldinc_sym = jl_symbol("worldinc"); } JL_DLLEXPORT void jl_lisp_prompt(void) diff --git a/src/interpreter.c b/src/interpreter.c index f9d981687c631..d79cd3f14fc20 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -643,6 +643,9 @@ static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip, jl_eval_const_decl(s->module, jl_exprarg(stmt, 0), val); s->locals[jl_source_nslots(s->src) + s->ip] = jl_nothing; } + else if (head == jl_worldinc_sym) { + ct->world_age = jl_atomic_load_acquire(&jl_world_counter); + } else if (jl_is_toplevel_only_expr(stmt)) { jl_toplevel_eval(s->module, stmt); } diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 7acc8a1954bc5..20a3dec75dc11 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -4512,6 +4512,7 @@ f(x) = yt(x) ((struct_type) "\"struct\" expression") ((method) "method definition") ((set_binding_type!) (string "type declaration for global \"" (deparse (cadr e)) "\"")) + ((worldinc) "World age increment") (else (string "\"" h "\" expression")))) (if (not (null? (cadr lam))) (error (string (head-to-text (car e)) " not at top level")))) @@ -4979,8 +4980,13 @@ f(x) = yt(x) (if tail (emit-return tail val)) val)) + ((worldinc-if-toplevel) + (if (null? (cadr lam)) + (emit `(worldinc))) + '(null)) + ;; other top level expressions - ((import using export public) + ((import using export public worldinc) (check-top-level e) (emit e) (let ((have-ret? (and (pair? code) (pair? (car code)) (eq? (caar code) 'return)))) diff --git a/src/julia_internal.h b/src/julia_internal.h index 776fea3b1dbf1..d19ce65e6dfb8 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -1856,6 +1856,7 @@ extern JL_DLLEXPORT jl_sym_t *jl_release_sym; extern JL_DLLEXPORT jl_sym_t *jl_acquire_release_sym; extern JL_DLLEXPORT jl_sym_t *jl_sequentially_consistent_sym; extern JL_DLLEXPORT jl_sym_t *jl_uninferred_sym; +extern JL_DLLEXPORT jl_sym_t *jl_worldinc_sym; JL_DLLEXPORT enum jl_memory_order jl_get_atomic_order(jl_sym_t *order, char loading, char storing); JL_DLLEXPORT enum jl_memory_order jl_get_atomic_order_checked(jl_sym_t *order, char loading, char storing); diff --git a/src/toplevel.c b/src/toplevel.c index b0163683cf87c..4a0c021940e77 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -607,7 +607,8 @@ int jl_is_toplevel_only_expr(jl_value_t *e) JL_NOTSAFEPOINT ((jl_expr_t*)e)->head == jl_const_sym || ((jl_expr_t*)e)->head == jl_toplevel_sym || ((jl_expr_t*)e)->head == jl_error_sym || - ((jl_expr_t*)e)->head == jl_incomplete_sym); + ((jl_expr_t*)e)->head == jl_incomplete_sym || + ((jl_expr_t*)e)->head == jl_worldinc_sym); } int jl_needs_lowering(jl_value_t *e) JL_NOTSAFEPOINT From 1b5b99905f425bb1021f0538b942af76814e0df3 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Tue, 12 Nov 2024 17:05:49 +0000 Subject: [PATCH 2/2] worldinc -> latestworld --- base/boot.jl | 2 +- src/ast.c | 4 ++-- src/interpreter.c | 2 +- src/julia-syntax.scm | 8 ++++---- src/julia_internal.h | 2 +- src/toplevel.c | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/base/boot.jl b/base/boot.jl index 63cc1e39b3a59..0df0cde64f8c0 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -271,7 +271,7 @@ macro nospecialize(x) end Expr(@nospecialize args...) = _expr(args...) -macro worldinc() Expr(:worldinc) end +macro latestworld() Expr(:latestworld) end _is_internal(__module__) = __module__ === Core # can be used in place of `@assume_effects :total` (supposed to be used for bootstrapping) diff --git a/src/ast.c b/src/ast.c index 51dc6d4680c8c..474c0661f5230 100644 --- a/src/ast.c +++ b/src/ast.c @@ -119,7 +119,7 @@ JL_DLLEXPORT jl_sym_t *jl_release_sym; JL_DLLEXPORT jl_sym_t *jl_acquire_release_sym; JL_DLLEXPORT jl_sym_t *jl_sequentially_consistent_sym; JL_DLLEXPORT jl_sym_t *jl_uninferred_sym; -JL_DLLEXPORT jl_sym_t *jl_worldinc_sym; +JL_DLLEXPORT jl_sym_t *jl_latestworld_sym; static const uint8_t flisp_system_image[] = { #include @@ -462,7 +462,7 @@ void jl_init_common_symbols(void) jl_acquire_release_sym = jl_symbol("acquire_release"); jl_sequentially_consistent_sym = jl_symbol("sequentially_consistent"); jl_uninferred_sym = jl_symbol("uninferred"); - jl_worldinc_sym = jl_symbol("worldinc"); + jl_latestworld_sym = jl_symbol("latestworld"); } JL_DLLEXPORT void jl_lisp_prompt(void) diff --git a/src/interpreter.c b/src/interpreter.c index d79cd3f14fc20..13dc45cf2ae6e 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -643,7 +643,7 @@ static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip, jl_eval_const_decl(s->module, jl_exprarg(stmt, 0), val); s->locals[jl_source_nslots(s->src) + s->ip] = jl_nothing; } - else if (head == jl_worldinc_sym) { + else if (head == jl_latestworld_sym) { ct->world_age = jl_atomic_load_acquire(&jl_world_counter); } else if (jl_is_toplevel_only_expr(stmt)) { diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 20a3dec75dc11..e82c436e5a730 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -4512,7 +4512,7 @@ f(x) = yt(x) ((struct_type) "\"struct\" expression") ((method) "method definition") ((set_binding_type!) (string "type declaration for global \"" (deparse (cadr e)) "\"")) - ((worldinc) "World age increment") + ((latestworld) "World age increment") (else (string "\"" h "\" expression")))) (if (not (null? (cadr lam))) (error (string (head-to-text (car e)) " not at top level")))) @@ -4980,13 +4980,13 @@ f(x) = yt(x) (if tail (emit-return tail val)) val)) - ((worldinc-if-toplevel) + ((latestworld-if-toplevel) (if (null? (cadr lam)) - (emit `(worldinc))) + (emit `(latestworld))) '(null)) ;; other top level expressions - ((import using export public worldinc) + ((import using export public latestworld) (check-top-level e) (emit e) (let ((have-ret? (and (pair? code) (pair? (car code)) (eq? (caar code) 'return)))) diff --git a/src/julia_internal.h b/src/julia_internal.h index d19ce65e6dfb8..db09477de287b 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -1856,7 +1856,7 @@ extern JL_DLLEXPORT jl_sym_t *jl_release_sym; extern JL_DLLEXPORT jl_sym_t *jl_acquire_release_sym; extern JL_DLLEXPORT jl_sym_t *jl_sequentially_consistent_sym; extern JL_DLLEXPORT jl_sym_t *jl_uninferred_sym; -extern JL_DLLEXPORT jl_sym_t *jl_worldinc_sym; +extern JL_DLLEXPORT jl_sym_t *jl_latestworld_sym; JL_DLLEXPORT enum jl_memory_order jl_get_atomic_order(jl_sym_t *order, char loading, char storing); JL_DLLEXPORT enum jl_memory_order jl_get_atomic_order_checked(jl_sym_t *order, char loading, char storing); diff --git a/src/toplevel.c b/src/toplevel.c index 4a0c021940e77..cedc008af5cd0 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -608,7 +608,7 @@ int jl_is_toplevel_only_expr(jl_value_t *e) JL_NOTSAFEPOINT ((jl_expr_t*)e)->head == jl_toplevel_sym || ((jl_expr_t*)e)->head == jl_error_sym || ((jl_expr_t*)e)->head == jl_incomplete_sym || - ((jl_expr_t*)e)->head == jl_worldinc_sym); + ((jl_expr_t*)e)->head == jl_latestworld_sym); } int jl_needs_lowering(jl_value_t *e) JL_NOTSAFEPOINT