Skip to content

Commit 87eb2ca

Browse files
committed
AST: Don't strip bound dependent member types when forming keys in a generic environment
1 parent 7d8f3e6 commit 87eb2ca

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

lib/AST/GenericEnvironment.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,6 @@ auto GenericEnvironment::getOrCreateNestedTypeStorage() -> NestedTypeStorage & {
273273
return *nestedTypeStorage;
274274
}
275275

276-
static Type stripBoundDependentMemberTypes(Type t) {
277-
if (auto *depMemTy = t->getAs<DependentMemberType>()) {
278-
return DependentMemberType::get(
279-
stripBoundDependentMemberTypes(depMemTy->getBase()),
280-
depMemTy->getName());
281-
}
282-
283-
return t;
284-
}
285276
Type
286277
GenericEnvironment::getOrCreateArchetypeFromInterfaceType(Type depType) {
287278
auto genericSig = getGenericSignature();
@@ -315,12 +306,11 @@ GenericEnvironment::getOrCreateArchetypeFromInterfaceType(Type depType) {
315306
// First, write an ErrorType to the location where this type is cached,
316307
// to catch re-entrant lookups that might arise from an invalid generic
317308
// signature (eg, <X where X == Array<X>>).
318-
CanDependentMemberType nestedDependentMemberType;
309+
CanDependentMemberType nestedType;
319310
GenericTypeParamType *genericParam = nullptr;
320311
if (auto depMemTy = requirements.anchor->getAs<DependentMemberType>()) {
321-
nestedDependentMemberType = cast<DependentMemberType>(
322-
stripBoundDependentMemberTypes(depMemTy)->getCanonicalType());
323-
auto &entry = getOrCreateNestedTypeStorage()[nestedDependentMemberType];
312+
nestedType = cast<DependentMemberType>(depMemTy->getCanonicalType());
313+
auto &entry = getOrCreateNestedTypeStorage()[nestedType];
324314
if (entry)
325315
return entry;
326316

@@ -342,7 +332,9 @@ GenericEnvironment::getOrCreateArchetypeFromInterfaceType(Type depType) {
342332

343333
Type result;
344334

345-
if (requirements.anchor->getRootGenericParam()->isTypeSequence()) {
335+
auto rootGP = requirements.anchor->getRootGenericParam();
336+
if (rootGP->isTypeSequence()) {
337+
assert(getKind() == Kind::Normal);
346338
result = SequenceArchetypeType::get(ctx, this, requirements.anchor,
347339
requirements.protos, superclass,
348340
requirements.layout);
@@ -384,7 +376,6 @@ GenericEnvironment::getOrCreateArchetypeFromInterfaceType(Type depType) {
384376
// If the anchor type isn't rooted in a generic parameter that
385377
// represents an opaque declaration, then apply the outer substitutions.
386378
// It would be incorrect to build an opaque type archetype here.
387-
auto rootGP = requirements.anchor->getRootGenericParam();
388379
unsigned opaqueDepth =
389380
getOpaqueTypeDecl()->getOpaqueGenericParams().front()->getDepth();
390381
if (rootGP->getDepth() < opaqueDepth) {
@@ -403,7 +394,7 @@ GenericEnvironment::getOrCreateArchetypeFromInterfaceType(Type depType) {
403394
if (genericParam)
404395
addMapping(genericParam, result);
405396
else
406-
getOrCreateNestedTypeStorage()[nestedDependentMemberType] = result;
397+
getOrCreateNestedTypeStorage()[nestedType] = result;
407398

408399
return result;
409400
}

0 commit comments

Comments
 (0)