Skip to content

Commit c5ab104

Browse files
committed
IRGen: Stub out more support for type parameter packs
1 parent 9f3267b commit c5ab104

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,10 +3409,16 @@ void irgen::bindFromGenericRequirementsBuffer(IRGenFunction &IGF,
34093409
}
34103410

34113411
// Cast if necessary.
3412-
if (requirements[index].isWitnessTable()) {
3412+
switch (requirements[index].getKind()) {
3413+
case GenericRequirement::Kind::Shape:
3414+
slot = IGF.Builder.CreateElementBitCast(slot, IGF.IGM.SizeTy);
3415+
break;
3416+
case GenericRequirement::Kind::Metadata:
3417+
slot = IGF.Builder.CreateElementBitCast(slot, IGF.IGM.TypeMetadataPtrTy);
3418+
break;
3419+
case GenericRequirement::Kind::WitnessTable:
34133420
slot = IGF.Builder.CreateElementBitCast(slot, IGF.IGM.WitnessTablePtrTy);
3414-
} else {
3415-
assert(requirements[index].isMetadata());
3421+
break;
34163422
}
34173423

34183424
llvm::Value *value = IGF.Builder.CreateLoad(slot);

lib/IRGen/GenericArguments.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,16 @@ struct GenericArguments {
6464
void collectTypes(IRGenModule &IGM,
6565
const GenericTypeRequirements &requirements) {
6666
for (auto &requirement : requirements.getRequirements()) {
67-
if (requirement.isWitnessTable()) {
68-
Types.push_back(IGM.WitnessTablePtrTy);
69-
} else {
70-
assert(requirement.isMetadata());
67+
switch (requirement.getKind()) {
68+
case GenericRequirement::Kind::Shape:
69+
Types.push_back(IGM.SizeTy);
70+
break;
71+
case GenericRequirement::Kind::Metadata:
7172
Types.push_back(IGM.TypeMetadataPtrTy);
73+
break;
74+
case GenericRequirement::Kind::WitnessTable:
75+
Types.push_back(IGM.WitnessTablePtrTy);
76+
break;
7277
}
7378
}
7479
}

lib/IRGen/MetadataRequest.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,14 +2408,21 @@ MetadataResponse irgen::emitGenericTypeMetadataAccessFunction(
24082408
IGM.setColocateMetadataSection(thunkFn);
24092409

24102410
// Call out to the helper.
2411+
auto getNextParam = [&]() -> llvm::Value * {
2412+
auto *param = params.claimNext();
2413+
if (param->getType()->isPointerTy())
2414+
return IGF.Builder.CreateBitCast(param, IGM.Int8PtrTy);
2415+
return IGF.Builder.CreateIntToPtr(param, IGM.Int8PtrTy);
2416+
};
2417+
24112418
auto arg0 = numArguments >= 1
2412-
? IGF.Builder.CreateBitCast(params.claimNext(), IGM.Int8PtrTy)
2419+
? getNextParam()
24132420
: llvm::UndefValue::get(IGM.Int8PtrTy);
24142421
auto arg1 = numArguments >= 2
2415-
? IGF.Builder.CreateBitCast(params.claimNext(), IGM.Int8PtrTy)
2422+
? getNextParam()
24162423
: llvm::UndefValue::get(IGM.Int8PtrTy);
24172424
auto arg2 = numArguments >= 3
2418-
? IGF.Builder.CreateBitCast(params.claimNext(), IGM.Int8PtrTy)
2425+
? getNextParam()
24192426
: llvm::UndefValue::get(IGM.Int8PtrTy);
24202427

24212428
llvm::CallInst *call;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend -emit-ir -primary-file %s -enable-experimental-feature VariadicGenerics | %FileCheck %s
2+
3+
// Because of -enable-experimental-feature VariadicGenerics
4+
// REQUIRES: asserts
5+
6+
// REQUIRES: PTRSIZE=64
7+
8+
struct G<T...> {
9+
// CHECK-LABEL: define hidden swiftcc void @"$s22variadic_generic_types1GV6calleeyyF"(i64 %0, %swift.type* %T)
10+
// CHECK: ret void
11+
func callee() {}
12+
13+
// CHECK-LABEL: define hidden swiftcc void @"$s22variadic_generic_types1GV6calleryyF"(i64 %0, %swift.type* %T)
14+
// CHECK: call swiftcc void @"$s22variadic_generic_types1GV6calleeyyF"(i64 %0, %swift.type* %T)
15+
// CHECK: ret void
16+
func caller() {
17+
callee()
18+
}
19+
}

0 commit comments

Comments
 (0)