Skip to content

Commit e7995e4

Browse files
authored
ml-matches: fix performance trap (#41925)
While normally we try to only call `jl_type_morespecific` on types with a non-empty intersection (to be more precise about ambiguity reporting), the only work we would do here (if the intersect is empty) would also be to call continue. Fixes #41518
1 parent 24e0831 commit e7995e4

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/gf.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,6 +2938,14 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
29382938
int subt2 = matc2->fully_covers == FULLY_COVERS; // jl_subtype((jl_value_t*)type, (jl_value_t*)m2->sig)
29392939
int rsubt2 = jl_egal((jl_value_t*)matc2->spec_types, m2->sig);
29402940
jl_value_t *ti;
2941+
if (!subt && !subt2 && rsubt && rsubt2 && lim == -1 && ambig == NULL)
2942+
// these would only be filtered out of the list as
2943+
// ambiguous if they are also type-equal, as we
2944+
// aren't skipping matches and the user doesn't
2945+
// care if we report any ambiguities
2946+
continue;
2947+
if (jl_type_morespecific((jl_value_t*)m->sig, (jl_value_t*)m2->sig))
2948+
continue;
29412949
if (subt) {
29422950
ti = (jl_value_t*)matc2->spec_types;
29432951
isect2 = NULL;
@@ -2946,18 +2954,11 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
29462954
ti = (jl_value_t*)matc->spec_types;
29472955
isect2 = NULL;
29482956
}
2949-
else if (rsubt && rsubt2 && lim == -1 && ambig == NULL) {
2950-
// these would only be filtered out of the list as
2951-
// ambiguous if they are also type-equal, as we
2952-
// aren't skipping matches and the user doesn't
2953-
// care if we report any ambiguities
2954-
ti = jl_bottom_type;
2955-
}
29562957
else {
29572958
jl_type_intersection2((jl_value_t*)matc->spec_types, (jl_value_t*)matc2->spec_types, &env.match.ti, &isect2);
29582959
ti = env.match.ti;
29592960
}
2960-
if (ti != jl_bottom_type && !jl_type_morespecific((jl_value_t*)m->sig, (jl_value_t*)m2->sig)) {
2961+
if (ti != jl_bottom_type) {
29612962
disjoint = 0;
29622963
// m and m2 are ambiguous, but let's see if we can find another method (m3)
29632964
// that dominates their intersection, and means we can ignore this

0 commit comments

Comments
 (0)