Skip to content

[SpaceEngine] Remove isUseful and don't include redundant spaces. #17805

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 2 commits into from
Jul 7, 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
38 changes: 4 additions & 34 deletions lib/Sema/TypeCheckSwitchStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,38 +319,6 @@ namespace {
return TypeAndVal.getInt();
}

// Defines a "usefulness" metric that returns whether the given space
// contributes meaningfully to the exhaustiveness of a pattern.
bool isUseful() const {
auto subspacesUseful = [](const Space &space) {
for (auto &subspace : space.getSpaces()) {
if (!subspace.isUseful()) {
return false;
}
}
return true;
};

switch (getKind()) {
case SpaceKind::Empty:
return false;
case SpaceKind::Type:
case SpaceKind::BooleanConstant:
case SpaceKind::UnknownCase:
return true;
case SpaceKind::Disjunct:
if (getSpaces().empty()) {
return false;
}
return subspacesUseful(*this);
case SpaceKind::Constructor:
if (getSpaces().empty()) {
return true;
}
return subspacesUseful(*this);
}
}

// An optimization that computes if the difference of this space and
// another space is empty.
bool isSubspace(const Space &other, TypeChecker &TC,
Expand Down Expand Up @@ -1178,13 +1146,14 @@ namespace {
Space projection = projectPattern(TC, caseItem.getPattern(),
sawDowngradablePattern);

if (projection.isUseful()
&& projection.isSubspace(Space::forDisjunct(spaces), TC, DC)) {
if (!projection.isEmpty() &&
projection.isSubspace(Space::forDisjunct(spaces), TC, DC)) {
sawRedundantPattern |= true;

TC.diagnose(caseItem.getStartLoc(),
diag::redundant_particular_case)
.highlight(caseItem.getSourceRange());
continue;
} else {
Expr *cachedExpr = nullptr;
if (checkRedundantLiteral(caseItem.getPattern(), cachedExpr)) {
Expand All @@ -1195,6 +1164,7 @@ namespace {
TC.diagnose(cachedExpr->getLoc(),
diag::redundant_particular_literal_case_here)
.highlight(cachedExpr->getSourceRange());
continue;
}
}
spaces.push_back(projection);
Expand Down