@@ -2332,12 +2332,8 @@ void PatternMatchEmission::initSharedCaseBlockDest(CaseStmt *caseBlock,
2332
2332
auto *block = SGF.createBasicBlock ();
2333
2333
result.first ->second .first = block;
2334
2334
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 ()) {
2341
2337
if (!vd->hasName ())
2342
2338
continue ;
2343
2339
@@ -2365,14 +2361,10 @@ void PatternMatchEmission::emitAddressOnlyAllocations() {
2365
2361
for (auto &entry : SharedCases) {
2366
2362
CaseStmt *caseBlock = entry.first ;
2367
2363
2368
- auto caseBodyVars = caseBlock->getCaseBodyVariables ();
2369
- if (!caseBodyVars)
2370
- continue ;
2371
-
2372
2364
// If we have a shared case with bound decls, setup the arguments for the
2373
2365
// shared block by emitting the temporary allocation used for the arguments
2374
2366
// of the shared block.
2375
- for (auto *vd : *caseBodyVars ) {
2367
+ for (auto *vd : caseBlock-> getCaseBodyVariablesOrEmptyArray () ) {
2376
2368
if (!vd->hasName ())
2377
2369
continue ;
2378
2370
@@ -2436,8 +2428,7 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
2436
2428
assert (SGF.getCleanupsDepth () == PatternMatchStmtDepth);
2437
2429
SWIFT_DEFER { assert (SGF.getCleanupsDepth () == PatternMatchStmtDepth); };
2438
2430
2439
- auto caseBodyVars = caseBlock->getCaseBodyVariables ();
2440
- if (!caseBodyVars) {
2431
+ if (!caseBlock->hasCaseBodyVariables ()) {
2441
2432
emitCaseBody (caseBlock);
2442
2433
continue ;
2443
2434
}
@@ -2448,7 +2439,7 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
2448
2439
// args needing Cleanup will get that as well.
2449
2440
Scope scope (SGF.Cleanups , CleanupLocation (caseBlock));
2450
2441
unsigned argIndex = 0 ;
2451
- for (auto *vd : *caseBodyVars ) {
2442
+ for (auto *vd : caseBlock-> getCaseBodyVariables () ) {
2452
2443
if (!vd->hasName ())
2453
2444
continue ;
2454
2445
@@ -2606,14 +2597,14 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
2606
2597
if (!row.hasFallthroughTo () && caseBlock->getCaseLabelItems ().size () == 1 ) {
2607
2598
// If we have case body vars, set them up to point at the matching var
2608
2599
// decls.
2609
- if (auto caseBodyVars = caseBlock->getCaseBodyVariables ()) {
2600
+ if (caseBlock->hasCaseBodyVariables ()) {
2610
2601
// Since we know that we only have one case label item, grab its pattern
2611
2602
// vars and use that to update expected with the right SILValue.
2612
2603
//
2613
2604
// TODO: Do we need a copy here?
2614
2605
SmallVector<VarDecl *, 4 > patternVars;
2615
2606
row.getCasePattern ()->collectVariables (patternVars);
2616
- for (auto *expected : *caseBodyVars ) {
2607
+ for (auto *expected : caseBlock-> getCaseBodyVariables () ) {
2617
2608
if (!expected->hasName ())
2618
2609
continue ;
2619
2610
for (auto *vd : patternVars) {
@@ -2640,8 +2631,7 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
2640
2631
2641
2632
// If we do not have any bound decls, we do not need to setup any
2642
2633
// variables. Just jump to the shared destination.
2643
- auto caseBodyVars = caseBlock->getCaseBodyVariables ();
2644
- if (!caseBodyVars) {
2634
+ if (!caseBlock->hasCaseBodyVariables ()) {
2645
2635
// Don't emit anything yet, we emit it at the cleanup level of the switch
2646
2636
// statement.
2647
2637
JumpDest sharedDest = emission.getSharedCaseBlockDest (caseBlock);
@@ -2658,7 +2648,7 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
2658
2648
SILModule &M = SGF.F .getModule ();
2659
2649
SmallVector<VarDecl *, 4 > patternVars;
2660
2650
row.getCasePattern ()->collectVariables (patternVars);
2661
- for (auto *expected : *caseBodyVars ) {
2651
+ for (auto *expected : caseBlock-> getCaseBodyVariables () ) {
2662
2652
if (!expected->hasName ())
2663
2653
continue ;
2664
2654
for (auto *var : patternVars) {
@@ -2845,8 +2835,7 @@ void SILGenFunction::emitSwitchFallthrough(FallthroughStmt *S) {
2845
2835
2846
2836
// If our destination case doesn't have any bound decls, there is no rebinding
2847
2837
// to do. Just jump to the shared dest.
2848
- auto destCaseBodyVars = destCaseStmt->getCaseBodyVariables ();
2849
- if (!destCaseBodyVars) {
2838
+ if (!destCaseStmt->hasCaseBodyVariables ()) {
2850
2839
Cleanups.emitBranchAndCleanups (sharedDest, S);
2851
2840
return ;
2852
2841
}
@@ -2856,13 +2845,13 @@ void SILGenFunction::emitSwitchFallthrough(FallthroughStmt *S) {
2856
2845
SmallVector<SILValue, 4 > args;
2857
2846
CaseStmt *fallthroughSourceStmt = S->getFallthroughSource ();
2858
2847
2859
- for (auto *expected : *destCaseBodyVars ) {
2848
+ for (auto *expected : destCaseStmt-> getCaseBodyVariables () ) {
2860
2849
if (!expected->hasName ())
2861
2850
continue ;
2862
2851
2863
2852
// The type checker enforces that if our destination case has variables then
2864
2853
// our fallthrough source must as well.
2865
- for (auto *var : * fallthroughSourceStmt->getCaseBodyVariables ()) {
2854
+ for (auto *var : fallthroughSourceStmt->getCaseBodyVariables ()) {
2866
2855
if (!var->hasName () || var->getName () != expected->getName ()) {
2867
2856
continue ;
2868
2857
}
0 commit comments