@@ -1307,6 +1307,8 @@ static int subtype_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_stenv_t *e, in
1307
1307
return ans ;
1308
1308
}
1309
1309
1310
+ static int try_subtype_by_bounds (jl_value_t * a , jl_value_t * b , jl_stenv_t * e );
1311
+
1310
1312
// `param` means we are currently looking at a parameter of a type constructor
1311
1313
// (as opposed to being outside any type constructor, or comparing variable bounds).
1312
1314
// this is used to record the positions where type variables occur for the
@@ -1357,7 +1359,8 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
1357
1359
if (yy ) record_var_occurrence (yy , e , param );
1358
1360
if (yr ) {
1359
1361
record_var_occurrence (xx , e , param );
1360
- return subtype (xx -> lb , yy -> ub , e , 0 );
1362
+ int trysub = e -> intersection ? try_subtype_by_bounds (xx -> lb , yy -> ub , e ) : 0 ;
1363
+ return trysub || subtype (xx -> lb , yy -> ub , e , 0 );
1361
1364
}
1362
1365
return var_lt ((jl_tvar_t * )x , y , e , param );
1363
1366
}
@@ -2489,7 +2492,7 @@ static jl_value_t *bound_var_below(jl_tvar_t *tv, jl_varbinding_t *bb, jl_stenv_
2489
2492
2490
2493
static int subtype_by_bounds (jl_value_t * x , jl_value_t * y , jl_stenv_t * e ) JL_NOTSAFEPOINT ;
2491
2494
2492
- // similar to `subtype_by_bounds`, used to avoid stack-overflow caused by circulation constraints.
2495
+ // similar to `subtype_by_bounds`, used to avoid stack-overflow caused by circular constraints.
2493
2496
static int try_subtype_by_bounds (jl_value_t * a , jl_value_t * b , jl_stenv_t * e )
2494
2497
{
2495
2498
if (jl_is_uniontype (a ))
@@ -2498,22 +2501,21 @@ static int try_subtype_by_bounds(jl_value_t *a, jl_value_t *b, jl_stenv_t *e)
2498
2501
else if (jl_is_uniontype (b ))
2499
2502
return try_subtype_by_bounds (a , ((jl_uniontype_t * )b )-> a , e ) ||
2500
2503
try_subtype_by_bounds (a , ((jl_uniontype_t * )b )-> b , e );
2501
- else if (jl_egal (a , b ))
2504
+ else if (a == jl_bottom_type || b == ( jl_value_t * ) jl_any_type || obviously_egal (a , b ))
2502
2505
return 1 ;
2503
2506
else if (!jl_is_typevar (b ))
2504
2507
return 0 ;
2505
- jl_varbinding_t * vb = e -> vars ;
2506
- while (vb != NULL ) {
2507
- if (subtype_by_bounds (b , (jl_value_t * )vb -> var , e ) && obviously_in_union (a , vb -> ub ))
2508
- return 1 ;
2509
- vb = vb -> prev ;
2510
- }
2511
- return 0 ;
2508
+ else if (jl_is_typevar (a ) && subtype_by_bounds (a , b , e ))
2509
+ return 1 ;
2510
+ // check if `Union{a, ...} <: b`.
2511
+ jl_varbinding_t * vb = lookup (e , (jl_tvar_t * )b );
2512
+ jl_value_t * blb = vb ? vb -> lb : ((jl_tvar_t * )b )-> lb ;
2513
+ return obviously_in_union (a , blb );
2512
2514
}
2513
2515
2514
2516
static int try_subtype_in_env (jl_value_t * a , jl_value_t * b , jl_stenv_t * e )
2515
2517
{
2516
- if (a == jl_bottom_type || b == ( jl_value_t * ) jl_any_type || try_subtype_by_bounds (a , b , e ))
2518
+ if (try_subtype_by_bounds (a , b , e ))
2517
2519
return 1 ;
2518
2520
jl_savedenv_t se ;
2519
2521
save_env (e , & se , 1 );
0 commit comments