Skip to content

Commit 15b99ae

Browse files
committed
RequirementMachine: Concrete contraction gives up on recursive same-type and superclass requirements
A requirement of the form T == G<T> is never valid, and T == G<T.A> will leave behind a term T.[P:A] once the conformance T : P is dropped in contraction. So just ignore recursive requirements here, allowing them to be properly diagnosed later.
1 parent 5a49a33 commit 15b99ae

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/AST/RequirementMachine/ConcreteContraction.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ static Type stripBoundDependentMemberTypes(Type t) {
164164
return t;
165165
}
166166

167+
/// Returns true if \p lhs appears as the base of a member type in \p rhs.
168+
static bool typeOccursIn(Type lhs, Type rhs) {
169+
return rhs.findIf([lhs](Type t) -> bool {
170+
if (auto *memberType = t->getAs<DependentMemberType>())
171+
return memberType->getBase()->isEqual(lhs);
172+
return false;
173+
});
174+
}
175+
167176
namespace {
168177

169178
/// Utility class to store some shared state.
@@ -550,6 +559,15 @@ bool ConcreteContraction::performConcreteContraction(
550559
break;
551560

552561
subjectType = stripBoundDependentMemberTypes(subjectType);
562+
if (typeOccursIn(subjectType,
563+
stripBoundDependentMemberTypes(constraintType))) {
564+
if (Debug) {
565+
llvm::dbgs() << "@ Subject type of same-type requirement "
566+
<< subjectType << " == " << constraintType << " "
567+
<< "occurs in the constraint type, skipping\n";
568+
}
569+
break;
570+
}
553571
ConcreteTypes[subjectType->getCanonicalType()].insert(constraintType);
554572
break;
555573
}
@@ -559,6 +577,15 @@ bool ConcreteContraction::performConcreteContraction(
559577
"You forgot to call desugarRequirement()");
560578

561579
subjectType = stripBoundDependentMemberTypes(subjectType);
580+
if (typeOccursIn(subjectType,
581+
stripBoundDependentMemberTypes(constraintType))) {
582+
if (Debug) {
583+
llvm::dbgs() << "@ Subject type of superclass requirement "
584+
<< subjectType << " : " << constraintType << " "
585+
<< "occurs in the constraint type, skipping\n";
586+
}
587+
break;
588+
}
562589
Superclasses[subjectType->getCanonicalType()].insert(constraintType);
563590
break;
564591
}

0 commit comments

Comments
 (0)