Skip to content

Commit a3fc225

Browse files
committed
codegen: use compiler trampoline closing over method-instance
Replaces jlcall_api with inspection of the invoke closure to see if it is a known entity
1 parent c38298a commit a3fc225

21 files changed

+674
-619
lines changed

base/compiler/optimize.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ function optimize(me::InferenceState)
367367

368368
if proven_pure && !coverage_enabled()
369369
# use constant calling convention
370-
# Do not emit `jlcall_api == 2` if coverage is enabled
370+
# Do not emit `jl_fptr_const_return` if coverage is enabled
371371
# so that we don't need to add coverage support
372372
# to the `jl_call_method_internal` fast path
373373
# Still set pure flag to make sure `inference` tests pass
@@ -438,7 +438,7 @@ function finish(me::InferenceState)
438438
end
439439

440440
# don't store inferred code if we've decided to interpret this function
441-
if !already_inferred && me.linfo.jlcall_api != 4
441+
if !already_inferred && invoke_api(me.linfo) != 4
442442
const_flags = (me.const_ret) << 1 | me.const_api
443443
if me.const_ret
444444
if isa(me.bestguess, Const)
@@ -1320,7 +1320,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
13201320
isa(linfo, MethodInstance) || return invoke_NF(argexprs0, e.typ, atypes0, sv,
13211321
atype_unlimited, invoke_data)
13221322
linfo = linfo::MethodInstance
1323-
if linfo.jlcall_api == 2
1323+
if invoke_api(linfo) == 2
13241324
# in this case function can be inlined to a constant
13251325
add_backedge!(linfo, sv)
13261326
return inline_as_constant(linfo.inferred_const, argexprs, sv, invoke_data)

base/compiler/typeinfer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function typeinf_code(linfo::MethodInstance, optimize::Bool, cached::Bool,
164164
# so need to check whether the code itself is also inferred
165165
if min_world(linfo) <= params.world <= max_world(linfo)
166166
inf = linfo.inferred
167-
if linfo.jlcall_api == 2
167+
if invoke_api(linfo) == 2
168168
method = linfo.def::Method
169169
tree = ccall(:jl_new_code_info_uninit, Ref{CodeInfo}, ())
170170
tree.code = Any[ Expr(:return, quoted(linfo.inferred_const)) ]

base/compiler/utilities.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ end
8888
# MethodInstance/CodeInfo #
8989
###########################
9090

91+
function invoke_api(li::MethodInstance)
92+
return ccall(:jl_invoke_api, Cint, (Any,), li)
93+
end
94+
9195
function get_staged(li::MethodInstance)
9296
try
9397
# user code might throw errors – ignore them

src/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ static jl_value_t *jl_invoke_julia_macro(jl_array_t *args, jl_module_t *inmodule
993993
// unreachable
994994
}
995995
*ctx = mfunc->def.method->module;
996-
result = jl_call_method_internal(mfunc, margs, nargs);
996+
result = mfunc->invoke(mfunc, margs, nargs);
997997
}
998998
JL_CATCH {
999999
if (jl_loaderror_type == NULL) {

src/builtins.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,13 +1181,13 @@ static void add_builtin(const char *name, jl_value_t *v)
11811181
jl_set_const(jl_core_module, jl_symbol(name), v);
11821182
}
11831183

1184-
jl_fptr_t jl_get_builtin_fptr(jl_value_t *b)
1184+
jl_fptr_args_t jl_get_builtin_fptr(jl_value_t *b)
11851185
{
11861186
assert(jl_isa(b, (jl_value_t*)jl_builtin_type));
1187-
return jl_gf_mtable(b)->cache.leaf->func.linfo->fptr;
1187+
return jl_gf_mtable(b)->cache.leaf->func.linfo->specptr.fptr1;
11881188
}
11891189

1190-
static void add_builtin_func(const char *name, jl_fptr_t fptr)
1190+
static void add_builtin_func(const char *name, jl_fptr_args_t fptr)
11911191
{
11921192
jl_mk_builtin_func(NULL, name, fptr);
11931193
}

0 commit comments

Comments
 (0)