@@ -44,24 +44,26 @@ class DeallocPackCleanup : public Cleanup {
44
44
class DestroyPackCleanup : public Cleanup {
45
45
SILValue Addr;
46
46
CanPackType FormalPackType;
47
- unsigned FirstComponentIndex ;
47
+ unsigned BeginIndex, EndIndex ;
48
48
public:
49
49
DestroyPackCleanup (SILValue addr, CanPackType formalPackType,
50
- unsigned firstComponentIndex = 0 )
50
+ unsigned beginIndex, unsigned endIndex )
51
51
: Addr(addr), FormalPackType(formalPackType),
52
- FirstComponentIndex (firstComponentIndex ) {}
52
+ BeginIndex (beginIndex), EndIndex(endIndex ) {}
53
53
54
54
void emit (SILGenFunction &SGF, CleanupLocation l,
55
55
ForUnwind_t forUnwind) override {
56
- SGF.emitDestroyPack (l, Addr, FormalPackType, FirstComponentIndex );
56
+ SGF.emitDestroyPack (l, Addr, FormalPackType, BeginIndex, EndIndex );
57
57
}
58
58
59
59
void dump (SILGenFunction &) const override {
60
60
#ifndef NDEBUG
61
61
llvm::errs () << " DestroyPackCleanup\n "
62
- << " State: " << getState () << " \n "
63
- << " Addr: " << Addr << " FormalPackType: " << FormalPackType
64
- << " FirstComponentIndex:" << FirstComponentIndex << " \n " ;
62
+ << " State:" << getState () << " \n "
63
+ << " Addr:" << Addr << " \n "
64
+ << " FormalPackType:" << FormalPackType << " \n "
65
+ << " BeginIndex:" << BeginIndex << " \n "
66
+ << " EndIndex:" << EndIndex << " \n " ;
65
67
#endif
66
68
}
67
69
};
@@ -295,19 +297,29 @@ CleanupHandle SILGenFunction::enterDeallocPackCleanup(SILValue temp) {
295
297
296
298
CleanupHandle SILGenFunction::enterDestroyPackCleanup (SILValue addr,
297
299
CanPackType formalPackType) {
298
- Cleanups.pushCleanup <DestroyPackCleanup>(addr, formalPackType);
300
+ Cleanups.pushCleanup <DestroyPackCleanup>(addr, formalPackType,
301
+ 0 , formalPackType->getNumElements ());
299
302
return Cleanups.getTopCleanup ();
300
303
}
301
304
302
305
CleanupHandle
303
- SILGenFunction::enterDestroyRemainingPackComponentsCleanup (SILValue addr,
306
+ SILGenFunction::enterDestroyPrecedingPackComponentsCleanup (SILValue addr,
304
307
CanPackType formalPackType,
305
308
unsigned componentIndex) {
306
309
Cleanups.pushCleanup <DestroyPackCleanup>(addr, formalPackType,
307
- componentIndex);
310
+ 0 , componentIndex);
308
311
return Cleanups.getTopCleanup ();
309
312
}
310
313
314
+ CleanupHandle
315
+ SILGenFunction::enterDestroyRemainingPackComponentsCleanup (SILValue addr,
316
+ CanPackType formalPackType,
317
+ unsigned componentIndex) {
318
+ Cleanups.pushCleanup <DestroyPackCleanup>(addr, formalPackType,
319
+ componentIndex,
320
+ formalPackType->getNumElements ());
321
+ return Cleanups.getTopCleanup ();
322
+ }
311
323
312
324
CleanupHandle
313
325
SILGenFunction::enterPartialDestroyPackCleanup (SILValue addr,
@@ -369,12 +381,15 @@ SILGenFunction::enterDestroyRemainingTupleElementsCleanup(SILValue addr,
369
381
370
382
void SILGenFunction::emitDestroyPack (SILLocation loc, SILValue packAddr,
371
383
CanPackType formalPackType,
372
- unsigned firstComponentIndex) {
384
+ unsigned beginIndex,
385
+ unsigned endIndex) {
373
386
auto packTy = packAddr->getType ().castTo <SILPackType>();
374
387
388
+ assert (beginIndex <= endIndex);
389
+ assert (endIndex <= packTy->getNumElements ());
390
+
375
391
// Destroy each of the elements of the pack.
376
- for (auto componentIndex :
377
- range (firstComponentIndex, packTy->getNumElements ())) {
392
+ for (auto componentIndex : range (beginIndex, endIndex)) {
378
393
auto eltTy = packTy->getSILElementType (componentIndex);
379
394
380
395
// We can skip this if the whole thing is trivial.
0 commit comments