Skip to content

Commit 472031f

Browse files
authored
Merge pull request #17805 from xedin/minor-space-engine-fixes
[SpaceEngine] Remove `isUseful` and don't include redundant spaces.
2 parents 296b9d1 + 840269b commit 472031f

File tree

1 file changed

+4
-34
lines changed

1 file changed

+4
-34
lines changed

lib/Sema/TypeCheckSwitchStmt.cpp

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -319,38 +319,6 @@ namespace {
319319
return TypeAndVal.getInt();
320320
}
321321

322-
// Defines a "usefulness" metric that returns whether the given space
323-
// contributes meaningfully to the exhaustiveness of a pattern.
324-
bool isUseful() const {
325-
auto subspacesUseful = [](const Space &space) {
326-
for (auto &subspace : space.getSpaces()) {
327-
if (!subspace.isUseful()) {
328-
return false;
329-
}
330-
}
331-
return true;
332-
};
333-
334-
switch (getKind()) {
335-
case SpaceKind::Empty:
336-
return false;
337-
case SpaceKind::Type:
338-
case SpaceKind::BooleanConstant:
339-
case SpaceKind::UnknownCase:
340-
return true;
341-
case SpaceKind::Disjunct:
342-
if (getSpaces().empty()) {
343-
return false;
344-
}
345-
return subspacesUseful(*this);
346-
case SpaceKind::Constructor:
347-
if (getSpaces().empty()) {
348-
return true;
349-
}
350-
return subspacesUseful(*this);
351-
}
352-
}
353-
354322
// An optimization that computes if the difference of this space and
355323
// another space is empty.
356324
bool isSubspace(const Space &other, TypeChecker &TC,
@@ -1178,13 +1146,14 @@ namespace {
11781146
Space projection = projectPattern(TC, caseItem.getPattern(),
11791147
sawDowngradablePattern);
11801148

1181-
if (projection.isUseful()
1182-
&& projection.isSubspace(Space::forDisjunct(spaces), TC, DC)) {
1149+
if (!projection.isEmpty() &&
1150+
projection.isSubspace(Space::forDisjunct(spaces), TC, DC)) {
11831151
sawRedundantPattern |= true;
11841152

11851153
TC.diagnose(caseItem.getStartLoc(),
11861154
diag::redundant_particular_case)
11871155
.highlight(caseItem.getSourceRange());
1156+
continue;
11881157
} else {
11891158
Expr *cachedExpr = nullptr;
11901159
if (checkRedundantLiteral(caseItem.getPattern(), cachedExpr)) {
@@ -1195,6 +1164,7 @@ namespace {
11951164
TC.diagnose(cachedExpr->getLoc(),
11961165
diag::redundant_particular_literal_case_here)
11971166
.highlight(cachedExpr->getSourceRange());
1167+
continue;
11981168
}
11991169
}
12001170
spaces.push_back(projection);

0 commit comments

Comments
 (0)