@@ -521,7 +521,7 @@ static int var_outside(jl_stenv_t *e, jl_tvar_t *x, jl_tvar_t *y)
521521 return 0 ;
522522}
523523
524- static jl_value_t * intersect_ufirst (jl_value_t * x , jl_value_t * y , jl_stenv_t * e , int depth );
524+ static jl_value_t * intersect_aside (jl_value_t * x , jl_value_t * y , jl_stenv_t * e , int depth );
525525
526526// check that type var `b` is <: `a`, and update b's upper bound.
527527static int var_lt (jl_tvar_t * b , jl_value_t * a , jl_stenv_t * e , int param )
@@ -539,7 +539,7 @@ static int var_lt(jl_tvar_t *b, jl_value_t *a, jl_stenv_t *e, int param)
539539 // for this to work we need to compute issub(left,right) before issub(right,left),
540540 // since otherwise the issub(a, bb.ub) check in var_gt becomes vacuous.
541541 if (e -> intersection ) {
542- jl_value_t * ub = intersect_ufirst (bb -> ub , a , e , bb -> depth0 );
542+ jl_value_t * ub = intersect_aside (bb -> ub , a , e , bb -> depth0 );
543543 if (ub != (jl_value_t * )b )
544544 bb -> ub = ub ;
545545 }
@@ -1328,16 +1328,32 @@ JL_DLLEXPORT int jl_isa(jl_value_t *x, jl_value_t *t)
13281328
13291329static jl_value_t * intersect (jl_value_t * x , jl_value_t * y , jl_stenv_t * e , int param );
13301330
1331+ static jl_value_t * intersect_all (jl_value_t * x , jl_value_t * y , jl_stenv_t * e );
1332+
1333+ // intersect in nested union environment, similar to subtype_ccheck
1334+ static jl_value_t * intersect_aside (jl_value_t * x , jl_value_t * y , jl_stenv_t * e , int depth )
1335+ {
1336+ jl_value_t * res ;
1337+ int savedepth = e -> invdepth ;
1338+ jl_unionstate_t oldRunions = e -> Runions ;
1339+ e -> invdepth = depth ;
1340+
1341+ res = intersect_all (x , y , e );
1342+
1343+ e -> Runions = oldRunions ;
1344+ e -> invdepth = savedepth ;
1345+ return res ;
1346+ }
1347+
13311348static jl_value_t * intersect_union (jl_value_t * x , jl_uniontype_t * u , jl_stenv_t * e , int8_t R , int param )
13321349{
13331350 if (param == 2 || (!jl_has_free_typevars (x ) && !jl_has_free_typevars ((jl_value_t * )u ))) {
1334- jl_value_t * a = NULL , * b = NULL , * save = NULL ; jl_savedenv_t se ;
1335- JL_GC_PUSH3 (& a , & b , & save );
1336- save_env (e , & save , & se );
1337- a = R ? intersect (x , u -> a , e , param ) : intersect (u -> a , x , e , param );
1338- restore_env (e , NULL , & se );
1339- b = R ? intersect (x , u -> b , e , param ) : intersect (u -> b , x , e , param );
1340- free (se .buf );
1351+ jl_value_t * a = NULL , * b = NULL ;
1352+ JL_GC_PUSH2 (& a , & b );
1353+ jl_unionstate_t oldRunions = e -> Runions ;
1354+ a = R ? intersect_all (x , u -> a , e ) : intersect_all (u -> a , x , e );
1355+ b = R ? intersect_all (x , u -> b , e ) : intersect_all (u -> b , x , e );
1356+ e -> Runions = oldRunions ;
13411357 jl_value_t * i = simple_join (a ,b );
13421358 JL_GC_POP ();
13431359 return i ;
@@ -1347,21 +1363,6 @@ static jl_value_t *intersect_union(jl_value_t *x, jl_uniontype_t *u, jl_stenv_t
13471363 return R ? intersect (x , choice , e , param ) : intersect (choice , x , e , param );
13481364}
13491365
1350- static jl_value_t * intersect_ufirst (jl_value_t * x , jl_value_t * y , jl_stenv_t * e , int depth )
1351- {
1352- jl_value_t * res ;
1353- int savedepth = e -> invdepth ;
1354- e -> invdepth = depth ;
1355- if (jl_is_uniontype (x ) && jl_is_typevar (y ))
1356- res = intersect_union (y , (jl_uniontype_t * )x , e , 0 , 0 );
1357- else if (jl_is_typevar (x ) && jl_is_uniontype (y ))
1358- res = intersect_union (x , (jl_uniontype_t * )y , e , 1 , 0 );
1359- else
1360- res = intersect (x , y , e , 0 );
1361- e -> invdepth = savedepth ;
1362- return res ;
1363- }
1364-
13651366// set a variable to a non-type constant
13661367static jl_value_t * set_var_to_const (jl_varbinding_t * bb , jl_value_t * v JL_MAYBE_UNROOTED , jl_varbinding_t * othervar )
13671368{
@@ -1386,13 +1387,11 @@ static jl_value_t *set_var_to_const(jl_varbinding_t *bb, jl_value_t *v JL_MAYBE_
13861387
13871388static int try_subtype_in_env (jl_value_t * a , jl_value_t * b , jl_stenv_t * e )
13881389{
1389- jl_value_t * root = NULL ; jl_savedenv_t se ; int ret = 0 ;
1390+ jl_value_t * root = NULL ; jl_savedenv_t se ;
13901391 JL_GC_PUSH1 (& root );
13911392 save_env (e , & root , & se );
1392- if (subtype_in_env (a , b , e ))
1393- ret = 1 ;
1394- else
1395- restore_env (e , root , & se );
1393+ int ret = subtype_in_env (a , b , e );
1394+ restore_env (e , root , & se );
13961395 free (se .buf );
13971396 JL_GC_POP ();
13981397 return ret ;
@@ -1402,15 +1401,15 @@ static jl_value_t *intersect_var(jl_tvar_t *b, jl_value_t *a, jl_stenv_t *e, int
14021401{
14031402 jl_varbinding_t * bb = lookup (e , b );
14041403 if (bb == NULL )
1405- return R ? intersect_ufirst (a , b -> ub , e , 0 ) : intersect_ufirst (b -> ub , a , e , 0 );
1404+ return R ? intersect_aside (a , b -> ub , e , 0 ) : intersect_aside (b -> ub , a , e , 0 );
14061405 if (bb -> lb == bb -> ub && jl_is_typevar (bb -> lb ))
14071406 return intersect (a , bb -> lb , e , param );
14081407 if (!jl_is_type (a ) && !jl_is_typevar (a ))
14091408 return set_var_to_const (bb , a , NULL );
14101409 int d = bb -> depth0 ;
14111410 jl_value_t * root = NULL ; jl_savedenv_t se ;
14121411 if (param == 2 ) {
1413- jl_value_t * ub = R ? intersect_ufirst (a , bb -> ub , e , d ) : intersect_ufirst (bb -> ub , a , e , d );
1412+ jl_value_t * ub = R ? intersect_aside (a , bb -> ub , e , d ) : intersect_aside (bb -> ub , a , e , d );
14141413 JL_GC_PUSH2 (& ub , & root );
14151414 if (!jl_has_free_typevars (ub ) && !jl_has_free_typevars (bb -> lb )) {
14161415 save_env (e , & root , & se );
@@ -1450,10 +1449,10 @@ static jl_value_t *intersect_var(jl_tvar_t *b, jl_value_t *a, jl_stenv_t *e, int
14501449 if (try_subtype_in_env (bb -> ub , a , e ))
14511450 return (jl_value_t * )b ;
14521451 }
1453- return R ? intersect_ufirst (a , bb -> ub , e , d ) : intersect_ufirst (bb -> ub , a , e , d );
1452+ return R ? intersect_aside (a , bb -> ub , e , d ) : intersect_aside (bb -> ub , a , e , d );
14541453 }
14551454 else if (bb -> concrete || bb -> constraintkind == 1 ) {
1456- jl_value_t * ub = R ? intersect_ufirst (a , bb -> ub , e , d ) : intersect_ufirst (bb -> ub , a , e , d );
1455+ jl_value_t * ub = R ? intersect_aside (a , bb -> ub , e , d ) : intersect_aside (bb -> ub , a , e , d );
14571456 JL_GC_PUSH1 (& ub );
14581457 if (ub == jl_bottom_type || !subtype_in_env (bb -> lb , a , e )) {
14591458 JL_GC_POP ();
@@ -1473,7 +1472,7 @@ static jl_value_t *intersect_var(jl_tvar_t *b, jl_value_t *a, jl_stenv_t *e, int
14731472 return a ;
14741473 }
14751474 assert (bb -> constraintkind == 3 );
1476- jl_value_t * ub = R ? intersect_ufirst (a , bb -> ub , e , d ) : intersect_ufirst (bb -> ub , a , e , d );
1475+ jl_value_t * ub = R ? intersect_aside (a , bb -> ub , e , d ) : intersect_aside (bb -> ub , a , e , d );
14771476 if (ub == jl_bottom_type )
14781477 return jl_bottom_type ;
14791478 if (jl_is_typevar (a ))
@@ -1494,7 +1493,7 @@ static jl_value_t *intersect_var(jl_tvar_t *b, jl_value_t *a, jl_stenv_t *e, int
14941493 root = NULL ;
14951494 JL_GC_PUSH2 (& root , & ub );
14961495 save_env (e , & root , & se );
1497- jl_value_t * ii = R ? intersect_ufirst (a , bb -> lb , e , d ) : intersect_ufirst (bb -> lb , a , e , d );
1496+ jl_value_t * ii = R ? intersect_aside (a , bb -> lb , e , d ) : intersect_aside (bb -> lb , a , e , d );
14981497 if (ii == jl_bottom_type ) {
14991498 restore_env (e , root , & se );
15001499 ii = (jl_value_t * )b ;
@@ -2050,7 +2049,7 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa
20502049 return jl_bottom_type ;
20512050 jl_value_t * ub = NULL , * lb = NULL ;
20522051 JL_GC_PUSH2 (& lb , & ub );
2053- ub = intersect_ufirst (xub , yub , e , xx ? xx -> depth0 : 0 );
2052+ ub = intersect_aside (xub , yub , e , xx ? xx -> depth0 : 0 );
20542053 lb = simple_join (xlb , ylb );
20552054 if (yy ) {
20562055 if (lb != y )
0 commit comments