Skip to content

Commit 43196c2

Browse files
committed
[IRGen] 'void **' -> 'void ***' in swift_getGenericWitnessTable.
This is simpler, because the native form of that last argument is: a pointer to a buffer (*) of pointers (*) to witness tables, which is modelled as a buffer of void *s. Thus, void ***.
1 parent ce1bb8b commit 43196c2

File tree

11 files changed

+25
-30
lines changed

11 files changed

+25
-30
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,7 @@ struct TargetGenericWitnessTable {
21452145
/// The instantiation function, which is called after the template is copied.
21462146
RelativeDirectPointer<void(TargetWitnessTable<Runtime> *instantiatedTable,
21472147
const TargetMetadata<Runtime> *type,
2148-
void * const *instantiationArgs),
2148+
void ** const *instantiationArgs),
21492149
/*nullable*/ true> Instantiator;
21502150

21512151
using PrivateDataType = void *[swift::NumGenericMetadataPrivateDataWords];
@@ -3435,7 +3435,7 @@ SWIFT_RUNTIME_EXPORT
34353435
const WitnessTable *
34363436
swift_getGenericWitnessTable(GenericWitnessTable *genericTable,
34373437
const Metadata *type,
3438-
void * const *instantiationArgs);
3438+
void **const *instantiationArgs);
34393439

34403440
/// \brief Fetch a uniqued metadata for a function type.
34413441
SWIFT_RUNTIME_EXPORT

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,12 +823,12 @@ FUNCTION(AllocateGenericValueMetadata, swift_allocateGenericValueMetadata,
823823
// const ProtocolWitnessTable *
824824
// swift_getGenericWitnessTable(GenericProtocolWitnessTable *genericTable,
825825
// const Metadata *type,
826-
// void * const *instantiationArgs);
826+
// void ** const *instantiationArgs);
827827
FUNCTION(GetGenericWitnessTable, swift_getGenericWitnessTable, C_CC,
828828
RETURNS(WitnessTablePtrTy),
829829
ARGS(getGenericWitnessTableCacheTy()->getPointerTo(),
830830
TypeMetadataPtrTy,
831-
Int8PtrPtrTy),
831+
WitnessTablePtrPtrTy),
832832
ATTRS(NoUnwind, ReadOnly))
833833

834834
// Metadata *swift_getMetatypeMetadata(Metadata *instanceTy);

