Skip to content

Commit 6d4a1f7

Browse files
committed
[SILGen] Don't SILGen an @objc entry point for a deinit with no body
In general we'll want to investigate what we are and aren't SILGen-ing for textual interfaces of resilient modules, but for fragile modules we may as well generate everything we can for potential optimization purposes.
1 parent ceaa5db commit 6d4a1f7

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
904904
DestructorDecl *dd) {
905905
// Emit the native deallocating destructor for -dealloc.
906906
// Destructors are a necessary part of class metadata, so can't be delayed.
907-
{
907+
if (dd->hasBody()) {
908908
SILDeclRef dealloc(dd, SILDeclRef::Kind::Deallocator);
909909
SILFunction *f = getFunction(dealloc, ForDefinition);
910910
preEmitFunction(dealloc, dd, f, dd);
@@ -916,7 +916,7 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
916916

917917
// Emit the Objective-C -dealloc entry point if it has
918918
// something to do beyond messaging the superclass's -dealloc.
919-
if (dd->getBody()->getNumElements() != 0)
919+
if (dd->hasBody() && dd->getBody()->getNumElements() != 0)
920920
emitObjCDestructorThunk(dd);
921921

922922
// Emit the ivar initializer, if needed.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t/ObjC.swiftmodule -O -enable-objc-interop %s
3+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t/ObjC.swiftmodule -O -enable-objc-interop -enable-resilience %s
4+
5+
// FIXME: This test is self-contained, so it shouldn't require objc_interop
6+
// (just -enable-objc-interop), but it's failing in Linux SILGen.
7+
// https://bugs.swift.org/browse/SR-8877
8+
// REQUIRES: objc_interop
9+
10+
import Foundation
11+
12+
public class SomeClass {
13+
@objc init?(_: Any)
14+
@objc func foo()
15+
@objc var bar: Int { get set }
16+
@objc subscript(_: Int) -> Int { get set }
17+
@objc deinit
18+
}
19+
20+
public class SomeClassInlinable {
21+
@usableFromInline init()
22+
@objc @inlinable convenience init?(_: Any) { self.init() }
23+
@objc @inlinable func foo() {}
24+
@objc var bar: Int {
25+
@inlinable get { return 0 }
26+
@inlinable set {}
27+
}
28+
@objc @inlinable subscript(_: Int) -> Int {
29+
@inlinable get { return 0 }
30+
@inlinable set {}
31+
}
32+
@objc @inlinable deinit {
33+
print("bye")
34+
}
35+
}
36+
public class SomeNSObject : NSObject {
37+
@objc init?(_: Any)
38+
@objc func foo()
39+
@objc var bar: Int { get set }
40+
@objc subscript(_: Int) -> Int { get set }
41+
@objc deinit
42+
}
43+
44+
public class SomeNSObjectInlinable : NSObject {
45+
public override init()
46+
@objc @inlinable convenience init?(_: Any) { self.init() }
47+
@objc @inlinable func foo() {}
48+
@objc var bar: Int {
49+
@inlinable get { return 0 }
50+
@inlinable set {}
51+
}
52+
@objc @inlinable subscript(_: Int) -> Int {
53+
@inlinable get { return 0 }
54+
@inlinable set {}
55+
}
56+
@objc @inlinable deinit {
57+
print("bye")
58+
}
59+
}

0 commit comments

Comments
 (0)