Files
swift-mirror/test/SILOptimizer/dead_partial_apply_arg.swift
Slava Pestov c543838854 Sema: Rewrite partial applications into closures
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.
2020-03-18 09:29:22 -04:00

29 lines
1.2 KiB
Swift

// RUN: %target-swift-frontend -parse-as-library -module-name=test -primary-file %s -O -emit-sil | %FileCheck %s
// Check if the compiler can convert a partial_apply of a dead argument (an
// unused metatype) to a thin_to_thick_function
extension Int32 {
// This function has an unused metatype argument.
public static func lessthan (lhs: Int32, rhs: Int32) -> Bool {
return lhs < rhs
}
}
// CHECK-LABEL: sil hidden @$s4test6callitSbs5Int32V_ADtcyF : $@convention(thin) () -> @owned @callee_guaranteed (Int32, Int32) -> Bool
// CHECK: [[F:%[0-9]+]] = function_ref @$s4test6callitSbs5Int32V_ADtcyFSbAD_ADtcADmcfu_SbAD_ADtcfu0_Tf4nnd_n : $@convention(thin) (Int32, Int32) -> Bool
// CHECK: [[R:%[0-9]+]] = thin_to_thick_function [[F]]
// CHECK: return [[R]]
// The function gets inlined into the curry thunk, and the
// unused metatype argument deleted.
// CHECK-LABEL: sil private @$s4test6callitSbs5Int32V_ADtcyFSbAD_ADtcADmcfu_SbAD_ADtcfu0_Tf4nnd_n : $@convention(thin) (Int32, Int32) -> Bool
// CHECK: builtin "cmp_slt_Int32"(%6 : $Builtin.Int32, %7 : $Builtin.Int32) : $Builtin.Int1
// CHECK: return
func callit() -> (Int32, Int32) -> Bool {
return (Int32.lessthan)
}