Skip to content

Commit 437e938

Browse files
committed
IRGen: Bind local type metadata from conformance's type in a conditional conformance's instantiation function
rdar://43096256 SR-8495
1 parent 9b29e8d commit 437e938

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,8 @@ llvm::Constant *WitnessTableBuilder::buildInstantiationFunction() {
20312031
Explosion params = IGF.collectParameters();
20322032
Address wtable(params.claimNext(), PointerAlignment);
20332033
llvm::Value *metadata = params.claimNext();
2034+
IGF.bindLocalTypeDataFromTypeMetadata(ConcreteType, IsExact, metadata,
2035+
MetadataState::Complete);
20342036
llvm::Value *instantiationArgs = params.claimNext();
20352037
Address conditionalTables(
20362038
IGF.Builder.CreateBitCast(instantiationArgs,

test/IRGen/associated_type_witness.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ struct GenericComputed<T: P> : DerivedFromSimpleAssoc {
195195
}
196196

197197
// Instantiation function for GenericComputed : DerivedFromSimpleAssoc.
198-
// CHECK-LABEL: define internal void @"$S23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWI"(i8**, %swift.type*, i8**)
199-
// CHECK: [[T0:%.*]] = call i8** @"$S23associated_type_witness15GenericComputedVyxGAA14HasSimpleAssocAAWa"(%swift.type* %1, i8*** undef)
198+
// CHECK-LABEL: define internal void @"$S23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWI"(i8**, %swift.type* %"GenericComputed<T>", i8**)
199+
// CHECK: [[T0:%.*]] = call i8** @"$S23associated_type_witness15GenericComputedVyxGAA14HasSimpleAssocAAWa"(%swift.type* %"GenericComputed<T>", i8*** undef)
200200
// CHECK-NEXT: [[T1:%.*]] = bitcast i8** [[T0]] to i8*
201201
// CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i8*, i8** %0, i32 1
202202
// CHECK-NEXT: store i8* [[T1]], i8** [[T2]], align 8

test/Inputs/conditional_conformance_basic_conformances.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ public func double_concrete_concrete() {
259259

260260
// witness table instantiator for Single : P1
261261

262-
// CHECK-LABEL: define internal void @"$S42conditional_conformance_basic_conformances6SingleVyxGAA2P1A2A2P2RzlWI"(i8**, %swift.type*, i8**)
262+
// CHECK-LABEL: define internal void @"$S42conditional_conformance_basic_conformances6SingleVyxGAA2P1A2A2P2RzlWI"(i8**, %swift.type* %"Single<A>", i8**)
263263
// CHECK-NEXT: entry:
264-
// CHECK-NEXT: [[TABLES:%.*]] = bitcast i8** %2 to i8***
264+
// CHECK-NEXT: [[TABLES:%.*]] = bitcast i8** %1 to i8***
265265

266266
// CHECK-NEXT: [[A_P2_SRC:%.*]] = getelementptr inbounds i8**, i8*** [[TABLES]], i32 0
267267
// CHECK-NEXT: [[A_P2_DEST:%.*]] = getelementptr inbounds i8*, i8** %0, i32 -1
@@ -274,9 +274,9 @@ public func double_concrete_concrete() {
274274

275275
// witness table instantiator for Double : P1
276276

277-
// CHECK-LABEL: define internal void @"$S42conditional_conformance_basic_conformances6DoubleVyxq_GAA2P1A2A2P2RzAA2P3R_rlWI"(i8**, %swift.type*, i8**)
277+
// CHECK-LABEL: define internal void @"$S42conditional_conformance_basic_conformances6DoubleVyxq_GAA2P1A2A2P2RzAA2P3R_rlWI"(i8**, %swift.type* %"Double<B, C>", i8**)
278278
// CHECK-NEXT: entry:
279-
// CHECK-NEXT: [[TABLES:%.*]] = bitcast i8** %2 to i8***
279+
// CHECK-NEXT: [[TABLES:%.*]] = bitcast i8** %1 to i8***
280280

281281
// CHECK-NEXT: [[B_P2_SRC:%.*]] = getelementptr inbounds i8**, i8*** [[TABLES]], i32 0
282282
// CHECK-NEXT: [[B_P2_DEST:%.*]] = getelementptr inbounds i8*, i8** %0, i32 -1

test/Inputs/conditional_conformance_subclass.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ public func subclassgenericconcrete() {
178178

179179
// witness tabel instantiation function for Base : P1
180180

181-
// CHECK-LABEL: define internal void @"$S32conditional_conformance_subclass4BaseCyxGAA2P1A2A2P2RzlWI"(i8**, %swift.type*, i8**)
181+
// CHECK-LABEL: define internal void @"$S32conditional_conformance_subclass4BaseCyxGAA2P1A2A2P2RzlWI"(i8**, %swift.type* %"Base<A>", i8**)
182182
// CHECK-NEXT: entry:
183-
// CHECK-NEXT: [[TABLES:%.*]] = bitcast i8** %2 to i8***
183+
// CHECK-NEXT: [[TABLES:%.*]] = bitcast i8** %1 to i8***
184184

185185
// CHECK-NEXT: [[A_P2_SRC:%.*]] = getelementptr inbounds i8**, i8*** [[TABLES]], i32 0
186186
// CHECK-NEXT: [[A_P2_DEST:%.*]] = getelementptr inbounds i8*, i8** %0, i32 -1

test/Inputs/conditional_conformance_with_assoc.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ public func concrete_concrete() {
222222

223223
// witness table instantiator for Double : P1
224224

225-
// CHECK-LABEL: define internal void @"$S34conditional_conformance_with_assoc6DoubleVyxq_GAA2P1A2A2P3R_AA2P23AT2RpzAafH_AhaGP3AT3RPzrlWI"(i8**, %swift.type*, i8**)
225+
// CHECK-LABEL: define internal void @"$S34conditional_conformance_with_assoc6DoubleVyxq_GAA2P1A2A2P3R_AA2P23AT2RpzAafH_AhaGP3AT3RPzrlWI"(i8**, %swift.type* %"Double<B, C>", i8**)
226226
// CHECK-NEXT: entry:
227-
// CHECK-NEXT: [[TABLES:%.*]] = bitcast i8** %2 to i8***
227+
// CHECK-NEXT: [[TABLES:%.*]] = bitcast i8** %1 to i8***
228228

229229
// CHECK-NEXT: [[C_P3_SRC:%.*]] = getelementptr inbounds i8**, i8*** [[TABLES]], i32 0
230230
// CHECK-NEXT: [[C_P3_DEST:%.*]] = getelementptr inbounds i8*, i8** %0, i32 -1
@@ -247,3 +247,27 @@ public func concrete_concrete() {
247247
// CHECK-NEXT: ret void
248248
// CHECK-NEXT: }
249249

250+
protocol Base {
251+
}
252+
253+
protocol Sub : Base {
254+
associatedtype S : Base
255+
}
256+
257+
struct X<T> {
258+
}
259+
260+
extension X: Base where T: Base { }
261+
extension X: Sub where T: Sub, T.S == T {
262+
typealias S = X<T>
263+
}
264+
265+
// Make sure we can recover the type metadata from X<T>.Type.
266+
// CHECK: define internal void @"$S34conditional_conformance_with_assoc1XVyxGAA3SubA2aERz1SQzRszlWI"(i8**, %swift.type* %"X<T>", i8**)
267+
// CHECK: entry:
268+
// CHECK: [[XT_TYPE:%.*]] = bitcast %swift.type* %"X<T>" to %swift.type**
269+
// CHECK: [[ADDR:%.*]] = getelementptr inbounds %swift.type*, %swift.type** [[XT_TYPE]], i64 2
270+
// CHECK: [[T:%.*]] = load %swift.type*, %swift.type** [[ADDR]]
271+
// CHECK: %T.Base = call swiftcc i8** {{.*}}(%swift.type* %T, %swift.type* %T, i8** {{.*}})
272+
// CHECK: ret void
273+
// CHECK: }

0 commit comments

Comments
 (0)