mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +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.
22 lines
761 B
Swift
22 lines
761 B
Swift
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
|
|
|
|
class C {
|
|
__consuming func consumesSelf() {}
|
|
}
|
|
|
|
func referencesConsumesSelf(_ c: C) {
|
|
_ = C.consumesSelf
|
|
C.consumesSelf(c)()
|
|
}
|
|
|
|
// The method...
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @$s28partial_apply_consuming_self1CC12consumesSelfyyF : $@convention(method) (@owned C) -> () {
|
|
|
|
// The curry thunk's outer closure...
|
|
|
|
// CHECK-LABEL: sil private [ossa] @$s28partial_apply_consuming_self22referencesConsumesSelfyyAA1CCFyycADncfu_ : $@convention(thin) (@owned C) -> @owned @callee_guaranteed () -> () {
|
|
|
|
// The curry thunk's inner closure...
|
|
|
|
// CHECK-LABEL: sil private [ossa] @$s28partial_apply_consuming_self22referencesConsumesSelfyyAA1CCFyycADncfu_yycfu0_ : $@convention(thin) (@guaranteed C) -> () { |