RequirementMachine: Don't add unnecessary rule in merged associated types step

If we have a rewrite rule of the form

    X.[P:A] => X.[Q:A]

We introduce a pair of rules

    X.[P:A] => X.[P&Q:A]
    X.[Q:A] => X.[P&Q:A]

But in reality only the second one is necessary. The first one is redundant
because you obtain the same result by applying the original rule followed by
the second rule.
This commit is contained in:
Slava Pestov
2021-08-19 17:47:45 -04:00
parent 7de1d9b9a4
commit 6ec2aad857
2 changed files with 23 additions and 25 deletions

View File

@@ -123,6 +123,10 @@ bool RewriteSystem::addRule(MutableTerm lhs, MutableTerm rhs) {
lhs.back().getKind() == Symbol::Kind::AssociatedType &&
rhs.back().getKind() == Symbol::Kind::AssociatedType &&
lhs.back().getName() == rhs.back().getName()) {
if (Debug.contains(DebugFlags::Merge)) {
llvm::dbgs() << "## Associated type merge candidate ";
llvm::dbgs() << lhs << " => " << rhs << "\n\n";
}
MergedAssociatedTypes.emplace_back(lhs, rhs);
}