Skip to content

Commit 0008354

Browse files
authored
Merge pull request swiftlang#10169 from CodaFi/sweeps
[NFC] Run clang format on the space engine
2 parents 2a8950f + acd95d1 commit 0008354

File tree

1 file changed

+151
-151
lines changed

1 file changed

+151
-151
lines changed

lib/Sema/TypeCheckSwitchStmt.cpp

Lines changed: 151 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ namespace {
134134
}
135135

136136
public:
137-
explicit
138-
Space(Type T)
137+
explicit Space(Type T)
139138
: Kind(SpaceKind::Type), TypeAndVal(T, false), Head(Identifier()),
140139
Spaces({}){}
141-
explicit Space(Type T, Identifier H, bool downgrade, SmallVectorImpl<Space> &SP)
140+
explicit Space(Type T, Identifier H, bool downgrade,
141+
SmallVectorImpl<Space> &SP)
142142
: Kind(SpaceKind::Constructor), TypeAndVal(T, downgrade), Head(H),
143143
Spaces(SP.begin(), SP.end()) {}
144144
explicit Space(Type T, Identifier H, bool downgrade,
@@ -399,145 +399,145 @@ namespace {
399399
};
400400

401401
switch (PairSwitch(getKind(), other.getKind())) {
402-
PAIRCASE (SpaceKind::Empty, SpaceKind::Disjunct):
403-
PAIRCASE (SpaceKind::Type, SpaceKind::Disjunct):
404-
PAIRCASE (SpaceKind::Constructor, SpaceKind::Disjunct):
405-
PAIRCASE (SpaceKind::Disjunct, SpaceKind::Disjunct):
406-
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Disjunct): {
407-
// S & (S1 || ... || Sn) iff (S & S1) && ... && (S & Sn)
408-
SmallVector<Space, 4> intersectedCases;
409-
std::transform(other.getSpaces().begin(), other.getSpaces().end(),
410-
std::back_inserter(intersectedCases),
411-
[&](const Space &s) {
412-
return this->intersect(s, TC);
413-
});
414-
// Optimization: Remove all empty spaces.
415-
SmallVector<Space, 4> filteredCases;
416-
std::copy_if(intersectedCases.begin(), intersectedCases.end(),
417-
std::back_inserter(filteredCases),
402+
PAIRCASE (SpaceKind::Empty, SpaceKind::Disjunct):
403+
PAIRCASE (SpaceKind::Type, SpaceKind::Disjunct):
404+
PAIRCASE (SpaceKind::Constructor, SpaceKind::Disjunct):
405+
PAIRCASE (SpaceKind::Disjunct, SpaceKind::Disjunct):
406+
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Disjunct): {
407+
// S & (S1 || ... || Sn) iff (S & S1) && ... && (S & Sn)
408+
SmallVector<Space, 4> intersectedCases;
409+
std::transform(other.getSpaces().begin(), other.getSpaces().end(),
410+
std::back_inserter(intersectedCases),
418411
[&](const Space &s) {
419-
return !s.isEmpty();
420-
});
421-
return examineDecomp(filteredCases);
422-
}
412+
return this->intersect(s, TC);
413+
});
414+
// Optimization: Remove all empty spaces.
415+
SmallVector<Space, 4> filteredCases;
416+
std::copy_if(intersectedCases.begin(), intersectedCases.end(),
417+
std::back_inserter(filteredCases),
418+
[&](const Space &s) {
419+
return !s.isEmpty();
420+
});
421+
return examineDecomp(filteredCases);
422+
}
423423

