Skip to content

Commit e8b0b35

Browse files
authored
Merge pull request swiftlang#16747 from xedin/space-engine-cleanups
[SpaceEngine] NFC: Avoid redundant empty sub-space checking before co…
2 parents 3a51bd6 + 61fff9c commit e8b0b35

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

lib/Sema/TypeCheckSwitchStmt.cpp

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,7 @@ namespace {
524524
[&](const Space &s) {
525525
return this->intersect(s, TC, DC);
526526
});
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);
535528
}
536529

537530
PAIRCASE (SpaceKind::Disjunct, SpaceKind::Empty):
@@ -546,14 +539,7 @@ namespace {
546539
[&](const Space &s) {
547540
return s.intersect(other, TC, DC);
548541
});
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);
557543
}
558544
PAIRCASE (SpaceKind::Type, SpaceKind::Type): {
559545
// Optimization: The intersection of equal types is that type.
@@ -623,8 +609,10 @@ namespace {
623609
auto j = other.getSpaces().begin();
624610
for (; i != this->getSpaces().end() && j != other.getSpaces().end();
625611
++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()) {
628616
return Space();
629617
}
630618
paramSpace.push_back(intersection);
@@ -1006,16 +994,14 @@ namespace {
1006994
// Simplify each component subspace. If, after simplification, any
1007995
// subspace contains an empty, then the whole space is empty.
1008996
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())
10161000
return Space();
1017-
}
1001+
1002+
simplifiedSpaces.push_back(simplified);
10181003
}
1004+
10191005
return Space::forConstructor(getType(), Head, canDowngradeToWarning(),
10201006
simplifiedSpaces);
10211007
}
@@ -1040,19 +1026,7 @@ namespace {
10401026
[&](const Space &el){
10411027
return el.simplify(TC, DC);
10421028
});
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);
10561030
}
10571031
default:
10581032
return *this;

0 commit comments

Comments
 (0)