mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
When a method is called with fewer than two parameter lists,
transform it into a fully-applied call by wrapping it in a
closure.
Eg,
Foo.bar => { self in { args... self.bar(args...) } }
foo.bar => { self in { args... self.bar(args...) } }(self)
super.bar => { args... in super.bar(args...) }
With this change, SILGen only ever sees fully-applied calls,
which will allow ripping out some code.
This new way of doing curry thunks fixes a long-standing bug
where unbound references to protocol methods did not work.
This is because such a reference must open the existential
*inside* the closure, after 'self' has been applied, whereas
the old SILGen implementation of curry thunks really wanted
the type of the method reference to match the opened type of
the method.
A follow-up cleanup will remove the SILGen curry thunk
implementation.
Fixes rdar://21289579 and https://bugs.swift.org/browse/SR-75.
34 lines
1.3 KiB
Swift
34 lines
1.3 KiB
Swift
|
|
// RUN: %empty-directory(%t)
|
|
// RUN: %build-silgen-test-overlays
|
|
|
|
// RUN: %target-swift-emit-silgen(mock-sdk: -sdk %S/Inputs -I %t) -module-name inlinable_attribute_objc -Xllvm -sil-full-demangle -primary-file %s | %FileCheck %s
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
public class Horse : NSObject {
|
|
@objc public dynamic func gallop() {}
|
|
@objc public func someMethod() {}
|
|
@objc public convenience init(saddle: ()) {
|
|
self.init()
|
|
}
|
|
@objc public override init() {}
|
|
}
|
|
|
|
// @objc thunks are not serialized, since they are only referenced from
|
|
// method tables.
|
|
|
|
// CHECK-LABEL: sil [thunk] [ossa] @$s24inlinable_attribute_objc5HorseC6gallopyyFTo : $@convention(objc_method) (Horse) -> ()
|
|
// CHECK-LABEL: sil [thunk] [ossa] @$s24inlinable_attribute_objc5HorseC10someMethodyyFTo : $@convention(objc_method) (Horse) -> ()
|
|
// CHECK-LABEL: sil [thunk] [ossa] @$s24inlinable_attribute_objc5HorseC6saddleACyt_tcfcTo : $@convention(objc_method) (@owned Horse) -> @owned Horse
|
|
// CHECK-LABEL: sil [thunk] [ossa] @$s24inlinable_attribute_objc5HorseCACycfcTo : $@convention(objc_method) (@owned Horse) -> @owned Horse
|
|
|
|
// However, make sure we can reference dynamic thunks and curry thunks
|
|
// from inlinable scopes
|
|
|
|
@inlinable public func talkAboutAHorse(h: Horse) {
|
|
_ = h.gallop
|
|
}
|