424-
PAIRCASE (SpaceKind::Disjunct, SpaceKind::Empty):
425-
PAIRCASE (SpaceKind::Disjunct, SpaceKind::Type):
426-
PAIRCASE (SpaceKind::Disjunct, SpaceKind::Constructor):
427-
PAIRCASE (SpaceKind::Disjunct, SpaceKind::BooleanConstant): {
428-
// (S1 || ... || Sn) & S iff (S & S1) && ... && (S & Sn)
429-
SmallVector<Space, 4> intersectedCases;
430-
std::transform(this->getSpaces().begin(), this->getSpaces().end(),
431-
std::back_inserter(intersectedCases),
432-
[&](const Space &s) {
433-
return s.intersect(other, TC);
434-
});
435-
// Optimization: Remove all empty spaces.
436-
SmallVector<Space, 4> filteredCases;
437-
std::copy_if(intersectedCases.begin(), intersectedCases.end(),
438-
std::back_inserter(filteredCases),
424+
PAIRCASE (SpaceKind::Disjunct, SpaceKind::Empty):
425+
PAIRCASE (SpaceKind::Disjunct, SpaceKind::Type):
426+
PAIRCASE (SpaceKind::Disjunct, SpaceKind::Constructor):
427+
PAIRCASE (SpaceKind::Disjunct, SpaceKind::BooleanConstant): {
428+
// (S1 || ... || Sn) & S iff (S & S1) && ... && (S & Sn)
429+
SmallVector<Space, 4> intersectedCases;
430+
std::transform(this->getSpaces().begin(), this->getSpaces().end(),
431+
std::back_inserter(intersectedCases),
439432
[&](const Space &s) {
440-
return !s.isEmpty();
441-
});
442-
return examineDecomp(filteredCases);
443-
}
444-
PAIRCASE (SpaceKind::Type, SpaceKind::Type): {
445-
// Optimization: The intersection of equal types is that type.
446-
if (this->getType()->isEqual(other.getType())) {
447-
return other;
448-
} else if (canDecompose(this->getType())) {
449-
SmallVector<Space, 4> spaces;
450-
decompose(TC, this->getType(), spaces);
451-
auto decomposition = examineDecomp(spaces);
452-
return decomposition.intersect(other, TC);
453-
} else if (canDecompose(other.getType())) {
454-
SmallVector<Space, 4> spaces;
455-
decompose(TC, other.getType(), spaces);
456-
auto disjunctSp = examineDecomp(spaces);
457-
return this->intersect(disjunctSp, TC);
458-
} else {
459-
return other;
460-
}
433+
return s.intersect(other, TC);
434+
});
435+
// Optimization: Remove all empty spaces.
436+
SmallVector<Space, 4> filteredCases;
437+
std::copy_if(intersectedCases.begin(), intersectedCases.end(),
438+
std::back_inserter(filteredCases),
439+
[&](const Space &s) {
440+
return !s.isEmpty();
441+
});
442+
return examineDecomp(filteredCases);
443+
}
444+
PAIRCASE (SpaceKind::Type, SpaceKind::Type): {
445+
// Optimization: The intersection of equal types is that type.
446+
if (this->getType()->isEqual(other.getType())) {
447+
return other;
448+
} else if (canDecompose(this->getType())) {
449+
SmallVector<Space, 4> spaces;
450+
decompose(TC, this->getType(), spaces);
451+
auto decomposition = examineDecomp(spaces);
452+
return decomposition.intersect(other, TC);
453+
} else if (canDecompose(other.getType())) {
454+
SmallVector<Space, 4> spaces;
455+
decompose(TC, other.getType(), spaces);
456+
auto disjunctSp = examineDecomp(spaces);
457+
return this->intersect(disjunctSp, TC);
458+
} else {
459+
return other;
461460
}
462-
PAIRCASE (SpaceKind::Type, SpaceKind::Constructor): {
463-
if (canDecompose(this->getType())) {
464-
SmallVector<Space, 4> spaces;
465-
decompose(TC, this->getType(), spaces);
466-
auto decomposition = examineDecomp(spaces);
467-
return decomposition.intersect(other, TC);
468-
} else {
469-
return other;
470-
}
461+
}
462+
PAIRCASE (SpaceKind::Type, SpaceKind::Constructor): {
463+
if (canDecompose(this->getType())) {
464+
SmallVector<Space, 4> spaces;
465+
decompose(TC, this->getType(), spaces);
466+
auto decomposition = examineDecomp(spaces);
467+
return decomposition.intersect(other, TC);
468+
} else {
469+
return other;
471470
}
472-
PAIRCASE (SpaceKind::Constructor, SpaceKind::Type):
473-
return *this;
471+
}
472+
PAIRCASE (SpaceKind::Constructor, SpaceKind::Type):
473+
return *this;
474474

475-
PAIRCASE (SpaceKind::Constructor, SpaceKind::Constructor): {
476-
// Optimization: If the heads don't match, the intersection of
477-
// the constructor spaces is empty.
478-
if (this->getHead().compare(other.Head) != 0) {
479-
return Space();
480-
}
475+
PAIRCASE (SpaceKind::Constructor, SpaceKind::Constructor): {
476+
// Optimization: If the heads don't match, the intersection of
477+
// the constructor spaces is empty.
478+
if (this->getHead().compare(other.Head) != 0) {
479+
return Space();
480+
}
481481

482-
// Special Case: A constructor pattern may include the head but not
483-
// the payload patterns. In that case, the intersection is the
484-
// whole original space.
485-
if (other.getSpaces().empty()) {
486-
return *this;
487-
}
482+
// Special Case: A constructor pattern may include the head but not
483+
// the payload patterns. In that case, the intersection is the
484+
// whole original space.
485+
if (other.getSpaces().empty()) {
486+
return *this;
487+
}
488488

489-
SmallVector<Space, 4> paramSpace;
490-
auto i = this->getSpaces().begin();
491-
auto j = other.getSpaces().begin();
492-
for (; i != this->getSpaces().end() && j != other.getSpaces().end();
493-
++i, ++j) {
494-
auto intersection = (*i).intersect(*j, TC);
495-
if (intersection.simplify(TC).isEmpty()) {
496-
return Space();
497-
}
498-
paramSpace.push_back(intersection);
489+
SmallVector<Space, 4> paramSpace;
490+
auto i = this->getSpaces().begin();
491+
auto j = other.getSpaces().begin();
492+
for (; i != this->getSpaces().end() && j != other.getSpaces().end();
493+
++i, ++j) {
494+
auto intersection = (*i).intersect(*j, TC);
495+
if (intersection.simplify(TC).isEmpty()) {
496+
return Space();
499497
}
500-
501-
return examineDecomp(paramSpace);
498+
paramSpace.push_back(intersection);
502499
}
503500

504-
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::BooleanConstant):
505-
return this->getBoolValue() == other.getBoolValue() ? *this : Space();
501+
return examineDecomp(paramSpace);
502+
}
506503

507-
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Type): {
508-
if (other.getType()->isBool()) {
509-
return this->getKind() == SpaceKind::BooleanConstant ? *this : Space();
510-
}
504+
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::BooleanConstant):
505+
return this->getBoolValue() == other.getBoolValue() ? *this : Space();
511506

512-
if (canDecompose(other.getType())) {
513-
SmallVector<Space, 4> spaces;
514-
decompose(TC, other.getType(), spaces);
515-
auto disjunctSp = examineDecomp(spaces);
516-
return this->intersect(disjunctSp, TC);
517-
}
518-
return Space();
507+
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Type): {
508+
if (other.getType()->isBool()) {
509+
return this->getKind() == SpaceKind::BooleanConstant ? *this : Space();
519510
}
520-
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Empty):
521-
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Constructor):
522-
return Space();
523511

