@@ -377,18 +377,14 @@ namespace {
377
377
378
378
// (_ : Ty1) <= (_ : Ty2) iff D(Ty1) == D(Ty2)
379
379
if (canDecompose (this ->getType (), DC)) {
380
- SmallVector<Space, 4 > disjuncts;
381
- decompose (TC, DC, this ->getType (), disjuncts);
382
- Space or1Space = Space::forDisjunct (disjuncts);
380
+ Space or1Space = decompose (TC, DC, this ->getType ());
383
381
if (or1Space.isSubspace (other, TC, DC)) {
384
382
return true ;
385
383
}
386
384
}
387
385
388
386
if (canDecompose (other.getType (), DC)) {
389
- SmallVector<Space, 4 > disjuncts;
390
- decompose (TC, DC, other.getType (), disjuncts);
391
- Space or2Space = Space::forDisjunct (disjuncts);
387
+ Space or2Space = decompose (TC, DC, other.getType ());
392
388
return this ->isSubspace (or2Space, TC, DC);
393
389
}
394
390
@@ -406,17 +402,13 @@ namespace {
406
402
if (!canDecompose (this ->getType (), DC)) {
407
403
return false ;
408
404
}
409
- SmallVector<Space, 4 > disjuncts;
410
- decompose (TC, DC, this ->getType (), disjuncts);
411
- Space or1Space = Space::forDisjunct (disjuncts);
405
+ Space or1Space = decompose (TC, DC, this ->getType ());
412
406
return or1Space.isSubspace (other, TC, DC);
413
407
}
414
408
PAIRCASE (SpaceKind::Type, SpaceKind::Constructor): {
415
409
// (_ : Ty1) <= H(p1 | ... | pn) iff D(Ty1) <= H(p1 | ... | pn)
416
410
if (canDecompose (this ->getType (), DC)) {
417
- SmallVector<Space, 4 > disjuncts;
418
- decompose (TC, DC, this ->getType (), disjuncts);
419
- Space or1Space = Space::forDisjunct (disjuncts);
411
+ Space or1Space = decompose (TC, DC, this ->getType ());
420
412
return or1Space.isSubspace (other, TC, DC);
421
413
}
422
414
// An undecomposable type is always larger than its constructor space.
@@ -544,24 +536,18 @@ namespace {
544
536
if (this ->getType ()->isEqual (other.getType ())) {
545
537
return other;
546
538
} else if (canDecompose (this ->getType (), DC)) {
547
- SmallVector<Space, 4 > spaces;
548
- decompose (TC, DC, this ->getType (), spaces);
549
- auto decomposition = Space::forDisjunct (spaces);
539
+ auto decomposition = decompose (TC, DC, this ->getType ());
550
540
return intersect (decomposition, other, TC, DC);
551
541
} else if (canDecompose (other.getType (), DC)) {
552
- SmallVector<Space, 4 > spaces;
553
- decompose (TC, DC, other.getType (), spaces);
554
- auto disjunctSp = Space::forDisjunct (spaces);
555
- return intersect (*this , disjunctSp, TC, DC);
542
+ auto decomposition = decompose (TC, DC, other.getType ());
543
+ return intersect (*this , decomposition, TC, DC);
556
544
} else {
557
545
return other;
558
546
}
559
547
}
560
548
PAIRCASE (SpaceKind::Type, SpaceKind::Constructor): {
561
549
if (canDecompose (this ->getType (), DC)) {
562
- SmallVector<Space, 4 > spaces;
563
- decompose (TC, DC, this ->getType (), spaces);
564
- auto decomposition = Space::forDisjunct (spaces);
550
+ auto decomposition = decompose (TC, DC, this ->getType ());
565
551
return intersect (decomposition, other, TC, DC);
566
552
} else {
567
553
return other;
@@ -620,8 +606,8 @@ namespace {
620
606
return Space::forDisjunct (paramSpace);
621
607
}
622
608
623
- PAIRCASE (SpaceKind::UnknownCase, SpaceKind::Type):
624
- PAIRCASE (SpaceKind::UnknownCase, SpaceKind::Constructor):
609
+ PAIRCASE (SpaceKind::UnknownCase, SpaceKind::Type):
610
+ PAIRCASE (SpaceKind::UnknownCase, SpaceKind::Constructor):
625
611
return intersect (other, *this , TC, DC);
626
612
PAIRCASE (SpaceKind::UnknownCase, SpaceKind::UnknownCase):
627
613
if (other.isAllowedButNotRequired ())
@@ -637,10 +623,8 @@ namespace {
637
623
}
638
624
639
625
if (canDecompose (other.getType (), DC)) {
640
- SmallVector<Space, 4 > spaces;
641
- decompose (TC, DC, other.getType (), spaces);
642
- auto disjunctSp = Space::forDisjunct (spaces);
643
- return intersect (*this , disjunctSp, TC, DC);
626
+ auto decomposition = decompose (TC, DC, other.getType ());
627
+ return intersect (*this , decomposition, TC, DC);
644
628
}
645
629
return Space ();
646
630
}
@@ -693,23 +677,18 @@ namespace {
693
677
if (this ->getType ()->isEqual (other.getType ())) {
694
678
return Space ();
695
679
} else if (canDecompose (this ->getType (), DC)) {
696
- SmallVector<Space, 4 > spaces;
697
- this ->decompose (TC, DC, this ->getType (), spaces);
698
- return intersect (Space::forDisjunct (spaces), other, TC, DC);
680
+ auto decomposition = decompose (TC, DC, this ->getType ());
681
+ return intersect (decomposition, other, TC, DC);
699
682
} else if (canDecompose (other.getType (), DC)) {
700
- SmallVector<Space, 4 > spaces;
701
- this ->decompose (TC, DC, other.getType (), spaces);
702
- auto decomp = Space::forDisjunct (spaces);
703
- return intersect (*this , decomp, TC, DC);
683
+ auto decomposition = decompose (TC, DC, other.getType ());
684
+ return intersect (*this , decomposition, TC, DC);
704
685
}
705
686
return Space ();
706
687
}
707
688
PAIRCASE (SpaceKind::Type, SpaceKind::Constructor): {
708
689
if (canDecompose (this ->getType (), DC)) {
709
- SmallVector<Space, 4 > spaces;
710
- this ->decompose (TC, DC, this ->getType (), spaces);
711
- auto decomp = Space::forDisjunct (spaces);
712
- return decomp.minus (other, TC, DC, minusCount);
690
+ auto decomposition = decompose (TC, DC, this ->getType ());
691
+ return decomposition.minus (other, TC, DC, minusCount);
713
692
} else {
714
693
return *this ;
715
694
}
@@ -854,10 +833,8 @@ namespace {
854
833
}
855
834
856
835
if (canDecompose (other.getType (), DC)) {
857
- SmallVector<Space, 4 > spaces;
858
- this ->decompose (TC, DC, other.getType (), spaces);
859
- auto disjunctSp = Space::forDisjunct (spaces);
860
- return this ->minus (disjunctSp, TC, DC, minusCount);
836
+ auto decomposition = decompose (TC, DC, other.getType ());
837
+ return this ->minus (decomposition, TC, DC, minusCount);
861
838
}
862
839
return *this ;
863
840
}
@@ -868,9 +845,7 @@ namespace {
868
845
869
846
PAIRCASE (SpaceKind::Type, SpaceKind::BooleanConstant): {
870
847
if (canDecompose (this ->getType (), DC)) {
871
- SmallVector<Space, 4 > spaces;
872
- this ->decompose (TC, DC, this ->getType (), spaces);
873
- auto orSpace = Space::forDisjunct (spaces);
848
+ auto orSpace = decompose (TC, DC, this ->getType ());
874
849
return orSpace.minus (other, TC, DC, minusCount);
875
850
} else {
876
851
return *this ;
@@ -1109,6 +1084,13 @@ namespace {
1109
1084
}
1110
1085
}
1111
1086
1087
+ static Space decompose (TypeChecker &TC, const DeclContext *DC,
1088
+ Type type) {
1089
+ SmallVector<Space, 4 > spaces;
1090
+ decompose (TC, DC, type, spaces);
1091
+ return Space::forDisjunct (spaces);
1092
+ }
1093
+
1112
1094
static bool canDecompose (Type tp, const DeclContext *DC) {
1113
1095
return tp->is <TupleType>() || tp->isBool () ||
1114
1096
tp->getEnumOrBoundGenericEnum ();
0 commit comments