@@ -2332,12 +2332,8 @@ void PatternMatchEmission::initSharedCaseBlockDest(CaseStmt *caseBlock,
23322332 auto *block = SGF.createBasicBlock ();
23332333 result.first ->second .first = block;
23342334
2335- // Add args for any pattern variables
2336- auto caseBodyVars = caseBlock->getCaseBodyVariables ();
2337- if (!caseBodyVars)
2338- return ;
2339-
2340- for (auto *vd : *caseBodyVars) {
2335+ // Add args for any pattern variables if we have any.
2336+ for (auto *vd : caseBlock->getCaseBodyVariablesOrEmptyArray ()) {
23412337 if (!vd->hasName ())
23422338 continue ;
23432339
@@ -2365,14 +2361,10 @@ void PatternMatchEmission::emitAddressOnlyAllocations() {
23652361 for (auto &entry : SharedCases) {
23662362 CaseStmt *caseBlock = entry.first ;
23672363
2368- auto caseBodyVars = caseBlock->getCaseBodyVariables ();
2369- if (!caseBodyVars)
2370- continue ;
2371-
23722364 // If we have a shared case with bound decls, setup the arguments for the
23732365 // shared block by emitting the temporary allocation used for the arguments
23742366 // of the shared block.
2375- for (auto *vd : *caseBodyVars ) {
2367+ for (auto *vd : caseBlock-> getCaseBodyVariablesOrEmptyArray () ) {
23762368 if (!vd->hasName ())
23772369 continue ;
23782370
@@ -2436,8 +2428,7 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24362428 assert (SGF.getCleanupsDepth () == PatternMatchStmtDepth);
24372429 SWIFT_DEFER { assert (SGF.getCleanupsDepth () == PatternMatchStmtDepth); };
24382430
2439- auto caseBodyVars = caseBlock->getCaseBodyVariables ();
2440- if (!caseBodyVars) {
2431+ if (!caseBlock->hasCaseBodyVariables ()) {
24412432 emitCaseBody (caseBlock);
24422433 continue ;
24432434 }
@@ -2448,7 +2439,7 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24482439 // args needing Cleanup will get that as well.
24492440 Scope scope (SGF.Cleanups , CleanupLocation (caseBlock));
24502441 unsigned argIndex = 0 ;
2451- for (auto *vd : *caseBodyVars ) {
2442+ for (auto *vd : caseBlock-> getCaseBodyVariables () ) {
24522443 if (!vd->hasName ())
24532444 continue ;
24542445
@@ -2606,14 +2597,14 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
26062597 if (!row.hasFallthroughTo () && caseBlock->getCaseLabelItems ().size () == 1 ) {
26072598 // If we have case body vars, set them up to point at the matching var
26082599 // decls.
2609- if (auto caseBodyVars = caseBlock->getCaseBodyVariables ()) {
2600+ if (caseBlock->hasCaseBodyVariables ()) {
26102601 // Since we know that we only have one case label item, grab its pattern
26112602 // vars and use that to update expected with the right SILValue.
26122603 //
26132604 // TODO: Do we need a copy here?
26142605 SmallVector<VarDecl *, 4 > patternVars;
26152606 row.getCasePattern ()->collectVariables (patternVars);
2616- for (auto *expected : *caseBodyVars ) {
2607+ for (auto *expected : caseBlock-> getCaseBodyVariables () ) {
26172608 if (!expected->hasName ())
26182609 continue ;
26192610 for (auto *vd : patternVars) {
@@ -2622,7 +2613,8 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
26222613 }
26232614
26242615 // Ok, we found a match. Update the VarLocs for the case block.
2625- SGF.VarLocs [expected] = SGF.VarLocs [vd];
2616+ auto v = SGF.VarLocs [vd];
2617+ SGF.VarLocs [expected] = v;
26262618 }
26272619 }
26282620 }
@@ -2639,8 +2631,7 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
26392631
26402632 // If we do not have any bound decls, we do not need to setup any
26412633 // variables. Just jump to the shared destination.
2642- auto caseBodyVars = caseBlock->getCaseBodyVariables ();
2643- if (!caseBodyVars) {
2634+ if (!caseBlock->hasCaseBodyVariables ()) {
26442635 // Don't emit anything yet, we emit it at the cleanup level of the switch
26452636 // statement.
26462637 JumpDest sharedDest = emission.getSharedCaseBlockDest (caseBlock);
@@ -2657,7 +2648,7 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
26572648 SILModule &M = SGF.F .getModule ();
26582649 SmallVector<VarDecl *, 4 > patternVars;
26592650 row.getCasePattern ()->collectVariables (patternVars);
2660- for (auto *expected : *caseBodyVars ) {
2651+ for (auto *expected : caseBlock-> getCaseBodyVariables () ) {
26612652 if (!expected->hasName ())
26622653 continue ;
26632654 for (auto *var : patternVars) {
@@ -2844,8 +2835,7 @@ void SILGenFunction::emitSwitchFallthrough(FallthroughStmt *S) {
28442835
28452836 // If our destination case doesn't have any bound decls, there is no rebinding
28462837 // to do. Just jump to the shared dest.
2847- auto destCaseBodyVars = destCaseStmt->getCaseBodyVariables ();
2848- if (!destCaseBodyVars) {
2838+ if (!destCaseStmt->hasCaseBodyVariables ()) {
28492839 Cleanups.emitBranchAndCleanups (sharedDest, S);
28502840 return ;
28512841 }
@@ -2855,13 +2845,13 @@ void SILGenFunction::emitSwitchFallthrough(FallthroughStmt *S) {
28552845 SmallVector<SILValue, 4 > args;
28562846 CaseStmt *fallthroughSourceStmt = S->getFallthroughSource ();
28572847
2858- for (auto *expected : *destCaseBodyVars ) {
2848+ for (auto *expected : destCaseStmt-> getCaseBodyVariables () ) {
28592849 if (!expected->hasName ())
28602850 continue ;
28612851
28622852 // The type checker enforces that if our destination case has variables then
28632853 // our fallthrough source must as well.
2864- for (auto *var : * fallthroughSourceStmt->getCaseBodyVariables ()) {
2854+ for (auto *var : fallthroughSourceStmt->getCaseBodyVariables ()) {
28652855 if (!var->hasName () || var->getName () != expected->getName ()) {
28662856 continue ;
28672857 }
0 commit comments