Skip to content

Commit 3b134d4

Browse files
committed
SIL: @objc thunks should not be serialized
1 parent ae21b8b commit 3b134d4

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/SIL/SILDeclRef.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,11 @@ bool SILDeclRef::isTransparent() const {
444444

445445
/// True if the function should have its body serialized.
446446
IsSerialized_t SILDeclRef::isSerialized() const {
447+
// Native-to-foreign thunks are only referenced from the Objective-C
448+
// method table.
449+
if (isForeign)
450+
return IsNotSerialized;
451+
447452
DeclContext *dc;
448453
if (auto closure = getAbstractClosureExpr())
449454
dc = closure->getLocalContext();

test/ClangImporter/static_inline.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// RUN: %FileCheck < %t/static_inline.sil %s
77
// RUN: %target-swift-frontend -parse-as-library -module-name=static_inline -O -emit-ir %t/static_inline.sil -enable-objc-interop -import-objc-header %S/Inputs/static_inline.h | %FileCheck --check-prefix=CHECK-IR %s
88

9-
// CHECK: sil shared [serializable] [clang c_inline_func] @c_inline_func : $@convention(c) (Int32) -> Int32
9+
// CHECK: sil shared [clang c_inline_func] @c_inline_func : $@convention(c) (Int32) -> Int32
1010

1111
// CHECK-IR-LABEL: define{{.*}} i32 @"$s13static_inline6testit1xs5Int32VAE_tF"(i32)
1212
// CHECK-IR: = add {{.*}}, 27

test/SILGen/inlinable_attribute_objc.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,22 @@ import Foundation
1010

1111
public class Horse : NSObject {
1212
@objc public dynamic func gallop() {}
13+
@objc public func someMethod() {}
14+
@objc public convenience init(saddle: ()) {
15+
self.init()
16+
}
17+
@objc public override init() {}
1318
}
1419

15-
// Make sure we can reference dynamic thunks and curry thunks
20+
// @objc thunks are not serialized, since they are only referenced from
21+
// method tables.
22+
23+
// CHECK-LABEL: sil [thunk] [ossa] @$s24inlinable_attribute_objc5HorseC6gallopyyFTo : $@convention(objc_method) (Horse) -> ()
24+
// CHECK-LABEL: sil [thunk] [ossa] @$s24inlinable_attribute_objc5HorseC10someMethodyyFTo : $@convention(objc_method) (Horse) -> ()
25+
// CHECK-LABEL: sil [thunk] [ossa] @$s24inlinable_attribute_objc5HorseC6saddleACyt_tcfcTo : $@convention(objc_method) (@owned Horse) -> @owned Horse
26+
// CHECK-LABEL: sil [thunk] [ossa] @$s24inlinable_attribute_objc5HorseCACycfcTo : $@convention(objc_method) (@owned Horse) -> @owned Horse
27+
28+
// However, make sure we can reference dynamic thunks and curry thunks
1629
// from inlinable scopes
1730

1831
// CHECK-LABEL: sil [serialized] [ossa] @$s24inlinable_attribute_objc15talkAboutAHorse1hyAA5HorseC_tF : $@convention(thin) (@guaranteed Horse) -> () {

0 commit comments

Comments
 (0)