Skip to content

Commit 28a06fe

Browse files
Added isolated deallocator to TBDGen
1 parent d7248e3 commit 28a06fe

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

include/swift/SIL/SILModule.h

+3
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,9 @@ namespace Lowering {
10871087
/// Determine whether the given class will be allocated/deallocated using the
10881088
/// Objective-C runtime, i.e., +alloc and -dealloc.
10891089
LLVM_LIBRARY_VISIBILITY bool usesObjCAllocator(ClassDecl *theClass);
1090+
/// Determine if isolating destructor is needed.
1091+
LLVM_LIBRARY_VISIBILITY bool needsIsolatingDestructor(DestructorDecl *dd);
1092+
10901093
} // namespace Lowering
10911094
} // namespace swift
10921095

lib/SIL/IR/SILSymbolVisitor.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,9 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
714714
}
715715

716716
void visitDestructorDecl(DestructorDecl *DD) {
717-
// Destructors come in two forms (deallocating and non-deallocating), like
718-
// constructors above. Classes use both but move only non-class nominal
719-
// types only use the deallocating one. This is the deallocating one:
717+
// Destructors come in three forms (non-deallocating, deallocating, isolated
718+
// deallocating) Classes use all three but move only non-class nominal types
719+
// only use the deallocating one. This is the deallocating one:
720720
visitAbstractFunctionDecl(DD);
721721

722722
if (auto parentClass = DD->getParent()->getSelfClassDecl()) {
@@ -725,6 +725,11 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
725725
addFunction(SILDeclRef(DD, SILDeclRef::Kind::Destroyer));
726726
}
727727
}
728+
729+
// And isolated also does not always exist
730+
if (Lowering::needsIsolatingDestructor(DD)) {
731+
addFunction(SILDeclRef(DD, SILDeclRef::Kind::IsolatedDeallocator));
732+
}
728733
}
729734

730735
void visitExtensionDecl(ExtensionDecl *ED) {

lib/SILGen/SILGen.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
11141114
}
11151115
case SILDeclRef::Kind::Deallocator: {
11161116
auto *dd = cast<DestructorDecl>(constant.getDecl());
1117-
if (SILGenFunction::shouldEmitIsolatingDestructor(dd)) {
1117+
if (needsIsolatingDestructor(dd)) {
11181118
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
11191119
preEmitFunction(constant, f, loc);
11201120
PrettyStackTraceSILFunction X("silgen emitIsolatingDestructor", f);
@@ -1573,8 +1573,7 @@ bool SILGenModule::requiresIVarDestroyer(ClassDecl *cd) {
15731573
void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
15741574
DestructorDecl *dd) {
15751575

1576-
const bool isActorIsolated =
1577-
SILGenFunction::shouldEmitIsolatingDestructor(dd);
1576+
const bool isActorIsolated = needsIsolatingDestructor(dd);
15781577

15791578
// Emit the isolated deallocating destructor.
15801579
// If emitted, it implements actual deallocating and deallocating destructor
@@ -1663,7 +1662,7 @@ void SILGenModule::emitDestructor(ClassDecl *cd, DestructorDecl *dd) {
16631662
// Emit the isolated deallocating destructor.
16641663
// If emitted, it implements actual deallocating and deallocating destructor
16651664
// only switches executor
1666-
if (SILGenFunction::shouldEmitIsolatingDestructor(dd)) {
1665+
if (needsIsolatingDestructor(dd)) {
16671666
SILDeclRef deallocator(dd, SILDeclRef::Kind::IsolatedDeallocator);
16681667
emitFunctionDefinition(deallocator,
16691668
getFunction(deallocator, ForDefinition));

lib/SILGen/SILGenDestructor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void SILGenFunction::emitDeallocatingMoveOnlyDestructor(DestructorDecl *dd) {
283283
B.createReturn(loc, emitEmptyTuple(loc));
284284
}
285285

286-
bool SILGenFunction::shouldEmitIsolatingDestructor(DestructorDecl *dd) {
286+
bool Lowering::needsIsolatingDestructor(DestructorDecl *dd) {
287287
auto ai = swift::getActorIsolation(dd);
288288
if (!ai.isActorIsolated()) {
289289
return false;

lib/SILGen/SILGenFunction.h

-3
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
828828
/// definite initialization.
829829
bool isCtorWithHopsInjectedByDefiniteInit();
830830

831-
/// Checks if isolating destructor is needed.
832-
static bool shouldEmitIsolatingDestructor(DestructorDecl *dd);
833-
834831
/// Generates code for a struct constructor.
835832
/// This allocates the new 'self' value, emits the
836833
/// body code, then returns the final initialized 'self'.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-ir %s | %FileCheck %s
2+
3+
import Foundation
4+
5+
public class Foo {
6+
@MainActor
7+
deinit {}
8+
}
9+
10+
// CHECK: @"$s20deinit_isolation_tbd3FooCfZ"
11+
// CHECK: @"$s20deinit_isolation_tbd3FooCfD"

0 commit comments

Comments
 (0)