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