lib/IRGen/GenProto.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,12 +1760,11 @@ void WitnessTableBuilder::buildAccessFunction(llvm::Constant *wtable) {
17601760

17611761
if (Conformance.witnessTableAccessorRequiresArguments()) {
17621762
metadata = params.claimNext();
1763-
auto conditionalReqtWtables = params.claimNext();
1764-
instantiationArgs =
1765-
IGF.Builder.CreateBitCast(conditionalReqtWtables, IGF.IGM.Int8PtrPtrTy);
1763+
instantiationArgs = params.claimNext();
17661764
} else {
17671765
metadata = llvm::ConstantPointerNull::get(IGF.IGM.TypeMetadataPtrTy);
1768-
instantiationArgs = llvm::ConstantPointerNull::get(IGF.IGM.Int8PtrPtrTy);
1766+
instantiationArgs =
1767+
llvm::ConstantPointerNull::get(IGF.IGM.WitnessTablePtrPtrTy);
17691768
}
17701769

17711770
// Okay, we need a cache. Build the cache structure.

stdlib/public/runtime/Metadata.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,9 +2872,10 @@ allocateWitnessTable(GenericWitnessTable *genericTable,
28722872
return entry;
28732873
}
28742874

2875-
const WitnessTable *swift::swift_getGenericWitnessTable(
2876-
GenericWitnessTable *genericTable, const Metadata *type,
2877-
void *const *instantiationArgs) {
2875+
const WitnessTable *
2876+
swift::swift_getGenericWitnessTable(GenericWitnessTable *genericTable,
2877+
const Metadata *type,
2878+
void **const *instantiationArgs) {
28782879
if (doesNotRequireInstantiation(genericTable)) {
28792880
return genericTable->Pattern;
28802881
}

test/IRGen/associated_type_witness.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ struct Computed<T, U> : Assocked {
136136
// Witness table accessor function for Computed : Assocked.
137137
// CHECK-LABEL: define hidden i8** @"$S23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWa"(%swift.type*, i8***)
138138
// CHECK-NEXT: entry:
139-
// CHECK-NEXT: [[CAST_CONDITIONAL_TABLES:%.*]] = bitcast i8*** %1 to i8**
140-
// CHECK-NEXT: [[WTABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWG", %swift.type* %0, i8** [[CAST_CONDITIONAL_TABLES]])
139+
// CHECK-NEXT: [[WTABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWG", %swift.type* %0, i8*** %1)
141140
// CHECK-NEXT: ret i8** [[WTABLE]]
142141

143142

@@ -180,8 +179,7 @@ struct GenericComputed<T: P> : DerivedFromSimpleAssoc {
180179
// Witness table accessor function for GenericComputed : HasSimpleAssoc..
181180
// CHECK-LABEL: define hidden i8** @"$S23associated_type_witness15GenericComputedVyxGAA14HasSimpleAssocAAWa"(%swift.type*, i8***)
182181
// CHECK-NEXT: entry:
183-
// CHECK-NEXT: [[CAST_CONDITIONAL_TABLES:%.*]] = bitcast i8*** %1 to i8**
184-
// CHECK-NEXT: [[WTABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S23associated_type_witness15GenericComputedVyxGAA14HasSimpleAssocAAWG", %swift.type* %0, i8** [[CAST_CONDITIONAL_TABLES]])
182+
// CHECK-NEXT: [[WTABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S23associated_type_witness15GenericComputedVyxGAA14HasSimpleAssocAAWG", %swift.type* %0, i8*** %1)
185183
// CHECK-NEXT: ret i8** [[WTABLE]]
186184

187185

test/IRGen/partial_apply_forwarder.sil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ sil hidden_external @takingEmptyAndQ : $@convention(thin) <τ_0_0 where τ_0_0
9494
// CHECK: [[GENPARAMSADDR:%.*]] = bitcast %swift.type* [[TY]] to %swift.type**
9595
// CHECK: [[PARAMTYADDR:%.*]] = getelementptr inbounds %swift.type*, %swift.type** [[GENPARAMSADDR]], {{(i64 10|i32 13)}}
9696
// CHECK: %"BaseProducer<\CF\84_0_1>" = load %swift.type*, %swift.type** [[PARAMTYADDR]]
97-
// CHECK: [[WITNESS:%.*]] = call i8** @"$S23partial_apply_forwarder12BaseProducerVyxGAA1QAAWa"(%swift.type* %"BaseProducer<\CF\84_0_1>", i8*** undef, {{i32|i64}} 0)
97+
// CHECK: [[WITNESS:%.*]] = call i8** @"$S23partial_apply_forwarder12BaseProducerVyxGAA1QAAWa"(%swift.type* %"BaseProducer<\CF\84_0_1>", i8*** undef)
9898
// CHECK: [[OBJ:%.*]] = bitcast %swift.refcounted* %0 to %T23partial_apply_forwarder7WeakBoxC.1*
9999
// CHECK: tail call swiftcc void @takingQ(%T23partial_apply_forwarder7WeakBoxC.1* [[OBJ]], i8** [[WITNESS]])
100100
// CHECK: }
@@ -151,7 +151,7 @@ bb0(%0 : $*τ_0_1, %2: $EmptyType):
151151
// CHECK: [[TYPARAMSADDR:%.*]] = bitcast %swift.type* [[TY]] to %swift.type**
152152
// CHECK: [[TYPARAM:%.*]] = getelementptr inbounds %swift.type*, %swift.type** [[TYPARAMSADDR]], {{(i64 10|i32 13)}}
153153
// CHECK: %"BaseProducer<\CF\84_0_1>" = load %swift.type*, %swift.type** [[TYPARAM]]
154-
// CHECK: [[WITNESS:%.*]] = call i8** @"$S23partial_apply_forwarder12BaseProducerVyxGAA1QAAWa"(%swift.type* %"BaseProducer<\CF\84_0_1>", i8*** undef, {{i32|i64}} 0)
154+
// CHECK: [[WITNESS:%.*]] = call i8** @"$S23partial_apply_forwarder12BaseProducerVyxGAA1QAAWa"(%swift.type* %"BaseProducer<\CF\84_0_1>", i8*** undef)
155155
// CHECK: tail call swiftcc void @takingQ(%T23partial_apply_forwarder7WeakBoxC.1* [[CAST]], i8** [[WITNESS]])
156156
// CHECK: ret void
157157

@@ -203,7 +203,7 @@ sil hidden_external @takingQAndS : $@convention(thin) <τ_0_0 where τ_0_0 : Q>
203203
// CHECK: [[GENPARAMSADDR:%.*]] = bitcast %swift.type* [[TY]] to %swift.type**
204204
// CHECK: [[GENPARAMADDR:%.*]] = getelementptr inbounds %swift.type*, %swift.type** [[GENPARAMSADDR]], {{(i64 10|i32 13)}}
205205
// CHECK: %"BaseProducer<\CF\84_0_1>" = load %swift.type*, %swift.type** [[GENPARAMADDR]]
206-
// CHECK: [[WITNESS:%.*]] = call i8** @"$S23partial_apply_forwarder12BaseProducerVyxGAA1QAAWa"(%swift.type* %"BaseProducer<\CF\84_0_1>", i8*** undef, {{i32|i64}} 0)
206+
// CHECK: [[WITNESS:%.*]] = call i8** @"$S23partial_apply_forwarder12BaseProducerVyxGAA1QAAWa"(%swift.type* %"BaseProducer<\CF\84_0_1>", i8*** undef)
207207
// CHECK: tail call swiftcc void @takingQAndS(i64 [[X]], %T23partial_apply_forwarder7WeakBoxC.1* %.asUnsubstituted, i8** [[WITNESS]])
208208

209209
sil public @bind_polymorphic_param_from_context_with_layout : $@convention(thin) <τ_0_1>(@in τ_0_1, S) -> @owned @callee_owned () -> () {

test/IRGen/protocol_resilience.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ bb0(%0 : $*ResilientConformingType):
296296

297297
// CHECK-LABEL: define{{( protected)?}} i8** @"$S19protocol_resilience23ResilientConformingTypeV010resilient_A005OtherC8ProtocolAAWa"()
298298
// CHECK-NEXT: entry:
299-
// CHECK-NEXT: [[WTABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S19protocol_resilience23ResilientConformingTypeV010resilient_A005OtherC8ProtocolAAWG", %swift.type* null, i8** null)
299+
// CHECK-NEXT: [[WTABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S19protocol_resilience23ResilientConformingTypeV010resilient_A005OtherC8ProtocolAAWG", %swift.type* null, i8*** null)
300300
// CHECK-NEXT: ret i8** [[WTABLE]]
301301

302302

test/IRGen/witness_method.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct SyncUp<Deliverable> : Synergy {
6565
// CHECK-LABEL: define{{( protected)?}} swiftcc void @testGenericWitnessMethod(%swift.opaque* noalias nocapture sret, %T14witness_method6SyncUpV* noalias nocapture, %swift.type* %T)
6666
// CHECK: entry:
6767
// CHECK: [[METADATA:%.*]] = call %swift.type* @"$S14witness_method6SyncUpVMa"(%swift.type* %T)
68-
// CHECK: [[WTABLE:%.*]] = call i8** @"$S14witness_method6SyncUpVyxGAA7SynergyAAWa"(%swift.type* [[METADATA]], i8*** undef, {{i32|i64}} 0)
68+
// CHECK: [[WTABLE:%.*]] = call i8** @"$S14witness_method6SyncUpVyxGAA7SynergyAAWa"(%swift.type* [[METADATA]], i8*** undef)
6969
// CHECK: [[WITNESS_ADDR:%.*]] = getelementptr inbounds i8*, i8** [[WTABLE]], i32 2
7070
// CHECK: [[WITNESS_FN:%.*]] = load i8*, i8** [[WITNESS_ADDR]]
7171
// CHECK: [[WITNESS:%.*]] = bitcast i8* [[WITNESS_FN]] to void (%swift.opaque*, %swift.opaque*, %swift.type*, i8**)*

test/Inputs/conditional_conformance_basic_conformances.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public func single_generic<T: P2>(_: T.Type) {
6363

6464
// CHECK-LABEL: define{{( protected)?}} i8** @"$S42conditional_conformance_basic_conformances6SingleVyxGAA2P1A2A2P2RzlWa"(%swift.type*, i8***)
6565
// CHECK-NEXT: entry:
66-
// CHECK-NEXT: [[CAST_CONDITIONAL_TABLES:%.*]] = bitcast i8*** %1 to i8**
67-
// CHECK-NEXT: [[TABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S42conditional_conformance_basic_conformances6SingleVyxGAA2P1A2A2P2RzlWG", %swift.type* %0, i8** [[CAST_CONDITIONAL_TABLES]])
66+
// CHECK-NEXT: [[TABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S42conditional_conformance_basic_conformances6SingleVyxGAA2P1A2A2P2RzlWG", %swift.type* %0, i8*** %1)
6867
// CHECK-NEXT: ret i8** [[TABLE]]
6968
// CHECK-NEXT: }
7069

@@ -186,8 +185,7 @@ public func double_generic_generic<U: P2, V: P3>(_: U.Type, _: V.Type) {
186185

187186
// CHECK-LABEL: define{{( protected)?}} i8** @"$S42conditional_conformance_basic_conformances6DoubleVyxq_GAA2P1A2A2P2RzAA2P3R_rlWa"(%swift.type*, i8***)
188187
// CHECK-NEXT: entry:
189-
// CHECK-NEXT: [[CAST_CONDITIONAL_TABLES:%.*]] = bitcast i8*** %1 to i8**
190-
// CHECK-NEXT: [[TABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S42conditional_conformance_basic_conformances6DoubleVyxq_GAA2P1A2A2P2RzAA2P3R_rlWG", %swift.type* %0, i8** [[CAST_CONDITIONAL_TABLES]])
188+
// CHECK-NEXT: [[TABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S42conditional_conformance_basic_conformances6DoubleVyxq_GAA2P1A2A2P2RzAA2P3R_rlWG", %swift.type* %0, i8*** %1)
191189
// CHECK-NEXT: ret i8** [[TABLE]]
192190
// CHECK-NEXT: }
193191

test/Inputs/conditional_conformance_subclass.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public func subclassgeneric_generic<T: P2>(_: T.Type) {
6363

6464
// CHECK-LABEL: define{{( protected)?}} i8** @"$S32conditional_conformance_subclass4BaseCyxGAA2P1A2A2P2RzlWa"(%swift.type*, i8***)
6565
// CHECK-NEXT: entry:
66-
// CHECK-NEXT: [[CAST_CONDITIONAL_TABLES:%.*]] = bitcast i8*** %1 to i8**
67-
// CHECK-NEXT: [[TABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S32conditional_conformance_subclass4BaseCyxGAA2P1A2A2P2RzlWG", %swift.type* %0, i8** [[CAST_CONDITIONAL_TABLES]])
66+
// CHECK-NEXT: [[TABLE:%.*]] = call i8** @swift_getGenericWitnessTable(%swift.generic_witness_table_cache* @"$S32conditional_conformance_subclass4BaseCyxGAA2P1A2A2P2RzlWG", %swift.type* %0, i8*** %1)
6867
// CHECK-NEXT: ret i8** [[TABLE]]
6968
// CHECK-NEXT: }
7069

unittests/runtime/Metadata.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ static void initializeRelativePointer(int32_t *ptr, T value) {
774774

775775
static void witnessTableInstantiator(WitnessTable *instantiatedTable,
776776
const Metadata *type,
777-
void * const *instantiationArgs) {
777+
void **const *instantiationArgs) {
778778
EXPECT_EQ(type, nullptr);
779779

780780
EXPECT_EQ(((void **) instantiatedTable)[1], (void*) 123);
@@ -903,7 +903,7 @@ TEST(WitnessTableTest, getGenericWitnessTable) {
903903
RaceTest_ExpectEqual<const WitnessTable *>(
904904
[&]() -> const WitnessTable * {
905905
const WitnessTable *instantiatedTable = swift_getGenericWitnessTable(
906-
table, nullptr, (void **)conditionalTablesBuffer);
906+
table, nullptr, (void ***)conditionalTablesBuffer);
907907

908908
EXPECT_NE(instantiatedTable, table->Pattern.get());
909909

@@ -942,7 +942,7 @@ TEST(WitnessTableTest, getGenericWitnessTable) {
942942
RaceTest_ExpectEqual<const WitnessTable *>(
943943
[&]() -> const WitnessTable * {
944944
const WitnessTable *instantiatedTable = swift_getGenericWitnessTable(
945-
table, nullptr, (void **)conditionalTablesBuffer);
945+
table, nullptr, (void ***)conditionalTablesBuffer);
946946

947947
EXPECT_NE(instantiatedTable, table->Pattern.get());
948948

@@ -982,7 +982,7 @@ TEST(WitnessTableTest, getGenericWitnessTable) {
982982
RaceTest_ExpectEqual<const WitnessTable *>(
983983
[&]() -> const WitnessTable * {
984984
const WitnessTable *instantiatedTable = swift_getGenericWitnessTable(
985-
table, nullptr, (void **)conditionalTablesBuffer);
985+
table, nullptr, (void ***)conditionalTablesBuffer);
986986

987987
EXPECT_NE(instantiatedTable, table->Pattern.get());
988988

0 commit comments

Comments
 (0)