Skip to content

Commit 396cc94

Browse files
Added isolated deallocator to TBDGen
1 parent fd38dfa commit 396cc94

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

include/swift/SIL/SILModule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,10 @@ namespace Lowering {
10241024
/// Determine whether the given class will be allocated/deallocated using the
10251025
/// Objective-C runtime, i.e., +alloc and -dealloc.
10261026
LLVM_LIBRARY_VISIBILITY bool usesObjCAllocator(ClassDecl *theClass);
1027+
1028+
/// Determine if isolating destructor is needed.
1029+
LLVM_LIBRARY_VISIBILITY bool needsIsolatingDestructor(DestructorDecl *dd);
1030+
10271031
} // namespace Lowering
10281032

10291033
} // namespace swift

lib/SILGen/SILGen.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
10951095
}
10961096
case SILDeclRef::Kind::Deallocator: {
10971097
auto *dd = cast<DestructorDecl>(constant.getDecl());
1098-
if (SILGenFunction::shouldEmitIsolatingDestructor(dd)) {
1098+
if (needsIsolatingDestructor(dd)) {
10991099
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
11001100
preEmitFunction(constant, f, loc);
11011101
PrettyStackTraceSILFunction X("silgen emitIsolatingDestructor", f);
@@ -1554,8 +1554,7 @@ bool SILGenModule::requiresIVarDestroyer(ClassDecl *cd) {
15541554
void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
15551555
DestructorDecl *dd) {
15561556

1557-
const bool isActorIsolated =
1558-
SILGenFunction::shouldEmitIsolatingDestructor(dd);
1557+
const bool isActorIsolated = needsIsolatingDestructor(dd);
15591558

15601559
// Emit the isolated deallocating destructor.
15611560
// If emitted, it implements actual deallocating and deallocating destructor
@@ -1642,7 +1641,7 @@ void SILGenModule::emitDestructor(ClassDecl *cd, DestructorDecl *dd) {
16421641
// Emit the isolated deallocating destructor.
16431642
// If emitted, it implements actual deallocating and deallocating destructor
16441643
// only switches executor
1645-
if (SILGenFunction::shouldEmitIsolatingDestructor(dd)) {
1644+
if (needsIsolatingDestructor(dd)) {
16461645
SILDeclRef deallocator(dd, SILDeclRef::Kind::IsolatedDeallocator);
16471646
emitFunctionDefinition(deallocator,
16481647
getFunction(deallocator, ForDefinition));

lib/SILGen/SILGenDestructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void SILGenFunction::emitDeallocatingDestructor(DestructorDecl *dd) {
213213
B.createReturn(loc, emitEmptyTuple(loc));
214214
}
215215

216-
bool SILGenFunction::shouldEmitIsolatingDestructor(DestructorDecl *dd) {
216+
bool Lowering::needsIsolatingDestructor(DestructorDecl *dd) {
217217
auto ai = swift::getActorIsolation(dd);
218218
if (!ai.isActorIsolated()) {
219219
return false;

lib/SILGen/SILGenFunction.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
654654
/// and calls isolated deallocating destuctor on the right executor.
655655
void emitIsolatingDestructor(DestructorDecl *dd);
656656

657-
/// Checks if isolating destructor is needed.
658-
static bool shouldEmitIsolatingDestructor(DestructorDecl *dd);
659-
660657
/// Generates code for a struct constructor.
661658
/// This allocates the new 'self' value, emits the
662659
/// body code, then returns the final initialized 'self'.

lib/TBDGen/TBDGen.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,8 @@ void TBDGenVisitor::visitConstructorDecl(ConstructorDecl *CD) {
995995
}
996996

997997
void TBDGenVisitor::visitDestructorDecl(DestructorDecl *DD) {
998-
// Class destructors come in two forms (deallocating and non-deallocating),
999-
// like constructors above. This is the deallocating one:
998+
// Class destructors come in three forms (non-deallocating, deallocating,
999+
// isolated deallocating). This is the deallocating one:
10001000
visitAbstractFunctionDecl(DD);
10011001

10021002
auto parentClass = DD->getParent()->getSelfClassDecl();
@@ -1005,6 +1005,11 @@ void TBDGenVisitor::visitDestructorDecl(DestructorDecl *DD) {
10051005
if (!Lowering::usesObjCAllocator(parentClass)) {
10061006
addSymbol(SILDeclRef(DD, SILDeclRef::Kind::Destroyer));
10071007
}
1008+
1009+
// And isolated also does not always exist
1010+
if (Lowering::needsIsolatingDestructor(DD)) {
1011+
addSymbol(SILDeclRef(DD, SILDeclRef::Kind::IsolatedDeallocator));
1012+
}
10081013
}
10091014

10101015
void TBDGenVisitor::visitExtensionDecl(ExtensionDecl *ED) {
Lines changed: 11 additions & 0 deletions
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)