@@ -481,20 +481,20 @@ void RewriteSystem::minimizeRewriteSystem() {
481
481
propagateExplicitBits ();
482
482
483
483
// First pass:
484
- // - Eliminate all simplified non-conformance rules.
484
+ // - Eliminate all LHS-simplified non-conformance rules.
485
+ // - Eliminate all RHS-simplified and substitution-simplified rules.
485
486
// - Eliminate all rules with unresolved symbols.
486
487
performHomotopyReduction ([&](unsigned ruleID) -> bool {
487
488
const auto &rule = getRule (ruleID);
488
489
489
- if ((rule.isLHSSimplified () ||
490
- rule.isRHSSimplified () ||
491
- rule.isSubstitutionSimplified ()) &&
490
+ if (rule.isLHSSimplified () &&
492
491
!rule.isAnyConformanceRule ())
493
492
return true ;
494
493
495
- // Other rules involving unresolved name symbols are derived from an
496
- // associated type introduction rule together with a conformance rule.
497
- // They are eliminated in the first pass.
494
+ if (rule.isRHSSimplified () ||
495
+ rule.isSubstitutionSimplified ())
496
+ return true ;
497
+
498
498
if (rule.getLHS ().containsUnresolvedSymbols ())
499
499
return true ;
500
500
@@ -694,22 +694,31 @@ void RewriteSystem::verifyMinimizedRules(
694
694
continue ;
695
695
}
696
696
697
- // Simplified rules should be redundant, unless they're protocol conformance
698
- // rules, which unfortunately might no be redundant, because we try to keep
699
- // them in the original protocol definition for compatibility with the
700
- // GenericSignatureBuilder's minimization algorithm.
701
- if ((rule.isLHSSimplified () ||
702
- rule.isRHSSimplified () ||
703
- rule.isSubstitutionSimplified ()) &&
697
+ // LHS-simplified rules should be redundant, unless they're protocol
698
+ // conformance rules, which unfortunately might no be redundant, because
699
+ // we try to keep them in the original protocol definition for
700
+ // compatibility with the GenericSignatureBuilder's minimization algorithm.
701
+ if (rule.isLHSSimplified () &&
704
702
!rule.isRedundant () &&
705
703
!rule.isProtocolConformanceRule ()) {
706
704
llvm::errs () << " Simplified rule is not redundant: " << rule << " \n\n " ;
707
705
dump (llvm::errs ());
708
706
abort ();
709
707
}
710
708
709
+ // RHS-simplified and substitution-simplified rules should be redundant.
710
+ if ((rule.isRHSSimplified () ||
711
+ rule.isSubstitutionSimplified ()) &&
712
+ !rule.isRedundant ()) {
713
+ llvm::errs () << " Simplified rule is not redundant: " << rule << " \n\n " ;
714
+ dump (llvm::errs ());
715
+ abort ();
716
+ }
717
+
711
718
if (rule.isRedundant () &&
712
719
rule.isAnyConformanceRule () &&
720
+ !rule.isRHSSimplified () &&
721
+ !rule.isSubstitutionSimplified () &&
713
722
!rule.containsUnresolvedSymbols () &&
714
723
!redundantConformances.count (ruleID)) {
715
724
llvm::errs () << " Minimal conformance is redundant: " << rule << " \n\n " ;
0 commit comments