524-
PAIRCASE (SpaceKind::Type, SpaceKind::BooleanConstant): {
525-
if (canDecompose(this->getType())) {
526-
SmallVector<Space, 4> spaces;
527-
decompose(TC, this->getType(), spaces);
528-
auto disjunctSp = examineDecomp(spaces);
529-
return disjunctSp.intersect(other, TC);
530-
} else {
531-
return Space();
532-
}
512+
if (canDecompose(other.getType())) {
513+
SmallVector<Space, 4> spaces;
514+
decompose(TC, other.getType(), spaces);
515+
auto disjunctSp = examineDecomp(spaces);
516+
return this->intersect(disjunctSp, TC);
533517
}
518+
return Space();
519+
}
520+
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Empty):
521+
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Constructor):
522+
return Space();
534523

535-
PAIRCASE (SpaceKind::Empty, SpaceKind::BooleanConstant):
536-
PAIRCASE (SpaceKind::Constructor, SpaceKind::BooleanConstant):
524+
PAIRCASE (SpaceKind::Type, SpaceKind::BooleanConstant): {
525+
if (canDecompose(this->getType())) {
526+
SmallVector<Space, 4> spaces;
527+
decompose(TC, this->getType(), spaces);
528+
auto disjunctSp = examineDecomp(spaces);
529+
return disjunctSp.intersect(other, TC);
530+
} else {
537531
return Space();
532+
}
533+
}
534+
535+
PAIRCASE (SpaceKind::Empty, SpaceKind::BooleanConstant):
536+
PAIRCASE (SpaceKind::Constructor, SpaceKind::BooleanConstant):
537+
return Space();
538538

539-
default:
540-
llvm_unreachable("Uncovered pair found while computing intersect?");
539+
default:
540+
llvm_unreachable("Uncovered pair found while computing intersect?");
541541
}
542542
}
543543

