Skip to content
Closed
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
12 changes: 7 additions & 5 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4166,17 +4166,19 @@ end
compiler_chi(tup::Tuple) = CacheHeaderIncludes(expand_compiler_path(tup))

"""
precompile(f, argtypes::Tuple{Vararg{Any}})
precompile(f, argtypes::Tuple{Vararg{Any}}; check_only::Bool=false)

Compile the given function `f` for the argument tuple (of types) `argtypes`, but do not execute it.
If `check_only` is `true`, do not compile `f`; check whether `f` should be compileable for `argtypes`
and return `true` or `false` accordingly.
"""
function precompile(@nospecialize(f), @nospecialize(argtypes::Tuple))
precompile(Tuple{Core.Typeof(f), argtypes...})
function precompile(@nospecialize(f), @nospecialize(argtypes::Tuple); check_only::Bool=false)
precompile(Tuple{Core.Typeof(f), argtypes...}; check_only)
end

const ENABLE_PRECOMPILE_WARNINGS = Ref(false)
function precompile(@nospecialize(argt::Type))
ret = ccall(:jl_compile_hint, Int32, (Any,), argt) != 0
function precompile(@nospecialize(argt::Type); check_only::Bool=false)
ret = ccall(:jl_compile_hint, Int32, (Any, Cint), argt, check_only) != 0
if !ret && ENABLE_PRECOMPILE_WARNINGS[]
@warn "Inactive precompile statement" maxlog=100 form=argt _module=nothing _file=nothing _line=0
end
Expand Down
8 changes: 5 additions & 3 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3365,16 +3365,18 @@ JL_DLLEXPORT void jl_compile_method_sig(jl_method_t *m, jl_value_t *types, jl_sv
jl_compile_method_instance(mi, NULL, world);
}

JL_DLLEXPORT int jl_compile_hint(jl_tupletype_t *types)
JL_DLLEXPORT int jl_compile_hint(jl_tupletype_t *types, int check_only)
{
size_t world = jl_atomic_load_acquire(&jl_world_counter);
size_t min_valid = 0;
size_t max_valid = ~(size_t)0;
jl_method_instance_t *mi = jl_get_compile_hint_specialization(types, world, &min_valid, &max_valid, 1);
if (mi == NULL)
return 0;
JL_GC_PROMISE_ROOTED(mi);
jl_compile_method_instance(mi, types, world);
if (!check_only) {
JL_GC_PROMISE_ROOTED(mi);
jl_compile_method_instance(mi, types, world);
}
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ JL_DLLEXPORT const char *jl_debuginfo_name(jl_value_t *func) JL_NOTSAFEPOINT;
JL_DLLEXPORT int jl_is_compiled_codeinst(jl_code_instance_t *codeinst) JL_NOTSAFEPOINT;
JL_DLLEXPORT void jl_compile_method_instance(jl_method_instance_t *mi, jl_tupletype_t *types, size_t world);
JL_DLLEXPORT void jl_compile_method_sig(jl_method_t *m, jl_value_t *types, jl_svec_t *sparams, size_t world);
JL_DLLEXPORT int jl_compile_hint(jl_tupletype_t *types);
JL_DLLEXPORT int jl_compile_hint(jl_tupletype_t *types, int check_only);
JL_DLLEXPORT int jl_add_entrypoint(jl_tupletype_t *types);
jl_code_info_t *jl_code_for_interpreter(jl_method_instance_t *lam JL_PROPAGATES_ROOT, size_t world);
jl_value_t *jl_code_or_ci_for_interpreter(jl_method_instance_t *lam JL_PROPAGATES_ROOT, size_t world);
Expand Down
2 changes: 1 addition & 1 deletion src/precompile.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ JL_DLLEXPORT void jl_write_compiler_output(void)
jl_value_t *tt = jl_is_type(f) ? (jl_value_t*)jl_wrap_Type(f) : jl_typeof(f);
JL_GC_PUSH1(&tt);
tt = jl_apply_tuple_type_v(&tt, 1);
jl_compile_hint((jl_tupletype_t*)tt);
jl_compile_hint((jl_tupletype_t*)tt, 0);
if (jl_options.trim)
jl_add_entrypoint((jl_tupletype_t*)tt);
JL_GC_POP();
Expand Down
2 changes: 1 addition & 1 deletion src/precompile_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static int _compile_all_tvar_union(jl_value_t *methsig)
if (sig) {
roots[0] = sig;
if (jl_is_datatype(sig) && jl_has_concrete_subtype(sig))
all = all && jl_compile_hint((jl_tupletype_t*)sig);
all = all && jl_compile_hint((jl_tupletype_t*)sig, 0);
else
all = 0;
}
Expand Down