Skip to content

Commit 7427a17

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 af9d8c0 commit 7427a17

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/AST/RequirementMachine/ConcreteContraction.cpp

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

167+
/// Returns true if \p lhs appears inside \p rhs.
168+
static bool typeOccursIn(Type lhs, Type rhs) {
169+
return rhs.findIf([lhs](Type t) -> bool {
170+
return t->isEqual(lhs);
171+
});
172+
}
173+
167174
namespace {
168175

169176
/// Utility class to store some shared state.
@@ -550,6 +557,15 @@ bool ConcreteContraction::performConcreteContraction(
550557
break;
551558

552559
subjectType = stripBoundDependentMemberTypes(subjectType);
560+
if (typeOccursIn(subjectType,
561+
stripBoundDependentMemberTypes(constraintType))) {
562+
if (Debug) {
563+
llvm::dbgs() << "@ Subject type of same-type requirement "
564+
<< subjectType << " == " << constraintType << " "
565+
<< "occurs in the constraint type, skipping\n";
566+
}
567+
break;
568+
}
553569
ConcreteTypes[subjectType->getCanonicalType()].insert(constraintType);
554570
break;
555571
}
@@ -559,6 +575,15 @@ bool ConcreteContraction::performConcreteContraction(
559575
"You forgot to call desugarRequirement()");
560576

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

0 commit comments

Comments
 (0)