mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user