Skip to content

Commit d4c7164

Browse files
committed
Sema: Avoid another cycle with generic signatures
We can determine the associated types referenced from a function signature by canonicalizing the individual parameter and result types, rather than first canonicalizing the entire function type. Canonicalizing a function type creates a GenericSignatureBuilder, which can cause cycles. This fixes some cycles when the requirement machine is enabled.
1 parent ead8fd1 commit d4c7164

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2684,7 +2684,18 @@ ConformanceChecker::getReferencedAssociatedTypes(ValueDecl *req) {
26842684
};
26852685

26862686
Walker walker(Proto, assocTypes);
2687-
req->getInterfaceType()->getCanonicalType().walk(walker);
2687+
2688+
// This dance below is to avoid calling getCanonicalType() on a
2689+
// GenericFunctionType, which creates a GenericSignatureBuilder, which
2690+
// can in turn trigger associated type inference and cause a cycle.
2691+
auto reqTy = req->getInterfaceType();
2692+
if (auto *funcTy = reqTy->getAs<GenericFunctionType>()) {
2693+
for (auto param : funcTy->getParams())
2694+
param.getPlainType()->getCanonicalType().walk(walker);
2695+
funcTy->getResult()->getCanonicalType().walk(walker);
2696+
} else {
2697+
reqTy->getCanonicalType().walk(walker);
2698+
}
26882699

26892700
return assocTypes;
26902701
}

0 commit comments

Comments
 (0)