diff --git a/base/essentials.jl b/base/essentials.jl index 3fedb9b5f85d52..77fa385348dd21 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -261,4 +261,4 @@ in which case obsolete versions of `f` may otherwise be called. (The drawback is that `invokelatest` is somewhat slower than calling `f` directly, and the type of the result cannot be inferred by the compiler.) """ -invokelatest(f, args...) = ccall(:jl_invoke_latest, Any, (Any,Any), f, args) +invokelatest(f, args...) = Core._apply_latest(f, args) diff --git a/src/builtin_proto.h b/src/builtin_proto.h index 0cd436157fc7d0..b3b663a1dce492 100644 --- a/src/builtin_proto.h +++ b/src/builtin_proto.h @@ -23,6 +23,7 @@ DECLARE_BUILTIN(throw); DECLARE_BUILTIN(is); DECLARE_BUILTIN(typeof); DECLARE_BUILTIN(sizeof); DECLARE_BUILTIN(issubtype); DECLARE_BUILTIN(isa); DECLARE_BUILTIN(_apply); DECLARE_BUILTIN(_apply_pure); +DECLARE_BUILTIN(_apply_latest); DECLARE_BUILTIN(isdefined); DECLARE_BUILTIN(nfields); DECLARE_BUILTIN(tuple); DECLARE_BUILTIN(svec); DECLARE_BUILTIN(getfield); DECLARE_BUILTIN(setfield); diff --git a/src/builtins.c b/src/builtins.c index 721e6270d21cae..c55d499ff715b5 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -576,6 +576,17 @@ JL_CALLABLE(jl_f__apply_pure) return ret; } +// this is like `_apply`, but always runs in the newest world +JL_CALLABLE(jl_f__apply_latest) +{ + jl_ptls_t ptls = jl_get_ptls_states(); + size_t last_age = ptls->world_age; + ptls->world_age = jl_world_counter; + jl_value_t *ret = jl_f__apply(NULL, args, nargs); + ptls->world_age = last_age; + return ret; +} + // eval ----------------------------------------------------------------------- JL_DLLEXPORT jl_value_t *jl_toplevel_eval_in(jl_module_t *m, jl_value_t *ex) @@ -1174,6 +1185,7 @@ void jl_init_primitives(void) add_builtin_func("apply_type", jl_f_apply_type); add_builtin_func("_apply", jl_f__apply); add_builtin_func("_apply_pure", jl_f__apply_pure); + add_builtin_func("_apply_latest", jl_f__apply_latest); add_builtin_func("_expr", jl_f__expr); add_builtin_func("svec", jl_f_svec); diff --git a/src/codegen.cpp b/src/codegen.cpp index 7e953346d02a6e..db97d268aae2b6 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -5730,6 +5730,7 @@ static void init_julia_llvm_env(Module *m) builtin_func_map[jl_f_typeassert] = jlcall_func_to_llvm("jl_f_typeassert", &jl_f_typeassert, m); builtin_func_map[jl_f__apply] = jlcall_func_to_llvm("jl_f__apply", &jl_f__apply, m); builtin_func_map[jl_f__apply_pure] = jlcall_func_to_llvm("jl_f__apply_pure", &jl_f__apply_pure, m); + builtin_func_map[jl_f__apply_latest] = jlcall_func_to_llvm("jl_f__apply_latest", &jl_f__apply_latest, m); builtin_func_map[jl_f_throw] = jlcall_func_to_llvm("jl_f_throw", &jl_f_throw, m); builtin_func_map[jl_f_tuple] = jlcall_func_to_llvm("jl_f_tuple", &jl_f_tuple, m); builtin_func_map[jl_f_svec] = jlcall_func_to_llvm("jl_f_svec", &jl_f_svec, m); diff --git a/src/dump.c b/src/dump.c index 1a1668c06b71fa..c4800f57cd9517 100644 --- a/src/dump.c +++ b/src/dump.c @@ -73,7 +73,7 @@ static htable_t fptr_to_id; static const jl_fptr_t id_to_fptrs[] = { NULL, NULL, jl_f_throw, jl_f_is, jl_f_typeof, jl_f_issubtype, jl_f_isa, - jl_f_typeassert, jl_f__apply, jl_f__apply_pure, jl_f_isdefined, + jl_f_typeassert, jl_f__apply, jl_f__apply_pure, jl_f__apply_latest, jl_f_isdefined, jl_f_tuple, jl_f_svec, jl_f_intrinsic_call, jl_f_getfield, jl_f_setfield, jl_f_fieldtype, jl_f_nfields, jl_f_arrayref, jl_f_arrayset, jl_f_arraysize, jl_f_apply_type, diff --git a/src/gf.c b/src/gf.c index 5ed4c2677e75bf..60d98366878f68 100644 --- a/src/gf.c +++ b/src/gf.c @@ -2197,24 +2197,6 @@ JL_DLLEXPORT jl_value_t *jl_apply_generic(jl_value_t **args, uint32_t nargs) return verify_type(res); } -JL_DLLEXPORT jl_value_t *jl_invoke_latest(jl_value_t *f, jl_value_t *argtuple) -{ - assert(jl_is_tuple(argtuple)); - size_t nargs = jl_nfields(argtuple); - jl_value_t **argv; - JL_GC_PUSHARGS(argv, nargs+1); - argv[0] = f; - for(int i=1; iworld_age; - ptls->world_age = jl_world_counter; - jl_value_t *v = jl_apply(argv, nargs+1); - ptls->world_age = last_age; - JL_GC_POP(); - return v; -} - JL_DLLEXPORT jl_value_t *jl_gf_invoke_lookup(jl_datatype_t *types, size_t world) { jl_methtable_t *mt = ((jl_datatype_t*)jl_tparam0(types))->name->mt;