@@ -459,60 +459,6 @@ void RewriteSystem::performHomotopyReduction(
459
459
propagateRedundantRequirementIDs ();
460
460
}
461
461
462
- void RewriteSystem::normalizeRedundantRules () {
463
- llvm::DenseMap<unsigned , unsigned > RedundantRuleMap;
464
-
465
- // A redundant path in the range [0, i-1] might contain rewrite steps naming
466
- // rules that subsequently became redundant in the range [i, e-1].
467
- //
468
- // We back-substitute later rules into earlier paths here.
469
- for (unsigned i = 0 , e = RedundantRules.size (); i < e; ++i) {
470
- // Pre-condition: Redundant paths in the range [i+1, e-1] do not involve
471
- // any other redundant rules.
472
- unsigned j = e - i - 1 ;
473
-
474
- // Replace all occurrences of redundant rules with their path at
475
- // RedundantRules[i].
476
- auto &pair = RedundantRules[j];
477
- pair.second .replaceRulesWithPaths (
478
- [&](unsigned ruleID) -> RewritePath * {
479
- auto found = RedundantRuleMap.find (ruleID);
480
- if (found != RedundantRuleMap.end ())
481
- return &RedundantRules[found->second ].second ;
482
-
483
- return nullptr ;
484
- });
485
- pair.second .computeNormalForm (*this );
486
-
487
- RedundantRuleMap[RedundantRules[j].first ] = j;
488
-
489
- // Post-condition: the path for RedundantRules[i] does not contain any
490
- // redundant rules.
491
- }
492
-
493
- if (Debug.contains (DebugFlags::RedundantRules)) {
494
- llvm::dbgs () << " \n Redundant rules:\n " ;
495
- for (const auto &pair : RedundantRules) {
496
- const auto &rule = getRule (pair.first );
497
- llvm::dbgs () << " - ("
498
- << rule.getLHS () << " => "
499
- << rule.getRHS () << " ) ::== " ;
500
-
501
- MutableTerm lhs (rule.getLHS ());
502
- pair.second .dump (llvm::dbgs (), lhs, *this );
503
-
504
- llvm::dbgs () << " \n " ;
505
-
506
- if (Debug.contains (DebugFlags::RedundantRulesDetail)) {
507
- llvm::dbgs () << " \n " ;
508
- pair.second .dumpLong (llvm::dbgs (), lhs, *this );
509
-
510
- llvm::dbgs () << " \n\n " ;
511
- }
512
- }
513
- }
514
- }
515
-
516
462
// / Use the loops to delete redundant rewrite rules via a series of Tietze
517
463
// / transformations, updating and simplifying existing loops as each rule
518
464
// / is deleted.
@@ -644,12 +590,32 @@ void RewriteSystem::minimizeRewriteSystem() {
644
590
return false ;
645
591
});
646
592
647
- normalizeRedundantRules ();
648
-
649
593
// Check invariants after homotopy reduction.
650
594
verifyRewriteLoops ();
651
595
verifyRedundantConformances (redundantConformances);
652
596
verifyMinimizedRules (redundantConformances);
597
+
598
+ if (Debug.contains (DebugFlags::RedundantRules)) {
599
+ llvm::dbgs () << " \n Redundant rules:\n " ;
600
+ for (const auto &pair : RedundantRules) {
601
+ const auto &rule = getRule (pair.first );
602
+ llvm::dbgs () << " - ("
603
+ << rule.getLHS () << " => "
604
+ << rule.getRHS () << " ) ::== " ;
605
+
606
+ MutableTerm lhs (rule.getLHS ());
607
+ pair.second .dump (llvm::dbgs (), lhs, *this );
608
+
609
+ llvm::dbgs () << " \n " ;
610
+
611
+ if (Debug.contains (DebugFlags::RedundantRulesDetail)) {
612
+ llvm::dbgs () << " \n " ;
613
+ pair.second .dumpLong (llvm::dbgs (), lhs, *this );
614
+
615
+ llvm::dbgs () << " \n\n " ;
616
+ }
617
+ }
618
+ }
653
619
}
654
620
655
621
// / Returns flags indicating if the rewrite system has unresolved or
@@ -849,7 +815,11 @@ void RewriteSystem::verifyMinimizedRules(
849
815
abort ();
850
816
}
851
817
852
- for (const auto &pair : RedundantRules) {
818
+ // Replacement paths for redundant rules can only reference other redundant
819
+ // rules if those redundant rules were made redundant later, ie if they
820
+ // appear later in the array.
821
+ llvm::DenseSet<unsigned > laterRedundantRules;
822
+ for (const auto &pair : llvm::reverse (RedundantRules)) {
853
823
const auto &rule = getRule (pair.first );
854
824
if (!rule.isRedundant ()) {
855
825
llvm::errs () << " Recorded replacement path for non-redundant rule "
@@ -860,14 +830,19 @@ void RewriteSystem::verifyMinimizedRules(
860
830
861
831
for (const auto &step : pair.second ) {
862
832
if (step.Kind == RewriteStep::Rule) {
863
- const auto &rule = getRule (step.getRuleID ());
864
- if (rule.isRedundant ()) {
833
+ unsigned otherRuleID = step.getRuleID ();
834
+ const auto &otherRule = getRule (otherRuleID);
835
+ if (otherRule.isRedundant () &&
836
+ !laterRedundantRules.count (otherRuleID)) {
865
837
llvm::errs () << " Redundant requirement path contains a redundant "
866
- " rule " << rule << " \n " ;
838
+ " rule " << otherRule << " \n " ;
867
839
dump (llvm::errs ());
868
840
abort ();
869
841
}
870
842
}
871
843
}
844
+
845
+ laterRedundantRules.insert (pair.first );
872
846
}
847
+
873
848
}
0 commit comments