Skip to content

Commit de283f8

Browse files
committed
Make BlackHoleInitialization support pack initialization
Fixes rdar://107151145
1 parent 08a9211 commit de283f8

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/SILGen/Initialization.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,15 @@ class BlackHoleInitialization : public Initialization {
491491
return buf;
492492
}
493493

494+
bool canPerformPackExpansionInitialization() const override {
495+
return true;
496+
}
497+
498+
void performPackExpansionInitialization(SILGenFunction &SGF,
499+
SILLocation loc,
500+
SILValue indexWithinComponent,
501+
llvm::function_ref<void(Initialization *into)> fn) override;
502+
494503
void copyOrInitValueInto(SILGenFunction &SGF, SILLocation loc,
495504
ManagedValue value, bool isInit) override;
496505

lib/SILGen/SILGenDecl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,15 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
21722172
llvm_unreachable("unhandled case");
21732173
}
21742174

2175+
void BlackHoleInitialization::performPackExpansionInitialization(
2176+
SILGenFunction &SGF,
2177+
SILLocation loc,
2178+
SILValue indexWithinComponent,
2179+
llvm::function_ref<void(Initialization *into)> fn) {
2180+
BlackHoleInitialization subInit;
2181+
fn(&subInit);
2182+
}
2183+
21752184
void BlackHoleInitialization::copyOrInitValueInto(SILGenFunction &SGF, SILLocation loc,
21762185
ManagedValue value, bool isInit) {
21772186
// Normally we do not do anything if we have a black hole

test/SILGen/variadic-generic-tuples.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,11 @@ struct MemberwiseTupleHolder<each T> {
283283
func callVariadicMemberwiseInit() -> MemberwiseTupleHolder<Int, String> {
284284
return MemberwiseTupleHolder(content: (0, "hello"))
285285
}
286+
287+
// rdar://107151145: when we tuple-destructure a black hole
288+
// initialization, the resulting element initializations need to
289+
// handle pack expansion initialization
290+
struct EmptyContainer<each T> {}
291+
func f<each T>(_: repeat each T) {
292+
let _ = (repeat EmptyContainer<each T>())
293+
}

0 commit comments

Comments
 (0)