Skip to content

Commit f7136c9

Browse files
JeffBezansonKristofferC
authored andcommitted
don't strip keyword argument names with --strip-metadata (#58412)
These are used by `hasmethod`, and in any case including keyword argument symbols is unavoidable so there is no cost to keeping these. (cherry picked from commit c5df018)
1 parent 3c4d207 commit f7136c9

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
@@ -2612,12 +2612,12 @@ static void jl_prune_module_bindings(jl_module_t * m) JL_GC_DISABLED
26122612
jl_gc_wb(m, jl_atomic_load_relaxed(&bindingkeyset2));
26132613
}
26142614

2615-
static void strip_slotnames(jl_array_t *slotnames)
2615+
static void strip_slotnames(jl_array_t *slotnames, int n)
26162616
{
26172617
// replace slot names with `?`, except unused_sym since the compiler looks at it
26182618
jl_sym_t *questionsym = jl_symbol("?");
2619-
int i, l = jl_array_len(slotnames);
2620-
for (i = 0; i < l; i++) {
2619+
int i;
2620+
for (i = 0; i < n; i++) {
26212621
jl_value_t *s = jl_array_ptr_ref(slotnames, i);
26222622
if (s != (jl_value_t*)jl_unused_sym)
26232623
jl_array_ptr_set(slotnames, i, questionsym);
@@ -2636,7 +2636,7 @@ static jl_value_t *strip_codeinfo_meta(jl_method_t *m, jl_value_t *ci_, jl_code_
26362636
else {
26372637
ci = (jl_code_info_t*)ci_;
26382638
}
2639-
strip_slotnames(ci->slotnames);
2639+
strip_slotnames(ci->slotnames, jl_array_len(ci->slotnames));
26402640
ci->debuginfo = jl_nulldebuginfo;
26412641
jl_gc_wb(ci, ci->debuginfo);
26422642
jl_value_t *ret = (jl_value_t*)ci;
@@ -2710,7 +2710,11 @@ static int strip_all_codeinfos__(jl_typemap_entry_t *def, void *_env)
27102710
}
27112711
jl_array_t *slotnames = jl_uncompress_argnames(m->slot_syms);
27122712
JL_GC_PUSH1(&slotnames);
2713-
strip_slotnames(slotnames);
2713+
int tostrip = jl_array_len(slotnames);
2714+
// for keyword methods, strip only nargs to keep the keyword names at the end for reflection
2715+
if (jl_tparam0(jl_unwrap_unionall(m->sig)) == jl_typeof(jl_kwcall_func))
2716+
tostrip = m->nargs;
2717+
strip_slotnames(slotnames, tostrip);
27142718
m->slot_syms = jl_compress_argnames(slotnames);
27152719
jl_gc_wb(m, m->slot_syms);
27162720
JL_GC_POP();

test/cmdlineargs.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,3 +1271,13 @@ end
12711271
timeout = 120
12721272
@test parse(Int,read(`$exename --timeout-for-safepoint-straggler=$timeout -E "Base.JLOptions().timeout_for_safepoint_straggler_s"`, String)) == timeout
12731273
end
1274+
1275+
@testset "--strip-metadata" begin
1276+
mktempdir() do dir
1277+
@test success(pipeline(`$(Base.julia_cmd()) --strip-metadata -t1,0 --output-o $(dir)/sys.o.a -e 0`, stderr=stderr, stdout=stdout))
1278+
if isfile(joinpath(dir, "sys.o.a"))
1279+
Base.Linking.link_image(joinpath(dir, "sys.o.a"), joinpath(dir, "sys.so"))
1280+
@test readchomp(`$(Base.julia_cmd()) -t1,0 -J $(dir)/sys.so -E 'hasmethod(sort, (Vector{Int},), (:dims,))'`) == "true"
1281+
end
1282+
end
1283+
end

0 commit comments

Comments
 (0)