Skip to content

Commit 385c7f9

Browse files
authored
Merge pull request swiftlang#41974 from slavapestov/rqm-opaque-archetype-tests
RequirementMachine: Better tests for concrete type requirements with opaque archetypes
2 parents a93a574 + 57d1600 commit 385c7f9

5 files changed

+71
-36
lines changed

lib/AST/RequirementMachine/NameLookup.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ swift::rewriting::lookupConcreteNestedType(
3434
auto *genericEnv = archetype->getGenericEnvironment();
3535
auto genericSig = genericEnv->getGenericSignature();
3636

37-
concreteDecls.push_back(
38-
genericSig->lookupNestedType(archetype->getInterfaceType(), name));
37+
auto *typeDecl =
38+
genericSig->lookupNestedType(archetype->getInterfaceType(), name);
39+
if (typeDecl != nullptr)
40+
concreteDecls.push_back(typeDecl);
3941
}
4042
}
4143

test/Generics/opaque_archetype_concrete_requirement.swift

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -typecheck -verify %s -disable-availability-checking -debug-generic-signatures -requirement-machine-inferred-signatures=on -enable-requirement-machine-opaque-archetypes 2>&1 | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-silgen %s -disable-availability-checking -requirement-machine-inferred-signatures=on -enable-requirement-machine-opaque-archetypes
23

34
protocol P1 {
45
associatedtype T : P2
@@ -51,31 +52,3 @@ extension HasP where T == DefinesOpaqueP1.T, U == G<T.T> {
5152
func checkSameType1(_ t: T.T) -> DefinesOpaqueP1.T.T { return t }
5253
func checkSameType2(_ u: T.U) -> DefinesOpaqueP1.T.U { return u }
5354
}
54-
55-
// FIXME: This does not work with -enable-requirement-machine-opaque-archetypes.
56-
// See opaque_archetype_concrete_requirement_recursive.swift for a demonstration
57-
// that it works without the flag (but more involved examples like the above
58-
// won't work).
59-
60-
protocol RecursiveP {
61-
associatedtype T : RecursiveP
62-
}
63-
64-
struct S_RecursiveP : RecursiveP {
65-
typealias T = S_RecursiveP
66-
}
67-
68-
struct DefinesRecursiveP : P {
69-
var t: some RecursiveP {
70-
return S_RecursiveP()
71-
}
72-
}
73-
74-
protocol HasRecursiveP {
75-
associatedtype T : RecursiveP
76-
}
77-
78-
extension HasRecursiveP where T == DefinesRecursiveP.T {}
79-
// expected-error@-1 {{cannot build rewrite system for generic signature; rule length limit exceeded}}
80-
// expected-note@-2 {{failed rewrite rule is τ_0_0.[HasRecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[concrete: (((((((((@_opaqueReturnTypeOf("$s37opaque_archetype_concrete_requirement17DefinesRecursivePV1tQrvp", 0) __.T).T).T).T).T).T).T).T).T).T] => τ_0_0.[HasRecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T]}}
81-
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-frontend -typecheck -verify %s -disable-availability-checking -requirement-machine-inferred-signatures=on -enable-requirement-machine-opaque-archetypes
2+
3+
protocol P1 {}
4+
5+
struct S_P1 : P1 {}
6+
7+
protocol P {
8+
associatedtype T
9+
10+
var t: T { get }
11+
}
12+
13+
struct DefinesOpaqueP1 : P {
14+
var t: some P1 {
15+
return S_P1()
16+
}
17+
}
18+
19+
protocol HasP {
20+
associatedtype T : P1
21+
associatedtype U
22+
}
23+
24+
extension HasP where T == DefinesOpaqueP1.T, U == T.DoesNotExist {}
25+
// expected-error@-1 {{'DoesNotExist' is not a member type of type 'Self.T'}}

test/Generics/opaque_archetype_concrete_requirement_recursive.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// RUN: %target-swift-frontend -typecheck -verify %s -disable-availability-checking -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-silgen %s -disable-availability-checking -requirement-machine-inferred-signatures=on
3+
4+
// FIXME: This does not work with -enable-requirement-machine-opaque-archetypes.
5+
// See opaque_archetype_concrete_requirement_rejected.swift for a demonstration
6+
// that it fails with the flag.
27

38
protocol P {
49
associatedtype T
510

611
var t: T { get }
712
}
813

9-
// FIXME: This does not work with -enable-requirement-machine-opaque-archetypes.
10-
// See opaque_archetype_concrete_requirement.swift for a demonstration that it
11-
// fails with the flag.
12-
1314
protocol RecursiveP {
1415
associatedtype T : RecursiveP
1516
}
@@ -31,6 +32,5 @@ protocol HasRecursiveP {
3132
// CHECK-LABEL: ExtensionDecl line={{.*}} base=HasRecursiveP
3233
// CHECK-NEXT: Generic signature: <Self where Self : HasRecursiveP, Self.[HasRecursiveP]T == some RecursiveP>
3334
extension HasRecursiveP where T == DefinesRecursiveP.T {
34-
func checkSameType1(_ t: T) -> DefinesRecursiveP.T { return t }
35-
func checkSameType2(_ t: T.T) -> DefinesRecursiveP.T.T { return t }
35+
func checkSameType(_ t: T) -> DefinesRecursiveP.T { return t }
3636
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -requirement-machine-inferred-signatures=on -enable-requirement-machine-opaque-archetypes
2+
3+
// FIXME: This does not work with -enable-requirement-machine-opaque-archetypes.
4+
// See opaque_archetype_concrete_requirement_recursive.swift for a demonstration
5+
// that it works without the flag (but more involved examples like the above
6+
// won't work).
7+
8+
protocol P {
9+
associatedtype T
10+
11+
var t: T { get }
12+
}
13+
14+
protocol RecursiveP {
15+
associatedtype T : RecursiveP
16+
}
17+
18+
struct S_RecursiveP : RecursiveP {
19+
typealias T = S_RecursiveP
20+
}
21+
22+
struct DefinesRecursiveP : P {
23+
var t: some RecursiveP {
24+
return S_RecursiveP()
25+
}
26+
}
27+
28+
protocol HasRecursiveP {
29+
associatedtype T : RecursiveP
30+
}
31+
32+
extension HasRecursiveP where T == DefinesRecursiveP.T {}
33+
// expected-error@-1 {{cannot build rewrite system for generic signature; rule length limit exceeded}}
34+
// expected-note@-2 {{failed rewrite rule is τ_0_0.[HasRecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[concrete: (((((((((@_opaqueReturnTypeOf("$s56opaque_archetype_concrete_requirement_recursive_rejected17DefinesRecursivePV1tQrvp", 0) __.T).T).T).T).T).T).T).T).T).T] => τ_0_0.[HasRecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T].[RecursiveP:T]}}
35+

0 commit comments

Comments
 (0)