Skip to content

Commit e4f6128

Browse files
committed
RequirementMachine: Don't simplify terms inside concrete substitutions when adding a rule
The effect of doing this is difficult to represent with homotopy generators, so let's just not bother.
1 parent e9c3433 commit e4f6128

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

lib/AST/RequirementMachine/PropertyMap.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,6 @@ static Type getTypeFromSubstitutionSchema(Type schema,
162162
// Skip creation of a new MutableTerm in the case where the
163163
// prefix is empty.
164164
return ctx.getTypeForTerm(substitution, genericParams, protos);
165-
} else if (substitution.size() == 1 &&
166-
substitution[0].getKind() == Symbol::Kind::Protocol) {
167-
// If the prefix is non-empty and the substitution is the
168-
// protocol 'Self' type for some protocol, just use the prefix.
169-
return ctx.getTypeForTerm(prefix, genericParams, protos);
170165
} else {
171166
// Otherwise build a new term by appending the substitution
172167
// to the prefix.

lib/AST/RequirementMachine/RewriteContext.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,23 @@ Type getTypeForSymbolRange(Iter begin, Iter end, Type root,
293293
continue;
294294
}
295295

296+
// We can end up with an unsimplified term like this:
297+
//
298+
// X.[P].[P:X]
299+
//
300+
// Simplification will rewrite X.[P] to X, so just ignore a protocol symbol
301+
// in the middle of a term.
302+
if (symbol.getKind() == Symbol::Kind::Protocol) {
303+
#ifndef NDEBUG
304+
// Ensure that the domain of the suffix contains P.
305+
if (begin + 1 < end) {
306+
auto protos = (begin + 1)->getProtocols();
307+
assert(std::find(protos.begin(), protos.end(), symbol.getProtocol()));
308+
}
309+
#endif
310+
continue;
311+
}
312+
296313
// We should have a resolved type at this point.
297314
auto *assocType =
298315
const_cast<RewriteContext &>(ctx)

lib/AST/RequirementMachine/RewriteSystem.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ bool RewriteSystem::addRule(MutableTerm lhs, MutableTerm rhs) {
6666
llvm::dbgs() << "# Adding rule " << lhs << " == " << rhs << "\n";
6767
}
6868

69-
// First, simplify terms appearing inside concrete substitutions before
70-
// doing anything else.
71-
if (lhs.back().isSuperclassOrConcreteType())
72-
lhs.back() = simplifySubstitutionsInSuperclassOrConcreteSymbol(lhs.back());
73-
else if (rhs.back().isSuperclassOrConcreteType())
74-
rhs.back() = simplifySubstitutionsInSuperclassOrConcreteSymbol(rhs.back());
75-
7669
// Now simplify both sides as much as possible with the rules we have so far.
7770
//
7871
// This avoids unnecessary work in the completion algorithm.

0 commit comments

Comments
 (0)