Skip to content

Commit 0a87b5a

Browse files
committed
IRGen: Test default witnesses for protocols with associated types now that IRGen supports this
1 parent ceb58ea commit 0a87b5a

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

test/IRGen/protocol_resilience.sil

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import SwiftShims
99

1010
import resilient_protocol
1111

12-
// TODO: default implementations for protocols with associated types
13-
14-
1512
// Witness table for conformance with resilient associated type
1613

1714
// CHECK: @_TWPV19protocol_resilience26ConformsWithResilientAssocS_17HasResilientAssocS_ = {{(protected )?}}constant [2 x i8*] [
@@ -32,6 +29,8 @@ import resilient_protocol
3229

3330

3431
public protocol ResilientProtocol {
32+
associatedtype T : OtherResilientProtocol
33+
3534
func noDefaultA()
3635
func noDefaultB()
3736
func defaultC()
@@ -74,17 +73,17 @@ bb0(%0 : $*Self):
7473

7574
// CHECK-NEXT: call void @defaultC(%swift.opaque* noalias nocapture %0, %swift.type* %Self, i8** %SelfWitnessTable)
7675
%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) -> ()
7877

7978
// Make sure we can do dynamic dispatch to other protocol requirements
8079
// from a default implementation
8180

82-
// CHECK-NEXT: [[WITNESS_ADDR:%.*]] = getelementptr inbounds i8*, i8** %SelfWitnessTable, i32 2
81+
// CHECK-NEXT: [[WITNESS_ADDR:%.*]] = getelementptr inbounds i8*, i8** %SelfWitnessTable, i32 4
8382
// CHECK-NEXT: [[WITNESS_FN:%.*]] = load i8*, i8** [[WITNESS_ADDR]]
8483
// CHECK-NEXT: [[WITNESS:%.*]] = bitcast i8* [[WITNESS_FN]] to void (%swift.opaque*, %swift.type*, i8**)*
8584
// CHECK-NEXT: call void [[WITNESS]](%swift.opaque* noalias nocapture %0, %swift.type* %Self, i8** %SelfWitnessTable)
8685
%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) -> ()
8887

8988
// Make sure we can partially apply a static reference to a default
9089
// implementation
@@ -96,7 +95,7 @@ bb0(%0 : $*Self):
9695
// CHECK-NEXT: store i8* [[WTABLE]], i8** [[WTABLE_ADDR]]
9796

9897
%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) -> ()
10099

101100
// CHECK-NEXT: ret void
102101
%result = tuple ()
@@ -110,7 +109,13 @@ sil_default_witness_table ResilientProtocol 2 {
110109
}
111110

112111

112+
public struct ResilientConformingType : OtherResilientProtocol {}
113+
114+
sil_witness_table ResilientConformingType : OtherResilientProtocol module protocol_resilience {}
115+
116+
113117
struct ConformingStruct : ResilientProtocol {
118+
typealias T = ResilientConformingType
114119
func noDefaultA()
115120
func noDefaultB()
116121
func defaultC()
@@ -128,9 +133,9 @@ bb0(%0 : $*ConformingStruct):
128133
// might)
129134

130135
// 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))
132137
%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) -> ()
134139

135140
// CHECK-NEXT: ret void
136141
%result = tuple ()
@@ -149,17 +154,20 @@ bb0(%0 : $*ConformingStruct):
149154
// CHECK-NEXT: [[CONTEXT:%.*]] = call noalias %swift.refcounted* @swift_allocObject({{.*}})
150155
// CHECK-NEXT: [[LAYOUT:%.*]] = bitcast %swift.refcounted* [[CONTEXT]] to <{ %swift.refcounted, i8* }>*
151156
// 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]]
153158

154159
%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) -> ()
156161

157162
// CHECK-NEXT: ret void
158163
%result = tuple ()
159164
return %result : $()
160165
}
161166

162167
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+
163171
method #ResilientProtocol.noDefaultA!1: @noDefaultA
164172
method #ResilientProtocol.noDefaultB!1: @noDefaultB
165173
method #ResilientProtocol.defaultC!1: @defaultC
@@ -171,10 +179,6 @@ sil_witness_table ConformingStruct : ResilientProtocol module protocol_resilienc
171179
// Make sure resilient conformances are accessed with an accessor function
172180
//
173181

174-
public struct ResilientConformingType : OtherResilientProtocol {}
175-
176-
sil_witness_table ResilientConformingType : OtherResilientProtocol module protocol_resilience {}
177-
178182
// CHECK-LABEL: define{{( protected)?}} void @doSomething(%swift.opaque* noalias nocapture, %swift.type* %T, i8** %T.OtherResilientProtocol)
179183
sil @doSomething : $@convention(thin) <T : OtherResilientProtocol> (@in T) -> () {
180184
bb0(%0 : $*T):
@@ -280,7 +284,7 @@ struct ConformsWithResilientAssoc : HasResilientAssoc {
280284
}
281285

282286
sil_witness_table ConformsWithResilientAssoc : HasResilientAssoc module protocol_resilience {
283-
associated_type T: OtherResilientProtocol
287+
associated_type T: ResilientConformingType
284288
associated_type_protocol (T: OtherResilientProtocol): ResilientConformingType: OtherResilientProtocol module protocol_resilience
285289
}
286290

@@ -316,4 +320,4 @@ bb0(%0 : $*ConformsWithResilientAssoc):
316320

317321
// CHECK-LABEL: define{{( protected)?}} i8** @_TWaV19protocol_resilience16ConformingStructS_17ResilientProtocolS_()
318322
// 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

Comments
 (0)