@@ -474,7 +474,6 @@ bool RewriteLoop::isInContext(const RewriteSystem &system) const {
474474// / minimization algorithm.
475475bool RewriteSystem::
476476isCandidateForDeletion (unsigned ruleID,
477- bool firstPass,
478477 const llvm::DenseSet<unsigned > *redundantConformances) const {
479478 const auto &rule = getRule (ruleID);
480479
@@ -493,22 +492,15 @@ isCandidateForDeletion(unsigned ruleID,
493492 // Other rules involving unresolved name symbols are derived from an
494493 // associated type introduction rule together with a conformance rule.
495494 // 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 ;
505497
506498 // Protocol conformance rules are eliminated via a different
507499 // algorithm which computes "generating conformances".
508500 //
509- // The first and second passes skip protocol conformance rules.
501+ // The first pass skips protocol conformance rules.
510502 //
511- // The third pass eliminates any protocol conformance rule which is
503+ // The second pass eliminates any protocol conformance rule which is
512504 // redundant according to both homotopy reduction and the generating
513505 // conformances algorithm.
514506 //
@@ -532,25 +524,19 @@ isCandidateForDeletion(unsigned ruleID,
532524// / once in empty context. Returns a redundant rule to delete if one was found,
533525// / otherwise returns None.
534526// /
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.
537528// /
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.
540531// /
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.
543533// /
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
547536// / not generating conformances.
548537Optional<unsigned > RewriteSystem::
549- findRuleToDelete (bool firstPass,
550- const llvm::DenseSet<unsigned > *redundantConformances,
538+ findRuleToDelete (const llvm::DenseSet<unsigned > *redundantConformances,
551539 RewritePath &replacementPath) {
552- assert (!firstPass || redundantConformances == nullptr );
553-
554540 SmallVector<std::pair<unsigned , unsigned >, 2 > redundancyCandidates;
555541 for (unsigned loopID : indices (Loops)) {
556542 const auto &loop = Loops[loopID];
@@ -566,7 +552,7 @@ findRuleToDelete(bool firstPass,
566552
567553 for (const auto &pair : redundancyCandidates) {
568554 unsigned ruleID = pair.second ;
569- if (!isCandidateForDeletion (ruleID, firstPass, redundantConformances))
555+ if (!isCandidateForDeletion (ruleID, redundantConformances))
570556 continue ;
571557
572558 if (!found) {
@@ -665,12 +651,10 @@ void RewriteSystem::deleteRule(unsigned ruleID,
665651}
666652
667653void RewriteSystem::performHomotopyReduction (
668- bool firstPass,
669654 const llvm::DenseSet<unsigned > *redundantConformances) {
670655 while (true ) {
671656 RewritePath replacementPath;
672- auto optRuleID = findRuleToDelete (firstPass,
673- redundantConformances,
657+ auto optRuleID = findRuleToDelete (redundantConformances,
674658 replacementPath);
675659
676660 // If no redundant rules remain which can be eliminated by this pass, stop.
@@ -703,13 +687,8 @@ void RewriteSystem::minimizeRewriteSystem() {
703687 // Check invariants before homotopy reduction.
704688 verifyRewriteLoops ();
705689
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 );
713692
714693 // Now find a minimal set of generating conformances.
715694 //
@@ -719,9 +698,8 @@ void RewriteSystem::minimizeRewriteSystem() {
719698 llvm::DenseSet<unsigned > redundantConformances;
720699 computeGeneratingConformances (redundantConformances);
721700
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);
725703
726704 // Check invariants after homotopy reduction.
727705 verifyRewriteLoops ();
0 commit comments