@@ -2325,16 +2325,18 @@ void PatternMatchEmission::initSharedCaseBlockDest(CaseStmt *caseBlock,
23252325 }
23262326
23272327 auto pattern = caseBlock->getCaseLabelItems ()[0 ].getPattern ();
2328- pattern->forEachVariable ([&](VarDecl *V) {
2329- if (!V->hasName ())
2330- return ;
2328+ SmallVector<VarDecl *, 4 > patternVarDecls;
2329+ pattern->collectVariables (patternVarDecls);
2330+ for (auto *vd : patternVarDecls) {
2331+ if (!vd->hasName ())
2332+ continue ;
23312333
23322334 // We don't pass address-only values in basic block arguments.
2333- SILType ty = SGF.getLoweredType (V ->getType ());
2335+ SILType ty = SGF.getLoweredType (vd ->getType ());
23342336 if (ty.isAddressOnly (SGF.F .getModule ()))
2335- return ;
2336- block->createPhiArgument (ty, ValueOwnershipKind::Owned, V );
2337- });
2337+ continue ;
2338+ block->createPhiArgument (ty, ValueOwnershipKind::Owned, vd );
2339+ }
23382340}
23392341
23402342// / Retrieve the jump destination for a shared case block.
@@ -2362,9 +2364,11 @@ void PatternMatchEmission::emitAddressOnlyAllocations() {
23622364 // to point to the incoming args and setup initialization so any args needing
23632365 // cleanup will get that as well.
23642366 auto pattern = caseBlock->getCaseLabelItems ()[0 ].getPattern ();
2365- pattern->forEachVariable ([&](VarDecl *vd) {
2367+ SmallVector<VarDecl *, 4 > patternVarDecls;
2368+ pattern->collectVariables (patternVarDecls);
2369+ for (auto *vd : patternVarDecls) {
23662370 if (!vd->hasName ())
2367- return ;
2371+ continue ;
23682372
23692373 SILType ty = SGF.getLoweredType (vd->getType ());
23702374 if (ty.isNull ()) {
@@ -2383,12 +2387,11 @@ void PatternMatchEmission::emitAddressOnlyAllocations() {
23832387 }
23842388 }
23852389
2386- if (ty.isAddressOnly (SGF.F .getModule ())) {
2387- assert (!Temporaries[vd]);
2388- Temporaries[vd] = SGF.emitTemporaryAllocation (vd, ty);
2389- return ;
2390- }
2391- });
2390+ if (!ty.isAddressOnly (SGF.F .getModule ()))
2391+ continue ;
2392+ assert (!Temporaries[vd]);
2393+ Temporaries[vd] = SGF.emitTemporaryAllocation (vd, ty);
2394+ }
23922395 }
23932396
23942397 // Now we have all of our cleanups entered, so we can record the
@@ -2458,12 +2461,14 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24582461 // needing cleanup will get that as well.
24592462 Scope scope (SGF.Cleanups , CleanupLocation (caseBlock));
24602463 auto pattern = caseBlock->getCaseLabelItems ()[0 ].getPattern ();
2464+ SmallVector<VarDecl *, 4 > patternVarDecls;
2465+ pattern->collectVariables (patternVarDecls);
24612466 unsigned argIndex = 0 ;
2462- pattern-> forEachVariable ([&](VarDecl *V ) {
2463- if (!V ->hasName ())
2464- return ;
2467+ for ( auto *vd : patternVarDecls ) {
2468+ if (!vd ->hasName ())
2469+ continue ;
24652470
2466- SILType ty = SGF.getLoweredType (V ->getType ());
2471+ SILType ty = SGF.getLoweredType (vd ->getType ());
24672472
24682473 // Initialize mv at +1. We always pass values in at +1 for today into
24692474 // shared blocks.
@@ -2478,7 +2483,7 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24782483 //
24792484 // There's nothing to do here, since the value should already have
24802485 // been initialized on entry.
2481- auto found = Temporaries.find (V );
2486+ auto found = Temporaries.find (vd );
24822487 assert (found != Temporaries.end ());
24832488 mv = SGF.emitManagedRValueWithCleanup (found->second );
24842489 } else {
@@ -2488,20 +2493,20 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24882493 mv = SGF.emitManagedRValueWithCleanup (arg);
24892494 }
24902495
2491- if (V ->isLet ()) {
2496+ if (vd ->isLet ()) {
24922497 // Just emit a let and leave the cleanup alone.
2493- SGF.VarLocs [V ].value = mv.getValue ();
2494- return ;
2498+ SGF.VarLocs [vd ].value = mv.getValue ();
2499+ continue ;
24952500 }
24962501
24972502 // Otherwise, the pattern variables were all emitted as lets and one got
24982503 // passed in. Since we have a var, alloc a box for the var and forward in
24992504 // the chosen value.
2500- SGF.VarLocs .erase (V );
2501- auto newVar = SGF.emitInitializationForVarDecl (V, V ->isLet ());
2502- newVar->copyOrInitValueInto (SGF, V , mv, /* isInit*/ true );
2505+ SGF.VarLocs .erase (vd );
2506+ auto newVar = SGF.emitInitializationForVarDecl (vd, vd ->isLet ());
2507+ newVar->copyOrInitValueInto (SGF, vd , mv, /* isInit*/ true );
25032508 newVar->finishInitialization (SGF);
2504- });
2509+ }
25052510
25062511 // Now that we have setup all of the VarLocs correctly, emit the shared case
25072512 // body.
0 commit comments