[SILGen] Don't SILGen an @objc entry point for a deinit with no body (#19472)

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.
This commit is contained in:
Jordan Rose
2018-09-28 13:17:47 -07:00
committed by GitHub
parent 5898df0e2d
commit c66fcf2e61
2 changed files with 61 additions and 2 deletions

View File

@@ -904,7 +904,7 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
DestructorDecl *dd) {
// Emit the native deallocating destructor for -dealloc.
// Destructors are a necessary part of class metadata, so can't be delayed.
{
if (dd->hasBody()) {
SILDeclRef dealloc(dd, SILDeclRef::Kind::Deallocator);
SILFunction *f = getFunction(dealloc, ForDefinition);
preEmitFunction(dealloc, dd, f, dd);
@@ -916,7 +916,7 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
// Emit the Objective-C -dealloc entry point if it has
// something to do beyond messaging the superclass's -dealloc.
if (dd->getBody()->getNumElements() != 0)
if (dd->hasBody() && dd->getBody()->getNumElements() != 0)
emitObjCDestructorThunk(dd);
// Emit the ivar initializer, if needed.

View File

@@ -0,0 +1,59 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t/ObjC.swiftmodule -O -enable-objc-interop %s
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t/ObjC.swiftmodule -O -enable-objc-interop -enable-resilience %s
// FIXME: This test is self-contained, so it shouldn't require objc_interop
// (just -enable-objc-interop), but it's failing in Linux SILGen.
// https://bugs.swift.org/browse/SR-8877
// REQUIRES: objc_interop
import Foundation
public class SomeClass {
@objc init?(_: Any)
@objc func foo()
@objc var bar: Int { get set }
@objc subscript(_: Int) -> Int { get set }
@objc deinit
}
public class SomeClassInlinable {
@usableFromInline init()
@objc @inlinable convenience init?(_: Any) { self.init() }
@objc @inlinable func foo() {}
@objc var bar: Int {
@inlinable get { return 0 }
@inlinable set {}
}
@objc @inlinable subscript(_: Int) -> Int {
@inlinable get { return 0 }
@inlinable set {}
}
@objc @inlinable deinit {
print("bye")
}
}
public class SomeNSObject : NSObject {
@objc init?(_: Any)
@objc func foo()
@objc var bar: Int { get set }
@objc subscript(_: Int) -> Int { get set }
@objc deinit
}
public class SomeNSObjectInlinable : NSObject {
public override init()
@objc @inlinable convenience init?(_: Any) { self.init() }
@objc @inlinable func foo() {}
@objc var bar: Int {
@inlinable get { return 0 }
@inlinable set {}
}
@objc @inlinable subscript(_: Int) -> Int {
@inlinable get { return 0 }
@inlinable set {}
}
@objc @inlinable deinit {
print("bye")
}
}