Skip to content

Commit 866a049

Browse files
committed
RequirementMachine: When simplifying right hand sides, add new rules instead of mutating
We need to keep the original rules around for homotopy generators.
1 parent b2a21b3 commit 866a049

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/AST/RequirementMachine/RewriteSystem.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ bool RewriteSystem::simplify(MutableTerm &term, RewritePath *path) const {
242242
/// Must be run after the completion procedure, since the deletion of
243243
/// rules is only valid to perform if the rewrite system is confluent.
244244
void RewriteSystem::simplifyRewriteSystem() {
245-
for (auto ruleID : indices(Rules)) {
245+
for (unsigned ruleID = 0, e = Rules.size(); ruleID < e; ++ruleID) {
246246
auto &rule = getRule(ruleID);
247247
if (rule.isDeleted())
248248
continue;
@@ -283,8 +283,16 @@ void RewriteSystem::simplifyRewriteSystem() {
283283
if (!simplify(rhs))
284284
continue;
285285

286-
// If the right hand side was further reduced, update the rule.
287-
rule = Rule(rule.getLHS(), Term::get(rhs, Context));
286+
// We're adding a new rule, so the old rule won't apply anymore.
287+
rule.markDeleted();
288+
289+
unsigned newRuleID = Rules.size();
290+
291+
// Add a new rule with the simplified right hand side.
292+
Rules.emplace_back(lhs, Term::get(rhs, Context));
293+
auto oldRuleID = Trie.insert(lhs.begin(), lhs.end(), newRuleID);
294+
assert(oldRuleID == ruleID);
295+
(void) oldRuleID;
288296
}
289297
}
290298

0 commit comments

Comments
 (0)