Skip to content

Commit

Permalink
Add lowering and interpreter support for :latestworld (#56523)
Browse files Browse the repository at this point in the history
Split out from #56509 to facilitate adjusting downstream packages.
  • Loading branch information
Keno authored Nov 12, 2024
1 parent 45c5c9b commit 505907b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ macro nospecialize(x)
end
Expr(@nospecialize args...) = _expr(args...)

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)
macro _total_meta()
Expand Down
2 changes: 2 additions & 0 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_latestworld_sym;

static const uint8_t flisp_system_image[] = {
#include <julia_flisp.boot.inc>
Expand Down Expand Up @@ -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_latestworld_sym = jl_symbol("latestworld");
}

JL_DLLEXPORT void jl_lisp_prompt(void)
Expand Down
3 changes: 3 additions & 0 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_latestworld_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);
}
Expand Down
8 changes: 7 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)) "\""))
((latestworld) "World age increment")
(else (string "\"" h "\" expression"))))
(if (not (null? (cadr lam)))
(error (string (head-to-text (car e)) " not at top level"))))
Expand Down Expand Up @@ -4979,8 +4980,13 @@ f(x) = yt(x)
(if tail (emit-return tail val))
val))

((latestworld-if-toplevel)
(if (null? (cadr lam))
(emit `(latestworld)))
'(null))

;; other top level expressions
((import using export public)
((import using export public latestworld)
(check-top-level e)
(emit e)
(let ((have-ret? (and (pair? code) (pair? (car code)) (eq? (caar code) 'return))))
Expand Down
1 change: 1 addition & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_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);
Expand Down
3 changes: 2 additions & 1 deletion src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_latestworld_sym);
}

int jl_needs_lowering(jl_value_t *e) JL_NOTSAFEPOINT
Expand Down

0 comments on commit 505907b

Please sign in to comment.