Skip to content

Commit 54bf6ad

Browse files
committed
Revert "Sema: Don't resolve protocol typealiases to DependentMemberTypes"
This reverts commit 1dd79ae. Fixes rdar://problem/88230388.
1 parent 250fbf2 commit 54bf6ad

File tree

7 files changed

+56
-18
lines changed

7 files changed

+56
-18
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -431,18 +431,17 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
431431

432432
if (selfType->is<GenericTypeParamType>()) {
433433
if (typeDecl->getDeclContext()->getSelfProtocolDecl()) {
434-
auto *aliasDecl = dyn_cast<TypeAliasDecl>(typeDecl);
435-
if (getStage() == TypeResolutionStage::Structural &&
436-
aliasDecl && !aliasDecl->isGeneric()) {
437-
return aliasDecl->getStructuralType();
438-
}
439-
440-
if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
441-
typeDecl = assocType->getAssociatedTypeAnchor();
434+
if (isa<AssociatedTypeDecl>(typeDecl) ||
435+
(isa<TypeAliasDecl>(typeDecl) &&
436+
!cast<TypeAliasDecl>(typeDecl)->isGeneric())) {
437+
if (getStage() == TypeResolutionStage::Structural) {
438+
return DependentMemberType::get(selfType, typeDecl->getName());
439+
} else if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
440+
typeDecl = assocType->getAssociatedTypeAnchor();
441+
}
442442
}
443443
}
444444

445-
// FIXME: Remove this once the above FIXME is addressed.
446445
if (typeDecl->getDeclContext()->getSelfClassDecl()) {
447446
// We found a member of a class from a protocol or protocol
448447
// extension.
@@ -2638,7 +2637,14 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
26382637
// context, and then set isNoEscape if @escaping is not present.
26392638
if (!ty) ty = resolveType(repr, instanceOptions);
26402639
if (!ty || ty->hasError()) return ty;
2641-
2640+
2641+
// Type aliases inside protocols are not yet resolved in the structural
2642+
// stage of type resolution
2643+
if (ty->is<DependentMemberType>() &&
2644+
resolution.getStage() == TypeResolutionStage::Structural) {
2645+
return ty;
2646+
}
2647+
26422648
// Handle @escaping
26432649
if (ty->is<FunctionType>()) {
26442650
if (attrs.has(TAK_escaping)) {

test/Generics/infinite_concrete_type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class G<T> {}
44

55
protocol P1 { // expected-error {{cannot build rewrite system for protocol; concrete nesting limit exceeded}}
6-
// expected-note@-1 {{failed rewrite rule is [P1:A].[concrete: G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<[P1:A]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] => [P1:A]}}
6+
// expected-note@-1 {{failed rewrite rule is [P1:A].[concrete: G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<G<[P1].A>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] => [P1:A]}}
77
associatedtype A where A == G<B>
88
associatedtype B where B == G<A>
99
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P {
4+
func invoke()
5+
6+
associatedtype X
7+
associatedtype Y where Y : Q
8+
}
9+
10+
protocol Q {
11+
associatedtype T
12+
}
13+
14+
struct S: Q {
15+
typealias T = Int
16+
}
17+
18+
extension P where X == () {
19+
typealias Y = S
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P {
4+
associatedtype T where T == Self
5+
static func f() -> T
6+
}
7+
8+
extension P {
9+
typealias T = Self
10+
}

test/decl/protocol/req/associated_type_ambiguity.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// RUN: %target-typecheck-verify-swift -requirement-machine-inferred-signatures=on -requirement-machine-protocol-signatures=on
2-
// RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
33

44
protocol P1 {
5-
typealias T = Int // expected-note {{found this candidate}}
5+
typealias T = Int
66
}
77

88
protocol P2 {
9-
associatedtype T // expected-note {{found this candidate}}
9+
associatedtype T
1010
}
1111

1212
// CHECK: ExtensionDecl line={{.*}} base=P1
1313
// CHECK-NEXT: Generic signature: <Self where Self : P1, Self : P2>
14-
extension P1 where Self : P2, T == Int { // expected-error {{'T' is ambiguous for type lookup in this context}}
14+
extension P1 where Self : P2, T == Int {
1515
func takeT11(_: T) {}
1616
func takeT12(_: Self.T) {}
1717
}

test/decl/typealias/protocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ extension P10 {
268268
typealias U = Float
269269
}
270270

271-
extension P10 where T == Int { } // expected-warning{{neither type in same-type constraint ('Int' or 'Int') refers to a generic parameter or associated type}}
271+
extension P10 where T == Int { } // expected-warning{{neither type in same-type constraint ('Self.T' (aka 'Int') or 'Int') refers to a generic parameter or associated type}}
272272

273273
extension P10 where A == X<T> { }
274274

@@ -277,7 +277,7 @@ extension P10 where A == X<U> { }
277277
extension P10 where A == X<Self.U> { }
278278

279279
extension P10 where V == Int { } // expected-warning {{'V' is deprecated: just use Int, silly}}
280-
// expected-warning@-1{{neither type in same-type constraint ('Int' or 'Int') refers to a generic parameter or associated type}}
280+
// expected-warning@-1{{neither type in same-type constraint ('Self.V' (aka 'Int') or 'Int') refers to a generic parameter or associated type}}
281281

282282
// rdar://problem/36003312
283283
protocol P11 {

validation-test/compiler_crashers_2_fixed/sr11639.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %target-swift-frontend -emit-ir -primary-file %s -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -emit-ir -primary-file %s -debug-generic-signatures -requirement-machine-protocol-signatures=off 2>&1 | %FileCheck %s
2+
3+
// FIXME: Get this working with -requirement-machine-protocol-signatures=on again
24

35
public protocol FooProtocol {
46
associatedtype Bar

0 commit comments

Comments
 (0)