Skip to content

Commit 04f9bce

Browse files
committed
RequirementMachine: Treat LHS-simplified and RHS-simplified/substitution-simplified rules separately in minimization
1 parent aab4e43 commit 04f9bce

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -481,20 +481,20 @@ void RewriteSystem::minimizeRewriteSystem() {
481481
propagateExplicitBits();
482482

483483
// 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.
485486
// - Eliminate all rules with unresolved symbols.
486487
performHomotopyReduction([&](unsigned ruleID) -> bool {
487488
const auto &rule = getRule(ruleID);
488489

489-
if ((rule.isLHSSimplified() ||
490-
rule.isRHSSimplified() ||
491-
rule.isSubstitutionSimplified()) &&
490+
if (rule.isLHSSimplified() &&
492491
!rule.isAnyConformanceRule())
493492
return true;
494493

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+
498498
if (rule.getLHS().containsUnresolvedSymbols())
499499
return true;
500500

@@ -694,22 +694,31 @@ void RewriteSystem::verifyMinimizedRules(
694694
continue;
695695
}
696696

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() &&
704702
!rule.isRedundant() &&
705703
!rule.isProtocolConformanceRule()) {
706704
llvm::errs() << "Simplified rule is not redundant: " << rule << "\n\n";
707705
dump(llvm::errs());
708706
abort();
709707
}
710708

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+
711718
if (rule.isRedundant() &&
712719
rule.isAnyConformanceRule() &&
720+
!rule.isRHSSimplified() &&
721+
!rule.isSubstitutionSimplified() &&
713722
!rule.containsUnresolvedSymbols() &&
714723
!redundantConformances.count(ruleID)) {
715724
llvm::errs() << "Minimal conformance is redundant: " << rule << "\n\n";

lib/AST/RequirementMachine/MinimalConformances.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ void MinimalConformances::collectConformanceRules() {
375375
if (rule.isRedundant())
376376
continue;
377377

378+
if (rule.isRHSSimplified() ||
379+
rule.isSubstitutionSimplified())
380+
continue;
381+
378382
if (rule.containsUnresolvedSymbols())
379383
continue;
380384

0 commit comments

Comments
 (0)