Skip to content

Commit 1e56cef

Browse files
committed
don't strip keyword argument names with --strip-metadata
These are used by `hasmethod`, and in any case including keyword argument symbols is unavoidable so there is no cost to keeping these.
1 parent f4d1750 commit 1e56cef

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/staticdata.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,12 +2638,12 @@ static void jl_prune_module_bindings(jl_module_t * m) JL_GC_DISABLED
26382638
jl_gc_wb(m, jl_atomic_load_relaxed(&bindingkeyset2));
26392639
}
26402640

2641-
static void strip_slotnames(jl_array_t *slotnames)
2641+
static void strip_slotnames(jl_array_t *slotnames, int n)
26422642
{
26432643
// replace slot names with `?`, except unused_sym since the compiler looks at it
26442644
jl_sym_t *questionsym = jl_symbol("?");
2645-
int i, l = jl_array_len(slotnames);
2646-
for (i = 0; i < l; i++) {
2645+
int i;
2646+
for (i = 0; i < n; i++) {
26472647
jl_value_t *s = jl_array_ptr_ref(slotnames, i);
26482648
if (s != (jl_value_t*)jl_unused_sym)
26492649
jl_array_ptr_set(slotnames, i, questionsym);
@@ -2662,7 +2662,7 @@ static jl_value_t *strip_codeinfo_meta(jl_method_t *m, jl_value_t *ci_, jl_code_
26622662
else {
26632663
ci = (jl_code_info_t*)ci_;
26642664
}
2665-
strip_slotnames(ci->slotnames);
2665+
strip_slotnames(ci->slotnames, jl_array_len(ci->slotnames));
26662666
ci->debuginfo = jl_nulldebuginfo;
26672667
jl_gc_wb(ci, ci->debuginfo);
26682668
jl_value_t *ret = (jl_value_t*)ci;
@@ -2736,7 +2736,11 @@ static int strip_all_codeinfos__(jl_typemap_entry_t *def, void *_env)
27362736
}
27372737
jl_array_t *slotnames = jl_uncompress_argnames(m->slot_syms);
27382738
JL_GC_PUSH1(&slotnames);
2739-
strip_slotnames(slotnames);
2739+
int tostrip = jl_array_len(slotnames);
2740+
// for keyword methods, strip only nargs to keep the keyword names at the end for reflection
2741+
if (jl_tparam0(jl_unwrap_unionall(m->sig)) == jl_typeof(jl_kwcall_func))
2742+
tostrip = m->nargs;
2743+
strip_slotnames(slotnames, tostrip);
27402744
m->slot_syms = jl_compress_argnames(slotnames);
27412745
jl_gc_wb(m, m->slot_syms);
27422746
JL_GC_POP();

test/cmdlineargs.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,3 +1258,13 @@ end
12581258
timeout = 120
12591259
@test parse(Int,read(`$exename --timeout-for-safepoint-straggler=$timeout -E "Base.JLOptions().timeout_for_safepoint_straggler_s"`, String)) == timeout
12601260
end
1261+
1262+
@testset "--strip-metadata" begin
1263+
mktempdir() do dir
1264+
@test success(pipeline(`$(Base.julia_cmd()) --strip-metadata -t1,0 --output-o $(dir)/sys.o.a -e 0`, stderr=stderr, stdout=stdout))
1265+
if isfile(joinpath(dir, "sys.o.a"))
1266+
Base.Linking.link_image(joinpath(dir, "sys.o.a"), joinpath(dir, "sys.so"))
1267+
@test readchomp(`$(Base.julia_cmd()) -t1,0 -J $(dir)/sys.so -E 'hasmethod(sort, (Vector{Int},), (:dims,))'`) == "true"
1268+
end
1269+
end
1270+
end

0 commit comments

Comments
 (0)