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.
47 lines
2.4 KiB
Swift
47 lines
2.4 KiB
Swift
// RUN: %target-swift-emit-silgen -parse-as-library %s | %FileCheck %s
|
|
|
|
enum PartialApplyEnumPayload<T, U> {
|
|
case left(T)
|
|
case both(T, U)
|
|
|
|
case leftWithLabel(left: T)
|
|
case bothWithLabel(left: T, right: U)
|
|
|
|
case tupleWithLabel(both: (T, U))
|
|
|
|
// Note: SILGen can emit these thunks correctly, but we disabled
|
|
// the feature since calling the constructor directly (without a
|
|
// thunk) doesn't work yet.
|
|
/* case variadic(_: Int...)
|
|
case variadicWithLabel(indices: Int...)
|
|
case variadicTuple(_: (Int, Int)...)
|
|
case variadicWithOther(String, _: Int...) */
|
|
|
|
case autoclosure(@autoclosure () -> ())
|
|
}
|
|
|
|
struct S {}
|
|
struct C {}
|
|
|
|
func partialApplyEnumCases(_ x: S, y: C) {
|
|
_ = PartialApplyEnumPayload<S, C>.left
|
|
_ = PartialApplyEnumPayload<S, C>.both
|
|
_ = PartialApplyEnumPayload<S, C>.leftWithLabel
|
|
_ = PartialApplyEnumPayload<S, C>.tupleWithLabel
|
|
/* _ = PartialApplyEnumPayload<S, C>.variadic
|
|
_ = PartialApplyEnumPayload<S, C>.variadicWithLabel
|
|
_ = PartialApplyEnumPayload<S, C>.variadicTuple
|
|
_ = PartialApplyEnumPayload<S, C>.variadicWithOther */
|
|
_ = PartialApplyEnumPayload<S, C>.autoclosure
|
|
}
|
|
|
|
// CHECK-LABEL: sil private [ossa] @$s17enum_curry_thunks21partialApplyEnumCases_1yyAA1SV_AA1CVtFAA07PartialeF7PayloadOyAeGGAEcAJmcfu_AjEcfu0_ : $@convention(thin) (S, @thin PartialApplyEnumPayload<S, C>.Type) -> @owned PartialApplyEnumPayload<S, C> {
|
|
|
|
// CHECK-LABEL: sil private [ossa] @$s17enum_curry_thunks21partialApplyEnumCases_1yyAA1SV_AA1CVtFAA07PartialeF7PayloadOyAeGGAE_AGtcAJmcfu1_AjE_AGtcfu2_ : $@convention(thin) (S, C, @thin PartialApplyEnumPayload<S, C>.Type) -> @owned PartialApplyEnumPayload<S, C> {
|
|
|
|
// CHECK-LABEL: sil private [ossa] @$s17enum_curry_thunks21partialApplyEnumCases_1yyAA1SV_AA1CVtFAA07PartialeF7PayloadOyAeGGAEcAJmcfu3_AjEcfu4_ : $@convention(thin) (S, @thin PartialApplyEnumPayload<S, C>.Type) -> @owned PartialApplyEnumPayload<S, C> {
|
|
|
|
// CHECK-LABEL: sil private [ossa] @$s17enum_curry_thunks21partialApplyEnumCases_1yyAA1SV_AA1CVtFAA07PartialeF7PayloadOyAeGGAE_AGt_tcAJmcfu5_AjE_AGt_tcfu6_ : $@convention(thin) (S, C, @thin PartialApplyEnumPayload<S, C>.Type) -> @owned PartialApplyEnumPayload<S, C> {
|
|
|
|
// CHECK-LABEL: sil private [ossa] @$s17enum_curry_thunks21partialApplyEnumCases_1yyAA1SV_AA1CVtFAA07PartialeF7PayloadOyAeGGyyXAcAJmcfu7_AJyyXAcfu8_ : $@convention(thin) (@guaranteed @callee_guaranteed () -> (), @thin PartialApplyEnumPayload<S, C>.Type) -> @owned PartialApplyEnumPayload<S, C> {
|