Skip to content

Commit 89f688f

Browse files
committed
DI: Track of initialization state of trivial fields in root class initializers
While we don't need to destroy these fields, we still need to know when the class is _semantically_ fully initialized, since this will determine if we're going to release the class, running the deinitializer, or if we're going to deallocate the memory for the instance directly.
1 parent caed4e8 commit 89f688f

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ class DIMemoryObjectInfo {
176176
MemoryInst->isDerivedClassSelfOnly();
177177
}
178178

179+
/// True if this memory object is the 'self' of a root class init method.
180+
bool isRootClassSelf() const {
181+
return isClassInitSelf() && MemoryInst->isRootSelf();
182+
}
183+
179184
/// True if this memory object is the 'self' of a non-root class init method.
180185
bool isNonRootClassSelf() const {
181186
return isClassInitSelf() && !MemoryInst->isRootSelf();

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,13 @@ void LifetimeChecker::handleStoreUse(unsigned UseID) {
10711071
// it for later. Once we've collected all of the conditional init/assigns,
10721072
// we can insert a single control variable for the memory object for the
10731073
// whole function.
1074-
if (!Use.onlyTouchesTrivialElements(TheMemory))
1074+
//
1075+
// For root class initializers, we must keep track of initializations of
1076+
// trivial stored properties also, since we need to know when the object
1077+
// has been fully initialized when deciding if a strong_release should
1078+
// lower to a partial_dealloc_ref.
1079+
if (TheMemory.isRootClassSelf() ||
1080+
!Use.onlyTouchesTrivialElements(TheMemory))
10751081
HasConditionalInitAssign = true;
10761082
return;
10771083
}
@@ -2276,7 +2282,13 @@ SILValue LifetimeChecker::handleConditionalInitAssign() {
22762282
// If this ambiguous store is only of trivial types, then we don't need to
22772283
// do anything special. We don't even need keep the init bit for the
22782284
// element precise.
2279-
if (Use.onlyTouchesTrivialElements(TheMemory))
2285+
//
2286+
// For root class initializers, we must keep track of initializations of
2287+
// trivial stored properties also, since we need to know when the object
2288+
// has been fully initialized when deciding if a strong_release should
2289+
// lower to a partial_dealloc_ref.
2290+
if (!TheMemory.isRootClassSelf() &&
2291+
Use.onlyTouchesTrivialElements(TheMemory))
22802292
continue;
22812293

22822294
B.setInsertionPoint(Use.Inst);

0 commit comments

Comments
 (0)