Skip to content

Commit 8a6fddf

Browse files
authored
Merge pull request #66290 from slavapestov/class-allocating-init-with-pack
SILGen: Fix emission of class allocating init with pack expansion parameters
2 parents 1122050 + a158234 commit 8a6fddf

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -907,19 +907,25 @@ static void makeArgument(Type ty, ParamDecl *decl,
907907
SmallVectorImpl<SILValue> &args, SILGenFunction &SGF) {
908908
assert(ty && "no type?!");
909909

910+
if (ty->is<PackExpansionType>()) {
911+
ty = PackType::get(SGF.getASTContext(), {ty});
912+
}
913+
910914
// Destructure tuple value arguments.
911-
if (TupleType *tupleTy = decl->isInOut() ? nullptr : ty->getAs<TupleType>()) {
912-
for (auto fieldType : tupleTy->getElementTypes())
913-
makeArgument(fieldType, decl, args, SGF);
914-
} else {
915-
auto loweredTy = SGF.getLoweredTypeForFunctionArgument(ty);
916-
if (decl->isInOut())
917-
loweredTy = SILType::getPrimitiveAddressType(loweredTy.getASTType());
918-
auto arg = SGF.F.begin()->createFunctionArgument(loweredTy, decl);
919-
args.push_back(arg);
915+
if (!decl->isInOut()) {
916+
if (TupleType *tupleTy = ty->getAs<TupleType>()) {
917+
for (auto fieldType : tupleTy->getElementTypes())
918+
makeArgument(fieldType, decl, args, SGF);
919+
return;
920+
}
920921
}
921-
}
922922

923+
auto loweredTy = SGF.getLoweredTypeForFunctionArgument(ty);
924+
if (decl->isInOut())
925+
loweredTy = SILType::getPrimitiveAddressType(loweredTy.getASTType());
926+
auto arg = SGF.F.begin()->createFunctionArgument(loweredTy, decl);
927+
args.push_back(arg);
928+
}
923929

924930
void SILGenFunction::bindParameterForForwarding(ParamDecl *param,
925931
SmallVectorImpl<SILValue> &parameters) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-emit-silgen %s -disable-availability-checking | %FileCheck %s
2+
3+
class C<each T> {
4+
var values: (repeat each T)
5+
6+
// CHECK-LABEL: sil hidden [exact_self_class] [ossa] @$s32variadic_generic_allocating_init1CC9fromTupleACyxxQp_QPGxxQp_t_tcfC : $@convention(method) <each T> (@pack_owned Pack{repeat each T}, @thick C<repeat each T>.Type) -> @owned C<repeat each T> {
7+
// CHECK: bb0(%0 : $*Pack{repeat each T}, %1 : $@thick C<repeat each T>.Type):
8+
init(fromTuple: (repeat each T)) {
9+
self.values = fromTuple
10+
}
11+
12+
// CHECK-LABEL: sil hidden [exact_self_class] [ossa] @$s32variadic_generic_allocating_init1CC8fromPackACyxxQp_QPGxxQp_tcfC : $@convention(method) <each T> (@pack_owned Pack{repeat each T}, @thick C<repeat each T>.Type) -> @owned C<repeat each T> {
13+
// CHECK: bb0(%0 : $*Pack{repeat each T}, %1 : $@thick C<repeat each T>.Type):
14+
init(fromPack: repeat each T) {
15+
self.values = (repeat each fromPack)
16+
}
17+
}

0 commit comments

Comments
 (0)