Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1269,16 +1269,17 @@ macro invoke(ex)
return esc(out)
end

apply_gr(gr::GlobalRef, @nospecialize args...) = getglobal(gr.mod, gr.name)(args...)
apply_gr_kw(@nospecialize(kwargs::NamedTuple), gr::GlobalRef, @nospecialize args...) = Core.kwcall(kwargs, getglobal(gr.mod, gr.name), args...)
getglobalref(gr::GlobalRef, world::UInt) = ccall(:jl_eval_globalref, Any, (Any, UInt), gr, world)

function invokelatest_gr(gr::GlobalRef, @nospecialize args...; kwargs...)
function invokelatest_gr(gr::GlobalRef, args...; kwargs...)
@inline
kwargs = merge(NamedTuple(), kwargs)
world = get_world_counter()
f = getglobalref(gr, world)
if isempty(kwargs)
return invokelatest(apply_gr, gr, args...)
return invoke_in_world(world, f, args...)
end
return invokelatest(apply_gr_kw, kwargs, gr, args...)
return invoke_in_world(world, Core.kwcall, kwargs, f, args...)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ JL_DLLEXPORT jl_value_t *jl_lower(jl_value_t *expr, jl_module_t *inmodule,
{
jl_value_t *core_lower = NULL;
if (jl_core_module)
core_lower = jl_get_global_value(jl_core_module, jl_symbol("_lower"));
core_lower = jl_get_global_value(jl_core_module, jl_symbol("_lower"), jl_current_task->world_age);
if (!core_lower || core_lower == jl_nothing) {
return jl_fl_lower(expr, inmodule, filename, line, world, warn);
}
Expand Down
2 changes: 1 addition & 1 deletion src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ JL_CALLABLE(jl_f_getglobal)
jl_atomic_error("getglobal: module binding cannot be read non-atomically");
else if (order >= jl_memory_order_seq_cst)
jl_fence();
jl_value_t *v = jl_eval_global_var(mod, sym); // relaxed load
jl_value_t *v = jl_eval_global_var(mod, sym, jl_current_task->world_age); // relaxed load
if (order >= jl_memory_order_acquire)
jl_fence();
return v;
Expand Down
6 changes: 3 additions & 3 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,13 @@ JL_DLLEXPORT jl_code_info_t *jl_gdbcodetyped1(jl_method_instance_t *mi, size_t w
ct->world_age = jl_typeinf_world;
jl_value_t **fargs;
JL_GC_PUSHARGS(fargs, 4);
jl_module_t *CC = (jl_module_t*)jl_get_global_value(jl_core_module, jl_symbol("Compiler"));
jl_module_t *CC = (jl_module_t*)jl_get_global_value(jl_core_module, jl_symbol("Compiler"), ct->world_age);
if (CC != NULL && jl_is_module(CC)) {
JL_GC_PROMISE_ROOTED(CC);
fargs[0] = jl_get_global_value(CC, jl_symbol("NativeInterpreter"));;
fargs[0] = jl_get_global_value(CC, jl_symbol("NativeInterpreter"), ct->world_age);
fargs[1] = jl_box_ulong(world);
fargs[1] = jl_apply(fargs, 2);
fargs[0] = jl_get_global_value(CC, jl_symbol("typeinf_code"));
fargs[0] = jl_get_global_value(CC, jl_symbol("typeinf_code"), ct->world_age);
fargs[2] = (jl_value_t*)mi;
fargs[3] = jl_true;
ci = (jl_code_info_t*)jl_apply(fargs, 4);
Expand Down
4 changes: 2 additions & 2 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ JL_DLLEXPORT void jl_atexit_hook(int exitcode) JL_NOTSAFEPOINT_ENTER
if (jl_base_module) {
size_t last_age = ct->world_age;
ct->world_age = jl_get_world_counter();
jl_value_t *f = jl_get_global_value(jl_base_module, jl_symbol("_atexit"));
jl_value_t *f = jl_get_global_value(jl_base_module, jl_symbol("_atexit"), ct->world_age);
if (f != NULL) {
jl_value_t **fargs;
JL_GC_PUSHARGS(fargs, 2);
Expand Down Expand Up @@ -357,7 +357,7 @@ JL_DLLEXPORT void jl_postoutput_hook(void)
jl_task_t *ct = jl_get_current_task();
size_t last_age = ct->world_age;
ct->world_age = jl_get_world_counter();
jl_value_t *f = jl_get_global_value(jl_base_module, jl_symbol("_postoutput"));
jl_value_t *f = jl_get_global_value(jl_base_module, jl_symbol("_postoutput"), ct->world_age);
if (f != NULL) {
JL_TRY {
JL_GC_PUSH1(&f);
Expand Down
12 changes: 6 additions & 6 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,18 @@ static jl_value_t *do_invoke(jl_value_t **args, size_t nargs, interpreter_state
}

// get the global (throwing if null) in the current world
jl_value_t *jl_eval_global_var(jl_module_t *m, jl_sym_t *e)
jl_value_t *jl_eval_global_var(jl_module_t *m, jl_sym_t *e, size_t world)
{
jl_value_t *v = jl_get_global_value(m, e);
jl_value_t *v = jl_get_global_value(m, e, world);
if (v == NULL)
jl_undefined_var_error(e, (jl_value_t*)m);
return v;
}

// get the global (throwing if null) in the current world, optimized
jl_value_t *jl_eval_globalref(jl_globalref_t *g)
jl_value_t *jl_eval_globalref(jl_globalref_t *g, size_t world)
{
jl_value_t *v = jl_get_globalref_value(g);
jl_value_t *v = jl_get_globalref_value(g, world);
if (v == NULL)
jl_undefined_var_error(g->name, (jl_value_t*)g->mod);
return v;
Expand Down Expand Up @@ -218,10 +218,10 @@ static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s)
return jl_quotenode_value(e);
}
if (jl_is_globalref(e)) {
return jl_eval_globalref((jl_globalref_t*)e);
return jl_eval_globalref((jl_globalref_t*)e, jl_current_task->world_age);
}
if (jl_is_symbol(e)) { // bare symbols appear in toplevel exprs not wrapped in `thunk`
return jl_eval_global_var(s->module, (jl_sym_t*)e);
return jl_eval_global_var(s->module, (jl_sym_t*)e, jl_current_task->world_age);
}
if (jl_is_pinode(e)) {
jl_value_t *val = eval_value(jl_fieldref_noalloc(e, 0), s);
Expand Down
3 changes: 2 additions & 1 deletion src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ static void jl_uv_call_close_callback(jl_value_t *val)
JL_GC_PUSHARGS(args, 2); // val is "rooted" in the finalizer list only right now
args[0] = jl_eval_global_var(
jl_base_relative_to(((jl_datatype_t*)jl_typeof(val))->name->module),
jl_symbol("_uv_hook_close")); // topmod(typeof(val))._uv_hook_close
jl_symbol("_uv_hook_close"),
jl_current_task->world_age); // topmod(typeof(val))._uv_hook_close
args[1] = val;
jl_apply(args, 2); // TODO: wrap in try-catch?
JL_GC_POP();
Expand Down
2 changes: 1 addition & 1 deletion src/jlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ static NOINLINE int true_main(int argc, char *argv[])
ct->world_age = jl_get_world_counter();

jl_function_t *start_client = jl_base_module ?
(jl_function_t*)jl_get_global_value(jl_base_module, jl_symbol("_start")) : NULL;
(jl_function_t*)jl_get_global_value(jl_base_module, jl_symbol("_start"), ct->world_age) : NULL;

if (start_client) {
int ret = 1;
Expand Down
1 change: 1 addition & 0 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3287,6 +3287,7 @@ void jl_init_types(void) JL_GC_DISABLED
jl_perm_symsvec(3, "mod", "name", "binding"),
jl_svec(3, jl_module_type, jl_symbol_type, jl_binding_type),
jl_emptysvec, 0, 0, 3);
jl_globalref_type->name->mayinlinealloc = 0; // not at all worthwhile, since the only constructor returns a boxed object

jl_core_module = jl_new_module(jl_symbol("Core"), NULL);

Expand Down
2 changes: 0 additions & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -2094,9 +2094,7 @@ JL_DLLEXPORT jl_value_t *jl_get_existing_strong_gf(jl_binding_t *b JL_PROPAGATES
JL_DLLEXPORT int jl_boundp(jl_module_t *m, jl_sym_t *var, int allow_import);
JL_DLLEXPORT int jl_is_const(jl_module_t *m, jl_sym_t *var);
JL_DLLEXPORT int jl_globalref_is_const(jl_globalref_t *gr);
JL_DLLEXPORT jl_value_t *jl_get_globalref_value(jl_globalref_t *gr);
JL_DLLEXPORT jl_value_t *jl_get_global(jl_module_t *m JL_PROPAGATES_ROOT, jl_sym_t *var);
JL_DLLEXPORT jl_value_t *jl_get_global_value(jl_module_t *m, jl_sym_t *var);
JL_DLLEXPORT void jl_set_global(jl_module_t *m JL_ROOTING_ARGUMENT, jl_sym_t *var, jl_value_t *val JL_ROOTED_ARGUMENT);
JL_DLLEXPORT void jl_set_const(jl_module_t *m JL_ROOTING_ARGUMENT, jl_sym_t *var, jl_value_t *val JL_ROOTED_ARGUMENT);
void jl_set_initial_const(jl_module_t *m JL_ROOTING_ARGUMENT, jl_sym_t *var, jl_value_t *val JL_ROOTED_ARGUMENT, int exported);
Expand Down
5 changes: 4 additions & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,10 @@ STATIC_INLINE size_t module_usings_max(jl_module_t *m) JL_NOTSAFEPOINT {

JL_DLLEXPORT jl_sym_t *jl_module_name(jl_module_t *m) JL_NOTSAFEPOINT;
void jl_add_scanned_method(jl_module_t *m, jl_method_t *meth);
jl_value_t *jl_eval_global_var(jl_module_t *m JL_PROPAGATES_ROOT, jl_sym_t *e);
jl_value_t *jl_eval_global_var(jl_module_t *m JL_PROPAGATES_ROOT, jl_sym_t *e, size_t world);
JL_DLLEXPORT jl_value_t *jl_eval_globalref(jl_globalref_t *g, size_t world);
jl_value_t *jl_get_globalref_value(jl_globalref_t *gr, size_t world);
jl_value_t *jl_get_global_value(jl_module_t *m, jl_sym_t *var, size_t world);
jl_value_t *jl_interpret_opaque_closure(jl_opaque_closure_t *clos, jl_value_t **args, size_t nargs);
jl_value_t *jl_interpret_toplevel_thunk(jl_module_t *m, jl_code_info_t *src);
jl_value_t *jl_interpret_toplevel_expr_in(jl_module_t *m, jl_value_t *e,
Expand Down
12 changes: 6 additions & 6 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1540,20 +1540,20 @@ JL_DLLEXPORT jl_binding_t *jl_get_module_binding(jl_module_t *m, jl_sym_t *var,
}


// get the value (or null) in the current world
JL_DLLEXPORT jl_value_t *jl_get_globalref_value(jl_globalref_t *gr)
// get the value (or null) in the world
jl_value_t *jl_get_globalref_value(jl_globalref_t *gr, size_t world)
{
jl_binding_t *b = gr->binding;
if (!b)
b = jl_get_module_binding(gr->mod, gr->name, 1);
return jl_get_binding_value_depwarn(b, jl_current_task->world_age);
return jl_get_binding_value_depwarn(b, world);
}

// get the value (or null) in the current world
JL_DLLEXPORT jl_value_t *jl_get_global_value(jl_module_t *m, jl_sym_t *var)
// get the value (or null) in the world
jl_value_t *jl_get_global_value(jl_module_t *m, jl_sym_t *var, size_t world)
{
jl_binding_t *b = jl_get_module_binding(m, var, 1);
return jl_get_binding_value_depwarn(b, jl_current_task->world_age);
return jl_get_binding_value_depwarn(b, world);
}

// get the global (or null) in the latest world
Expand Down
4 changes: 2 additions & 2 deletions src/precompile.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void write_srctext(ios_t *f, jl_array_t *udeps, int64_t srctextpos) {
size_t last_age = ct->world_age;
ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
JL_GC_PUSH4(&deptuple, &depots, &replace_depot_func, &normalize_depots_func);
replace_depot_func = jl_eval_global_var(jl_base_module, jl_symbol("replace_depot_path"));
normalize_depots_func = jl_eval_global_var(jl_base_module, jl_symbol("normalize_depots_for_relocation"));
replace_depot_func = jl_eval_global_var(jl_base_module, jl_symbol("replace_depot_path"), jl_current_task->world_age);
normalize_depots_func = jl_eval_global_var(jl_base_module, jl_symbol("normalize_depots_for_relocation"), jl_current_task->world_age);
depots = jl_apply(&normalize_depots_func, 1);
jl_datatype_t *deptuple_p[5] = {jl_module_type, jl_string_type, jl_uint64_type, jl_uint32_type, jl_float64_type};
jl_value_t *jl_deptuple_type = jl_apply_tuple_type_v((jl_value_t**)deptuple_p, 5);
Expand Down
5 changes: 3 additions & 2 deletions src/rtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1596,10 +1596,11 @@ void jl_log(int level, jl_value_t *module, jl_value_t *group, jl_value_t *id,
jl_value_t *msg)
{
jl_value_t *logmsg_func = NULL;
jl_task_t *ct = jl_current_task;
if (jl_base_module) {
jl_value_t *corelogging = jl_get_global_value(jl_base_module, jl_symbol("CoreLogging"));
jl_value_t *corelogging = jl_get_global_value(jl_base_module, jl_symbol("CoreLogging"), ct->world_age);
if (corelogging && jl_is_module(corelogging)) {
logmsg_func = jl_get_global_value((jl_module_t*)corelogging, jl_symbol("logmsg_shim"));
logmsg_func = jl_get_global_value((jl_module_t*)corelogging, jl_symbol("logmsg_shim"), ct->world_age);
}
}
if (!logmsg_func) {
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void jl_task_wait_empty(void)
jl_wait_empty_begin();
size_t lastage = ct->world_age;
ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
jl_value_t *f = jl_get_global_value(jl_base_module, jl_symbol("wait"));
jl_value_t *f = jl_get_global_value(jl_base_module, jl_symbol("wait"), ct->world_age);
wait_empty = ct;
if (f) {
JL_GC_PUSH1(&f);
Expand Down
14 changes: 7 additions & 7 deletions src/staticdata_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,21 +544,21 @@ static int64_t write_dependency_list(ios_t *s, jl_array_t* worklist, jl_array_t
jl_value_t *get_compiletime_prefs_func = NULL;
JL_GC_PUSH8(&depots, &prefs_list, &unique_func, &replace_depot_func, &normalize_depots_func, &toplevel, &prefs_hash_func, &get_compiletime_prefs_func);

jl_array_t *udeps = (jl_array_t*)jl_get_global_value(jl_base_module, jl_symbol("_require_dependencies"));
jl_array_t *udeps = (jl_array_t*)jl_get_global_value(jl_base_module, jl_symbol("_require_dependencies"), ct->world_age);
*udepsp = udeps;

// unique(udeps) to eliminate duplicates while preserving order:
// we preserve order so that the topmost included .jl file comes first
if (udeps) {
unique_func = jl_eval_global_var(jl_base_module, jl_symbol("unique"));
unique_func = jl_eval_global_var(jl_base_module, jl_symbol("unique"), ct->world_age);
jl_value_t *uniqargs[2] = {unique_func, (jl_value_t*)udeps};
udeps = (jl_array_t*)jl_apply(uniqargs, 2);
*udepsp = udeps;
JL_TYPECHK(write_dependency_list, array_any, (jl_value_t*)udeps);
}

replace_depot_func = jl_get_global_value(jl_base_module, jl_symbol("replace_depot_path"));
normalize_depots_func = jl_eval_global_var(jl_base_module, jl_symbol("normalize_depots_for_relocation"));
replace_depot_func = jl_get_global_value(jl_base_module, jl_symbol("replace_depot_path"), ct->world_age);
normalize_depots_func = jl_eval_global_var(jl_base_module, jl_symbol("normalize_depots_for_relocation"), ct->world_age);

depots = jl_apply(&normalize_depots_func, 1);

Expand Down Expand Up @@ -616,9 +616,9 @@ static int64_t write_dependency_list(ios_t *s, jl_array_t* worklist, jl_array_t
// Calculate Preferences hash for current package.
if (jl_base_module) {
// Toplevel module is the module we're currently compiling, use it to get our preferences hash
toplevel = jl_get_global_value(jl_base_module, jl_symbol("__toplevel__"));
prefs_hash_func = jl_eval_global_var(jl_base_module, jl_symbol("get_preferences_hash"));
get_compiletime_prefs_func = jl_eval_global_var(jl_base_module, jl_symbol("get_compiletime_preferences"));
toplevel = jl_get_global_value(jl_base_module, jl_symbol("__toplevel__"), ct->world_age);
prefs_hash_func = jl_eval_global_var(jl_base_module, jl_symbol("get_preferences_hash"), ct->world_age);
get_compiletime_prefs_func = jl_eval_global_var(jl_base_module, jl_symbol("get_compiletime_preferences"), ct->world_age);

if (toplevel) {
// call get_compiletime_prefs(__toplevel__)
Expand Down
2 changes: 1 addition & 1 deletion src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void JL_NORETURN jl_finish_task(jl_task_t *ct)
// let the runtime know this task is dead and find a new task to run
jl_function_t *done = jl_atomic_load_relaxed(&task_done_hook_func);
if (done == NULL) {
done = (jl_function_t*)jl_get_global_value(jl_base_module, jl_symbol("task_done_hook"));
done = (jl_function_t*)jl_get_global_value(jl_base_module, jl_symbol("task_done_hook"), ct->world_age);
if (done != NULL)
jl_atomic_store_release(&task_done_hook_func, done);
}
Expand Down
2 changes: 1 addition & 1 deletion src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ static void jl_init_task_lock(jl_task_t *ct)
ct->world_age = jl_get_world_counter();
jl_function_t *done = jl_atomic_load_relaxed(&init_task_lock_func);
if (done == NULL) {
done = (jl_function_t*)jl_get_global_value(jl_base_module, jl_symbol("init_task_lock"));
done = (jl_function_t*)jl_get_global_value(jl_base_module, jl_symbol("init_task_lock"), ct->world_age);
if (done != NULL)
jl_atomic_store_release(&init_task_lock_func, done);
}
Expand Down
Loading