Skip to content

Commit 94c9252

Browse files
committed
trimming: fix-up support for Core._apply_iterate
We only support a few built-in versions of this call (due to #57830), but those should at least be working now with this small tweak. This required a fix-up for built-in functions to be included in the method table for `--trim`'d executables, so that we can dynamically dispatch to them, as the verifier expects.
1 parent 1cc404e commit 94c9252

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Compiler/src/verifytrim.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ function verify_codeinstance!(interp::NativeInterpreter, codeinst::CodeInstance,
189189
end
190190
# TODO: check for calls to Base.atexit?
191191
elseif isexpr(stmt, :call)
192-
error = "unresolved call"
193192
farg = stmt.args[1]
194193
ftyp = widenconst(argextype(farg, codeinfo, sptypes))
195194
if ftyp <: IntrinsicFunction
@@ -250,6 +249,8 @@ function verify_codeinstance!(interp::NativeInterpreter, codeinst::CodeInstance,
250249
elseif Core.memoryrefmodify! isa ftyp
251250
error = "trim verification not yet implemented for builtin `Core.memoryrefmodify!`"
252251
else @assert false "unexpected builtin" end
252+
else
253+
error = "unresolved call"
253254
end
254255
extyp = argextype(SSAValue(i), codeinfo, sptypes)
255256
if extyp === Union{}

src/staticdata.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,11 +2956,31 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,
29562956
size_t num_mis;
29572957
jl_get_llvm_cis(native_functions, &num_mis, NULL);
29582958
arraylist_grow(&MIs, num_mis);
2959+
2960+
// Record MethodInstances for user-provided code (as reported by codegen)
29592961
jl_get_llvm_cis(native_functions, &num_mis, (jl_code_instance_t**)MIs.items);
29602962
for (size_t i = 0; i < num_mis; i++) {
29612963
jl_code_instance_t *ci = (jl_code_instance_t*)MIs.items[i];
29622964
MIs.items[i] = (void*)jl_get_ci_mi(ci);
29632965
}
2966+
2967+
// Record MethodInstances for built-ins (used when dynamically dispatching to a
2968+
// built-in, e.g., in the Core._apply_iterate implementation)
2969+
for (size_t i = 0; i < jl_n_builtins; i++) {
2970+
jl_value_t *builtin = jl_builtin_instances[i];
2971+
if (builtin == NULL)
2972+
continue;
2973+
2974+
jl_datatype_t *dt = (jl_datatype_t*)jl_typeof(builtin);
2975+
jl_value_t *params[2];
2976+
params[0] = dt->name->wrapper;
2977+
params[1] = jl_tparam0(jl_anytuple_type);
2978+
jl_datatype_t *tt = (jl_datatype_t*)jl_apply_tuple_type_v(params, 2);
2979+
2980+
jl_method_instance_t *mi = (jl_method_instance_t *)jl_method_lookup_by_tt(tt, /* world */ 1, /* mt */ jl_nothing);
2981+
assert(!jl_is_nothing(mi));
2982+
arraylist_push(&MIs, mi);
2983+
}
29642984
}
29652985
}
29662986
if (jl_options.trim) {

test/trimming/basic_jll.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function print_string(fptr::Ptr{Cvoid})
99
println(Core.stdout, unsafe_string(ccall(fptr, Cstring, ())))
1010
end
1111

12+
version_str::String = "1.2.3"
13+
1214
function @main(args::Vector{String})::Cint
1315
# Test the basic "Hello, world!"
1416
println(Core.stdout, "Julia! Hello, world!")
@@ -18,6 +20,9 @@ function @main(args::Vector{String})::Cint
1820
println(Core.stdout, ver)
1921
@assert ver == build_ver
2022

23+
parsed_ver = VersionNumber(version_str)
24+
@assert parsed_ver == v"1.2.3"
25+
2126
sleep(0.01)
2227

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

0 commit comments

Comments
 (0)