Skip to content

Commit 0fc6752

Browse files
authored
Merge pull request #85415 from slavapestov/fix-issue-78598
SILGen: Fix break/continue inside 'for ... in ... repeat' loop
2 parents 50ae204 + 522a6b7 commit 0fc6752

14 files changed

+231
-29
lines changed

lib/SILGen/ResultPlan.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ class PackTransformResultPlan final : public ResultPlan {
524524
// Loop over the pack, initializing each value with the appropriate
525525
// element.
526526
SGF.emitDynamicPackLoop(loc, FormalPackType, ComponentIndex, openedEnv,
527+
[]() -> SILBasicBlock * { return nullptr; },
527528
[&](SILValue indexWithinComponent,
528529
SILValue expansionIndex,
529530
SILValue packIndex) {
@@ -1313,6 +1314,7 @@ ResultPlanBuilder::buildPackExpansionIntoPack(SILValue packAddr,
13131314
// we can emit a dynamic loop to do that now.
13141315
if (init->canPerformInPlacePackInitialization(openedEnv, eltTy)) {
13151316
SGF.emitDynamicPackLoop(loc, formalPackType, componentIndex, openedEnv,
1317+
[]() -> SILBasicBlock * { return nullptr; },
13161318
[&](SILValue indexWithinComponent,
13171319
SILValue expansionPackIndex,
13181320
SILValue packIndex) {
@@ -1334,6 +1336,7 @@ ResultPlanBuilder::buildPackExpansionIntoPack(SILValue packAddr,
13341336
SILType::getPrimitiveObjectType(tupleTy));
13351337

13361338
SGF.emitDynamicPackLoop(loc, formalPackType, componentIndex, openedEnv,
1339+
[]() -> SILBasicBlock * { return nullptr; },
13371340
[&](SILValue indexWithinComponent,
13381341
SILValue expansionPackIndex,
13391342
SILValue packIndex) {

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4345,6 +4345,7 @@ class ArgEmitter {
43454345
auto openedElementEnv = expansionExpr->getGenericEnvironment();
43464346
SGF.emitDynamicPackLoop(expansionExpr, formalPackType,
43474347
packComponentIndex, openedElementEnv,
4348+
[]() -> SILBasicBlock * { return nullptr; },
43484349
[&](SILValue indexWithinComponent,
43494350
SILValue packExpansionIndex,
43504351
SILValue packIndex) {

lib/SILGen/SILGenConstructor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static RValue emitImplicitValueConstructorArg(SILGenFunction &SGF,
212212
auto formalPackType = CanPackType::get(SGF.getASTContext(), {type});
213213

214214
SGF.emitDynamicPackLoop(loc, formalPackType, /*component*/0, openedEnv,
215+
[]() -> SILBasicBlock * { return nullptr; },
215216
[&](SILValue indexWithinComponent,
216217
SILValue packExpansionIndex,
217218
SILValue packIndex) {

lib/SILGen/SILGenDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static void copyOrInitPackExpansionInto(SILGenFunction &SGF,
7676
SGF.Cleanups.forwardCleanup(componentCleanup);
7777

7878
SGF.emitDynamicPackLoop(loc, formalPackType, componentIndex, openedEnv,
79+
[]() -> SILBasicBlock * { return nullptr; },
7980
[&](SILValue indexWithinComponent,
8081
SILValue packExpansionIndex,
8182
SILValue packIndex) {

lib/SILGen/SILGenDestructor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ void SILGenFunction::emitIsolatingDestructor(DestructorDecl *dd) {
429429
B.createIntegerLiteral(loc, wordTy, 0);
430430

431431
// Schedule isolated execution
432-
B.createApply(loc, swiftDeinitOnExecutorFunc, {},
432+
B.createApply(loc, swiftDeinitOnExecutorFunc,
433+
getForwardingSubstitutionMap(),
433434
{castedSelf, castedDeallocator, executor, flagsInst});
434435
});
435436
}

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,7 @@ RValueEmitter::visitPackExpansionExpr(PackExpansionExpr *E,
16521652

16531653
SGF.emitDynamicPackLoop(E, formalPackType, /*component index*/ 0,
16541654
E->getGenericEnvironment(),
1655+
[]() -> SILBasicBlock * { return nullptr; },
16551656
[&](SILValue indexWithinComponent,
16561657
SILValue packExpansionIndex,
16571658
SILValue packIndex) {
@@ -7587,6 +7588,7 @@ static void emitIgnoredPackExpansion(SILGenFunction &SGF,
75877588
auto openedElementEnv = E->getGenericEnvironment();
75887589
SGF.emitDynamicPackLoop(E, formalPackType, /*component index*/ 0,
75897590
openedElementEnv,
7591+
[]() -> SILBasicBlock * { return nullptr; },
75907592
[&](SILValue indexWithinComponent,
75917593
SILValue packExpansionIndex,
75927594
SILValue packIndex) {

lib/SILGen/SILGenFunction.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,6 +3174,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
31743174
/// within the loop; can be null to bind no elements
31753175
/// \param reverse - if true, iterate the elements in reverse order,
31763176
/// starting at index limitWithinComponent - 1
3177+
/// \param emitLoopLatch - emit the entry block.
31773178
/// \param emitBody - a function that will be called to emit the body of
31783179
/// the loop. It's okay if this has paths that exit the body of the loop,
31793180
/// but it should leave the insertion point set at the end.
@@ -3191,20 +3192,20 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
31913192
SILLocation loc, CanPackType formalPackType, unsigned componentIndex,
31923193
SILValue startingAfterIndexWithinComponent, SILValue limitWithinComponent,
31933194
GenericEnvironment *openedElementEnv, bool reverse,
3195+
llvm::function_ref<SILBasicBlock *()> emitLoopLatch,
31943196
llvm::function_ref<void(SILValue indexWithinComponent,
31953197
SILValue packExpansionIndex, SILValue packIndex)>
3196-
emitBody,
3197-
SILBasicBlock *loopLatch = nullptr);
3198+
emitBody);
31983199

31993200
/// A convenience version of dynamic pack loop that visits an entire
32003201
/// pack expansion component in forward order.
32013202
void emitDynamicPackLoop(
32023203
SILLocation loc, CanPackType formalPackType, unsigned componentIndex,
32033204
GenericEnvironment *openedElementEnv,
3205+
llvm::function_ref<SILBasicBlock *()> emitLoopLatch,
32043206
llvm::function_ref<void(SILValue indexWithinComponent,
32053207
SILValue packExpansionIndex, SILValue packIndex)>
3206-
emitBody,
3207-
SILBasicBlock *loopLatch = nullptr);
3208+
emitBody);
32083209

32093210
/// Emit a transform on each element of a pack-expansion component
32103211
/// of a pack, write the result into a pack-expansion component of

lib/SILGen/SILGenPack.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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,
685691
void 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

698704
void 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) {

lib/SILGen/SILGenPoly.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4019,6 +4019,7 @@ ManagedValue ResultPlanner::expandPackExpansion(
40194019
// expansion in the inner pack.
40204020
SGF.emitDynamicPackLoop(Loc, innerFormalPackType, innerComponentIndex,
40214021
openedEnv,
4022+
[]() -> SILBasicBlock * { return nullptr; },
40224023
[&](SILValue indexWithinComponent,
40234024
SILValue packExpansionIndex,
40244025
SILValue innerPackIndex) {
@@ -4164,6 +4165,7 @@ ManagedValue TranslateArguments::expandPackExpansion(
41644165
// index.
41654166
SGF.emitDynamicPackLoop(Loc, innerFormalPackType, innerComponentIndex,
41664167
openedEnv,
4168+
[]() -> SILBasicBlock * { return nullptr; },
41674169
[&](SILValue indexWithinComponent,
41684170
SILValue packExpansionIndex,
41694171
SILValue innerPackIndex) {
@@ -4300,6 +4302,7 @@ void ResultPlanner::Operation::emitReabstractTupleIntoPackExpansion(
43004302

43014303
SGF.emitDynamicPackLoop(loc, innerFormalPackType, innerComponentIndex,
43024304
openedEnv,
4305+
[]() -> SILBasicBlock * { return nullptr; },
43034306
[&](SILValue indexWithinComponent,
43044307
SILValue packExpansionIndex,
43054308
SILValue innerPackIndex) {

lib/SILGen/SILGenProlog.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,11 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
597597
{&substEltType});
598598

599599
SGF.emitDynamicPackLoop(loc, inducedPackType, packComponentIndex,
600-
openedEnv, [&](SILValue indexWithinComponent,
601-
SILValue expansionPackIndex,
602-
SILValue packIndex) {
600+
openedEnv,
601+
[]() -> SILBasicBlock * { return nullptr; },
602+
[&](SILValue indexWithinComponent,
603+
SILValue expansionPackIndex,
604+
SILValue packIndex) {
603605
componentInit->performPackExpansionInitialization(SGF, loc,
604606
indexWithinComponent,
605607
[&](Initialization *eltInit) {

0 commit comments

Comments
 (0)