10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include " ArgumentScope.h"
14
+ #include " RValue.h"
13
15
#include " SILGenFunction.h"
14
16
#include " SILGenFunctionBuilder.h"
15
- #include " RValue.h"
16
- #include " ArgumentScope.h"
17
- #include " llvm/ADT/SmallSet.h"
18
17
#include " swift/AST/GenericSignature.h"
19
18
#include " swift/AST/SubstitutionMap.h"
20
19
#include " swift/SIL/TypeLowering.h"
20
+ #include " llvm/ADT/SmallSet.h"
21
21
22
22
using namespace swift ;
23
23
using namespace Lowering ;
@@ -220,76 +220,79 @@ void SILGenFunction::destroyClassMember(SILLocation cleanupLoc,
220
220
}
221
221
}
222
222
223
- llvm::SmallSetVector<VarDecl*, 4 > findRecursiveLinks (DeclContext* DC, ClassDecl *cd) {
223
+ llvm::SmallSetVector<VarDecl *, 4 > findRecursiveLinks (DeclContext *DC,
224
+ ClassDecl *cd) {
224
225
auto SelfTy = DC->mapTypeIntoContext (cd->getDeclaredType ());
225
226
226
227
// Collect all stored properties that would form a recursive structure,
227
228
// so we can remove the recursion and prevent the call stack from
228
229
// overflowing.
229
- llvm::SmallSetVector<VarDecl*, 4 > recursiveLinks;
230
+ llvm::SmallSetVector<VarDecl *, 4 > recursiveLinks;
230
231
for (VarDecl *vd : cd->getStoredProperties ()) {
231
232
auto Ty = vd->getType ()->getOptionalObjectType ();
232
233
if (Ty && Ty->getCanonicalType () == SelfTy->getCanonicalType ()) {
233
234
recursiveLinks.insert (vd);
234
235
}
235
236
}
236
237
237
- // NOTE: Right now we only optimize linear recursion, so if there is more than one link,
238
- // clear out the set and don't perform any recursion optimization.
238
+ // NOTE: Right now we only optimize linear recursion, so if there is more than
239
+ // one link, clear out the set and don't perform any recursion optimization.
239
240
if (recursiveLinks.size () < 1 ) {
240
241
recursiveLinks.clear ();
241
242
}
242
243
243
244
return recursiveLinks;
244
245
}
245
246
246
-
247
- void SILGenFunction::emitRecursiveChainDestruction (ManagedValue selfValue,
248
- ClassDecl *cd,
249
- SmallSetVector<VarDecl*, 4 > recursiveLinks,
250
- CleanupLocation cleanupLoc) {
247
+ void SILGenFunction::emitRecursiveChainDestruction (
248
+ ManagedValue selfValue, ClassDecl *cd,
249
+ SmallSetVector<VarDecl *, 4 > recursiveLinks, CleanupLocation cleanupLoc) {
251
250
auto SelfTy = F.mapTypeIntoContext (cd->getDeclaredType ());
252
251
253
252
assert (recursiveLinks.size () <= 1 && " Only linear recursion supported." );
254
253
255
254
auto SelfTyLowered = getTypeLowering (SelfTy).getLoweredType ();
256
- for (VarDecl* vd : recursiveLinks) {
257
- SILBasicBlock* cleanBB = createBasicBlock ();
258
- SILBasicBlock* noneBB = createBasicBlock ();
259
- SILBasicBlock* notUniqueBB = createBasicBlock ();
260
- SILBasicBlock* uniqueBB = createBasicBlock ();
261
- SILBasicBlock* someBB = createBasicBlock ();
262
- SILBasicBlock* loopBB = createBasicBlock ();
255
+ for (VarDecl * vd : recursiveLinks) {
256
+ SILBasicBlock * cleanBB = createBasicBlock ();
257
+ SILBasicBlock * noneBB = createBasicBlock ();
258
+ SILBasicBlock * notUniqueBB = createBasicBlock ();
259
+ SILBasicBlock * uniqueBB = createBasicBlock ();
260
+ SILBasicBlock * someBB = createBasicBlock ();
261
+ SILBasicBlock * loopBB = createBasicBlock ();
263
262
264
263
// var iter = self.link
265
264
// self.link = nil
266
265
auto Ty = getTypeLowering (vd->getType ()).getLoweredType ();
267
266
auto optionalNone = B.createOptionalNone (cleanupLoc, Ty);
268
- SILValue varAddr =
269
- B.createRefElementAddr (cleanupLoc, selfValue.getValue (), vd,
270
- Ty.getAddressType ());
267
+ SILValue varAddr = B.createRefElementAddr (cleanupLoc, selfValue.getValue (),
268
+ vd, Ty.getAddressType ());
271
269
auto iterAddr = B.createAllocStack (cleanupLoc, Ty);
272
- SILValue addr = B.createBeginAccess (
273
- cleanupLoc, varAddr, SILAccessKind::Modify, SILAccessEnforcement::Static,
274
- false /* noNestedConflict*/ , false /* fromBuiltin*/ );
275
- SILValue iter = B.createLoad (cleanupLoc, addr, LoadOwnershipQualifier::Copy);
276
- B.createStore (cleanupLoc, optionalNone, addr, StoreOwnershipQualifier::Assign);
270
+ SILValue addr =
271
+ B.createBeginAccess (cleanupLoc, varAddr, SILAccessKind::Modify,
272
+ SILAccessEnforcement::Static,
273
+ false /* noNestedConflict*/ , false /* fromBuiltin*/ );
274
+ SILValue iter =
275
+ B.createLoad (cleanupLoc, addr, LoadOwnershipQualifier::Copy);
276
+ B.createStore (cleanupLoc, optionalNone, addr,
277
+ StoreOwnershipQualifier::Assign);
277
278
B.createEndAccess (cleanupLoc, addr, false /* is aborting*/ );
278
279
B.createStore (cleanupLoc, iter, iterAddr, StoreOwnershipQualifier::Init);
279
280
280
281
B.createBranch (cleanupLoc, loopBB);
281
282
282
283
// while iter != nil {
283
284
B.emitBlock (loopBB);
284
- SILValue operand = B.createLoad (cleanupLoc, iterAddr, LoadOwnershipQualifier::Copy);
285
+ SILValue operand =
286
+ B.createLoad (cleanupLoc, iterAddr, LoadOwnershipQualifier::Copy);
285
287
auto operandCopy = B.createCopyValue (cleanupLoc, operand);
286
288
auto operandAddr = B.createAllocStack (cleanupLoc, Ty);
287
- B.createStore (cleanupLoc, operandCopy, operandAddr, StoreOwnershipQualifier::Init);
289
+ B.createStore (cleanupLoc, operandCopy, operandAddr,
290
+ StoreOwnershipQualifier::Init);
288
291
B.createDestroyValue (cleanupLoc, operand);
289
292
B.createSwitchEnumAddr (
290
- cleanupLoc, operandAddr, nullptr ,
291
- {{getASTContext ().getOptionalSomeDecl (), someBB},
292
- {std::make_pair (getASTContext ().getOptionalNoneDecl (), noneBB)}});
293
+ cleanupLoc, operandAddr, nullptr ,
294
+ {{getASTContext ().getOptionalSomeDecl (), someBB},
295
+ {std::make_pair (getASTContext ().getOptionalNoneDecl (), noneBB)}});
293
296
294
297
// if isKnownUniquelyReferenced(&iter) {
295
298
B.emitBlock (someBB);
@@ -298,7 +301,6 @@ void SILGenFunction::emitRecursiveChainDestruction(ManagedValue selfValue,
298
301
auto isUnique = B.createIsUnique (cleanupLoc, iterAddr);
299
302
B.createCondBranch (cleanupLoc, isUnique, uniqueBB, notUniqueBB);
300
303
301
-
302
304
// we have a uniquely referenced link, so we need to deinit
303
305
B.emitBlock (uniqueBB);
304
306
@@ -309,32 +311,24 @@ void SILGenFunction::emitRecursiveChainDestruction(ManagedValue selfValue,
309
311
310
312
// let tail = iter.unsafelyUnwrapped.next
311
313
// iter = tail
312
- SILValue _iter = B.createLoad (cleanupLoc, iterAddr, LoadOwnershipQualifier::Copy);
314
+ SILValue _iter =
315
+ B.createLoad (cleanupLoc, iterAddr, LoadOwnershipQualifier::Copy);
313
316
auto iterBorrow = B.createBeginBorrow (cleanupLoc, _iter);
314
- auto iterBorrowAddr = B.createAllocStack (cleanupLoc, Ty);
315
- B.createStoreBorrow (cleanupLoc, iterBorrow, iterBorrowAddr);
316
- auto xx = B.createLoadBorrow (cleanupLoc, iterBorrowAddr);
317
- auto * link = B.createUncheckedEnumData (cleanupLoc,
318
- xx,
319
- getASTContext ().getOptionalSomeDecl (),
320
- SelfTyLowered);
321
- varAddr = B.createRefElementAddr (cleanupLoc,
322
- link,
323
- vd,
324
- Ty.getAddressType ());
317
+ auto *link = B.createUncheckedEnumData (
318
+ cleanupLoc, iterBorrow, getASTContext ().getOptionalSomeDecl (),
319
+ SelfTyLowered);
320
+ varAddr = B.createRefElementAddr (cleanupLoc, link, vd, Ty.getAddressType ());
325
321
326
322
addr = B.createBeginAccess (
327
- cleanupLoc, varAddr, SILAccessKind::Read, SILAccessEnforcement::Static,
328
- false /* noNestedConflict */ , false /* fromBuiltin*/ );
323
+ cleanupLoc, varAddr, SILAccessKind::Read, SILAccessEnforcement::Static,
324
+ false /* noNestedConflict */ , false /* fromBuiltin*/ );
329
325
iter = B.createLoad (cleanupLoc, addr, LoadOwnershipQualifier::Copy);
330
326
B.createEndAccess (cleanupLoc, addr, false /* is aborting*/ );
331
327
B.createStore (cleanupLoc, iter, iterAddr, StoreOwnershipQualifier::Assign);
332
328
333
- B.createEndBorrow (cleanupLoc, xx);
334
329
B.createEndBorrow (cleanupLoc, iterBorrow);
335
330
336
331
B.createDestroyValue (cleanupLoc, _iter);
337
- B.createDeallocStack (cleanupLoc, iterBorrowAddr);
338
332
339
333
B.createBranch (cleanupLoc, loopBB);
340
334
@@ -347,7 +341,6 @@ void SILGenFunction::emitRecursiveChainDestruction(ManagedValue selfValue,
347
341
B.createDeallocStack (cleanupLoc, operandAddr);
348
342
B.createBranch (cleanupLoc, cleanBB);
349
343
350
-
351
344
B.emitBlock (cleanBB);
352
345
B.createDestroyAddr (cleanupLoc, iterAddr);
353
346
B.createDeallocStack (cleanupLoc, iterAddr);
@@ -374,8 +367,9 @@ void SILGenFunction::emitClassMemberDestruction(ManagedValue selfValue,
374
367
// / A distributed actor may be 'remote' in which case there is no need to
375
368
// / destroy "all" members, because they never had storage to begin with.
376
369
if (cd->isDistributedActor ()) {
377
- normalMemberDestroyBB = createBasicBlock ();
378
370
finishBB = createBasicBlock ();
371
+ normalMemberDestroyBB = createBasicBlock ();
372
+
379
373
emitDistributedActorClassMemberDestruction (cleanupLoc, selfValue, cd,
380
374
normalMemberDestroyBB,
381
375
finishBB);
0 commit comments