@@ -2756,11 +2756,16 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
2756
2756
}
2757
2757
// - it may even dominate some choices that are not subtypes!
2758
2758
// move those into the subtype group, where we're filter them out shortly after
2759
- // (and avoid potentially reporting these as an ambiguity)
2760
- if (!all_subtypes && minmax != NULL && !minmax_ambig ) {
2759
+ // (potentially avoiding reporting these as an ambiguity, and
2760
+ // potentially allowing us to hit the next fast path)
2761
+ // - we could always check here if *any* FULLY_COVERS method is
2762
+ // more-specific (instead of just considering minmax), but that may
2763
+ // cost much extra and is less likely to help us hit a fast path
2764
+ // (we will look for this later, when we compute ambig_groupid, for
2765
+ // correctness)
2766
+ if (!all_subtypes && minmax != NULL ) {
2761
2767
jl_method_t * minmaxm = minmax -> method ;
2762
- if (!include_ambiguous )
2763
- all_subtypes = 1 ;
2768
+ all_subtypes = 1 ;
2764
2769
for (i = 0 ; i < len ; i ++ ) {
2765
2770
jl_method_match_t * matc = (jl_method_match_t * )jl_array_ptr_ref (env .t , i );
2766
2771
if (matc -> fully_covers != FULLY_COVERS ) {
@@ -2780,6 +2785,10 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
2780
2785
len = 0 ;
2781
2786
env .t = jl_an_empty_vec_any ;
2782
2787
}
2788
+ else if (lim == 1 ) {
2789
+ JL_GC_POP ();
2790
+ return jl_false ;
2791
+ }
2783
2792
}
2784
2793
else {
2785
2794
assert (minmax != NULL );
@@ -2798,8 +2807,8 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
2798
2807
env .matc = (jl_method_match_t * )jl_array_ptr_ref (env .t , i );
2799
2808
jl_method_t * m = env .matc -> method ;
2800
2809
int subt = env .matc -> fully_covers != NOT_FULLY_COVERS ;
2801
- if ((minmax != NULL || minmax_ambig ) && !include_ambiguous && subt ) {
2802
- continue ; // already the biggest
2810
+ if ((minmax != NULL || ( minmax_ambig && !include_ambiguous )) && subt ) {
2811
+ continue ; // already the biggest (skip will filter others)
2803
2812
}
2804
2813
for (j = 0 ; j < i ; j ++ ) {
2805
2814
jl_method_match_t * matc2 = (jl_method_match_t * )jl_array_ptr_ref (env .t , i - j - 1 );
@@ -2815,34 +2824,6 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
2815
2824
}
2816
2825
jl_array_ptr_set (env .t , i - j , env .matc );
2817
2826
}
2818
- // final step to finish sort:
2819
- // we stopped early with just having all non-subtypes before all
2820
- // subtypes, but the case on the boundary might be wrongly placed:
2821
- // check for that now
2822
- if (minmax == NULL && !minmax_ambig ) {
2823
- for (i = 0 ; i < len ; i ++ ) {
2824
- jl_method_match_t * matc = (jl_method_match_t * )jl_array_ptr_ref (env .t , i );
2825
- if (matc -> fully_covers == FULLY_COVERS )
2826
- break ;
2827
- }
2828
- for (; i > 0 ; i -- ) {
2829
- env .matc = (jl_method_match_t * )jl_array_ptr_ref (env .t , i - 1 );
2830
- jl_method_t * m = env .matc -> method ;
2831
- for (j = i ; j < len ; j ++ ) {
2832
- jl_method_match_t * matc2 = (jl_method_match_t * )jl_array_ptr_ref (env .t , j );
2833
- jl_method_t * m2 = matc2 -> method ;
2834
- if (matc2 -> fully_covers != FULLY_COVERS )
2835
- break ;
2836
- if (!jl_type_morespecific ((jl_value_t * )m2 -> sig , (jl_value_t * )m -> sig ))
2837
- break ;
2838
- jl_array_ptr_set (env .t , j - 1 , matc2 );
2839
- }
2840
- if (j == i )
2841
- break ;
2842
- env .matc -> fully_covers = SENTINEL ;
2843
- jl_array_ptr_set (env .t , j - 1 , env .matc );
2844
- }
2845
- }
2846
2827
char * skip = (char * )alloca (len );
2847
2828
memset (skip , 0 , len );
2848
2829
// if we had a minmax method (any subtypes), now may now be able to
@@ -2861,7 +2842,7 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
2861
2842
// as we go, keep a rough count of how many methods are disjoint, which
2862
2843
// gives us a lower bound on how many methods we will be returning
2863
2844
// and lets us stop early if we reach our limit
2864
- int ndisjoint = 0 ;
2845
+ int ndisjoint = minmax ? 1 : 0 ;
2865
2846
for (i = 0 ; i < len ; i ++ ) {
2866
2847
// can't use skip[i] here, since we still need to make sure the minmax dominates
2867
2848
jl_method_match_t * matc = (jl_method_match_t * )jl_array_ptr_ref (env .t , i );
0 commit comments