@@ -2325,16 +2325,18 @@ void PatternMatchEmission::initSharedCaseBlockDest(CaseStmt *caseBlock,
2325
2325
}
2326
2326
2327
2327
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 ;
2331
2333
2332
2334
// 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 ());
2334
2336
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
+ }
2338
2340
}
2339
2341
2340
2342
// / Retrieve the jump destination for a shared case block.
@@ -2362,9 +2364,11 @@ void PatternMatchEmission::emitAddressOnlyAllocations() {
2362
2364
// to point to the incoming args and setup initialization so any args needing
2363
2365
// cleanup will get that as well.
2364
2366
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) {
2366
2370
if (!vd->hasName ())
2367
- return ;
2371
+ continue ;
2368
2372
2369
2373
SILType ty = SGF.getLoweredType (vd->getType ());
2370
2374
if (ty.isNull ()) {
@@ -2383,12 +2387,11 @@ void PatternMatchEmission::emitAddressOnlyAllocations() {
2383
2387
}
2384
2388
}
2385
2389
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
+ }
2392
2395
}
2393
2396
2394
2397
// Now we have all of our cleanups entered, so we can record the
@@ -2458,12 +2461,14 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
2458
2461
// needing cleanup will get that as well.
2459
2462
Scope scope (SGF.Cleanups , CleanupLocation (caseBlock));
2460
2463
auto pattern = caseBlock->getCaseLabelItems ()[0 ].getPattern ();
2464
+ SmallVector<VarDecl *, 4 > patternVarDecls;
2465
+ pattern->collectVariables (patternVarDecls);
2461
2466
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 ;
2465
2470
2466
- SILType ty = SGF.getLoweredType (V ->getType ());
2471
+ SILType ty = SGF.getLoweredType (vd ->getType ());
2467
2472
2468
2473
// Initialize mv at +1. We always pass values in at +1 for today into
2469
2474
// shared blocks.
@@ -2478,7 +2483,7 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
2478
2483
//
2479
2484
// There's nothing to do here, since the value should already have
2480
2485
// been initialized on entry.
2481
- auto found = Temporaries.find (V );
2486
+ auto found = Temporaries.find (vd );
2482
2487
assert (found != Temporaries.end ());
2483
2488
mv = SGF.emitManagedRValueWithCleanup (found->second );
2484
2489
} else {
@@ -2488,20 +2493,20 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
2488
2493
mv = SGF.emitManagedRValueWithCleanup (arg);
2489
2494
}
2490
2495
2491
- if (V ->isLet ()) {
2496
+ if (vd ->isLet ()) {
2492
2497
// 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 ;
2495
2500
}
2496
2501
2497
2502
// Otherwise, the pattern variables were all emitted as lets and one got
2498
2503
// passed in. Since we have a var, alloc a box for the var and forward in
2499
2504
// 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 );
2503
2508
newVar->finishInitialization (SGF);
2504
- });
2509
+ }
2505
2510
2506
2511
// Now that we have setup all of the VarLocs correctly, emit the shared case
2507
2512
// body.
0 commit comments