@@ -923,10 +923,11 @@ namespace {
923923
void checkExhaustiveness(bool limitedChecking) {
924924
if (limitedChecking) {
925925
// Reject switch statements with empty blocks.
926-
if (Switch->getCases().empty())
926+
if (Switch->getCases().empty()) {
927927
SpaceEngine::diagnoseMissingCases(TC, Switch,
928928
/*justNeedsDefault*/true,
929929
SpaceEngine::Space());
930+
}
930931
return;
931932
}
932933

@@ -1013,27 +1014,27 @@ namespace {
10131014
// @_downgrade_exhaustivity_check.
10141015
static bool shouldDowngradeToWarning(const Space &masterSpace) {
10151016
switch (masterSpace.getKind()) {
1016-
case SpaceKind::Type:
1017-
case SpaceKind::BooleanConstant:
1018-
case SpaceKind::Empty:
1019-
return false;
1020-
// Traverse the constructor and its subspaces.
1021-
case SpaceKind::Constructor:
1022-
return masterSpace.canDowngrade()
1023-
|| std::accumulate(masterSpace.getSpaces().begin(),
1024-
masterSpace.getSpaces().end(),
1025-
false,
1026-
[](bool acc, const Space &space) {
1027-
return acc || shouldDowngradeToWarning(space);
1028-
});
1029-
case SpaceKind::Disjunct:
1030-
// Traverse the disjunct's subspaces.
1031-
return std::accumulate(masterSpace.getSpaces().begin(),
1032-
masterSpace.getSpaces().end(),
1033-
false,
1034-
[](bool acc, const Space &space) {
1035-
return acc || shouldDowngradeToWarning(space);
1036-
});
1017+
case SpaceKind::Type:
1018+
case SpaceKind::BooleanConstant:
1019+
case SpaceKind::Empty:
1020+
return false;
1021+
// Traverse the constructor and its subspaces.
1022+
case SpaceKind::Constructor:
1023+
return masterSpace.canDowngrade()
1024+
|| std::accumulate(masterSpace.getSpaces().begin(),
1025+
masterSpace.getSpaces().end(),
1026+
false,
1027+
[](bool acc, const Space &space) {
1028+
return acc || shouldDowngradeToWarning(space);
1029+
});
1030+
case SpaceKind::Disjunct:
1031+
// Traverse the disjunct's subspaces.
1032+
return std::accumulate(masterSpace.getSpaces().begin(),
1033+
masterSpace.getSpaces().end(),
1034+
false,
1035+
[](bool acc, const Space &space) {
1036+
return acc || shouldDowngradeToWarning(space);
1037+
});
10371038
}
10381039
}
10391040

@@ -1109,7 +1110,6 @@ namespace {
11091110
TC.diagnose(startLoc, diag::non_exhaustive_switch);
11101111
TC.diagnose(startLoc, diag::missing_several_cases, false)
11111112
.fixItInsert(endLoc, buffer.str());
1112-
11131113
} else {
11141114
TC.Context.Diags.diagnose(startLoc, mainDiagType);
11151115

@@ -1238,8 +1238,7 @@ namespace {
12381238
case PatternKind::Named:
12391239
return Space(item->getType());
12401240
case PatternKind::Bool: {
1241-
auto *BP = cast<BoolPattern>(item);
1242-
return Space(BP->getValue());
1241+
return Space(cast<BoolPattern>(item)->getValue());
12431242
}
12441243
case PatternKind::Is: {
12451244
auto *IP = cast<IsPattern>(item);
@@ -1272,7 +1271,8 @@ namespace {
12721271
}
12731272
case PatternKind::OptionalSome: {
12741273
auto *OSP = cast<OptionalSomePattern>(item);
1275-
auto subSpace = projectPattern(TC, OSP->getSubPattern(), sawDowngradablePattern);
1274+
auto subSpace = projectPattern(TC, OSP->getSubPattern(),
1275+
sawDowngradablePattern);
12761276
// To match patterns like (_, _, ...)?, we must rewrite the underlying
12771277
// tuple pattern to .some(_, _, ...) first.
12781278
if (subSpace.getKind() == SpaceKind::Constructor
@@ -1283,8 +1283,8 @@ namespace {
12831283
SmallVector<Space, 1> payload = {
12841284
projectPattern(TC, OSP->getSubPattern(), sawDowngradablePattern)
12851285
};
1286-
return Space(item->getType(), TC.Context.getIdentifier("some"), /*canDowngrade*/false,
1287-
payload);
1286+
return Space(item->getType(), TC.Context.getIdentifier("some"),
1287+
/*canDowngrade*/false, payload);
12881288
}
12891289
case PatternKind::EnumElement: {
12901290
auto *VP = cast<EnumElementPattern>(item);

0 commit comments

Comments
 (0)