Skip to content

[SpaceEngine] NFC: Remove convenience intersect because simplify #17751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions lib/Sema/TypeCheckSwitchStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,6 @@ namespace {
}
}

/// Convenience declaration to make the intersection operation look more
/// symmetric.
static Space intersect(const Space &a, const Space &b, TypeChecker &TC,
const DeclContext *DC) {
return a.intersect(b, TC, DC);
}

// Returns the intersection of this space with another. The intersection
// is the largest shared subspace occupied by both arguments.
Space intersect(const Space &other, TypeChecker &TC,
Expand All @@ -530,7 +523,7 @@ namespace {
std::transform(
other.getSpaces().begin(), other.getSpaces().end(),
std::back_inserter(intersectedCases),
[&](const Space &s) { return intersect(*this, s, TC, DC); });
[&](const Space &s) { return this->intersect(s, TC, DC); });
return Space::forDisjunct(intersectedCases);
}

Expand All @@ -540,26 +533,26 @@ namespace {
PAIRCASE (SpaceKind::Disjunct, SpaceKind::BooleanConstant):
PAIRCASE (SpaceKind::Disjunct, SpaceKind::UnknownCase): {
// (S1 || ... || Sn) & S iff (S & S1) && ... && (S & Sn)
return intersect(other, *this, TC, DC);
return other.intersect(*this, TC, DC);
}
PAIRCASE (SpaceKind::Type, SpaceKind::Type): {
// Optimization: The intersection of equal types is that type.
if (this->getType()->isEqual(other.getType())) {
return other;
} else if (canDecompose(this->getType(), DC)) {
auto decomposition = decompose(TC, DC, this->getType());
return intersect(decomposition, other, TC, DC);
return decomposition.intersect(other, TC, DC);
} else if (canDecompose(other.getType(), DC)) {
auto decomposition = decompose(TC, DC, other.getType());
return intersect(*this, decomposition, TC, DC);
return this->intersect(decomposition, TC, DC);
} else {
return other;
}
}
PAIRCASE (SpaceKind::Type, SpaceKind::Constructor): {
if (canDecompose(this->getType(), DC)) {
auto decomposition = decompose(TC, DC, this->getType());
return intersect(decomposition, other, TC, DC);
return decomposition.intersect(other, TC, DC);
} else {
return other;
}
Expand All @@ -580,7 +573,7 @@ namespace {
std::transform(this->getSpaces().begin(), this->getSpaces().end(),
std::back_inserter(newSubSpaces),
[&](const Space &subSpace) {
return intersect(subSpace, other, TC, DC);
return subSpace.intersect(other, TC, DC);
});
return Space::forConstructor(this->getType(), this->getHead(),
this->canDowngradeToWarning(),
Expand All @@ -605,7 +598,7 @@ namespace {
auto j = other.getSpaces().begin();
for (; i != this->getSpaces().end() && j != other.getSpaces().end();
++i, ++j) {
auto result = intersect(*i, *j, TC, DC);
auto result = i->intersect(*j, TC, DC);
// If at least one of the constructor sub-spaces is empty,
// it makes the whole space empty as well.
if (result.isEmpty()) {
Expand All @@ -619,7 +612,7 @@ namespace {

PAIRCASE (SpaceKind::UnknownCase, SpaceKind::Type):
PAIRCASE (SpaceKind::UnknownCase, SpaceKind::Constructor):
return intersect(other, *this, TC, DC);
return other.intersect(*this, TC, DC);
PAIRCASE (SpaceKind::UnknownCase, SpaceKind::UnknownCase):
if (other.isAllowedButNotRequired())
return other;
Expand All @@ -635,7 +628,7 @@ namespace {

if (canDecompose(other.getType(), DC)) {
auto decomposition = decompose(TC, DC, other.getType());
return intersect(*this, decomposition, TC, DC);
return this->intersect(decomposition, TC, DC);
}
return Space();
}
Expand All @@ -645,7 +638,7 @@ namespace {
return Space();

PAIRCASE (SpaceKind::Type, SpaceKind::BooleanConstant): {
return intersect(other, *this, TC, DC);
return other.intersect(*this, TC, DC);
}

PAIRCASE (SpaceKind::Empty, SpaceKind::BooleanConstant):
Expand Down Expand Up @@ -689,10 +682,10 @@ namespace {
return Space();
} else if (canDecompose(this->getType(), DC)) {
auto decomposition = decompose(TC, DC, this->getType());
return intersect(decomposition, other, TC, DC);
return decomposition.intersect(other, TC, DC);
} else if (canDecompose(other.getType(), DC)) {
auto decomposition = decompose(TC, DC, other.getType());
return intersect(*this, decomposition, TC, DC);
return this->intersect(decomposition, TC, DC);
}
return Space();
}
Expand Down Expand Up @@ -783,7 +776,7 @@ namespace {
auto &s2 = *j;
// If the intersection of each subspace is ever empty then the
// two spaces are disjoint and their difference is the first space.
if (intersect(s1, s2, TC, DC).isEmpty()) {
if (s1.intersect(s2, TC, DC).isEmpty()) {
return *this;
}

Expand Down