@@ -223,10 +223,17 @@ namespace {
223
223
}
224
224
static Space forConstructor (Type T, Identifier H, bool downgrade,
225
225
ArrayRef<Space> SP) {
226
+ if (llvm::any_of (SP, std::mem_fn (&Space::isEmpty))) {
227
+ // A constructor with an unconstructible parameter can never actually
228
+ // be used.
229
+ return Space ();
230
+ }
226
231
return Space (T, H, downgrade, SP);
227
232
}
228
233
static Space forConstructor (Type T, Identifier H, bool downgrade,
229
234
std::forward_list<Space> SP) {
235
+ // No need to filter SP here; this is only used to copy other
236
+ // Constructor spaces.
230
237
return Space (T, H, downgrade, SP);
231
238
}
232
239
static Space forBool (bool C) {
@@ -495,9 +502,11 @@ namespace {
495
502
}
496
503
}
497
504
505
+ // / Convenience declaration to make the intersection operation look more
506
+ // / symmetric.
498
507
static Space intersect (const Space &a, const Space &b, TypeChecker &TC,
499
508
const DeclContext *DC) {
500
- return a.intersect (b, TC, DC). simplify (TC, DC) ;
509
+ return a.intersect (b, TC, DC);
501
510
}
502
511
503
512
// Returns the intersection of this space with another. The intersection
@@ -738,13 +747,12 @@ namespace {
738
747
PAIRCASE (SpaceKind::Constructor, SpaceKind::UnknownCase): {
739
748
SmallVector<Space, 4 > newSubSpaces;
740
749
for (auto subSpace : this ->getSpaces ()) {
741
- auto diff = subSpace.minus (other, TC, DC, minusCount);
742
- if (!diff )
750
+ auto nextSpace = subSpace.minus (other, TC, DC, minusCount);
751
+ if (!nextSpace )
743
752
return None;
744
- auto nextSpace = diff->simplify (TC, DC);
745
- if (nextSpace.isEmpty ())
753
+ if (nextSpace.getValue ().isEmpty ())
746
754
return Space ();
747
- newSubSpaces.push_back (nextSpace);
755
+ newSubSpaces.push_back (nextSpace. getValue () );
748
756
}
749
757
return Space::forConstructor (this ->getType (), this ->getHead (),
750
758
this ->canDowngradeToWarning (),
@@ -949,59 +957,6 @@ namespace {
949
957
}
950
958
}
951
959
952
- // For optimization, attempt to simplify a space by removing any empty
953
- // cases and unpacking empty or singular disjunctions where possible.
954
- Space simplify (TypeChecker &TC, const DeclContext *DC) const {
955
- switch (getKind ()) {
956
- case SpaceKind::Constructor: {
957
- // If a constructor has no spaces it is an enum without a payload and
958
- // cannot be optimized further.
959
- if (getSpaces ().empty ()) {
960
- return *this ;
961
- }
962
-
963
- // Simplify each component subspace. If, after simplification, any
964
- // subspace contains an empty, then the whole space is empty.
965
- SmallVector<Space, 4 > simplifiedSpaces;
966
- for (const auto &space : Spaces) {
967
- auto simplified = space.simplify (TC, DC);
968
- if (simplified.isEmpty ())
969
- return Space ();
970
-
971
- simplifiedSpaces.push_back (simplified);
972
- }
973
-
974
- return Space::forConstructor (getType (), Head, canDowngradeToWarning (),
975
- simplifiedSpaces);
976
- }
977
- case SpaceKind::Type: {
978
- // If the decomposition of a space is empty, the space is empty.
979
- if (canDecompose (this ->getType (), DC)) {
980
- SmallVector<Space, 4 > ss;
981
- decompose (TC, DC, this ->getType (), ss);
982
- if (ss.empty ()) {
983
- return Space ();
984
- }
985
- return *this ;
986
- } else {
987
- return *this ;
988
- }
989
- }
990
- case SpaceKind::Disjunct: {
991
- // Simplify each disjunct.
992
- SmallVector<Space, 4 > simplifiedSpaces;
993
- std::transform (Spaces.begin (), Spaces.end (),
994
- std::back_inserter (simplifiedSpaces),
995
- [&](const Space &el){
996
- return el.simplify (TC, DC);
997
- });
998
- return Space::forDisjunct (simplifiedSpaces);
999
- }
1000
- default :
1001
- return *this ;
1002
- }
1003
- }
1004
-
1005
960
static bool isSwift3DowngradeExhaustivityCase (TypeChecker &TC,
1006
961
const EnumElementDecl *eed){
1007
962
if (TC.getLangOpts ().isSwiftVersionAtLeast (4 ))
@@ -1270,7 +1225,7 @@ namespace {
1270
1225
return ;
1271
1226
}
1272
1227
1273
- auto uncovered = diff-> simplify (TC, DC );
1228
+ auto uncovered = diff. getValue ( );
1274
1229
if (unknownCase && uncovered.isEmpty ()) {
1275
1230
TC.diagnose (unknownCase->getLoc (), diag::redundant_particular_case)
1276
1231
.highlight (unknownCase->getSourceRange ());
@@ -1281,7 +1236,6 @@ namespace {
1281
1236
// that are implicitly frozen.
1282
1237
uncovered = *uncovered.minus (Space::forUnknown (unknownCase == nullptr ),
1283
1238
TC, DC, /* &minusCount*/ nullptr );
1284
- uncovered = uncovered.simplify (TC, DC);
1285
1239
1286
1240
if (uncovered.isEmpty ())
1287
1241
return ;
0 commit comments