Skip to content

Commit c49ae82

Browse files
vtjnashpull[bot]
authored andcommitted
staticdata: ensure lookup is for a Type narrower than the Method signature (#49444)
The type_more_complex widening might result in a wider value here, based on the needs of inference, but we only care about the dispatch lookups that could have resulted in this particular Method before, not any other wider results.
1 parent 51d83d5 commit c49ae82

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/staticdata_utils.c

+18-10
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ static void jl_collect_edges(jl_array_t *edges, jl_array_t *ext_targets, jl_arra
475475
// and compute the old methods list, ready for serialization
476476
jl_value_t *matches = NULL;
477477
jl_array_t *callee_ids = NULL;
478-
JL_GC_PUSH2(&matches, &callee_ids);
478+
jl_value_t *sig = NULL;
479+
JL_GC_PUSH3(&matches, &callee_ids, &sig);
479480
for (size_t i = 0; i < l; i += 2) {
480481
jl_array_t *callees = (jl_array_t*)jl_array_ptr_ref(edges, i + 1);
481482
size_t l = jl_array_len(callees);
@@ -519,14 +520,17 @@ static void jl_collect_edges(jl_array_t *edges, jl_array_t *ext_targets, jl_arra
519520
}
520521
}
521522
else {
522-
jl_value_t *sig;
523-
if (jl_is_method_instance(callee))
524-
sig = ((jl_method_instance_t*)callee)->specTypes;
525-
else
523+
if (jl_is_method_instance(callee)) {
524+
jl_method_instance_t *mi = (jl_method_instance_t*)callee;
525+
sig = jl_type_intersection(mi->def.method->sig, (jl_value_t*)mi->specTypes);
526+
}
527+
else {
526528
sig = callee;
529+
}
527530
int ambig = 0;
528531
matches = jl_matching_methods((jl_tupletype_t*)sig, jl_nothing,
529532
INT32_MAX, 0, world, &min_valid, &max_valid, &ambig);
533+
sig = NULL;
530534
if (matches == jl_nothing) {
531535
callee_ids = NULL; // invalid
532536
break;
@@ -840,7 +844,8 @@ static jl_array_t *jl_verify_edges(jl_array_t *targets, size_t minworld)
840844
memset(jl_array_data(maxvalids), 0, l * sizeof(size_t));
841845
jl_value_t *loctag = NULL;
842846
jl_value_t *matches = NULL;
843-
JL_GC_PUSH3(&maxvalids, &matches, &loctag);
847+
jl_value_t *sig = NULL;
848+
JL_GC_PUSH4(&maxvalids, &matches, &sig, &loctag);
844849
for (i = 0; i < l; i++) {
845850
jl_value_t *invokesig = jl_array_ptr_ref(targets, i * 3);
846851
jl_value_t *callee = jl_array_ptr_ref(targets, i * 3 + 1);
@@ -867,18 +872,21 @@ static jl_array_t *jl_verify_edges(jl_array_t *targets, size_t minworld)
867872
}
868873
}
869874
else {
870-
jl_value_t *sig;
871-
if (jl_is_method_instance(callee))
872-
sig = ((jl_method_instance_t*)callee)->specTypes;
873-
else
875+
if (jl_is_method_instance(callee)) {
876+
jl_method_instance_t *mi = (jl_method_instance_t*)callee;
877+
sig = jl_type_intersection(mi->def.method->sig, (jl_value_t*)mi->specTypes);
878+
}
879+
else {
874880
sig = callee;
881+
}
875882
assert(jl_is_array(expected));
876883
int ambig = 0;
877884
// TODO: possibly need to included ambiguities too (for the optimizer correctness)?
878885
// len + 1 is to allow us to log causes of invalidation (SnoopCompile's @snoopr)
879886
matches = jl_matching_methods((jl_tupletype_t*)sig, jl_nothing,
880887
_jl_debug_method_invalidation ? INT32_MAX : jl_array_len(expected),
881888
0, minworld, &min_valid, &max_valid, &ambig);
889+
sig = NULL;
882890
if (matches == jl_nothing) {
883891
max_valid = 0;
884892
}

0 commit comments

Comments
 (0)