@@ -527,6 +527,7 @@ void SILGenFunction::emitPartialDestroyPack(SILLocation loc, SILValue packAddr,
527527 emitDynamicPackLoop (loc, formalPackType, componentIndex,
528528 /* startAfter*/ SILValue (), limitWithinComponent,
529529 elementEnv, /* reverse*/ true ,
530+ []() -> SILBasicBlock * { return nullptr ; },
530531 [&](SILValue indexWithinComponent,
531532 SILValue packExpansionIndex,
532533 SILValue packIndex) {
@@ -548,6 +549,7 @@ void SILGenFunction::emitPartialDestroyRemainingPack(SILLocation loc,
548549 emitDynamicPackLoop (loc, formalPackType, componentIndex,
549550 /* startAfter*/ currentIndexWithinComponent,
550551 /* limit*/ SILValue (), elementEnv, /* reverse*/ false ,
552+ []() -> SILBasicBlock * { return nullptr ; },
551553 [&](SILValue indexWithinComponent,
552554 SILValue packExpansionIndex,
553555 SILValue packIndex) {
@@ -570,6 +572,7 @@ void SILGenFunction::emitPartialDestroyTuple(SILLocation loc,
570572 emitDynamicPackLoop (loc, inducedPackType, componentIndex,
571573 /* startAfter*/ SILValue (), limitWithinComponent,
572574 elementEnv, /* reverse*/ true ,
575+ []() -> SILBasicBlock * { return nullptr ; },
573576 [&](SILValue indexWithinComponent,
574577 SILValue packExpansionIndex,
575578 SILValue packIndex) {
@@ -592,6 +595,7 @@ void SILGenFunction::emitPartialDestroyRemainingTuple(SILLocation loc,
592595 emitDynamicPackLoop (loc, inducedPackType, componentIndex,
593596 /* startAfter*/ currentIndexWithinComponent,
594597 /* limit*/ SILValue (), elementEnv, /* reverse*/ false ,
598+ []() -> SILBasicBlock * { return nullptr ; },
595599 [&](SILValue indexWithinComponent,
596600 SILValue packExpansionIndex,
597601 SILValue packIndex) {
@@ -650,6 +654,7 @@ void SILGenFunction::copyPackElementsToTuple(SILLocation loc,
650654
651655 emitDynamicPackLoop (
652656 loc, formalPackType, /* componentIndex=*/ 0 , elementEnv,
657+ []() -> SILBasicBlock * { return nullptr ; },
653658 [&](SILValue indexWithinComponent,
654659 SILValue packExpansionIndex,
655660 SILValue packIndex) {
@@ -673,6 +678,7 @@ void SILGenFunction::projectTupleElementsToPack(SILLocation loc,
673678
674679 emitDynamicPackLoop (
675680 loc, formalPackType, /* componentIndex=*/ 0 , elementEnv,
681+ []() -> SILBasicBlock * { return nullptr ; },
676682 [&](SILValue indexWithinComponent,
677683 SILValue packExpansionIndex,
678684 SILValue packIndex) {
@@ -685,24 +691,24 @@ void SILGenFunction::projectTupleElementsToPack(SILLocation loc,
685691void SILGenFunction::emitDynamicPackLoop (
686692 SILLocation loc, CanPackType formalPackType, unsigned componentIndex,
687693 GenericEnvironment *openedElementEnv,
694+ llvm::function_ref<SILBasicBlock *()> emitLoopLatch,
688695 llvm::function_ref<void(SILValue indexWithinComponent,
689696 SILValue packExpansionIndex, SILValue packIndex)>
690- emitBody,
691- SILBasicBlock *loopLatch) {
697+ emitBody) {
692698 return emitDynamicPackLoop (loc, formalPackType, componentIndex,
693699 /* startAfter*/ SILValue (), /* limit*/ SILValue (),
694- openedElementEnv, /* reverse*/ false , emitBody,
695- loopLatch );
700+ openedElementEnv, /* reverse*/ false ,
701+ emitLoopLatch, emitBody );
696702}
697703
698704void SILGenFunction::emitDynamicPackLoop (
699705 SILLocation loc, CanPackType formalPackType, unsigned componentIndex,
700706 SILValue startingAfterIndexInComponent, SILValue limitWithinComponent,
701707 GenericEnvironment *openedElementEnv, bool reverse,
708+ llvm::function_ref<SILBasicBlock *()> emitLoopLatch,
702709 llvm::function_ref<void(SILValue indexWithinComponent,
703710 SILValue packExpansionIndex, SILValue packIndex)>
704- emitBody,
705- SILBasicBlock *loopLatch) {
711+ emitBody) {
706712 assert (isa<PackExpansionType>(formalPackType.getElementType (componentIndex)));
707713 assert ((!startingAfterIndexInComponent || !reverse) &&
708714 " cannot reverse with a starting index" );
@@ -719,6 +725,8 @@ void SILGenFunction::emitDynamicPackLoop(
719725 if (auto *expansion = loc.getAsASTNode <PackExpansionExpr>())
720726 prepareToEmitPackExpansionExpr (expansion);
721727
728+ auto *loopLatch = emitLoopLatch ();
729+
722730 auto wordTy = SILType::getBuiltinWordType (ctx);
723731 auto boolTy = SILType::getBuiltinIntegerType (1 , ctx);
724732
@@ -1073,6 +1081,7 @@ SILGenFunction::emitPackTransform(SILLocation loc,
10731081 }
10741082
10751083 emitDynamicPackLoop (loc, inputFormalPackType, inputComponentIndex, openedEnv,
1084+ []() -> SILBasicBlock * { return nullptr ; },
10761085 [&](SILValue indexWithinComponent,
10771086 SILValue packExpansionIndex,
10781087 SILValue inputPackIndex) {
0 commit comments