@@ -9,9 +9,6 @@ import SwiftShims
9
9
10
10
import resilient_protocol
11
11
12
- // TODO: default implementations for protocols with associated types
13
-
14
-
15
12
// Witness table for conformance with resilient associated type
16
13
17
14
// CHECK: @_TWPV19protocol_resilience26ConformsWithResilientAssocS_17HasResilientAssocS_ = {{(protected )?}}constant [2 x i8*] [
@@ -32,6 +29,8 @@ import resilient_protocol
32
29
33
30
34
31
public protocol ResilientProtocol {
32
+ associatedtype T : OtherResilientProtocol
33
+
35
34
func noDefaultA()
36
35
func noDefaultB()
37
36
func defaultC()
@@ -74,17 +73,17 @@ bb0(%0 : $*Self):
74
73
75
74
// CHECK-NEXT: call void @defaultC(%swift.opaque* noalias nocapture %0, %swift.type* %Self, i8** %SelfWitnessTable)
76
75
%fn1 = function_ref @defaultC : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
77
- %ignore1 = apply %fn1<Self>(%0) : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
76
+ %ignore1 = apply %fn1<Self, Self.T >(%0) : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
78
77
79
78
// Make sure we can do dynamic dispatch to other protocol requirements
80
79
// from a default implementation
81
80
82
- // CHECK-NEXT: [[WITNESS_ADDR:%.*]] = getelementptr inbounds i8*, i8** %SelfWitnessTable, i32 2
81
+ // CHECK-NEXT: [[WITNESS_ADDR:%.*]] = getelementptr inbounds i8*, i8** %SelfWitnessTable, i32 4
83
82
// CHECK-NEXT: [[WITNESS_FN:%.*]] = load i8*, i8** [[WITNESS_ADDR]]
84
83
// CHECK-NEXT: [[WITNESS:%.*]] = bitcast i8* [[WITNESS_FN]] to void (%swift.opaque*, %swift.type*, i8**)*
85
84
// CHECK-NEXT: call void [[WITNESS]](%swift.opaque* noalias nocapture %0, %swift.type* %Self, i8** %SelfWitnessTable)
86
85
%fn2 = witness_method $Self, #ResilientProtocol.defaultC!1 : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
87
- %ignore2 = apply %fn2<Self>(%0) : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
86
+ %ignore2 = apply %fn2<Self, Self.T >(%0) : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
88
87
89
88
// Make sure we can partially apply a static reference to a default
90
89
// implementation
@@ -96,7 +95,7 @@ bb0(%0 : $*Self):
96
95
// CHECK-NEXT: store i8* [[WTABLE]], i8** [[WTABLE_ADDR]]
97
96
98
97
%fn3 = function_ref @defaultC : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
99
- %ignore3 = partial_apply %fn3<Self>() : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
98
+ %ignore3 = partial_apply %fn3<Self, Self.T >() : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
100
99
101
100
// CHECK-NEXT: ret void
102
101
%result = tuple ()
@@ -110,7 +109,13 @@ sil_default_witness_table ResilientProtocol 2 {
110
109
}
111
110
112
111
112
+ public struct ResilientConformingType : OtherResilientProtocol {}
113
+
114
+ sil_witness_table ResilientConformingType : OtherResilientProtocol module protocol_resilience {}
115
+
116
+
113
117
struct ConformingStruct : ResilientProtocol {
118
+ typealias T = ResilientConformingType
114
119
func noDefaultA()
115
120
func noDefaultB()
116
121
func defaultC()
@@ -128,9 +133,9 @@ bb0(%0 : $*ConformingStruct):
128
133
// might)
129
134
130
135
// CHECK-NEXT: [[SELF:%.*]] = bitcast %V19protocol_resilience16ConformingStruct* %0 to %swift.opaque*
131
- // CHECK-NEXT: call void @defaultC(%swift.opaque* noalias nocapture [[SELF]], %swift.type* bitcast ({{i32|i64}}* {{.*}}) to %swift.type*), i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @_TWPV19protocol_resilience16ConformingStructS_17ResilientProtocolS_, i32 0, i32 0))
136
+ // CHECK-NEXT: call void @defaultC(%swift.opaque* noalias nocapture [[SELF]], %swift.type* bitcast ({{i32|i64}}* {{.*}}) to %swift.type*), i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @_TWPV19protocol_resilience16ConformingStructS_17ResilientProtocolS_, i32 0, i32 0))
132
137
%fn1 = function_ref @defaultC : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
133
- %ignore1 = apply %fn1<ConformingStruct>(%0) : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
138
+ %ignore1 = apply %fn1<ConformingStruct, ResilientConformingType >(%0) : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
134
139
135
140
// CHECK-NEXT: ret void
136
141
%result = tuple ()
@@ -149,17 +154,20 @@ bb0(%0 : $*ConformingStruct):
149
154
// CHECK-NEXT: [[CONTEXT:%.*]] = call noalias %swift.refcounted* @swift_allocObject({{.*}})
150
155
// CHECK-NEXT: [[LAYOUT:%.*]] = bitcast %swift.refcounted* [[CONTEXT]] to <{ %swift.refcounted, i8* }>*
151
156
// CHECK-NEXT: [[WTABLE:%.*]] = getelementptr inbounds <{ %swift.refcounted, i8* }>, <{ %swift.refcounted, i8* }>* [[LAYOUT]], i32 0, i32 1
152
- // CHECK-NEXT: store i8* bitcast ([4 x i8*]* @_TWPV19protocol_resilience16ConformingStructS_17ResilientProtocolS_ to i8*), i8** [[WTABLE]]
157
+ // CHECK-NEXT: store i8* bitcast ([6 x i8*]* @_TWPV19protocol_resilience16ConformingStructS_17ResilientProtocolS_ to i8*), i8** [[WTABLE]]
153
158
154
159
%fn1 = function_ref @defaultC : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
155
- %ignore1 = partial_apply %fn1<ConformingStruct>() : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
160
+ %ignore1 = partial_apply %fn1<ConformingStruct, ResilientConformingType >() : $@convention(witness_method) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> ()
156
161
157
162
// CHECK-NEXT: ret void
158
163
%result = tuple ()
159
164
return %result : $()
160
165
}
161
166
162
167
sil_witness_table ConformingStruct : ResilientProtocol module protocol_resilience {
168
+ associated_type T: ResilientConformingType
169
+ associated_type_protocol (T: OtherResilientProtocol): ResilientConformingType: OtherResilientProtocol module protocol_resilience
170
+
163
171
method #ResilientProtocol.noDefaultA!1: @noDefaultA
164
172
method #ResilientProtocol.noDefaultB!1: @noDefaultB
165
173
method #ResilientProtocol.defaultC!1: @defaultC
@@ -171,10 +179,6 @@ sil_witness_table ConformingStruct : ResilientProtocol module protocol_resilienc
171
179
// Make sure resilient conformances are accessed with an accessor function
172
180
//
173
181
174
- public struct ResilientConformingType : OtherResilientProtocol {}
175
-
176
- sil_witness_table ResilientConformingType : OtherResilientProtocol module protocol_resilience {}
177
-
178
182
// CHECK-LABEL: define{{( protected)?}} void @doSomething(%swift.opaque* noalias nocapture, %swift.type* %T, i8** %T.OtherResilientProtocol)
179
183
sil @doSomething : $@convention(thin) <T : OtherResilientProtocol> (@in T) -> () {
180
184
bb0(%0 : $*T):
@@ -280,7 +284,7 @@ struct ConformsWithResilientAssoc : HasResilientAssoc {
280
284
}
281
285
282
286
sil_witness_table ConformsWithResilientAssoc : HasResilientAssoc module protocol_resilience {
283
- associated_type T: OtherResilientProtocol
287
+ associated_type T: ResilientConformingType
284
288
associated_type_protocol (T: OtherResilientProtocol): ResilientConformingType: OtherResilientProtocol module protocol_resilience
285
289
}
286
290
@@ -316,4 +320,4 @@ bb0(%0 : $*ConformsWithResilientAssoc):
316
320
317
321
// CHECK-LABEL: define{{( protected)?}} i8** @_TWaV19protocol_resilience16ConformingStructS_17ResilientProtocolS_()
318
322
// CHECK-NEXT: entry:
319
- // CHECK-NEXT: ret i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @_TWPV19protocol_resilience16ConformingStructS_17ResilientProtocolS_, i32 0, i32 0)
323
+ // CHECK-NEXT: ret i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @_TWPV19protocol_resilience16ConformingStructS_17ResilientProtocolS_, i32 0, i32 0)
0 commit comments