@@ -524,14 +524,7 @@ namespace {
524
524
[&](const Space &s) {
525
525
return this ->intersect (s, TC, DC);
526
526
});
527
- // Optimization: Remove all empty spaces.
528
- SmallVector<Space, 4 > filteredCases;
529
- std::copy_if (intersectedCases.begin (), intersectedCases.end (),
530
- std::back_inserter (filteredCases),
531
- [&](const Space &s) {
532
- return !s.isEmpty ();
533
- });
534
- return Space::forDisjunct (filteredCases);
527
+ return Space::forDisjunct (intersectedCases);
535
528
}
536
529
537
530
PAIRCASE (SpaceKind::Disjunct, SpaceKind::Empty):
@@ -546,14 +539,7 @@ namespace {
546
539
[&](const Space &s) {
547
540
return s.intersect (other, TC, DC);
548
541
});
549
- // Optimization: Remove all empty spaces.
550
- SmallVector<Space, 4 > filteredCases;
551
- std::copy_if (intersectedCases.begin (), intersectedCases.end (),
552
- std::back_inserter (filteredCases),
553
- [&](const Space &s) {
554
- return !s.isEmpty ();
555
- });
556
- return Space::forDisjunct (filteredCases);
542
+ return Space::forDisjunct (intersectedCases);
557
543
}
558
544
PAIRCASE (SpaceKind::Type, SpaceKind::Type): {
559
545
// Optimization: The intersection of equal types is that type.
@@ -623,8 +609,10 @@ namespace {
623
609
auto j = other.getSpaces ().begin ();
624
610
for (; i != this ->getSpaces ().end () && j != other.getSpaces ().end ();
625
611
++i, ++j) {
626
- auto intersection = (*i).intersect (*j, TC, DC);
627
- if (intersection.simplify (TC, DC).isEmpty ()) {
612
+ auto intersection = (*i).intersect (*j, TC, DC).simplify (TC, DC);
613
+ // If at least one of the constructor sub-spaces is empty,
614
+ // it makes the whole space empty as well.
615
+ if (intersection.isEmpty ()) {
628
616
return Space ();
629
617
}
630
618
paramSpace.push_back (intersection);
@@ -1006,16 +994,14 @@ namespace {
1006
994
// Simplify each component subspace. If, after simplification, any
1007
995
// subspace contains an empty, then the whole space is empty.
1008
996
SmallVector<Space, 4 > simplifiedSpaces;
1009
- std::transform (getSpaces ().begin (), getSpaces ().end (),
1010
- std::back_inserter (simplifiedSpaces),
1011
- [&](const Space &el) {
1012
- return el.simplify (TC, DC);
1013
- });
1014
- for (auto &el : simplifiedSpaces) {
1015
- if (el.isEmpty ()) {
997
+ for (const auto &space : Spaces) {
998
+ auto simplified = space.simplify (TC, DC);
999
+ if (simplified.isEmpty ())
1016
1000
return Space ();
1017
- }
1001
+
1002
+ simplifiedSpaces.push_back (simplified);
1018
1003
}
1004
+
1019
1005
return Space::forConstructor (getType (), Head, canDowngradeToWarning (),
1020
1006
simplifiedSpaces);
1021
1007
}
@@ -1040,19 +1026,7 @@ namespace {
1040
1026
[&](const Space &el){
1041
1027
return el.simplify (TC, DC);
1042
1028
});
1043
- // If the disjunct is singular, unpack it into its component.
1044
- if (simplifiedSpaces.size () == 1 ) {
1045
- return simplifiedSpaces.front ();
1046
- }
1047
-
1048
- // Otherwise, remove any empties.
1049
- SmallVector<Space, 4 > compatifiedSpaces;
1050
- std::copy_if (simplifiedSpaces.begin (), simplifiedSpaces.end (),
1051
- std::back_inserter (compatifiedSpaces),
1052
- [&](const Space &el) {
1053
- return !el.isEmpty ();
1054
- });
1055
- return Space::forDisjunct (compatifiedSpaces);
1029
+ return Space::forDisjunct (simplifiedSpaces);
1056
1030
}
1057
1031
default :
1058
1032
return *this ;
0 commit comments