Skip to content

don't strip keyword argument names with --strip-metadata #58412

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

Merged
merged 1 commit into from
May 22, 2025
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
14 changes: 9 additions & 5 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2638,12 +2638,12 @@ static void jl_prune_module_bindings(jl_module_t * m) JL_GC_DISABLED
jl_gc_wb(m, jl_atomic_load_relaxed(&bindingkeyset2));
}

static void strip_slotnames(jl_array_t *slotnames)
static void strip_slotnames(jl_array_t *slotnames, int n)
{
// replace slot names with `?`, except unused_sym since the compiler looks at it
jl_sym_t *questionsym = jl_symbol("?");
int i, l = jl_array_len(slotnames);
for (i = 0; i < l; i++) {
int i;
for (i = 0; i < n; i++) {
jl_value_t *s = jl_array_ptr_ref(slotnames, i);
if (s != (jl_value_t*)jl_unused_sym)
jl_array_ptr_set(slotnames, i, questionsym);
Expand All @@ -2662,7 +2662,7 @@ static jl_value_t *strip_codeinfo_meta(jl_method_t *m, jl_value_t *ci_, jl_code_
else {
ci = (jl_code_info_t*)ci_;
}
strip_slotnames(ci->slotnames);
strip_slotnames(ci->slotnames, jl_array_len(ci->slotnames));
ci->debuginfo = jl_nulldebuginfo;
jl_gc_wb(ci, ci->debuginfo);
jl_value_t *ret = (jl_value_t*)ci;
Expand Down Expand Up @@ -2736,7 +2736,11 @@ static int strip_all_codeinfos__(jl_typemap_entry_t *def, void *_env)
}
jl_array_t *slotnames = jl_uncompress_argnames(m->slot_syms);
JL_GC_PUSH1(&slotnames);
strip_slotnames(slotnames);
int tostrip = jl_array_len(slotnames);
// for keyword methods, strip only nargs to keep the keyword names at the end for reflection
if (jl_tparam0(jl_unwrap_unionall(m->sig)) == jl_typeof(jl_kwcall_func))
tostrip = m->nargs;
strip_slotnames(slotnames, tostrip);
m->slot_syms = jl_compress_argnames(slotnames);
jl_gc_wb(m, m->slot_syms);
JL_GC_POP();
Expand Down
10 changes: 10 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1258,3 +1258,13 @@ end
timeout = 120
@test parse(Int,read(`$exename --timeout-for-safepoint-straggler=$timeout -E "Base.JLOptions().timeout_for_safepoint_straggler_s"`, String)) == timeout
end

@testset "--strip-metadata" begin
mktempdir() do dir
@test success(pipeline(`$(Base.julia_cmd()) --strip-metadata -t1,0 --output-o $(dir)/sys.o.a -e 0`, stderr=stderr, stdout=stdout))
if isfile(joinpath(dir, "sys.o.a"))
Base.Linking.link_image(joinpath(dir, "sys.o.a"), joinpath(dir, "sys.so"))
@test readchomp(`$(Base.julia_cmd()) -t1,0 -J $(dir)/sys.so -E 'hasmethod(sort, (Vector{Int},), (:dims,))'`) == "true"
end
end
end