Merge pull request #10169 from CodaFi/sweeps

[NFC] Run clang format on the space engine
diff --git a/lib/Sema/TypeCheckSwitchStmt.cpp b/lib/Sema/TypeCheckSwitchStmt.cpp
index 4940d1e..fdd5280 100644
--- a/lib/Sema/TypeCheckSwitchStmt.cpp
+++ b/lib/Sema/TypeCheckSwitchStmt.cpp
@@ -134,11 +134,11 @@
       }
       
     public:
-      explicit
-      Space(Type T)
+      explicit Space(Type T)
         : Kind(SpaceKind::Type), TypeAndVal(T, false), Head(Identifier()),
           Spaces({}){}
-      explicit Space(Type T, Identifier H, bool downgrade, SmallVectorImpl<Space> &SP)
+      explicit Space(Type T, Identifier H, bool downgrade,
+                     SmallVectorImpl<Space> &SP)
         : Kind(SpaceKind::Constructor), TypeAndVal(T, downgrade), Head(H),
           Spaces(SP.begin(), SP.end()) {}
       explicit Space(Type T, Identifier H, bool downgrade,
@@ -399,145 +399,145 @@
         };
 
         switch (PairSwitch(getKind(), other.getKind())) {
-          PAIRCASE (SpaceKind::Empty, SpaceKind::Disjunct):
-          PAIRCASE (SpaceKind::Type, SpaceKind::Disjunct):
-          PAIRCASE (SpaceKind::Constructor, SpaceKind::Disjunct):
-          PAIRCASE (SpaceKind::Disjunct, SpaceKind::Disjunct):
-          PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Disjunct): {
-            // S & (S1 || ... || Sn) iff (S & S1) && ... && (S & Sn)
-            SmallVector<Space, 4> intersectedCases;
-            std::transform(other.getSpaces().begin(), other.getSpaces().end(),
-                           std::back_inserter(intersectedCases),
-                           [&](const Space &s) {
-              return this->intersect(s, TC);
-            });
-            // Optimization: Remove all empty spaces.
-            SmallVector<Space, 4> filteredCases;
-            std::copy_if(intersectedCases.begin(), intersectedCases.end(),
-                         std::back_inserter(filteredCases),
+        PAIRCASE (SpaceKind::Empty, SpaceKind::Disjunct):
+        PAIRCASE (SpaceKind::Type, SpaceKind::Disjunct):
+        PAIRCASE (SpaceKind::Constructor, SpaceKind::Disjunct):
+        PAIRCASE (SpaceKind::Disjunct, SpaceKind::Disjunct):
+        PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Disjunct): {
+          // S & (S1 || ... || Sn) iff (S & S1) && ... && (S & Sn)
+          SmallVector<Space, 4> intersectedCases;
+          std::transform(other.getSpaces().begin(), other.getSpaces().end(),
+                         std::back_inserter(intersectedCases),
                          [&](const Space &s) {
-              return !s.isEmpty();
-            });
-            return examineDecomp(filteredCases);
-          }
+            return this->intersect(s, TC);
+          });
+          // Optimization: Remove all empty spaces.
+          SmallVector<Space, 4> filteredCases;
+          std::copy_if(intersectedCases.begin(), intersectedCases.end(),
+                       std::back_inserter(filteredCases),
+                       [&](const Space &s) {
+            return !s.isEmpty();
+          });
+          return examineDecomp(filteredCases);
+        }
 
