Skip to content
Open
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
3 changes: 2 additions & 1 deletion Compiler/src/verifytrim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ function verify_codeinstance!(interp::NativeInterpreter, codeinst::CodeInstance,
end
# TODO: check for calls to Base.atexit?
elseif isexpr(stmt, :call)
error = "unresolved call"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes things less parallel structured here (normally the function sets the error message, then uses continue to skip it, instead of attempting to catch every possible else clause)

farg = stmt.args[1]
ftyp = widenconst(argextype(farg, codeinfo, sptypes))
if ftyp <: IntrinsicFunction
Expand Down Expand Up @@ -250,6 +249,8 @@ function verify_codeinstance!(interp::NativeInterpreter, codeinst::CodeInstance,
elseif Core.memoryrefmodify! isa ftyp
error = "trim verification not yet implemented for builtin `Core.memoryrefmodify!`"
else @assert false "unexpected builtin" end
else
error = "unresolved call"
end
extyp = argextype(SSAValue(i), codeinfo, sptypes)
if extyp === Union{}
Expand Down
20 changes: 20 additions & 0 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2956,11 +2956,31 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,
size_t num_mis;
jl_get_llvm_cis(native_functions, &num_mis, NULL);
arraylist_grow(&MIs, num_mis);

// Record MethodInstances for user-provided code (as reported by codegen)
jl_get_llvm_cis(native_functions, &num_mis, (jl_code_instance_t**)MIs.items);
for (size_t i = 0; i < num_mis; i++) {
jl_code_instance_t *ci = (jl_code_instance_t*)MIs.items[i];
MIs.items[i] = (void*)jl_get_ci_mi(ci);
}

// Record MethodInstances for built-ins (used when dynamically dispatching to a
// built-in, e.g., in the Core._apply_iterate implementation)
for (size_t i = 0; i < jl_n_builtins; i++) {
jl_value_t *builtin = jl_builtin_instances[i];
if (builtin == NULL)
continue;

jl_datatype_t *dt = (jl_datatype_t*)jl_typeof(builtin);
jl_value_t *params[2];
params[0] = dt->name->wrapper;
params[1] = jl_tparam0(jl_anytuple_type);
jl_datatype_t *tt = (jl_datatype_t*)jl_apply_tuple_type_v(params, 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs gc root for tt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GC is disabled just a few lines above this, but sure thing


jl_method_instance_t *mi = (jl_method_instance_t *)jl_method_lookup_by_tt(tt, /* world */ 1, /* mt */ jl_nothing);
assert(!jl_is_nothing(mi));
arraylist_push(&MIs, mi);
}
}
}
if (jl_options.trim) {
Expand Down
5 changes: 5 additions & 0 deletions test/trimming/basic_jll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function print_string(fptr::Ptr{Cvoid})
println(Core.stdout, unsafe_string(ccall(fptr, Cstring, ())))
end

version_str::String = "1.2.3"

function @main(args::Vector{String})::Cint
# Test the basic "Hello, world!"
println(Core.stdout, "Julia! Hello, world!")
Expand All @@ -18,6 +20,9 @@ function @main(args::Vector{String})::Cint
println(Core.stdout, ver)
@assert ver == build_ver

parsed_ver = VersionNumber(version_str)
@assert parsed_ver == v"1.2.3"

sleep(0.01)

# Add an indirection via `@cfunction` / 1-arg ccall
Expand Down