@@ -474,7 +474,6 @@ bool RewriteLoop::isInContext(const RewriteSystem &system) const {
474
474
// / minimization algorithm.
475
475
bool RewriteSystem::
476
476
isCandidateForDeletion (unsigned ruleID,
477
- bool firstPass,
478
477
const llvm::DenseSet<unsigned > *redundantConformances) const {
479
478
const auto &rule = getRule (ruleID);
480
479
@@ -493,22 +492,15 @@ isCandidateForDeletion(unsigned ruleID,
493
492
// Other rules involving unresolved name symbols are derived from an
494
493
// associated type introduction rule together with a conformance rule.
495
494
// They are eliminated in the first pass.
496
- if (firstPass)
497
- return rule.getLHS ().containsUnresolvedSymbols ();
498
-
499
- // In the second and third pass we should not have any rules involving
500
- // unresolved name symbols, except for permanent rules which were
501
- // already skipped above.
502
- //
503
- // FIXME: This isn't true with invalid code.
504
- assert (!rule.getLHS ().containsUnresolvedSymbols ());
495
+ if (rule.getLHS ().containsUnresolvedSymbols ())
496
+ return true ;
505
497
506
498
// Protocol conformance rules are eliminated via a different
507
499
// algorithm which computes "generating conformances".
508
500
//
509
- // The first and second passes skip protocol conformance rules.
501
+ // The first pass skips protocol conformance rules.
510
502
//
511
- // The third pass eliminates any protocol conformance rule which is
503
+ // The second pass eliminates any protocol conformance rule which is
512
504
// redundant according to both homotopy reduction and the generating
513
505
// conformances algorithm.
514
506
//
@@ -532,25 +524,19 @@ isCandidateForDeletion(unsigned ruleID,
532
524
// / once in empty context. Returns a redundant rule to delete if one was found,
533
525
// / otherwise returns None.
534
526
// /
535
- // / Minimization performs three passes over the rewrite system, with the
536
- // / \p firstPass and \p redundantConformances parameters as follows:
527
+ // / Minimization performs three passes over the rewrite system.
537
528
// /
538
- // / 1) First, rules involving unresolved name symbols are deleted, with
539
- // / \p firstPass equal to true and \p redundantConformances equal to nullptr.
529
+ // / 1) First, rules that are not conformance rules are deleted, with
530
+ // / \p redundantConformances equal to nullptr.
540
531
// /
541
- // / 2) Second, rules that are not conformance rules are deleted, with
542
- // / \p firstPass equal to false and \p redundantConformances equal to nullptr.
532
+ // / 2) Second, generating conformances are computed.
543
533
// /
544
- // / 3) Finally, conformance rules are deleted after computing a minimal set of
545
- // / generating conformances, with \p firstPass equal to false and
546
- // / \p redundantConformances equal to the set of conformance rules that are
534
+ // / 3) Finally, redundant conformance rules are deleted, with
535
+ // / \p redundantConformances equal to the set of conformance rules that are
547
536
// / not generating conformances.
548
537
Optional<unsigned > RewriteSystem::
549
- findRuleToDelete (bool firstPass,
550
- const llvm::DenseSet<unsigned > *redundantConformances,
538
+ findRuleToDelete (const llvm::DenseSet<unsigned > *redundantConformances,
551
539
RewritePath &replacementPath) {
552
- assert (!firstPass || redundantConformances == nullptr );
553
-
554
540
SmallVector<std::pair<unsigned , unsigned >, 2 > redundancyCandidates;
555
541
for (unsigned loopID : indices (Loops)) {
556
542
const auto &loop = Loops[loopID];
@@ -566,7 +552,7 @@ findRuleToDelete(bool firstPass,
566
552
567
553
for (const auto &pair : redundancyCandidates) {
568
554
unsigned ruleID = pair.second ;
569
- if (!isCandidateForDeletion (ruleID, firstPass, redundantConformances))
555
+ if (!isCandidateForDeletion (ruleID, redundantConformances))
570
556
continue ;
571
557
572
558
if (!found) {
@@ -665,12 +651,10 @@ void RewriteSystem::deleteRule(unsigned ruleID,
665
651
}
666
652
667
653
void RewriteSystem::performHomotopyReduction (
668
- bool firstPass,
669
654
const llvm::DenseSet<unsigned > *redundantConformances) {
670
655
while (true ) {
671
656
RewritePath replacementPath;
672
- auto optRuleID = findRuleToDelete (firstPass,
673
- redundantConformances,
657
+ auto optRuleID = findRuleToDelete (redundantConformances,
674
658
replacementPath);
675
659
676
660
// If no redundant rules remain which can be eliminated by this pass, stop.
@@ -703,13 +687,8 @@ void RewriteSystem::minimizeRewriteSystem() {
703
687
// Check invariants before homotopy reduction.
704
688
verifyRewriteLoops ();
705
689
706
- // First pass: Eliminate all redundant rules involving unresolved types.
707
- performHomotopyReduction (/* firstPass=*/ true ,
708
- /* redundantConformances=*/ nullptr );
709
-
710
- // Second pass: Eliminate all redundant rules that are not conformance rules.
711
- performHomotopyReduction (/* firstPass=*/ false ,
712
- /* redundantConformances=*/ nullptr );
690
+ // First pass: Eliminate all redundant rules that are not conformance rules.
691
+ performHomotopyReduction (/* redundantConformances=*/ nullptr );
713
692
714
693
// Now find a minimal set of generating conformances.
715
694
//
@@ -719,9 +698,8 @@ void RewriteSystem::minimizeRewriteSystem() {
719
698
llvm::DenseSet<unsigned > redundantConformances;
720
699
computeGeneratingConformances (redundantConformances);
721
700
722
- // Third pass: Eliminate all redundant conformance rules.
723
- performHomotopyReduction (/* firstPass=*/ false ,
724
- /* redundantConformances=*/ &redundantConformances);
701
+ // Second pass: Eliminate all redundant conformance rules.
702
+ performHomotopyReduction (/* redundantConformances=*/ &redundantConformances);
725
703
726
704
// Check invariants after homotopy reduction.
727
705
verifyRewriteLoops ();
0 commit comments