-          PAIRCASE (SpaceKind::Disjunct, SpaceKind::Empty):
-          PAIRCASE (SpaceKind::Disjunct, SpaceKind::Type):
-          PAIRCASE (SpaceKind::Disjunct, SpaceKind::Constructor):
-          PAIRCASE (SpaceKind::Disjunct, SpaceKind::BooleanConstant): {
-            // (S1 || ... || Sn) & S iff (S & S1) && ... && (S & Sn)
-            SmallVector<Space, 4> intersectedCases;
-            std::transform(this->getSpaces().begin(), this->getSpaces().end(),
-                           std::back_inserter(intersectedCases),
-                           [&](const Space &s) {
-              return s.intersect(other, TC);
-            });
-            // Optimization: Remove all empty spaces.
-            SmallVector<Space, 4> filteredCases;
-            std::copy_if(intersectedCases.begin(), intersectedCases.end(),
-                         std::back_inserter(filteredCases),
+        PAIRCASE (SpaceKind::Disjunct, SpaceKind::Empty):
+        PAIRCASE (SpaceKind::Disjunct, SpaceKind::Type):
+        PAIRCASE (SpaceKind::Disjunct, SpaceKind::Constructor):
+        PAIRCASE (SpaceKind::Disjunct, SpaceKind::BooleanConstant): {
+          // (S1 || ... || Sn) & S iff (S & S1) && ... && (S & Sn)
+          SmallVector<Space, 4> intersectedCases;
+          std::transform(this->getSpaces().begin(), this->getSpaces().end(),
+                         std::back_inserter(intersectedCases),
                          [&](const Space &s) {
-              return !s.isEmpty();
-            });
-            return examineDecomp(filteredCases);
+            return s.intersect(other, TC);
+          });
+          // Optimization: Remove all empty spaces.
+          SmallVector<Space, 4> filteredCases;
+          std::copy_if(intersectedCases.begin(), intersectedCases.end(),
+                       std::back_inserter(filteredCases),
+                       [&](const Space &s) {
+            return !s.isEmpty();
+          });
+          return examineDecomp(filteredCases);
+        }
+        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())) {
+            SmallVector<Space, 4> spaces;
+            decompose(TC, this->getType(), spaces);
+            auto decomposition = examineDecomp(spaces);
+            return decomposition.intersect(other, TC);
+          } else if (canDecompose(other.getType())) {
+            SmallVector<Space, 4> spaces;
+            decompose(TC, other.getType(), spaces);
+            auto disjunctSp = examineDecomp(spaces);
+            return this->intersect(disjunctSp, TC);
+          } else {
+            return other;
           }
-          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())) {
-              SmallVector<Space, 4> spaces;
-              decompose(TC, this->getType(), spaces);
-              auto decomposition = examineDecomp(spaces);
-              return decomposition.intersect(other, TC);
-            } else if (canDecompose(other.getType())) {
-              SmallVector<Space, 4> spaces;
-              decompose(TC, other.getType(), spaces);
-              auto disjunctSp = examineDecomp(spaces);
-              return this->intersect(disjunctSp, TC);
-            } else {
-              return other;
-            }
+        }
+        PAIRCASE (SpaceKind::Type, SpaceKind::Constructor): {
+          if (canDecompose(this->getType())) {
+            SmallVector<Space, 4> spaces;
+            decompose(TC, this->getType(), spaces);
+            auto decomposition = examineDecomp(spaces);
+            return decomposition.intersect(other, TC);
+          } else {
+            return other;
           }
-          PAIRCASE (SpaceKind::Type, SpaceKind::Constructor): {
-            if (canDecompose(this->getType())) {
-              SmallVector<Space, 4> spaces;
-              decompose(TC, this->getType(), spaces);
-              auto decomposition = examineDecomp(spaces);
-              return decomposition.intersect(other, TC);
-            } else {
-              return other;
-            }
-          }
-          PAIRCASE (SpaceKind::Constructor, SpaceKind::Type):
-            return *this;
+        }
+        PAIRCASE (SpaceKind::Constructor, SpaceKind::Type):
+          return *this;
             
