Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegen: use compiler trampoline closing over method-instance #26565

Merged
merged 1 commit into from
Apr 4, 2018
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
6 changes: 3 additions & 3 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function optimize(me::InferenceState)

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

# don't store inferred code if we've decided to interpret this function
if !already_inferred && me.linfo.jlcall_api != 4
if !already_inferred && invoke_api(me.linfo) != 4
const_flags = (me.const_ret) << 1 | me.const_api
if me.const_ret
if isa(me.bestguess, Const)
Expand Down Expand Up @@ -1320,7 +1320,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
isa(linfo, MethodInstance) || return invoke_NF(argexprs0, e.typ, atypes0, sv,
atype_unlimited, invoke_data)
linfo = linfo::MethodInstance
if linfo.jlcall_api == 2
if invoke_api(linfo) == 2
# in this case function can be inlined to a constant
add_backedge!(linfo, sv)
return inline_as_constant(linfo.inferred_const, argexprs, sv, invoke_data)
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function typeinf_code(linfo::MethodInstance, optimize::Bool, cached::Bool,
# so need to check whether the code itself is also inferred
if min_world(linfo) <= params.world <= max_world(linfo)
inf = linfo.inferred
if linfo.jlcall_api == 2
if invoke_api(linfo) == 2
method = linfo.def::Method
tree = ccall(:jl_new_code_info_uninit, Ref{CodeInfo}, ())
tree.code = Any[ Expr(:return, quoted(linfo.inferred_const)) ]
Expand Down
4 changes: 4 additions & 0 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ end
# MethodInstance/CodeInfo #
###########################

function invoke_api(li::MethodInstance)
return ccall(:jl_invoke_api, Cint, (Any,), li)
end

function get_staged(li::MethodInstance)
try
# user code might throw errors – ignore them
Expand Down
2 changes: 1 addition & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ static jl_value_t *jl_invoke_julia_macro(jl_array_t *args, jl_module_t *inmodule
// unreachable
}
*ctx = mfunc->def.method->module;
result = jl_call_method_internal(mfunc, margs, nargs);
result = mfunc->invoke(mfunc, margs, nargs);
}
JL_CATCH {
if (jl_loaderror_type == NULL) {
Expand Down
6 changes: 3 additions & 3 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,13 +1179,13 @@ static void add_builtin(const char *name, jl_value_t *v)
jl_set_const(jl_core_module, jl_symbol(name), v);
}

jl_fptr_t jl_get_builtin_fptr(jl_value_t *b)
jl_fptr_args_t jl_get_builtin_fptr(jl_value_t *b)
{
assert(jl_isa(b, (jl_value_t*)jl_builtin_type));
return jl_gf_mtable(b)->cache.leaf->func.linfo->fptr;
return jl_gf_mtable(b)->cache.leaf->func.linfo->specptr.fptr1;
}

static void add_builtin_func(const char *name, jl_fptr_t fptr)
static void add_builtin_func(const char *name, jl_fptr_args_t fptr)
{
jl_mk_builtin_func(NULL, name, fptr);
}
Expand Down
Loading