@@ -805,11 +805,18 @@ void RewriteSystem::minimizeRewriteSystem() {
805
805
// First pass:
806
806
// - Eliminate all LHS-simplified non-conformance rules.
807
807
// - Eliminate all RHS-simplified and substitution-simplified rules.
808
- // - Eliminate all rules with unresolved symbols.
808
+ //
809
+ // An example of a conformance rule that is LHS-simplified but not
810
+ // RHS-simplified is (T.[P] => T) where T is irreducible, but there
811
+ // is a rule (V.[P] => V) for some V with T == U.V.
812
+ //
813
+ // Such conformance rules can still be minimal, as part of a hack to
814
+ // maintain compatibility with the GenericSignatureBuilder's minimization
815
+ // algorithm.
809
816
if (Debug.contains (DebugFlags::HomotopyReduction)) {
810
- llvm::dbgs () << " --------------------------------------------- \n " ;
811
- llvm::dbgs () << " First pass: simplified and unresolved rules -\n " ;
812
- llvm::dbgs () << " --------------------------------------------- \n " ;
817
+ llvm::dbgs () << " ------------------------------\n " ;
818
+ llvm::dbgs () << " First pass: simplified rules -\n " ;
819
+ llvm::dbgs () << " ------------------------------\n " ;
813
820
}
814
821
815
822
performHomotopyReduction ([&](unsigned loopID, unsigned ruleID) -> bool {
@@ -823,8 +830,31 @@ void RewriteSystem::minimizeRewriteSystem() {
823
830
rule.isSubstitutionSimplified ())
824
831
return true ;
825
832
826
- if (rule.containsUnresolvedSymbols () &&
827
- !rule.isProtocolTypeAliasRule ())
833
+ return false ;
834
+ });
835
+
836
+ // Second pass:
837
+ // - Eliminate all rules with unresolved symbols which were *not*
838
+ // simplified.
839
+ //
840
+ // Two examples of such rules:
841
+ //
842
+ // - (T.X => T.[P:X]) obtained from resolving the overlap between
843
+ // (T.[P] => T) and ([P].X => [P:X]).
844
+ //
845
+ // - (T.X.[concrete: C] => T.X) obtained from resolving the overlap
846
+ // between (T.[P] => T) and a protocol typealias rule
847
+ // ([P].X.[concrete: C] => [P].X).
848
+ if (Debug.contains (DebugFlags::HomotopyReduction)) {
849
+ llvm::dbgs () << " -------------------------------\n " ;
850
+ llvm::dbgs () << " Second pass: unresolved rules -\n " ;
851
+ llvm::dbgs () << " -------------------------------\n " ;
852
+ }
853
+
854
+ performHomotopyReduction ([&](unsigned loopID, unsigned ruleID) -> bool {
855
+ const auto &rule = getRule (ruleID);
856
+
857
+ if (rule.containsUnresolvedSymbols ())
828
858
return true ;
829
859
830
860
return false ;
@@ -840,11 +870,11 @@ void RewriteSystem::minimizeRewriteSystem() {
840
870
llvm::DenseSet<unsigned > redundantConformances;
841
871
computeMinimalConformances (redundantConformances);
842
872
843
- // Second pass: Eliminate all non-minimal conformance rules.
873
+ // Third pass: Eliminate all non-minimal conformance rules.
844
874
if (Debug.contains (DebugFlags::HomotopyReduction)) {
845
- llvm::dbgs () << " -------------------------------------------- \n " ;
846
- llvm::dbgs () << " Second pass: non-minimal conformance rules -\n " ;
847
- llvm::dbgs () << " -------------------------------------------- \n " ;
875
+ llvm::dbgs () << " -------------------------------------------\n " ;
876
+ llvm::dbgs () << " Third pass: non-minimal conformance rules -\n " ;
877
+ llvm::dbgs () << " -------------------------------------------\n " ;
848
878
}
849
879
850
880
performHomotopyReduction ([&](unsigned loopID, unsigned ruleID) -> bool {
@@ -857,11 +887,11 @@ void RewriteSystem::minimizeRewriteSystem() {
857
887
return false ;
858
888
});
859
889
860
- // Third pass: Eliminate all other redundant non-conformance rules.
890
+ // Fourth pass: Eliminate all remaining redundant non-conformance rules.
861
891
if (Debug.contains (DebugFlags::HomotopyReduction)) {
862
- llvm::dbgs () << " ---------------------------------------\n " ;
863
- llvm::dbgs () << " Third pass: all other redundant rules -\n " ;
864
- llvm::dbgs () << " ---------------------------------------\n " ;
892
+ llvm::dbgs () << " ---------------------------------------- \n " ;
893
+ llvm::dbgs () << " Fourth pass: all other redundant rules -\n " ;
894
+ llvm::dbgs () << " ---------------------------------------- \n " ;
865
895
}
866
896
867
897
performHomotopyReduction ([&](unsigned loopID, unsigned ruleID) -> bool {
0 commit comments