Skip to content

Commit 45248fb

Browse files
committed
---
yaml --- r: 347124 b: refs/heads/master c: d23a7ba h: refs/heads/master
1 parent 6ed5082 commit 45248fb

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 88d1183e589363a9722c7db5090a55a5d1ec187b
2+
refs/heads/master: d23a7ba5271300c2e743e42831c04a91debc3a1c
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/SILGen/SILGenPattern.cpp

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)