@@ -953,7 +953,7 @@ static jl_method_instance_t *cache_method(
953
953
jl_methtable_t * mt , jl_typemap_t * * cache , jl_value_t * parent JL_PROPAGATES_ROOT ,
954
954
jl_tupletype_t * tt , // the original tupletype of the signature
955
955
jl_method_t * definition ,
956
- size_t world ,
956
+ size_t world , size_t min_valid , size_t max_valid ,
957
957
jl_svec_t * sparams )
958
958
{
959
959
// caller must hold the mt->writelock
@@ -996,12 +996,12 @@ static jl_method_instance_t *cache_method(
996
996
997
997
jl_tupletype_t * cachett = tt ;
998
998
jl_svec_t * guardsigs = jl_emptysvec ;
999
- size_t min_valid = 1 ;
1000
- size_t max_valid = ~(size_t )0 ;
1001
999
if (!cache_with_orig && mt ) {
1002
1000
// now examine what will happen if we chose to use this sig in the cache
1003
1001
// TODO: should we first check `compilationsig <: definition`?
1004
- temp = ml_matches (mt , 0 , compilationsig , MAX_UNSPECIALIZED_CONFLICTS , 1 , world , & min_valid , & max_valid , 0 );
1002
+ size_t min_valid2 = 1 ;
1003
+ size_t max_valid2 = ~(size_t )0 ;
1004
+ temp = ml_matches (mt , 0 , compilationsig , MAX_UNSPECIALIZED_CONFLICTS , 1 , world , & min_valid2 , & max_valid2 , 0 );
1005
1005
int guards = 0 ;
1006
1006
if (temp == jl_false ) {
1007
1007
cache_with_orig = 1 ;
@@ -1052,22 +1052,14 @@ static jl_method_instance_t *cache_method(
1052
1052
}
1053
1053
}
1054
1054
}
1055
- if (cache_with_orig ) {
1056
- min_valid = 1 ;
1057
- max_valid = ~(size_t )0 ;
1058
- }
1059
- else {
1055
+ if (!cache_with_orig ) {
1060
1056
// determined above that there's no ambiguity in also using compilationsig as the cacheablesig
1057
+ min_valid = min_valid2 ;
1058
+ max_valid = max_valid2 ;
1061
1059
cachett = compilationsig ;
1062
1060
}
1063
1061
}
1064
1062
1065
- if (cache_with_orig && mt ) {
1066
- // now examine defs to determine the min/max-valid range for this lookup result
1067
- (void )ml_matches (mt , 0 , cachett , -1 , 0 , world , & min_valid , & max_valid , 0 );
1068
- }
1069
- assert (mt == NULL || min_valid > 1 );
1070
-
1071
1063
// now scan `cachett` and ensure that `Type{T}` in the cache will be matched exactly by `typeof(T)`
1072
1064
// and also reduce the complexity of rejecting this entry in the cache
1073
1065
// by replacing non-simple types with jl_any_type to build a new `type`
@@ -1229,7 +1221,7 @@ static jl_method_instance_t *jl_mt_assoc_by_type(jl_methtable_t *mt, jl_datatype
1229
1221
entry = jl_typemap_morespecific_by_type (entry , (jl_value_t * )tt , & search .env , world );
1230
1222
if (entry != NULL ) {
1231
1223
jl_method_t * m = entry -> func .method ;
1232
- nf = cache_method (mt , & mt -> cache , (jl_value_t * )mt , tt , m , world , search .env );
1224
+ nf = cache_method (mt , & mt -> cache , (jl_value_t * )mt , tt , m , world , search .min_valid , search . max_valid , search . env );
1233
1225
}
1234
1226
}
1235
1227
JL_GC_POP ();
@@ -2088,7 +2080,13 @@ jl_method_instance_t *jl_get_specialization1(jl_tupletype_t *types JL_PROPAGATES
2088
2080
return NULL ;
2089
2081
2090
2082
// find if exactly 1 method matches (issue #7302)
2091
- jl_value_t * matches = jl_matching_methods (types , 1 , 1 , world , min_valid , max_valid );
2083
+ size_t min_valid2 = 1 ;
2084
+ size_t max_valid2 = ~(size_t )0 ;
2085
+ jl_value_t * matches = jl_matching_methods (types , 1 , 1 , world , & min_valid2 , & max_valid2 );
2086
+ if (* min_valid < min_valid2 )
2087
+ * min_valid = min_valid2 ;
2088
+ if (* max_valid > max_valid2 )
2089
+ * max_valid = max_valid2 ;
2092
2090
if (matches == jl_false || jl_array_len (matches ) != 1 )
2093
2091
return NULL ;
2094
2092
jl_tupletype_t * tt = NULL ;
@@ -2109,7 +2107,7 @@ jl_method_instance_t *jl_get_specialization1(jl_tupletype_t *types JL_PROPAGATES
2109
2107
// inject it there now if we think it will be
2110
2108
// used via dispatch later (e.g. because it was hinted via a call to `precompile`)
2111
2109
JL_LOCK (& mt -> writelock );
2112
- nf = cache_method (mt , & mt -> cache , (jl_value_t * )mt , ti , m , world , env );
2110
+ nf = cache_method (mt , & mt -> cache , (jl_value_t * )mt , ti , m , world , min_valid2 , max_valid2 , env );
2113
2111
JL_UNLOCK (& mt -> writelock );
2114
2112
}
2115
2113
else {
@@ -2538,7 +2536,7 @@ static jl_value_t *jl_gf_invoke_by_method(jl_method_t *method, jl_value_t *gf, j
2538
2536
if (method -> invokes == NULL )
2539
2537
method -> invokes = jl_nothing ;
2540
2538
2541
- mfunc = cache_method (NULL , & method -> invokes , (jl_value_t * )method , tt , method , 1 , tpenv );
2539
+ mfunc = cache_method (NULL , & method -> invokes , (jl_value_t * )method , tt , method , 1 , 1 , ~( size_t ) 0 , tpenv );
2542
2540
JL_UNLOCK (& method -> writelock );
2543
2541
JL_GC_POP ();
2544
2542
if (jl_options .malloc_log )
@@ -2588,7 +2586,7 @@ JL_DLLEXPORT jl_value_t *jl_get_invoke_lambda(jl_typemap_entry_t *entry, jl_valu
2588
2586
method -> invokes = jl_nothing ;
2589
2587
2590
2588
jl_method_instance_t * mfunc = cache_method (NULL , & method -> invokes , (jl_value_t * )method ,
2591
- (jl_tupletype_t * )tt , method , 1 , tpenv );
2589
+ (jl_tupletype_t * )tt , method , 1 , 1 , ~( size_t ) 0 , tpenv );
2592
2590
JL_GC_POP ();
2593
2591
JL_UNLOCK (& method -> writelock );
2594
2592
return (jl_value_t * )mfunc ;
@@ -2930,7 +2928,7 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
2930
2928
env .matc = (jl_svec_t * )jl_array_ptr_ref (env .t , 0 );
2931
2929
jl_method_t * meth = (jl_method_t * )jl_svecref (env .matc , 2 );
2932
2930
jl_svec_t * tpenv = (jl_svec_t * )jl_svecref (env .matc , 1 );
2933
- cache_method (mt , & mt -> cache , (jl_value_t * )mt , type , meth , world , tpenv );
2931
+ cache_method (mt , & mt -> cache , (jl_value_t * )mt , type , meth , world , env . min_valid , env . max_valid , tpenv );
2934
2932
}
2935
2933
}
2936
2934
JL_GC_POP ();
0 commit comments