Skip to content

Commit 251ac92

Browse files
committed
TypeResolution: Stop resolving unqualified protocol type aliases to DependentMemberType in structural stage
This workaround is no longer needed because `TypeAliasType` is now modeled using generic arguments (as opposed to a substitution map). Previously, computing the substitution map in `StructuralTypeRequest` to construct the resulting `TypeAliasType` could cause a request cycle around generic signature computation.
1 parent d620886 commit 251ac92

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,11 +1127,6 @@ Type StructuralTypeRequest::evaluate(Evaluator &evaluator,
11271127
/*packElementOpener*/ nullptr)
11281128
.resolveType(underlyingTypeRepr);
11291129

1130-
// Don't build a generic siganture for a protocol extension, because this
1131-
// request might be evaluated while building a protocol requirement signature.
1132-
if (parentDC->getSelfProtocolDecl())
1133-
return result;
1134-
11351130
Type parent;
11361131
if (parentDC->isTypeContext())
11371132
parent = parentDC->getSelfInterfaceType();

lib/Sema/TypeCheckType.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,17 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
560560
selfType = foundDC->getSelfInterfaceType();
561561

562562
if (selfType->is<GenericTypeParamType>()) {
563-
if (isa<ProtocolDecl>(typeDecl->getDeclContext())) {
564-
if (isa<AssociatedTypeDecl>(typeDecl) ||
565-
(isa<TypeAliasDecl>(typeDecl) &&
566-
!cast<TypeAliasDecl>(typeDecl)->isGeneric() &&
567-
!isSpecialized)) {
568-
if (getStage() == TypeResolutionStage::Structural) {
569-
return DependentMemberType::get(selfType, typeDecl->getName());
570-
} else if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
571-
typeDecl = assocType->getAssociatedTypeAnchor();
563+
if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
564+
if (getStage() == TypeResolutionStage::Structural) {
565+
return DependentMemberType::get(selfType, typeDecl->getName());
566+
}
567+
568+
typeDecl = assocType->getAssociatedTypeAnchor();
569+
} else if (auto *aliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
570+
if (isa<ProtocolDecl>(typeDecl->getDeclContext()) &&
571+
getStage() == TypeResolutionStage::Structural) {
572+
if (aliasDecl && !aliasDecl->isGeneric()) {
573+
return adjustAliasType(aliasDecl->getStructuralType());
572574
}
573575
}
574576
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-swift-5.9-abi-triple -enable-upcoming-feature ExistentialAny
2+
3+
// REQUIRES: swift_feature_ExistentialAny
4+
5+
protocol P {
6+
typealias PAlias1 = P
7+
8+
func f1() -> any PAlias1
9+
func g1<T>(_: T) -> any PAlias1
10+
}
11+
extension P {
12+
typealias PAlias2 = P
13+
14+
func f2() -> any PAlias2 {}
15+
func g2<T>(_: T) -> any PAlias2 {}
16+
}

0 commit comments

Comments
 (0)