-          PAIRCASE (SpaceKind::Constructor, SpaceKind::Constructor): {
-            // Optimization: If the heads don't match, the intersection of
-            // the constructor spaces is empty.
-            if (this->getHead().compare(other.Head) != 0) {
+        PAIRCASE (SpaceKind::Constructor, SpaceKind::Constructor): {
+          // Optimization: If the heads don't match, the intersection of
+          // the constructor spaces is empty.
+          if (this->getHead().compare(other.Head) != 0) {
+            return Space();
+          }
+
+          // Special Case: A constructor pattern may include the head but not
+          // the payload patterns.  In that case, the intersection is the
+          // whole original space.
+          if (other.getSpaces().empty()) {
+            return *this;
+          }
+
+          SmallVector<Space, 4> paramSpace;
+          auto i = this->getSpaces().begin();
+          auto j = other.getSpaces().begin();
+          for (; i != this->getSpaces().end() && j != other.getSpaces().end();
+               ++i, ++j) {
+            auto intersection = (*i).intersect(*j, TC);
+            if (intersection.simplify(TC).isEmpty()) {
               return Space();
             }
-
-            // Special Case: A constructor pattern may include the head but not
-            // the payload patterns.  In that case, the intersection is the
-            // whole original space.
-            if (other.getSpaces().empty()) {
-              return *this;
-            }
-
-            SmallVector<Space, 4> paramSpace;
-            auto i = this->getSpaces().begin();
-            auto j = other.getSpaces().begin();
-            for (; i != this->getSpaces().end() && j != other.getSpaces().end();
-                 ++i, ++j) {
-              auto intersection = (*i).intersect(*j, TC);
-              if (intersection.simplify(TC).isEmpty()) {
-                return Space();
-              }
-              paramSpace.push_back(intersection);
-            }
-
-            return examineDecomp(paramSpace);
+            paramSpace.push_back(intersection);
           }
 
-          PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::BooleanConstant):
-            return this->getBoolValue() == other.getBoolValue() ? *this : Space();
+          return examineDecomp(paramSpace);
+        }
 
-          PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Type): {
-            if (other.getType()->isBool()) {
-              return this->getKind() == SpaceKind::BooleanConstant ? *this : Space();
-            }
+        PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::BooleanConstant):
+          return this->getBoolValue() == other.getBoolValue() ? *this : Space();
 
-            if (canDecompose(other.getType())) {
-              SmallVector<Space, 4> spaces;
-              decompose(TC, other.getType(), spaces);
-              auto disjunctSp = examineDecomp(spaces);
-              return this->intersect(disjunctSp, TC);
-            }
-            return Space();
-          }
-          PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Empty):
-          PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Constructor):
-            return Space();
-
-          PAIRCASE (SpaceKind::Type, SpaceKind::BooleanConstant): {
-            if (canDecompose(this->getType())) {
-              SmallVector<Space, 4> spaces;
-              decompose(TC, this->getType(), spaces);
-              auto disjunctSp = examineDecomp(spaces);
-              return disjunctSp.intersect(other, TC);
-            } else {
-              return Space();
-            }
+        PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Type): {
+          if (other.getType()->isBool()) {
+            return this->getKind() == SpaceKind::BooleanConstant ? *this : Space();
           }
 
-          PAIRCASE (SpaceKind::Empty, SpaceKind::BooleanConstant):
-          PAIRCASE (SpaceKind::Constructor, SpaceKind::BooleanConstant):
-            return Space();
+          if (canDecompose(other.getType())) {
+            SmallVector<Space, 4> spaces;
+            decompose(TC, other.getType(), spaces);
+            auto disjunctSp = examineDecomp(spaces);
+            return this->intersect(disjunctSp, TC);
+          }
+          return Space();
+        }
+        PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Empty):
+        PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Constructor):
+          return Space();
 
-          default:
-            llvm_unreachable("Uncovered pair found while computing intersect?");
+        PAIRCASE (SpaceKind::Type, SpaceKind::BooleanConstant): {
+          if (canDecompose(this->getType())) {
+            SmallVector<Space, 4> spaces;
+            decompose(TC, this->getType(), spaces);
+            auto disjunctSp = examineDecomp(spaces);
+            return disjunctSp.intersect(other, TC);
+          } else {
+            return Space();
+          }
+        }
+
+        PAIRCASE (SpaceKind::Empty, SpaceKind::BooleanConstant):
+        PAIRCASE (SpaceKind::Constructor, SpaceKind::BooleanConstant):
+          return Space();
+
+        default:
+          llvm_unreachable("Uncovered pair found while computing intersect?");
         }
       }
 
