Skip to content

Commit 3c9344c

Browse files
committed
RequirementMachine: Improved verifyMinimizedRules()
1 parent 40b585f commit 3c9344c

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ void RewriteSystem::minimizeRewriteSystem() {
543543
// Check invariants after homotopy reduction.
544544
verifyRewriteLoops();
545545
verifyRedundantConformances(redundantConformances);
546-
verifyMinimizedRules();
546+
verifyMinimizedRules(redundantConformances);
547547
}
548548

549549
/// In a conformance-valid rewrite system, any rule with unresolved symbols on
@@ -656,7 +656,7 @@ void RewriteSystem::verifyRewriteLoops() const {
656656
/// Assert if homotopy reduction failed to eliminate a redundant conformance,
657657
/// since this suggests a misunderstanding on my part.
658658
void RewriteSystem::verifyRedundantConformances(
659-
llvm::DenseSet<unsigned> redundantConformances) const {
659+
const llvm::DenseSet<unsigned> &redundantConformances) const {
660660
#ifndef NDEBUG
661661
for (unsigned ruleID : redundantConformances) {
662662
const auto &rule = getRule(ruleID);
@@ -680,9 +680,12 @@ void RewriteSystem::verifyRedundantConformances(
680680

681681
// Assert if homotopy reduction failed to eliminate a rewrite rule it was
682682
// supposed to delete.
683-
void RewriteSystem::verifyMinimizedRules() const {
683+
void RewriteSystem::verifyMinimizedRules(
684+
const llvm::DenseSet<unsigned> &redundantConformances) const {
684685
#ifndef NDEBUG
685-
for (const auto &rule : Rules) {
686+
for (unsigned ruleID : indices(Rules)) {
687+
const auto &rule = getRule(ruleID);
688+
686689
// Note that sometimes permanent rules can be simplified, but they can never
687690
// be redundant.
688691
if (rule.isPermanent()) {
@@ -706,6 +709,15 @@ void RewriteSystem::verifyMinimizedRules() const {
706709
dump(llvm::errs());
707710
abort();
708711
}
712+
713+
if (rule.isRedundant() &&
714+
rule.isAnyConformanceRule() &&
715+
!rule.containsUnresolvedSymbols() &&
716+
!redundantConformances.count(ruleID)) {
717+
llvm::errs() << "Minimal conformance is redundant: " << rule << "\n\n";
718+
dump(llvm::errs());
719+
abort();
720+
}
709721
}
710722
#endif
711723
}

lib/AST/RequirementMachine/MinimalConformances.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -903,15 +903,8 @@ void MinimalConformances::verifyMinimalConformances() const {
903903
continue;
904904
}
905905

906-
if (rule.isRedundant()) {
907-
llvm::errs() << "Generating conformance is redundant: ";
908-
llvm::errs() << rule << "\n\n";
909-
dumpMinimalConformanceEquations(llvm::errs());
910-
abort();
911-
}
912-
913906
if (rule.getLHS().containsUnresolvedSymbols()) {
914-
llvm::errs() << "Generating conformance contains unresolved symbols: ";
907+
llvm::errs() << "Minimal conformance contains unresolved symbols: ";
915908
llvm::errs() << rule << "\n\n";
916909
dumpMinimalConformanceEquations(llvm::errs());
917910
abort();
@@ -922,7 +915,7 @@ void MinimalConformances::verifyMinimalConformances() const {
922915

923916
void MinimalConformances::dumpMinimalConformances(
924917
llvm::raw_ostream &out) const {
925-
out << "Generating conformances:\n";
918+
out << "Minimal conformances:\n";
926919

927920
for (const auto &pair : ConformancePaths) {
928921
if (RedundantConformances.count(pair.first) > 0)

lib/AST/RequirementMachine/RewriteSystem.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,10 @@ class RewriteSystem final {
461461
void verifyRewriteLoops() const;
462462

463463
void verifyRedundantConformances(
464-
llvm::DenseSet<unsigned> redundantConformances) const;
464+
const llvm::DenseSet<unsigned> &redundantConformances) const;
465465

466-
void verifyMinimizedRules() const;
466+
void verifyMinimizedRules(
467+
const llvm::DenseSet<unsigned> &redundantConformances) const;
467468

468469
public:
469470
void dump(llvm::raw_ostream &out) const;

0 commit comments

Comments
 (0)