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.
This commit is contained in:
Anthony Latsis
2025-02-12 12:25:56 +00:00
parent d620886106
commit 251ac929be
3 changed files with 27 additions and 14 deletions

View File

@@ -1127,11 +1127,6 @@ Type StructuralTypeRequest::evaluate(Evaluator &evaluator,
/*packElementOpener*/ nullptr)
.resolveType(underlyingTypeRepr);
// Don't build a generic siganture for a protocol extension, because this
// request might be evaluated while building a protocol requirement signature.
if (parentDC->getSelfProtocolDecl())
return result;
Type parent;
if (parentDC->isTypeContext())
parent = parentDC->getSelfInterfaceType();

View File

@@ -560,15 +560,17 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
selfType = foundDC->getSelfInterfaceType();
if (selfType->is<GenericTypeParamType>()) {
if (isa<ProtocolDecl>(typeDecl->getDeclContext())) {
if (isa<AssociatedTypeDecl>(typeDecl) ||
(isa<TypeAliasDecl>(typeDecl) &&
!cast<TypeAliasDecl>(typeDecl)->isGeneric() &&
!isSpecialized)) {
if (getStage() == TypeResolutionStage::Structural) {
return DependentMemberType::get(selfType, typeDecl->getName());
} else if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
typeDecl = assocType->getAssociatedTypeAnchor();
if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
if (getStage() == TypeResolutionStage::Structural) {
return DependentMemberType::get(selfType, typeDecl->getName());
}
typeDecl = assocType->getAssociatedTypeAnchor();
} else if (auto *aliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
if (isa<ProtocolDecl>(typeDecl->getDeclContext()) &&
getStage() == TypeResolutionStage::Structural) {
if (aliasDecl && !aliasDecl->isGeneric()) {
return adjustAliasType(aliasDecl->getStructuralType());
}
}
}

View File

@@ -0,0 +1,16 @@
// RUN: %target-typecheck-verify-swift -target %target-swift-5.9-abi-triple -enable-upcoming-feature ExistentialAny
// REQUIRES: swift_feature_ExistentialAny
protocol P {
typealias PAlias1 = P
func f1() -> any PAlias1
func g1<T>(_: T) -> any PAlias1
}
extension P {
typealias PAlias2 = P
func f2() -> any PAlias2 {}
func g2<T>(_: T) -> any PAlias2 {}
}