@@ -923,10 +923,11 @@
     void checkExhaustiveness(bool limitedChecking) {
       if (limitedChecking) {
         // Reject switch statements with empty blocks.
-        if (Switch->getCases().empty())
+        if (Switch->getCases().empty()) {
           SpaceEngine::diagnoseMissingCases(TC, Switch,
                                             /*justNeedsDefault*/true,
                                             SpaceEngine::Space());
+        }
         return;
       }
 
@@ -1013,27 +1014,27 @@
     // @_downgrade_exhaustivity_check.
     static bool shouldDowngradeToWarning(const Space &masterSpace) {
       switch (masterSpace.getKind()) {
-        case SpaceKind::Type:
-        case SpaceKind::BooleanConstant:
-        case SpaceKind::Empty:
-          return false;
-        // Traverse the constructor and its subspaces.
-        case SpaceKind::Constructor:
-          return masterSpace.canDowngrade()
-              || std::accumulate(masterSpace.getSpaces().begin(),
-                                 masterSpace.getSpaces().end(),
-                                false,
-                                [](bool acc, const Space &space) {
-            return acc || shouldDowngradeToWarning(space);
-          });
-        case SpaceKind::Disjunct:
-          // Traverse the disjunct's subspaces.
-          return std::accumulate(masterSpace.getSpaces().begin(),
-                                 masterSpace.getSpaces().end(),
-                                 false,
-                                 [](bool acc, const Space &space) {
-                                   return acc || shouldDowngradeToWarning(space);
-                                 });
+      case SpaceKind::Type:
+      case SpaceKind::BooleanConstant:
+      case SpaceKind::Empty:
+        return false;
+      // Traverse the constructor and its subspaces.
+      case SpaceKind::Constructor:
+        return masterSpace.canDowngrade()
+            || std::accumulate(masterSpace.getSpaces().begin(),
+                               masterSpace.getSpaces().end(),
+                              false,
+                              [](bool acc, const Space &space) {
+          return acc || shouldDowngradeToWarning(space);
+        });
+      case SpaceKind::Disjunct:
+        // Traverse the disjunct's subspaces.
+        return std::accumulate(masterSpace.getSpaces().begin(),
+                               masterSpace.getSpaces().end(),
+                               false,
+                               [](bool acc, const Space &space) {
+                                 return acc || shouldDowngradeToWarning(space);
+                               });
       }
     }
 
@@ -1109,7 +1110,6 @@
         TC.diagnose(startLoc, diag::non_exhaustive_switch);
         TC.diagnose(startLoc, diag::missing_several_cases, false)
           .fixItInsert(endLoc, buffer.str());
-
       } else {
         TC.Context.Diags.diagnose(startLoc, mainDiagType);
 
@@ -1238,8 +1238,7 @@
       case PatternKind::Named:
         return Space(item->getType());
       case PatternKind::Bool: {
-        auto *BP = cast<BoolPattern>(item);
-        return Space(BP->getValue());
+        return Space(cast<BoolPattern>(item)->getValue());
       }
       case PatternKind::Is: {
         auto *IP = cast<IsPattern>(item);
@@ -1272,7 +1271,8 @@
       }
       case PatternKind::OptionalSome: {
         auto *OSP = cast<OptionalSomePattern>(item);
-        auto subSpace = projectPattern(TC, OSP->getSubPattern(), sawDowngradablePattern);
+        auto subSpace = projectPattern(TC, OSP->getSubPattern(),
+                                       sawDowngradablePattern);
         // To match patterns like (_, _, ...)?, we must rewrite the underlying
         // tuple pattern to .some(_, _, ...) first.
         if (subSpace.getKind() == SpaceKind::Constructor
@@ -1283,8 +1283,8 @@
         SmallVector<Space, 1> payload = {
           projectPattern(TC, OSP->getSubPattern(), sawDowngradablePattern)
         };
-        return Space(item->getType(), TC.Context.getIdentifier("some"), /*canDowngrade*/false,
-                     payload);
+        return Space(item->getType(), TC.Context.getIdentifier("some"),
+                     /*canDowngrade*/false, payload);
       }
       case PatternKind::EnumElement: {
         auto *VP = cast<EnumElementPattern>(item);