Files
swift-mirror/test/SILGen/auto_closures.swift
Doug Gregor 793b3326af Implement the new rules for argument label defaults.
The rule changes are as follows:
  * All functions (introduced with the 'func' keyword) have argument
  labels for arguments beyond the first, by default. Methods are no
  longer special in this regard.
  * The presence of a default argument no longer implies an argument
  label.

The actual changes to the parser and printer are fairly simple; the
rest of the noise is updating the standard library, overlays, tests,
etc.

With the standard library, this change is intended to be API neutral:
I've added/removed #'s and _'s as appropriate to keep the user
interface the same. If we want to separately consider using argument
labels for more free functions now that the defaults in the language
have shifted, we can tackle that separately.

Fixes rdar://problem/17218256.

Swift SVN r27704
2015-04-24 19:03:30 +00:00

67 lines
2.8 KiB
Swift

// RUN: %target-swift-frontend -parse-stdlib -emit-silgen %s | FileCheck %s
struct Bool {}
var false_ = Bool()
// CHECK-LABEL: sil hidden @_TF13auto_closures17call_auto_closure
func call_auto_closure(@autoclosure var x: () -> Bool) -> Bool {
// CHECK: [[XBOX:%.*]] = alloc_box $@callee_owned () -> Bool
// CHECK: [[XLOAD:%.*]] = load [[XBOX]]#1
// CHECK: [[RET:%.*]] = apply [[XLOAD]]()
// CHECK: return [[RET]]
return x()
}
// CHECK-LABEL sil @_TF13auto_closures30test_auto_closure_with_capture
func test_auto_closure_with_capture(x: Bool) -> Bool {
// CHECK: [[CLOSURE:%.*]] = function_ref @_TFF13auto_closures30test_auto_closure_with_capture
// CHECK: [[WITHCAPTURE:%.*]] = partial_apply [[CLOSURE]](
// CHECK: [[RET:%.*]] = apply {{%.*}}([[WITHCAPTURE]])
// CHECK: return [[RET]]
return call_auto_closure(x)
}
// CHECK-LABEL: sil hidden @_TF13auto_closures33test_auto_closure_without_capture
func test_auto_closure_without_capture() -> Bool {
// CHECK: [[CLOSURE:%.*]] = function_ref @_TFF13auto_closures33test_auto_closure_without_capture
// CHECK: [[THICK:%.*]] = thin_to_thick_function [[CLOSURE]] : $@convention(thin) () -> Bool to $@callee_owned () -> Bool
// CHECK: [[RET:%.*]] = apply {{%.*}}([[THICK]])
// CHECK: return [[RET]]
return call_auto_closure(false_)
}
public class Base {
var x: Bool { return false_ }
}
public class Sub : Base {
// CHECK-LABEL: sil hidden @_TFC13auto_closures3Subg1xVS_4Bool : $@convention(method) (@guaranteed Sub) -> Bool {
// CHECK: [[AUTOCLOSURE:%.*]] = function_ref @_TFFC13auto_closures3Subg1xVS_4Boolu_KT_S1_ : $@convention(thin) (@owned Sub) -> Bool
// CHECK: = partial_apply [[AUTOCLOSURE]](%0)
// CHECK: return {{%.*}} : $Bool
// CHECK: }
// CHECK-LABEL: sil shared [transparent] @_TFFC13auto_closures3Subg1xVS_4Boolu_KT_S1_ : $@convention(thin) (@owned Sub) -> Bool {
// CHECK: [[SUPER:%.*]] = function_ref @_TFC13auto_closures4Baseg1xVS_4Bool
// CHECK: [[RET:%.*]] = apply [[SUPER]]({{%.*}})
// CHECK: return [[RET]]
override var x: Bool { return call_auto_closure(super.x) }
}
// CHECK-LABEL: sil hidden @_TF13auto_closures20closureInAutoclosureFTVS_4BoolS0__S0_ : $@convention(thin) (Bool, Bool) -> Bool {
// CHECK: }
// CHECK-LABEL: sil shared [transparent] @_TFF13auto_closures20closureInAutoclosureFTVS_4BoolS0__S0_u_KT_S0_ : $@convention(thin) (Bool, Bool) -> Bool {
// CHECK: }
// CHECK-LABEL: sil shared @_TFFF13auto_closures20closureInAutoclosureFTVS_4BoolS0__S0_u_KT_S0_U_FS0_S0_ : $@convention(thin) (Bool, Bool) -> Bool {
// CHECK: }
func compareBool(lhs: Bool, _ rhs: Bool) -> Bool { return false_ }
func testBool(x: Bool, _ pred: (Bool) -> Bool) -> Bool {
return pred(x)
}
func delayBool(@autoclosure fn: () -> Bool) -> Bool {
return fn()
}
func closureInAutoclosure(lhs: Bool, _ rhs: Bool) -> Bool {
return delayBool(testBool(lhs, { compareBool($0, rhs) }))
}