Skip to content

Commit d3c4230

Browse files
authored
Merge pull request #72579 from kavon/fix-infinite-subst
[NCGenerics] adjust infinite type substitution workaround
2 parents 298346f + 6cd5468 commit d3c4230

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/AST/ProtocolConformanceRef.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ ProtocolConformanceRef::subst(Type origType, InFlightSubstitution &IFS) const {
118118
return ProtocolConformanceRef::forInvalid();
119119
}
120120

121-
// If the type has been fully substituted and the requirement is for
122-
// an invertible protocol, just do a module lookup. This avoids an infinite
123-
// substitution issue by recognizing that these protocols are very simple
124-
// (see rdar://119950540 for the general issue).
125-
if (!substType->hasTypeParameter() && proto->getInvertibleProtocolKind())
126-
return proto->getModuleContext()->lookupConformance(substType, proto);
127-
128121
// Check the conformance map.
129122
// FIXME: Pack element level?
130123
return IFS.lookupConformance(origType->getCanonicalType(), substType, proto,

lib/AST/SubstitutionMap.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,16 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
355355
if (!type->isTypeParameter())
356356
return ProtocolConformanceRef::forInvalid();
357357

358+
// If the protocol is invertible, just do a global lookup. This avoids an
359+
// infinite substitution issue by recognizing that these protocols are
360+
// very simple (see rdar://119950540 for the general issue).
361+
if (proto->getInvertibleProtocolKind()) {
362+
auto substType = type.subst(*this);
363+
if (!substType->isTypeParameter())
364+
return proto->getModuleContext()->lookupConformance(substType, proto);
365+
return ProtocolConformanceRef(proto);
366+
}
367+
358368
auto genericSig = getGenericSignature();
359369

360370
auto getSignatureConformance =

0 commit comments

Comments
 (0)