Add builtins to initialize and destroy a default-actor member.

It would be more abstractly correct if this got DI support so
that we destroy the member if the constructor terminates
abnormally, but we can get to that later.
This commit is contained in:
John McCall
2020-12-08 23:13:51 -05:00
parent 1177cde4e3
commit d874479290
14 changed files with 175 additions and 11 deletions

View File

@@ -2026,6 +2026,18 @@ void LifetimeChecker::processUninitializedReleaseOfBox(
Destroys.push_back(B.createDeallocBox(Release->getLoc(), MUI));
}
static void emitDefaultActorDestroy(SILBuilder &B, SILLocation loc,
SILValue self) {
auto builtinName = B.getASTContext().getIdentifier(
getBuiltinName(BuiltinValueKind::DestroyDefaultActor));
auto resultTy = B.getModule().Types.getEmptyTupleType();
self = B.createBeginBorrow(loc, self);
B.createBuiltin(loc, builtinName, resultTy, /*subs*/{},
{ self });
B.createEndBorrow(loc, self);
}
void LifetimeChecker::processUninitializedRelease(SILInstruction *Release,
bool consumed,
SILBasicBlock::iterator InsertPt) {
@@ -2076,6 +2088,15 @@ void LifetimeChecker::processUninitializedRelease(SILInstruction *Release,
else
Metatype = B.createMetatype(Loc, SILMetatypeTy);
// If this is a root default actor, destroy the default-actor state.
// SILGen ensures that this is unconditionally initialized, so we
// don't need to track it specially.
if (!TheMemory.isDelegatingInit()) {
auto classDecl = TheMemory.getASTType().getClassOrBoundGenericClass();
if (classDecl && classDecl->isRootDefaultActor())
emitDefaultActorDestroy(B, Loc, Pointer);
}
// We've already destroyed any instance variables initialized by this
// constructor, now destroy instance variables initialized by subclass
// constructors that delegated to us, and finally free the memory.