Skip to content

Commit 3641b77

Browse files
committed
RequirementMachine: Split up first pass of homotopy reduction into two
Add a separate pass to consider rules with unresolved names which are not simplified.
1 parent f082c02 commit 3641b77

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -805,11 +805,18 @@ void RewriteSystem::minimizeRewriteSystem() {
805805
// First pass:
806806
// - Eliminate all LHS-simplified non-conformance rules.
807807
// - 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.
809816
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";
813820
}
814821

815822
performHomotopyReduction([&](unsigned loopID, unsigned ruleID) -> bool {
@@ -823,8 +830,31 @@ void RewriteSystem::minimizeRewriteSystem() {
823830
rule.isSubstitutionSimplified())
824831
return true;
825832

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())
828858
return true;
829859

830860
return false;
@@ -840,11 +870,11 @@ void RewriteSystem::minimizeRewriteSystem() {
840870
llvm::DenseSet<unsigned> redundantConformances;
841871
computeMinimalConformances(redundantConformances);
842872

843-
// Second pass: Eliminate all non-minimal conformance rules.
873+
// Third pass: Eliminate all non-minimal conformance rules.
844874
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";
848878
}
849879

850880
performHomotopyReduction([&](unsigned loopID, unsigned ruleID) -> bool {
@@ -857,11 +887,11 @@ void RewriteSystem::minimizeRewriteSystem() {
857887
return false;
858888
});
859889

860-
// Third pass: Eliminate all other redundant non-conformance rules.
890+
// Fourth pass: Eliminate all remaining redundant non-conformance rules.
861891
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";
865895
}
866896

867897
performHomotopyReduction([&](unsigned loopID, unsigned ruleID) -> bool {

0 commit comments

Comments
 (0)