@@ -134,11 +134,11 @@ namespace {
134
134
}
135
135
136
136
public:
137
- explicit
138
- Space (Type T)
137
+ explicit Space (Type T)
139
138
: Kind (SpaceKind::Type), TypeAndVal (T, false ), Head (Identifier ()),
140
139
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)
142
142
: Kind (SpaceKind::Constructor), TypeAndVal (T, downgrade), Head (H),
143
143
Spaces (SP.begin (), SP.end ()) {}
144
144
explicit Space (Type T, Identifier H, bool downgrade,
@@ -399,145 +399,145 @@ namespace {
399
399
};
400
400
401
401
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),
418
411
[&](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
+ }
423
423
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),
439
432
[&](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;
461
460
}
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;
471
470
}
472
- PAIRCASE (SpaceKind::Constructor, SpaceKind::Type):
473
- return *this ;
471
+ }
472
+ PAIRCASE (SpaceKind::Constructor, SpaceKind::Type):
473
+ return *this ;
474
474
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
+ }
481
481
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
+ }
488
488
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 ();
499
497
}
500
-
501
- return examineDecomp (paramSpace);
498
+ paramSpace.push_back (intersection);
502
499
}
503
500
504
- PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::BooleanConstant):
505
- return this -> getBoolValue () == other. getBoolValue () ? * this : Space ();
501
+ return examineDecomp (paramSpace);
502
+ }
506
503
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 ();
511
506
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 ();
519
510
}
520
- PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Empty):
521
- PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Constructor):
522
- return Space ();
523
511
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);
533
517
}
518
+ return Space ();
519
+ }
520
+ PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Empty):
521
+ PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Constructor):
522
+ return Space ();
534
523
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 {
537
531
return Space ();
532
+ }
533
+ }
534
+
535
+ PAIRCASE (SpaceKind::Empty, SpaceKind::BooleanConstant):
536
+ PAIRCASE (SpaceKind::Constructor, SpaceKind::BooleanConstant):
537
+ return Space ();
538
538
539
- default :
540
- llvm_unreachable (" Uncovered pair found while computing intersect?" );
539
+ default :
540
+ llvm_unreachable (" Uncovered pair found while computing intersect?" );
541
541
}
542
542
}
543
543
@@ -923,10 +923,11 @@ namespace {
923
923
void checkExhaustiveness (bool limitedChecking) {
924
924
if (limitedChecking) {
925
925
// Reject switch statements with empty blocks.
926
- if (Switch->getCases ().empty ())
926
+ if (Switch->getCases ().empty ()) {
927
927
SpaceEngine::diagnoseMissingCases (TC, Switch,
928
928
/* justNeedsDefault*/ true ,
929
929
SpaceEngine::Space ());
930
+ }
930
931
return ;
931
932
}
932
933
@@ -1013,27 +1014,27 @@ namespace {
1013
1014
// @_downgrade_exhaustivity_check.
1014
1015
static bool shouldDowngradeToWarning (const Space &masterSpace) {
1015
1016
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
+ });
1037
1038
}
1038
1039
}
1039
1040
@@ -1109,7 +1110,6 @@ namespace {
1109
1110
TC.diagnose (startLoc, diag::non_exhaustive_switch);
1110
1111
TC.diagnose (startLoc, diag::missing_several_cases, false )
1111
1112
.fixItInsert (endLoc, buffer.str ());
1112
-
1113
1113
} else {
1114
1114
TC.Context .Diags .diagnose (startLoc, mainDiagType);
1115
1115
@@ -1238,8 +1238,7 @@ namespace {
1238
1238
case PatternKind::Named:
1239
1239
return Space (item->getType ());
1240
1240
case PatternKind::Bool: {
1241
- auto *BP = cast<BoolPattern>(item);
1242
- return Space (BP->getValue ());
1241
+ return Space (cast<BoolPattern>(item)->getValue ());
1243
1242
}
1244
1243
case PatternKind::Is: {
1245
1244
auto *IP = cast<IsPattern>(item);
@@ -1272,7 +1271,8 @@ namespace {
1272
1271
}
1273
1272
case PatternKind::OptionalSome: {
1274
1273
auto *OSP = cast<OptionalSomePattern>(item);
1275
- auto subSpace = projectPattern (TC, OSP->getSubPattern (), sawDowngradablePattern);
1274
+ auto subSpace = projectPattern (TC, OSP->getSubPattern (),
1275
+ sawDowngradablePattern);
1276
1276
// To match patterns like (_, _, ...)?, we must rewrite the underlying
1277
1277
// tuple pattern to .some(_, _, ...) first.
1278
1278
if (subSpace.getKind () == SpaceKind::Constructor
@@ -1283,8 +1283,8 @@ namespace {
1283
1283
SmallVector<Space, 1 > payload = {
1284
1284
projectPattern (TC, OSP->getSubPattern (), sawDowngradablePattern)
1285
1285
};
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);
1288
1288
}
1289
1289
case PatternKind::EnumElement: {
1290
1290
auto *VP = cast<EnumElementPattern>(item);
0 commit comments