mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Make use of curried function declaration syntax an error.
<rdar://problem/23111018>
This commit is contained in:
@@ -671,8 +671,8 @@ ERROR(parameter_operator_keyword_argument,none,
|
||||
ERROR(parameter_unnamed,none,
|
||||
"unnamed parameters must be written with the empty name '_'", ())
|
||||
|
||||
WARNING(parameter_curry_syntax_removed,none,
|
||||
"curried function declaration syntax will be removed in a future version of Swift; use a single parameter list", ())
|
||||
ERROR(parameter_curry_syntax_removed,none,
|
||||
"curried function declaration syntax has been removed; use a single parameter list", ())
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Statement parsing diagnostics
|
||||
|
||||
@@ -520,7 +520,7 @@ Parser::parseFunctionArguments(SmallVectorImpl<Identifier> &NamePieces,
|
||||
paramContext = ParameterContextKind::Curried;
|
||||
}
|
||||
|
||||
// If the decl uses currying syntax, warn that that syntax is going away.
|
||||
// If the decl uses currying syntax, complain that that syntax has gone away.
|
||||
if (BodyParams.size() - FirstBodyPatternIndex > 1) {
|
||||
SourceRange allPatternsRange(
|
||||
BodyParams[FirstBodyPatternIndex]->getStartLoc(),
|
||||
|
||||
@@ -260,9 +260,9 @@ func rdar21784170() {
|
||||
}
|
||||
|
||||
// <rdar://problem/21829141> BOGUS: unexpected trailing closure
|
||||
func expect<T, U>(_: T)(_: U.Type) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func expect<T, U>(_: T, _: Int = 1)(_: U.Type) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
expect(Optional(3))(Optional<Int>.self)
|
||||
func expect<T, U>(_: T) -> (U.Type) -> () { return { ty in () } } // expected-note{{found this candidate}}
|
||||
func expect<T, U>(_: T, _: Int = 1) -> (U.Type) -> () { return { ty in () } } // expected-note{{found this candidate}}
|
||||
expect(Optional(3))(Optional<Int>.self) // expected-error{{ambiguous use of 'expect'}}
|
||||
|
||||
// <rdar://problem/19804707> Swift Enum Scoping Oddity
|
||||
func rdar19804707() {
|
||||
@@ -300,8 +300,8 @@ func r20789423() {
|
||||
|
||||
|
||||
|
||||
func f7(a: Int)(b : Int) -> Int { // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
return a+b
|
||||
func f7(a: Int) -> (b: Int) -> Int {
|
||||
return { b in a+b }
|
||||
}
|
||||
|
||||
f7(1)(b: 1)
|
||||
@@ -319,7 +319,7 @@ f8(b: 1.0) // expected-error {{cannot convert value of type 'Double' to
|
||||
|
||||
class CurriedClass {
|
||||
func method1() {}
|
||||
func method2(a: Int)(b : Int) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func method2(a: Int) -> (b : Int) -> () { return { b in () } }
|
||||
func method3(a: Int, b : Int) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ struct Z {
|
||||
func getI() -> Int { return i }
|
||||
mutating func incI() {}
|
||||
|
||||
func curried(x: Int)(y: Int) -> Int { return x + y } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func curried(x: Int) -> (Int) -> Int { return { y in x + y } }
|
||||
|
||||
subscript (k : Int) -> Int {
|
||||
get {
|
||||
@@ -78,7 +78,7 @@ var incI = z.incI // expected-error{{partial application of 'mutating'}}
|
||||
var zi = z.getI()
|
||||
var zcurried1 = z.curried
|
||||
var zcurried2 = z.curried(0)
|
||||
var zcurriedFull = z.curried(0)(y: 1)
|
||||
var zcurriedFull = z.curried(0)(1)
|
||||
|
||||
////
|
||||
// Members of modules
|
||||
@@ -110,7 +110,7 @@ enum W {
|
||||
case Omega
|
||||
|
||||
func foo(x: Int) {}
|
||||
func curried(x: Int)(y: Int) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func curried(x: Int) -> (Int) -> () {}
|
||||
}
|
||||
|
||||
var w = W.Omega
|
||||
@@ -118,7 +118,7 @@ var foo = w.foo
|
||||
var fooFull : () = w.foo(0)
|
||||
var wcurried1 = w.curried
|
||||
var wcurried2 = w.curried(0)
|
||||
var wcurriedFull : () = w.curried(0)(y: 1)
|
||||
var wcurriedFull : () = w.curried(0)(1)
|
||||
|
||||
// Member of enum Type
|
||||
func enumMetatypeMember(opt: Int?) {
|
||||
@@ -328,7 +328,7 @@ protocol Functional {
|
||||
func apply(v: Vector) -> Scalar
|
||||
}
|
||||
protocol Coalgebra {
|
||||
func coproduct(f: Functional)(v1: Vector, v2: Vector) -> Scalar // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func coproduct(f: Functional) -> (v1: Vector, v2: Vector) -> Scalar
|
||||
}
|
||||
|
||||
// Make sure existential is closed early when we partially apply
|
||||
|
||||
@@ -72,11 +72,13 @@ extension Int : PosixErrorReturn {
|
||||
}
|
||||
|
||||
func posixCantFail<A, T : protocol<Comparable, PosixErrorReturn>>
|
||||
(f:(A) -> T)(args:A) -> T // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
(f:(A) -> T) -> (args:A) -> T
|
||||
{
|
||||
let result = f(args)
|
||||
assert(result != T.errorReturnValue())
|
||||
return result
|
||||
return { args in
|
||||
let result = f(args)
|
||||
assert(result != T.errorReturnValue())
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
func open(name: String, oflag: Int) -> Int { }
|
||||
|
||||
@@ -54,13 +54,6 @@ class A {
|
||||
|
||||
}
|
||||
|
||||
// Curried functions have their arguments backwards.
|
||||
// CHECK: !DILocalVariable(name: "b", arg: 1,{{.*}} line: [[@LINE+2]]
|
||||
// CHECK: !DILocalVariable(name: "a", arg: 2,{{.*}} line: [[@LINE+1]]
|
||||
func uncurry (a: Int64) (b: Int64) -> (Int64, Int64) {
|
||||
return (a, b)
|
||||
}
|
||||
|
||||
// CHECK: !DILocalVariable(name: "x", arg: 1,{{.*}} line: [[@LINE+2]]
|
||||
// CHECK: !DILocalVariable(name: "y", arg: 2,{{.*}} line: [[@LINE+1]]
|
||||
func tuple(x: Int64, y: (Int64, Float, String)) -> Int64 {
|
||||
|
||||
@@ -85,8 +85,8 @@ public struct LazySequenceOf<S : SequenceType, A where S.Generator.Element == A>
|
||||
public subscript(i : A) -> A { return i }
|
||||
}
|
||||
|
||||
public func iterate<A>(f : A -> A)(x : A) -> LazySequenceOf<Iterate<A>, A>? { // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
return nil
|
||||
public func iterate<A>(f : A -> A) -> (x : A) -> LazySequenceOf<Iterate<A>, A>? {
|
||||
return { x in nil }
|
||||
}
|
||||
|
||||
public final class Iterate<A> : SequenceType {
|
||||
|
||||
@@ -177,30 +177,6 @@ struct d0100_FooStruct {
|
||||
}
|
||||
// PASS_COMMON-NEXT: {{^}} subscript (i: Int, j: Int) -> Double { get }{{$}}
|
||||
|
||||
func curriedVoidFunc1()() {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// PASS_COMMON-NEXT: {{^}} func curriedVoidFunc1()(){{$}}
|
||||
|
||||
func curriedVoidFunc2()(a: Int) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// PASS_COMMON-NEXT: {{^}} func curriedVoidFunc2()(a: Int){{$}}
|
||||
|
||||
func curriedVoidFunc3(a: Int)() {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// PASS_COMMON-NEXT: {{^}} func curriedVoidFunc3(a: Int)(){{$}}
|
||||
|
||||
func curriedVoidFunc4(a: Int)(b: Int) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// PASS_COMMON-NEXT: {{^}} func curriedVoidFunc4(a: Int)(b: Int){{$}}
|
||||
|
||||
func curriedStringFunc1()() -> String { return "" } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// PASS_COMMON-NEXT: {{^}} func curriedStringFunc1()() -> String{{$}}
|
||||
|
||||
func curriedStringFunc2()(a: Int) -> String { return "" } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// PASS_COMMON-NEXT: {{^}} func curriedStringFunc2()(a: Int) -> String{{$}}
|
||||
|
||||
func curriedStringFunc3(a: Int)() -> String { return "" } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// PASS_COMMON-NEXT: {{^}} func curriedStringFunc3(a: Int)() -> String{{$}}
|
||||
|
||||
func curriedStringFunc4(a: Int)(b: Int) -> String { return "" } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// PASS_COMMON-NEXT: {{^}} func curriedStringFunc4(a: Int)(b: Int) -> String{{$}}
|
||||
|
||||
func bodyNameVoidFunc1(a: Int, b x: Float) {}
|
||||
// PASS_COMMON-NEXT: {{^}} func bodyNameVoidFunc1(a: Int, b x: Float){{$}}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ func testVariadicFuncType(a: Int, b: Float...) {}
|
||||
// CHECK: FuncDecl '''testVariadicFuncType''' (Int, b: Float...) -> (){{$}}
|
||||
// FULL: FuncDecl '''testVariadicFuncType''' (Swift.Int, b: Swift.Float...) -> (){{$}}
|
||||
|
||||
func testCurriedFuncType1(a: Int)(b: Float) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func testCurriedFuncType1(a: Int) -> (b: Float) -> () {}
|
||||
// CHECK: FuncDecl '''testCurriedFuncType1''' (Int) -> (b: Float) -> (){{$}}
|
||||
// FULL: FuncDecl '''testCurriedFuncType1''' (Swift.Int) -> (b: Swift.Float) -> (){{$}}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import Swift
|
||||
// CHECK: [[TYPE:%swift.type]] = type
|
||||
// CHECK: [[C_CLASS:%C5class1C]] = type
|
||||
// CHECK: [[REF:%swift.refcounted]] = type
|
||||
// CHECK: [[D_CLASS:%C5class1D]] = type
|
||||
// CHECK: [[OBJCOBJ:%objc_object]] = type
|
||||
|
||||
class C {}
|
||||
@@ -44,26 +43,6 @@ sil_vtable C {}
|
||||
// \ CHECK: i64 add (i64 ptrtoint ({{.*}}* @_DATA__TtC5class1C to i64), i64 1)
|
||||
// \ CHECK: }
|
||||
|
||||
// CHECK: @_TMfC5class1D = internal global { {{.*}} } {
|
||||
// \ CHECK: void ([[D_CLASS]]*)* @_TFC5class1DD,
|
||||
// \ CHECK: i8** @_TWVBo,
|
||||
// \ CHECK: i64 ptrtoint ([[OBJCCLASS]]* @_TMmC5class1D to i64),
|
||||
// \ CHECK: [[OBJCCLASS]]* @"OBJC_CLASS_$_SwiftObject",
|
||||
// \ CHECK: [[OPAQUE]]* @_objc_empty_cache,
|
||||
// \ CHECK: [[OPAQUE]]* null,
|
||||
// \ CHECK: i64 add (i64 ptrtoint ({{.*}}* @_DATA__TtC5class1D to i64), i64 1),
|
||||
// \ CHECK: i32 3,
|
||||
// \ CHECK: i32 0,
|
||||
// \ CHECK: i32 16,
|
||||
// \ CHECK: i16 7,
|
||||
// \ CHECK: i16 0,
|
||||
// \ CHECK: i32 112,
|
||||
// \ CHECK: i32 16,
|
||||
// \ CHECK: {{.*}}* @_TMnC5class1D,
|
||||
// \ CHECK: i8* null,
|
||||
// \ CHECK: i32 (i16, i8, [[D_CLASS]]*)* @_TFC5class1D8multiplyfS0_fT1xBi8__FT1yBi16__Bi32_
|
||||
// \ CHECK: }
|
||||
|
||||
// Destroying destructor
|
||||
// CHECK: define [[REF]]* @_TFC5class1Cd([[C_CLASS]]*) {{.*}} {
|
||||
// CHECK-NEXT: entry:
|
||||
@@ -109,28 +88,6 @@ entry(%c : $C):
|
||||
return %r : $Builtin.UnknownObject
|
||||
}
|
||||
|
||||
// Part of rdar://16079147
|
||||
// vtable tested above
|
||||
class D {
|
||||
func multiply(x x : Builtin.Int8)(y : Builtin.Int16) -> Builtin.Int32
|
||||
}
|
||||
|
||||
sil @_TFC5class1DD : $@convention(method) (@owned D) -> () {
|
||||
bb0(%0 : $D):
|
||||
%1 = tuple ()
|
||||
return %1 : $()
|
||||
}
|
||||
|
||||
sil hidden @_TFC5class1D8multiplyfS0_fT1xBi8__FT1yBi16__Bi32_ : $@convention(method) (Builtin.Int16, Builtin.Int8, @guaranteed D) -> Builtin.Int32 {
|
||||
bb0(%0 : $Builtin.Int16, %1 : $Builtin.Int8, %2 : $D):
|
||||
%3 = integer_literal $Builtin.Int32, 0
|
||||
return %3 : $Builtin.Int32
|
||||
}
|
||||
|
||||
sil_vtable D {
|
||||
#D.multiply!2: _TFC5class1D8multiplyfS0_fT1xBi8__FT1yBi16__Bi32_
|
||||
}
|
||||
|
||||
// CHECK-LABEL: define %C5class1C* @alloc_ref_dynamic(%swift.type*)
|
||||
sil @alloc_ref_dynamic : $@convention(thin) (@thick C.Type) -> @owned C {
|
||||
bb0(%0 : $@thick C.Type):
|
||||
|
||||
@@ -25,8 +25,11 @@ struct Spoon: Runcible {
|
||||
typealias Element = Mince
|
||||
}
|
||||
|
||||
func split<Seq: Runcible>(seq: Seq)(isSeparator: Seq.Element -> Bool) { }
|
||||
|
||||
func split<Seq: Runcible>(seq: Seq) -> (Seq.Element -> Bool) -> () {
|
||||
return {(isSeparator: Seq.Element -> Bool) in
|
||||
return ()
|
||||
}
|
||||
}
|
||||
var seq = Spoon()
|
||||
var x = seq ~> split
|
||||
|
||||
@@ -39,10 +42,15 @@ var x = seq ~> split
|
||||
// CHECK: tail call { i8*, %swift.refcounted* } @_TF21partial_apply_generic5split{{.*}}(%swift.opaque* noalias nocapture [[REABSTRACT]],
|
||||
|
||||
struct HugeStruct { var a, b, c, d: Int }
|
||||
func hugeStructReturn()(h: HugeStruct) -> HugeStruct { return h }
|
||||
var y = hugeStructReturn()
|
||||
// CHECK-LABEL: define internal void @_TPA__TF21partial_apply_generic16hugeStructReturn{{.*}}(%V21partial_apply_generic10HugeStruct* noalias nocapture sret, %V21partial_apply_generic10HugeStruct* noalias nocapture dereferenceable({{.*}}), %swift.refcounted*) {{.*}} {
|
||||
// CHECK: tail call void @_TF21partial_apply_generic16hugeStructReturn{{.*}}(%V21partial_apply_generic10HugeStruct* noalias nocapture sret %0, %V21partial_apply_generic10HugeStruct* noalias nocapture dereferenceable({{.*}}) %1)
|
||||
struct S {
|
||||
func hugeStructReturn(h: HugeStruct) -> HugeStruct { return h }
|
||||
}
|
||||
|
||||
let s = S()
|
||||
var y = s.hugeStructReturn
|
||||
// CHECK-LABEL: define internal void @_TPA__TFV21partial_apply_generic1S16hugeStructReturnfVS_10HugeStructS1_(%V21partial_apply_generic10HugeStruct* noalias nocapture sret, %V21partial_apply_generic10HugeStruct* noalias nocapture dereferenceable(32), %swift.refcounted*) #0 {
|
||||
// CHECK: entry:
|
||||
// CHECK: tail call void @_TFV21partial_apply_generic1S16hugeStructReturnfVS_10HugeStructS1_(%V21partial_apply_generic10HugeStruct* noalias nocapture sret %0, %V21partial_apply_generic10HugeStruct* noalias nocapture dereferenceable(32) %1) #0
|
||||
// CHECK: ret void
|
||||
// CHECK: }
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// RUN: %target-run-simple-swift | FileCheck %s
|
||||
// REQUIRES: executable_test
|
||||
|
||||
func curry<T, U, V>(f: (T, U) -> V)(_ x: T)(_ y: U) -> V {
|
||||
return f(x, y)
|
||||
func curry<T, U, V>(f: (T, U) -> V) -> (T) -> (U) -> V {
|
||||
return { x in { y in f(x, y) } }
|
||||
}
|
||||
|
||||
func curry<T1, T2, T3, T4>(f: (T1, T2, T3) -> T4)(_ x: T1)(_ y: T2)(_ z: T3) -> T4 {
|
||||
return f(x, y, z)
|
||||
func curry<T1, T2, T3, T4>(f: (T1, T2, T3) -> T4) -> (T1) -> (T2) -> (T3) -> T4 {
|
||||
return { x in { y in { z in f(x, y, z) } } }
|
||||
}
|
||||
|
||||
func concat(x: String, _ y: String, _ z: String) -> String {
|
||||
@@ -91,8 +91,8 @@ print(test_compose_closure(20)) // CHECK-NEXT: 21
|
||||
|
||||
// rdar://problem/18988428
|
||||
|
||||
func clamp<T: Comparable>(minValue: T, _ maxValue: T)(n: T) -> T {
|
||||
return max(minValue, min(n, maxValue))
|
||||
func clamp<T: Comparable>(minValue: T, _ maxValue: T) -> (n: T) -> T {
|
||||
return { n in max(minValue, min(n, maxValue)) }
|
||||
}
|
||||
|
||||
let clampFoo2 = clamp(10.0, 30.0)
|
||||
@@ -105,8 +105,8 @@ func pair<T,U> (a: T) -> U -> (T,U) {
|
||||
return { b in (a,b) }
|
||||
}
|
||||
|
||||
func pair_<T,U> (a: T)(b: U) -> (T,U) {
|
||||
return (a,b)
|
||||
func pair_<T,U> (a: T) -> (b: U) -> (T,U) {
|
||||
return { b in (a,b) }
|
||||
}
|
||||
|
||||
infix operator <+> { }
|
||||
@@ -130,20 +130,20 @@ print((b <+> pair_)(a!)) // CHECK-NEXT: (42, 23)
|
||||
struct Identity<A> { let value: A }
|
||||
struct Const<A, B> { let value: A }
|
||||
|
||||
func fmap<A, B>(f: A -> B)(_ identity: Identity<A>) -> Identity<B> {
|
||||
return Identity(value: f(identity.value))
|
||||
func fmap<A, B>(f: A -> B) -> (Identity<A>) -> Identity<B> {
|
||||
return { identity in Identity(value: f(identity.value)) }
|
||||
}
|
||||
|
||||
func fmap<A, B>(f: A -> B)(_ const: Const<A, B>) -> Const<A, B> {
|
||||
return const
|
||||
func fmap<A, B>(f: A -> B) -> (Const<A, B>) -> Const<A, B> {
|
||||
return { const in const }
|
||||
}
|
||||
|
||||
// really Const()
|
||||
func _Const<A, B>(a: A) -> Const<A, B> {
|
||||
return Const(value: a)
|
||||
}
|
||||
func const<A, B>(a: A)(_: B) -> A {
|
||||
return a
|
||||
func const<A, B>(a: A) -> (B) -> A {
|
||||
return { _ in a }
|
||||
}
|
||||
|
||||
// really Identity()
|
||||
@@ -160,24 +160,24 @@ func runIdentity<A>(i: Identity<A>) -> A {
|
||||
}
|
||||
|
||||
|
||||
func view<S, A>(lens: (A -> Const<A, S>) -> S -> ((A -> S) -> Const<A, S> -> Const<A, S>) -> Const<A, S>)(_ s: S) -> A {
|
||||
return getConst(lens(_Const)(s)(fmap))
|
||||
func view<S, A>(lens: (A -> Const<A, S>) -> S -> ((A -> S) -> Const<A, S> -> Const<A, S>) -> Const<A, S>) -> (S) -> A {
|
||||
return { s in getConst(lens(_Const)(s)(fmap)) }
|
||||
}
|
||||
|
||||
func over<S, A>(lens: (A -> Identity<A>) -> S -> ((A -> S) -> Identity<A> -> Identity<S>) -> Identity<S>)(_ f: A -> A)(_ s: S) -> S {
|
||||
return runIdentity(lens({ _Identity(f($0)) })(s)(fmap))
|
||||
func over<S, A>(lens: (A -> Identity<A>) -> S -> ((A -> S) -> Identity<A> -> Identity<S>) -> Identity<S>) -> (A -> A) -> (S) -> S {
|
||||
return { f in { s in runIdentity(lens({ _Identity(f($0)) })(s)(fmap)) } }
|
||||
}
|
||||
|
||||
func set<S, A>(lens: (A -> Identity<A>) -> S -> ((A -> S) -> Identity<A> -> Identity<S>) -> Identity<S>)(_ x: A)(_ y: S) -> S {
|
||||
return over(lens)(const(x))(y)
|
||||
func set<S, A>(lens: (A -> Identity<A>) -> S -> ((A -> S) -> Identity<A> -> Identity<S>) -> Identity<S>) -> (A) -> (S) -> S {
|
||||
return { x in { y in over(lens)(const(x))(y) } }
|
||||
}
|
||||
|
||||
func _1<A, B, C, D>(f: A -> C)(_ x: A, _ y: B)(_ fmap: (A -> (A, B)) -> C -> D) -> D {
|
||||
return fmap({ ($0, y) })(f(x))
|
||||
func _1<A, B, C, D>(f: A -> C) -> (A, B) -> ((A -> (A, B)) -> C -> D) -> D {
|
||||
return { (x, y) in { fmap in fmap({ ($0, y) })(f(x)) } }
|
||||
}
|
||||
|
||||
func _2<A, B, C, D>(f: B -> C)(_ x: A, _ y: B)(_ fmap: (B -> (A, B)) -> C -> D) -> D {
|
||||
return fmap({ (x, $0) })(f(y))
|
||||
func _2<A, B, C, D>(f: B -> C) -> (A, B) -> ((B -> (A, B)) -> C -> D) -> D {
|
||||
return { (x, y) in { fmap in fmap({ (x, $0) })(f(y)) } }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ struct Steroids {}
|
||||
protocol Gymnast {
|
||||
func backflip(angle: Double) -> Self
|
||||
func compete() -> Medal -> Self
|
||||
func scandal()(s: Steroids) -> ()
|
||||
func scandal() -> (Steroids) -> ()
|
||||
static func currentYear() -> Int
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ final class Archimedes : Gymnast {
|
||||
}
|
||||
}
|
||||
|
||||
func scandal()(s: Steroids) -> () {
|
||||
print("Archimedes don't do that")
|
||||
func scandal() -> (Steroids) -> () {
|
||||
return { s in print("Archimedes don't do that") }
|
||||
}
|
||||
|
||||
static func currentYear() -> Int {
|
||||
|
||||
@@ -40,8 +40,8 @@ func getMandelbrotIterations(c: Complex, maxIterations: Int) -> Int {
|
||||
return n
|
||||
}
|
||||
|
||||
func fractal (densityFunc:(c: Complex, maxIterations: Int) -> Int)
|
||||
(xMin:Double, xMax:Double,
|
||||
func fractal (densityFunc:(c: Complex, maxIterations: Int) -> Int,
|
||||
xMin:Double, xMax:Double,
|
||||
yMin:Double, yMax:Double,
|
||||
rows:Int, cols:Int,
|
||||
maxIterations:Int) {
|
||||
@@ -59,9 +59,9 @@ func fractal (densityFunc:(c: Complex, maxIterations: Int) -> Int)
|
||||
}
|
||||
}
|
||||
|
||||
var mandelbrot = fractal(getMandelbrotIterations)
|
||||
mandelbrot(xMin: -1.35, xMax: 1.4, yMin: -2.0, yMax: 1.05, rows: 40, cols: 80,
|
||||
maxIterations: 200)
|
||||
fractal(getMandelbrotIterations,
|
||||
xMin: -1.35, xMax: 1.4, yMin: -2.0, yMax: 1.05, rows: 40, cols: 80,
|
||||
maxIterations: 200)
|
||||
|
||||
// CHECK: ################################################################################
|
||||
// CHECK: ##############################********************##############################
|
||||
@@ -118,9 +118,9 @@ func getBurningShipIterations(c: Complex, maxIterations: Int) -> Int {
|
||||
|
||||
print("\n== BURNING SHIP ==\n\n", terminator: "")
|
||||
|
||||
var burningShip = fractal(getBurningShipIterations)
|
||||
burningShip(xMin: -2.0, xMax: 1.2, yMin: -2.1, yMax: 1.2, rows: 40, cols: 80,
|
||||
maxIterations: 200)
|
||||
fractal(getBurningShipIterations,
|
||||
xMin: -2.0, xMax: 1.2, yMin: -2.1, yMax: 1.2, rows: 40, cols: 80,
|
||||
maxIterations: 200)
|
||||
|
||||
// CHECK: ################################################################################
|
||||
// CHECK: ################################################################################
|
||||
|
||||
@@ -5,8 +5,8 @@ func double(x: Int) -> Int {
|
||||
return x+x
|
||||
}
|
||||
|
||||
func curriedSubtract(x: Int)(_ y: Int) -> Int {
|
||||
return x-y
|
||||
func curriedSubtract(x: Int) -> (Int) -> Int {
|
||||
return { y in x - y }
|
||||
}
|
||||
|
||||
func twice(f: (Int) -> Int, _ x: Int) -> Int {
|
||||
@@ -41,4 +41,4 @@ func bar(c: C) { print("Right") }
|
||||
// CHECK: Right
|
||||
foo(D())
|
||||
// CHECK: Right
|
||||
bar(D())
|
||||
bar(D())
|
||||
|
||||
@@ -9,17 +9,19 @@ class B : A {
|
||||
}
|
||||
|
||||
func printA(v: A) { v.printA() }
|
||||
func printOpt<T>(subprint: T -> ())(x: T?) {
|
||||
switch (x) {
|
||||
case .Some(let y): print(".Some(", terminator: ""); subprint(y); print(")", terminator: "")
|
||||
case .None: print(".None", terminator: "")
|
||||
func printOpt<T>(subprint: T -> ()) -> (T?) -> () {
|
||||
return { x in
|
||||
switch (x) {
|
||||
case .Some(let y): print(".Some(", terminator: ""); subprint(y); print(")", terminator: "")
|
||||
case .None: print(".None", terminator: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func test(v: A????, _ cast: (A????) -> B?) {
|
||||
printOpt(printOpt(printOpt(printOpt(printA))))(x: v)
|
||||
printOpt(printOpt(printOpt(printOpt(printA))))(v)
|
||||
print(" as? B: ", terminator: "")
|
||||
printOpt(printA)(x: cast(v))
|
||||
printOpt(printA)(cast(v))
|
||||
print("\n", terminator: "")
|
||||
}
|
||||
test(.Some(.Some(.Some(.Some(A())))), { $0 as? B })
|
||||
@@ -36,9 +38,9 @@ test(.None, { $0 as? B })
|
||||
// CHECK: .None as? B: .None
|
||||
|
||||
func test(v: A????, _ cast: (A????) -> B??) {
|
||||
printOpt(printOpt(printOpt(printOpt(printA))))(x: v)
|
||||
printOpt(printOpt(printOpt(printOpt(printA))))(v)
|
||||
print(" as? B?: ", terminator: "")
|
||||
printOpt(printOpt(printA))(x: cast(v))
|
||||
printOpt(printOpt(printA))(cast(v))
|
||||
print("\n", terminator: "")
|
||||
}
|
||||
test(.Some(.Some(.Some(.Some(A())))), { $0 as? B? })
|
||||
@@ -55,9 +57,9 @@ test(.None, { $0 as? B? })
|
||||
// CHECK: .None as? B?: .None
|
||||
|
||||
func test(v: A????, _ cast: (A????) -> B???) {
|
||||
printOpt(printOpt(printOpt(printOpt(printA))))(x: v)
|
||||
printOpt(printOpt(printOpt(printOpt(printA))))(v)
|
||||
print(" as? B??: ", terminator: "")
|
||||
printOpt(printOpt(printOpt(printA)))(x: cast(v))
|
||||
printOpt(printOpt(printOpt(printA)))(cast(v))
|
||||
print("\n", terminator: "")
|
||||
}
|
||||
test(.Some(.Some(.Some(.Some(A())))), { $0 as? B?? })
|
||||
|
||||
@@ -27,29 +27,6 @@ func address_only_ignored_argument(_: Unloadable) {
|
||||
// CHECK: return
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF18address_only_types30address_only_curried_arguments
|
||||
func address_only_curried_arguments(x: Unloadable)(y: Unloadable) {
|
||||
// CHECK: bb0([[YARG:%[0-9]+]] : $*Unloadable, [[XARG:%[0-9]+]] : $*Unloadable):
|
||||
// CHECK-NEXT: debug_value_addr [[YARG]] : $*Unloadable, let, name "y"
|
||||
// CHECK-NEXT: debug_value_addr [[XARG]] : $*Unloadable, let, name "x"
|
||||
// CHECK-NEXT: destroy_addr [[XARG]]
|
||||
// CHECK-NEXT: destroy_addr [[YARG]]
|
||||
// CHECK-NEXT: tuple
|
||||
// CHECK-NEXT: return
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF18address_only_types41address_only_curried_arguments_and_return
|
||||
func address_only_curried_arguments_and_return(x: Unloadable)(y: Unloadable) -> Unloadable {
|
||||
// CHECK: bb0([[RET:%[0-9]+]] : $*Unloadable, [[YARG:%[0-9]+]] : $*Unloadable, [[XARG:%[0-9]+]] : $*Unloadable):
|
||||
// CHECK-NEXT: debug_value_addr [[YARG]] : $*Unloadable, let, name "y"
|
||||
// CHECK-NEXT: debug_value_addr [[XARG]] : $*Unloadable, let, name "x"
|
||||
// CHECK-NEXT: copy_addr [take] [[XARG]] to [initialization] [[RET]]
|
||||
// CHECK-NEXT: destroy_addr [[YARG]]
|
||||
// CHECK-NEXT: tuple
|
||||
// CHECK-NEXT: return
|
||||
return x
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF18address_only_types19address_only_return
|
||||
func address_only_return(x: Unloadable, y: Int) -> Unloadable {
|
||||
// CHECK: bb0([[RET:%[0-9]+]] : $*Unloadable, [[XARG:%[0-9]+]] : $*Unloadable, [[YARG:%[0-9]+]] : $Builtin.Int64):
|
||||
@@ -61,17 +38,6 @@ func address_only_return(x: Unloadable, y: Int) -> Unloadable {
|
||||
return x
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF18address_only_types27address_only_curried_return
|
||||
func address_only_curried_return(x: Unloadable)(y: Int) -> Unloadable {
|
||||
// CHECK: bb0([[RET:%[0-9]+]] : $*Unloadable, [[YARG:%[0-9]+]] : $Builtin.Int64, [[XADDR:%[0-9]+]] : $*Unloadable):
|
||||
// CHECK-NEXT: debug_value [[YARG]] : $Builtin.Int64, let, name "y"
|
||||
// CHECK-NEXT: debug_value_addr [[XADDR]] : $*Unloadable, let, name "x"
|
||||
// CHECK-NEXT: copy_addr [take] [[XADDR]] to [initialization] [[RET]]
|
||||
// CHECK-NEXT: [[VOID:%[0-9]+]] = tuple ()
|
||||
// CHECK-NEXT: return [[VOID]]
|
||||
return x
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF18address_only_types27address_only_missing_return
|
||||
func address_only_missing_return() -> Unloadable {
|
||||
// CHECK: unreachable
|
||||
|
||||
@@ -4,8 +4,8 @@ infix operator ~> { precedence 255 associativity left }
|
||||
|
||||
protocol P { }
|
||||
|
||||
func bar<T:P>(inout _: T)() {}
|
||||
func baz<T:P>(inout _: T)(_:Int) {}
|
||||
func bar<T:P>(inout _: T) -> () -> () { return {_ in ()} }
|
||||
func baz<T:P>(inout _: T) -> (Int) -> () { return {_ in ()} }
|
||||
|
||||
func ~> <T: P, Args, Result>(
|
||||
inout x: T,
|
||||
|
||||
@@ -97,20 +97,6 @@ func simple_arguments(x: Int, y: Int) -> Int {
|
||||
return x+y
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF5decls17curried_arguments
|
||||
// CHECK: bb0(%0 : $Int, %1 : $Int):
|
||||
// CHECK: [[X:%[0-9]+]] = alloc_box $Int
|
||||
// CHECK: [[PBX:%.*]] = project_box [[X]]
|
||||
// CHECK-NEXT: store %1 to [[PBX]]
|
||||
// CHECK: [[Y:%[0-9]+]] = alloc_box $Int
|
||||
// CHECK: [[PBY:%.*]] = project_box [[Y]]
|
||||
// CHECK-NEXT: store %0 to [[PBY]]
|
||||
func curried_arguments(x: Int)(y: Int) -> Int {
|
||||
var x = x
|
||||
var y = y
|
||||
return x+y
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF5decls14tuple_argument
|
||||
// CHECK: bb0(%0 : $Int, %1 : $Float):
|
||||
// CHECK: [[UNIT:%[0-9]+]] = tuple ()
|
||||
|
||||
@@ -23,41 +23,6 @@ func higher_order_function2(f: (Int, Int) -> Int, _ x: Int, _ y: Int) -> Int {
|
||||
return f(x, y)
|
||||
}
|
||||
|
||||
// -- Entry point BBs correspond to curried arguments in left-to-right order.
|
||||
// CHECK-LABEL: sil hidden @_TF9functions16curried_function{{.*}} : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> Builtin.Int64
|
||||
func curried_function(x: Int)(y: Int) -> Int {
|
||||
var x = x
|
||||
var y = y
|
||||
// CHECK: bb0(%0 : $Builtin.Int64, %1 : $Builtin.Int64):
|
||||
// CHECK: [[XADDR:%[0-9]+]] = alloc_box $Builtin.Int64
|
||||
// CHECK: [[PBX:%.*]] = project_box [[XADDR]]
|
||||
// CHECK: [[YADDR:%[0-9]+]] = alloc_box $Builtin.Int64
|
||||
// CHECK: [[PBY:%.*]] = project_box [[YADDR]]
|
||||
|
||||
return standalone_function(x, y)
|
||||
// CHECK: [[FUNC:%[0-9]+]] = function_ref @_TF9functions19standalone_function{{.*}} : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: [[X:%[0-9]+]] = load [[PBX]]
|
||||
// CHECK: [[Y:%[0-9]+]] = load [[PBY]]
|
||||
// CHECK: apply [[FUNC]]([[X]], [[Y]])
|
||||
|
||||
// CHECK: return
|
||||
}
|
||||
|
||||
// -- Curried generic function needs to forward archetypes through entry points
|
||||
func generic_curried_function<T, U>(x: T)(y: U) { }
|
||||
|
||||
// -- Curried function that returns a function uncurries to the right "natural" level
|
||||
// CHECK-LABEL: sil hidden @_TF9functions33curried_function_returns_function{{.*}} : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> @owned @callee_owned (Builtin.Int64) -> Builtin.Int64
|
||||
func curried_function_returns_function(x: Int)(y: Int) -> (z:Int) -> Int {
|
||||
var x = x
|
||||
var y = y
|
||||
// CHECK: bb0(%0 : $Builtin.Int64, %1 : $Builtin.Int64):
|
||||
return { z in standalone_function(standalone_function(x, y), z) }
|
||||
}
|
||||
// -- Local function has extra uncurry level with context
|
||||
// CHECK-LABEL: sil shared @_TFF9functions33curried_function_returns_function{{.*}} : $@convention(thin) (Builtin.Int64, @owned @box Builtin.Int64, @owned @box Builtin.Int64) -> Builtin.Int64
|
||||
// bb0(%0 : $@box Builtin.Int64, %1 : $@box Builtin.Int64, %4 : $Builtin.Int64):
|
||||
|
||||
struct SomeStruct {
|
||||
// -- Constructors and methods are uncurried in 'self'
|
||||
// -- Instance methods use 'method' cc
|
||||
@@ -67,13 +32,8 @@ struct SomeStruct {
|
||||
mutating
|
||||
func method(x: Int) {}
|
||||
|
||||
mutating
|
||||
func curried_method(x: Int)(y: Int) {}
|
||||
|
||||
static func static_method(x: Int) {}
|
||||
|
||||
static func static_curried_method(x: Int)(y: Int) {}
|
||||
|
||||
func generic_method<T>(x: T) {}
|
||||
}
|
||||
|
||||
@@ -92,18 +52,10 @@ class SomeClass {
|
||||
// CHECK: bb0(%0 : $Builtin.Int64, %1 : $SomeClass):
|
||||
func method(x: Int) {}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TFC9functions9SomeClass14curried_method{{.*}} : $@convention(method) (Builtin.Int64, Builtin.Int64, @guaranteed SomeClass) -> ()
|
||||
// CHECK: bb0(%0 : $Builtin.Int64, %1 : $Builtin.Int64, %2 : $SomeClass):
|
||||
func curried_method(x: Int)(y: Int) {}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TZFC9functions9SomeClass13static_method{{.*}} : $@convention(thin) (Builtin.Int64, @thick SomeClass.Type) -> ()
|
||||
// CHECK: bb0(%0 : $Builtin.Int64, %1 : $@thick SomeClass.Type):
|
||||
class func static_method(x: Int) {}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TZFC9functions9SomeClass21static_curried_method{{.*}} : $@convention(thin) (Builtin.Int64, Builtin.Int64, @thick SomeClass.Type) -> ()
|
||||
// CHECK: bb0(%0 : $Builtin.Int64, %1 : $Builtin.Int64, %2 : $@thick SomeClass.Type):
|
||||
class func static_curried_method(x: Int)(y: Int) {}
|
||||
|
||||
var someProperty: Int {
|
||||
get {
|
||||
return zero
|
||||
@@ -163,66 +115,6 @@ func calls(i: Int, j: Int, k: Int) {
|
||||
// CHECK: apply [[FUNC]]([[I]], [[J]])
|
||||
standalone_function(i, j)
|
||||
|
||||
// CHECK: [[FUNC:%[0-9]+]] = function_ref @_TF9functions16curried_function{{.*}} : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: [[I:%[0-9]+]] = load [[IADDR]]
|
||||
// CHECK: [[J:%[0-9]+]] = load [[JADDR]]
|
||||
// CHECK: apply [[FUNC]]([[J]], [[I]])
|
||||
curried_function(i)(y: j)
|
||||
|
||||
// -- Paren exprs shouldn't affect the uncurrying optimization.
|
||||
// CHECK: [[FUNC:%[0-9]+]] = function_ref @_TF9functions16curried_function{{.*}} : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: [[I:%[0-9]+]] = load [[IADDR]]
|
||||
// CHECK: [[J:%[0-9]+]] = load [[JADDR]]
|
||||
// CHECK: apply [[FUNC]]([[J]], [[I]])
|
||||
(curried_function)(i)(y: j)
|
||||
|
||||
// -- Coercions and function conversions shouldn't affect the uncurrying
|
||||
// optimization.
|
||||
// CHECK: [[FUNC:%[0-9]+]] = function_ref @_TF9functions16curried_function{{.*}} : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: [[I:%[0-9]+]] = load [[IADDR]]
|
||||
// CHECK: [[J:%[0-9]+]] = load [[JADDR]]
|
||||
// CHECK: apply [[FUNC]]([[J]], [[I]])
|
||||
(curried_function)(i)(y: j)
|
||||
|
||||
// CHECK: [[FUNC1:%[0-9]+]] = function_ref @_TF9functions33curried_function_returns_function{{.*}} : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> @owned @callee_owned (Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: [[I:%[0-9]+]] = load [[IADDR]]
|
||||
// CHECK: [[J:%[0-9]+]] = load [[JADDR]]
|
||||
// CHECK: [[FUNC2:%[0-9]+]] = apply [[FUNC1]]([[J]], [[I]])
|
||||
// CHECK: [[K:%[0-9]+]] = load [[KADDR]]
|
||||
// CHECK: apply [[FUNC2]]([[K]])
|
||||
curried_function_returns_function(i)(y: j)(z: k)
|
||||
|
||||
generic_curried_function(i)(y: j)
|
||||
// -- Use of curried entry points as values.
|
||||
|
||||
// CHECK: [[F1BOX:%[0-9]+]] = alloc_box $@callee_owned (Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: [[F1ADDR:%.*]] = project_box [[F1BOX]]
|
||||
// CHECK: [[FUNC:%[0-9]+]] = function_ref @_TF9functions16curried_function{{.*}} : $@convention(thin) (Builtin.Int64) -> @owned @callee_owned (Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: [[I:%[0-9]+]] = load [[IADDR]]
|
||||
// CHECK: [[FUNC_CURRY:%[0-9]+]] = apply [[FUNC]]([[I]])
|
||||
// CHECK: store [[FUNC_CURRY]] to [[F1ADDR]]
|
||||
var f1 = curried_function(i)
|
||||
// CHECK: [[F1:%[0-9]+]] = load [[F1ADDR]]
|
||||
// CHECK: [[J:%[0-9]+]] = load [[JADDR]]
|
||||
// CHECK: apply [[F1]]([[J]])
|
||||
f1(y: j)
|
||||
|
||||
// CHECK: [[F2BOX:%[0-9]+]] = alloc_box $@callee_owned (Builtin.Int64) -> @owned @callee_owned (Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: [[F2ADDR:%.*]] = project_box [[F2BOX]]
|
||||
// CHECK: [[FUNC:%[0-9]+]] = function_ref @_TF9functions16curried_function{{.*}} : $@convention(thin) (Builtin.Int64) -> @owned @callee_owned (Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: [[FUNC_THICK:%[0-9]+]] = thin_to_thick_function [[FUNC]] : ${{.*}} to $@callee_owned (Builtin.Int64) -> @owned @callee_owned (Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: store [[FUNC_THICK]] to [[F2ADDR]]
|
||||
var f2 = curried_function
|
||||
// CHECK: [[F2:%[0-9]+]] = load [[F2ADDR]]
|
||||
// CHECK: [[I:%[0-9]+]] = load [[IADDR]]
|
||||
// CHECK: [[F2_I:%[0-9]+]] = apply [[F2]]([[I]])
|
||||
// CHECK: [[J:%[0-9]+]] = load [[JADDR]]
|
||||
// CHECK: apply [[F2_I]]([[J]])
|
||||
f2(i)(y: j)
|
||||
|
||||
var gcf1: Int -> () = generic_curried_function(i)
|
||||
gcf1(j)
|
||||
|
||||
// -- Curry 'self' onto struct method argument lists.
|
||||
|
||||
// CHECK: [[ST_ADDR:%.*]] = alloc_box $SomeStruct
|
||||
@@ -239,10 +131,6 @@ func calls(i: Int, j: Int, k: Int) {
|
||||
// CHECK: [[THUNK_THICK:%.*]] = thin_to_thick_function [[THUNK]]
|
||||
var stm1 = SomeStruct.method
|
||||
stm1(&st)(i)
|
||||
// CHECK: [[THUNK:%.*]] = function_ref @_TFV9functions10SomeStruct14curried_method{{.*}}
|
||||
// CHECK: [[THUNK_THICK:%.*]] = thin_to_thick_function [[THUNK]]
|
||||
var stm2 = SomeStruct.curried_method
|
||||
stm2(&st)(i)(y: j)
|
||||
|
||||
// -- Curry 'self' onto method argument lists dispatched using class_method.
|
||||
|
||||
@@ -261,13 +149,6 @@ func calls(i: Int, j: Int, k: Int) {
|
||||
// CHECK: apply [[METHOD]]([[I]], [[C]])
|
||||
c.method(i)
|
||||
|
||||
// CHECK: [[C:%[0-9]+]] = load [[CADDR]]
|
||||
// CHECK: [[METHOD:%[0-9]+]] = class_method [[C]] : {{.*}}, #SomeClass.curried_method!2
|
||||
// CHECK: [[I:%[0-9]+]] = load [[IADDR]]
|
||||
// CHECK: [[J:%[0-9]+]] = load [[JADDR]]
|
||||
// CHECK: apply [[METHOD]]([[J]], [[I]], [[C]])
|
||||
c.curried_method(i)(y: j)
|
||||
|
||||
// -- Curry 'self' onto unapplied methods dispatched using class_method.
|
||||
// CHECK: [[METHOD_CURRY_THUNK:%.*]] = function_ref @_TFC9functions9SomeClass6method{{.*}}
|
||||
// CHECK: apply [[METHOD_CURRY_THUNK]]
|
||||
@@ -280,24 +161,6 @@ func calls(i: Int, j: Int, k: Int) {
|
||||
// CHECK: apply [[METHOD]]([[I]], [[C]])
|
||||
SomeClass.method(c)(i)
|
||||
|
||||
// CHECK: [[C:%[0-9]+]] = load [[CADDR]]
|
||||
// CHECK: [[METHOD:%[0-9]+]] = class_method [[C]] : {{.*}}, #SomeClass.curried_method!2
|
||||
// CHECK: [[I:%[0-9]+]] = load [[IADDR]]
|
||||
// CHECK: [[J:%[0-9]+]] = load [[JADDR]]
|
||||
// CHECK: apply [[METHOD]]([[J]], [[I]], [[C]])
|
||||
SomeClass.curried_method(c)(i)(y: j)
|
||||
|
||||
// -- Curry 'self' onto unapplied methods, after applying side effects from a Type expression.
|
||||
|
||||
// CHECK: [[C:%[0-9]+]] = load [[CADDR]]
|
||||
// CHECK: [[SIDEFUNC:%[0-9]+]] = function_ref @_TF9functions21SomeClassWithBenefitsFT_MCS_9SomeClass : $@convention(thin) () -> @thick SomeClass.Type
|
||||
// CHECK: apply [[SIDEFUNC]]()
|
||||
// CHECK: [[METHOD:%[0-9]+]] = class_method [[C]] : {{.*}}, #SomeClass.curried_method!2
|
||||
// CHECK: [[I:%[0-9]+]] = load [[IADDR]]
|
||||
// CHECK: [[J:%[0-9]+]] = load [[JADDR]]
|
||||
// CHECK: apply [[METHOD]]([[J]], [[I]], [[C]])
|
||||
SomeClassWithBenefits().curried_method(c)(i)(y: j)
|
||||
|
||||
// -- Curry the Type onto static method argument lists.
|
||||
|
||||
// CHECK: [[C:%[0-9]+]] = load [[CADDR]]
|
||||
@@ -306,25 +169,6 @@ func calls(i: Int, j: Int, k: Int) {
|
||||
// CHECK: apply [[METHOD]]([[I]], [[META]])
|
||||
c.dynamicType.static_method(i)
|
||||
|
||||
// CHECK: [[C:%[0-9]+]] = load [[CADDR]]
|
||||
// CHECK: [[METHOD:%[0-9]+]] = class_method [[META:%[0-9]+]] : {{.*}}, #SomeClass.static_curried_method!2
|
||||
// CHECK: [[I:%[0-9]+]] = load [[IADDR]]
|
||||
// CHECK: [[J:%[0-9]+]] = load [[JADDR]]
|
||||
// CHECK: apply [[METHOD]]([[J]], [[I]], [[META]])
|
||||
c.dynamicType.static_curried_method(i)(y: j)
|
||||
|
||||
// FIXME: use of curried method entry points as values
|
||||
//var m1 = c.curried_method(i)
|
||||
//m1(j)
|
||||
//var m2 = c.curried_method
|
||||
//m2(i)(j)
|
||||
//var m3 = SomeClass.curried_method
|
||||
//m3(c)(i)(j)
|
||||
//var s1 = c.Type.static_curried_method(i)
|
||||
//s1(j)
|
||||
//var s2 = c.Type.static_curried_method
|
||||
//s2(i)(j)
|
||||
|
||||
// -- Curry property accesses.
|
||||
|
||||
// -- FIXME: class_method-ify class getters.
|
||||
@@ -458,18 +302,6 @@ func calls(i: Int, j: Int, k: Int) {
|
||||
}
|
||||
|
||||
// -- Curried entry points
|
||||
// CHECK-LABEL: sil shared @_TF9functions16curried_function{{.*}} : $@convention(thin) (Builtin.Int64) -> @owned @callee_owned (Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: bb0([[X:%[0-9]+]] : $Builtin.Int64):
|
||||
// CHECK: [[FUNC:%[0-9]+]] = function_ref @_TF9functions16curried_function{{.*}} : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> Builtin.Int64
|
||||
// CHECK: [[CLOSURE:%[0-9]+]] = partial_apply [[FUNC]]([[X]])
|
||||
// CHECK: return [[CLOSURE]]
|
||||
|
||||
// CHECK-LABEL: sil shared @_TF9functions24generic_curried_function{{.*}} : $@convention(thin) <T, U> (@in T) -> @owned @callee_owned (@in U) -> () {
|
||||
// CHECK: bb0([[X:%.*]] : $*T):
|
||||
// CHECK: [[UNCURRIED:%.*]] = function_ref @_TF9functions24generic_curried_function{{.*}}
|
||||
// CHECK: [[CURRIED:%.*]] = partial_apply [[UNCURRIED]]<T, U>([[X]])
|
||||
// CHECK: return [[CURRIED]] : $@callee_owned (@in U) -> ()
|
||||
|
||||
// CHECK-LABEL: sil shared @_TFV9functions10SomeStruct6method{{.*}} : $@convention(thin) (@inout SomeStruct) -> @owned @callee_owned (Builtin.Int64) -> () {
|
||||
// CHECK: [[UNCURRIED:%.*]] = function_ref @_TFV9functions10SomeStruct6method{{.*}} : $@convention(method) (Builtin.Int64, @inout SomeStruct) -> () // user: %2
|
||||
// CHECK: [[CURRIED:%.*]] = partial_apply [[UNCURRIED]]
|
||||
|
||||
@@ -83,12 +83,6 @@ class NestedGeneric<U> {
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF16generic_closures24generic_curried_function{{.*}} : $@convention(thin) <T, U> (@in U, @in T) -> () {
|
||||
// CHECK-LABEL: sil shared @_TF16generic_closures24generic_curried_function{{.*}}
|
||||
func generic_curried_function<T, U>(x: T)(y: U) { }
|
||||
|
||||
var f: (Int) -> () = generic_curried_function(zero)
|
||||
|
||||
// <rdar://problem/15417773>
|
||||
// Ensure that nested closures capture the generic parameters of their nested
|
||||
// context.
|
||||
|
||||
@@ -454,109 +454,14 @@ extension FakeArray : SequenceType {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Make sure that we properly add retains when emitting code for curried
|
||||
// functions.
|
||||
// Make sure that we do not emit extra retains when accessing let fields of
|
||||
// guaranteed parameters.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class Kraken {
|
||||
func enrage() {}
|
||||
}
|
||||
|
||||
class CurriedTestBar {
|
||||
func bar(x: Kraken)(_ y: Kraken)(_ z: Kraken) -> Kraken {
|
||||
return z
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we create a closure and pass it in @owned with a retain before it.
|
||||
//
|
||||
// CHECK-LABEL: sil hidden @_TF15guaranteed_self13curried_test0FT_T_ : $@convention(thin) () -> () {
|
||||
// CHECK: [[FUNC:%.*]] = function_ref @_TFC15guaranteed_self14CurriedTestBarC{{.*}}
|
||||
// CHECK: [[CTB:%.*]] = apply [[FUNC]](
|
||||
// CHECK: [[THUNK_CONSTRUCTOR:%.*]] = function_ref @_TFC15guaranteed_self14CurriedTestBar3barF{{.*}} : $@convention(thin) (@owned CurriedTestBar) -> @owned @callee_owned (@owned Kraken) -> @owned @callee_owned (@owned Kraken) -> @owned @callee_owned (@owned Kraken) -> @owned Kraken
|
||||
// CHECK: strong_retain [[CTB]]
|
||||
// CHECK: [[CLOSURE:%.*]] = apply [[THUNK_CONSTRUCTOR]]([[CTB]]
|
||||
// CHECK-NOT: strong_release [[CTB]]
|
||||
// CHECK: strong_release [[CLOSURE]]
|
||||
// CHECK-NEXT: strong_release [[CTB]]
|
||||
// CHECK-NOT: strong_release
|
||||
// CHECK: return
|
||||
func curried_test0() {
|
||||
let b = CurriedTestBar()
|
||||
let bar1 = b.bar
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF15guaranteed_self13curried_test1FT_T_ : $@convention(thin) () -> () {
|
||||
// CHECK: [[KRAKEN_CONSTRUCTOR:%.*]] = function_ref @_TFC15guaranteed_self6KrakenC{{.*}} : $@convention(thin) (@thick Kraken.Type) -> @owned Kraken
|
||||
// CHECK: [[KRAKEN:%.*]] = apply [[KRAKEN_CONSTRUCTOR]](
|
||||
// CHECK: [[CTB_CONSTRUCTOR:%.*]] = function_ref @_TFC15guaranteed_self14CurriedTestBarC{{.*}}
|
||||
// CHECK: [[CTB:%.*]] = apply [[CTB_CONSTRUCTOR]](
|
||||
// CHECK: [[THUNK_CONSTRUCTOR:%.*]] = function_ref @_TFC15guaranteed_self14CurriedTestBar3bar{{.*}} : $@convention(thin) (@owned Kraken, @owned CurriedTestBar) -> @owned @callee_owned (@owned Kraken) -> @owned @callee_owned (@owned Kraken) -> @owned Kraken
|
||||
// CHECK: strong_retain [[CTB]]
|
||||
// CHECK-NEXT: strong_retain [[KRAKEN]]
|
||||
// CHECK-NEXT: [[CLOSURE:%.*]] = apply [[THUNK_CONSTRUCTOR]]([[KRAKEN]], [[CTB]])
|
||||
// CHECK-NEXT: debug_value
|
||||
// CHECK-NEXT: strong_release [[CLOSURE]]
|
||||
// CHECK-NEXT: strong_release [[CTB]]
|
||||
// CHECK-NEXT: strong_release [[KRAKEN]]
|
||||
// CHECK-NEXT: tuple
|
||||
// CHECK-NEXT: return
|
||||
func curried_test1() {
|
||||
let k = Kraken()
|
||||
let b = CurriedTestBar()
|
||||
let bar2 = b.bar(k)
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF15guaranteed_self13curried_test2FT_T_ : $@convention(thin) () -> () {
|
||||
// CHECK: [[KRAKEN_CONSTRUCTOR:%.*]] = function_ref @_TFC15guaranteed_self6KrakenC{{.*}} : $@convention(thin) (@thick Kraken.Type) -> @owned Kraken
|
||||
// CHECK: [[KRAKEN:%.*]] = apply [[KRAKEN_CONSTRUCTOR]](
|
||||
// CHECK: [[CTB_CONSTRUCTOR:%.*]] = function_ref @_TFC15guaranteed_self14CurriedTestBarC{{.*}}
|
||||
// CHECK: [[CTB:%.*]] = apply [[CTB_CONSTRUCTOR]](
|
||||
// CHECK: [[THUNK_CONSTRUCTOR:%.*]] = function_ref @_TFC15guaranteed_self14CurriedTestBar3bar{{.*}} : $@convention(thin) (@owned Kraken, @owned Kraken, @owned CurriedTestBar) -> @owned @callee_owned (@owned Kraken) -> @owned Kraken
|
||||
// CHECK: strong_retain [[CTB]]
|
||||
// CHECK-NEXT: strong_retain [[KRAKEN]]
|
||||
// CHECK-NEXT: strong_retain [[KRAKEN]]
|
||||
// CHECK-NEXT: [[CLOSURE:%.*]] = apply [[THUNK_CONSTRUCTOR]]([[KRAKEN]], [[KRAKEN]], [[CTB]])
|
||||
// CHECK-NEXT: debug_value
|
||||
// CHECK-NEXT: strong_release [[CLOSURE]]
|
||||
// CHECK-NEXT: strong_release [[CTB]]
|
||||
// CHECK-NEXT: strong_release [[KRAKEN]]
|
||||
// CHECK-NEXT: tuple
|
||||
// CHECK-NEXT: return
|
||||
func curried_test2() {
|
||||
let k = Kraken()
|
||||
let b = CurriedTestBar()
|
||||
let bar3 = b.bar(k)(k)
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF15guaranteed_self13curried_test3FT_T_ : $@convention(thin) () -> () {
|
||||
// CHECK: [[KRAKEN_CONSTRUCTOR:%.*]] = function_ref @_TFC15guaranteed_self6KrakenC{{.*}} : $@convention(thin) (@thick Kraken.Type) -> @owned Kraken
|
||||
// CHECK: [[KRAKEN:%.*]] = apply [[KRAKEN_CONSTRUCTOR]](
|
||||
// CHECK: [[CTB_CONSTRUCTOR:%.*]] = function_ref @_TFC15guaranteed_self14CurriedTestBarC{{.*}}
|
||||
// CHECK: [[CTB:%.*]] = apply [[CTB_CONSTRUCTOR]](
|
||||
// CHECK: [[CLASS_METHOD:%.*]] = class_method [[CTB]] : $CurriedTestBar, #CurriedTestBar.bar!3 : (CurriedTestBar) -> (Kraken) -> (Kraken) -> (Kraken) -> Kraken , $@convention(method) (@owned Kraken, @owned Kraken, @owned Kraken, @guaranteed CurriedTestBar) -> @owned Kraken
|
||||
// CHECK-NOT: strong_retain [[CTB]]
|
||||
// CHECK: strong_retain [[KRAKEN]]
|
||||
// CHECK-NEXT: strong_retain [[KRAKEN]]
|
||||
// CHECK-NEXT: strong_retain [[KRAKEN]]
|
||||
// CHECK-NEXT: [[NEW_KRAKEN:%.*]] = apply [[CLASS_METHOD]]([[KRAKEN]], [[KRAKEN]], [[KRAKEN]], [[CTB]])
|
||||
// CHECK-NEXT: debug_value
|
||||
// CHECK-NEXT: strong_release [[NEW_KRAKEN]]
|
||||
// CHECK-NEXT: strong_release [[CTB]]
|
||||
// CHECK-NEXT: strong_release [[KRAKEN]]
|
||||
// CHECK-NEXT: tuple
|
||||
// CHECK-NEXT: return
|
||||
func curried_test3() {
|
||||
let k = Kraken()
|
||||
let b = CurriedTestBar()
|
||||
let bar4 = b.bar(k)(k)(k)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Make sure that we do not emit extra retains when accessing let fields of
|
||||
// guaranteed parameters.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
func destroyShip(k: Kraken) {}
|
||||
|
||||
class LetFieldClass {
|
||||
|
||||
@@ -50,13 +50,6 @@ infix operator «+» {}
|
||||
// CHECK-LABEL: sil hidden @_TZF8manglingXoi7p_qcaDcFTSiSi_Si
|
||||
func «+»(a: Int, b: Int) -> Int { return a + b }
|
||||
|
||||
// Curried function entry points mangle in terms of their original types, not
|
||||
// their uncurried private SIL types.
|
||||
// CHECK-LABEL: sil hidden @_TF8mangling7curriedfT1aSi_FT1bSS_T_ : $@convention(thin) (@owned String, Int) -> ()
|
||||
// CHECK-LABEL: sil shared @_TF8mangling7curriedFT1aSi_FT1bSS_T_ : $@convention(thin) (Int) -> @owned @callee_owned (@owned String) -> ()
|
||||
func curried(a a: Int)(b: String) {}
|
||||
_ = curried(a: 1)
|
||||
|
||||
protocol Foo {}
|
||||
protocol Bar {}
|
||||
|
||||
|
||||
@@ -473,8 +473,6 @@ func testG<T>(m: GenericMetaHolder<T>, gg: G<T>.Type) {
|
||||
extension P1 {
|
||||
final func f1() { }
|
||||
|
||||
final func curried1(b: Bool)(_ i: Int64) { }
|
||||
|
||||
final subscript (i: Int64) -> Bool {
|
||||
get { return true }
|
||||
}
|
||||
@@ -504,11 +502,6 @@ func testExistentials1(p1: P1, b: Bool, i: Int64) {
|
||||
// CHECK: apply [[F1]]<@opened([[UUID]]) P1>([[POPENED]]) : $@convention(method) <τ_0_0 where τ_0_0 : P1> (@in_guaranteed τ_0_0) -> ()
|
||||
p1.f1()
|
||||
|
||||
// CHECK: [[POPENED:%[0-9]+]] = open_existential_addr [[P]] : $*P1 to $*@opened([[UUID:".*"]]) P1
|
||||
// CHECK: [[CURRIED1:%[0-9]+]] = function_ref @_TFE19protocol_extensionsPS_2P18curried1{{.*}}
|
||||
// CHECK: [[CURRIED1]]<@opened([[UUID]]) P1>([[I]], [[B]], [[POPENED]]) : $@convention(method) <τ_0_0 where τ_0_0 : P1> (Int64, Bool, @in_guaranteed τ_0_0) -> ()
|
||||
p1.curried1(b)(i)
|
||||
|
||||
// CHECK: [[POPENED:%[0-9]+]] = open_existential_addr [[P]] : $*P1 to $*@opened([[UUID:".*"]]) P1
|
||||
// CHECK: copy_addr [[POPENED]] to [initialization] [[POPENED_COPY:%.*]] :
|
||||
// CHECK: [[GETTER:%[0-9]+]] = function_ref @_TFE19protocol_extensionsPS_2P1g9subscriptFVs5Int64Sb
|
||||
|
||||
@@ -13,20 +13,12 @@ class GenericSuper<T> {
|
||||
func foo(x: T) -> T? {
|
||||
return nil
|
||||
}
|
||||
|
||||
func curried(x: T)(y: T) -> T? {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
class NongenericSub: GenericSuper<Int>, Fooable {
|
||||
override func foo(x: Int) -> Int? {
|
||||
return 6502
|
||||
}
|
||||
|
||||
override func curried(x: Int)(y: Int) -> Int? {
|
||||
return 6502
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden [transparent] [thunk] @_TTWC33vtable_thunks_reabstraction_final13NongenericSubS_7FooableS_FS1_3foo
|
||||
@@ -36,10 +28,6 @@ class GenericSub<U: AnyObject>: GenericSuper<U>, Barrable {
|
||||
override func foo(x: U) -> U? {
|
||||
return x
|
||||
}
|
||||
|
||||
override func curried(x: U)(y: U) -> U? {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden [transparent] [thunk] @_TTWuRxs9AnyObjectrGC33vtable_thunks_reabstraction_final10GenericSubx_S0_8BarrableS0_FS2_3foofwx3BarGSqwxS3__
|
||||
|
||||
@@ -40,10 +40,6 @@ var readonly: Foo {
|
||||
}
|
||||
|
||||
func bar(inout x x: Foo) {}
|
||||
func bas(inout x x: Foo)(inout y: Foo) {}
|
||||
func zim(inout x x: Foo)(inout y: Foo) -> (inout z: Foo) -> () {
|
||||
return { (inout z: Foo) in }
|
||||
}
|
||||
|
||||
// Writeback to value type 'self' argument
|
||||
x.foo()
|
||||
@@ -71,37 +67,6 @@ bar(x: &x)
|
||||
// CHECK: apply [[SET_X]]([[X1]]) : $@convention(thin) (Foo) -> ()
|
||||
// CHECK: dealloc_stack [[X_TEMP]] : $*Foo
|
||||
|
||||
// Writeback to curried arguments
|
||||
bas(x: &x)(y: &y)
|
||||
// CHECK: [[BAS:%.*]] = function_ref @_TF9writeback3basfT1xRVS_3Foo_FT1yRS0__T_ : $@convention(thin) (@inout Foo, @inout Foo) -> ()
|
||||
// CHECK: [[GET_X:%.*]] = function_ref @_TF9writebackg1xVS_3Foo : $@convention(thin) () -> Foo
|
||||
// CHECK: {{%.*}} = apply [[GET_X]]() : $@convention(thin) () -> Foo
|
||||
// CHECK: [[GET_Y:%.*]] = function_ref @_TF9writebackg1yVS_3Foo : $@convention(thin) () -> Foo
|
||||
// CHECK: {{%.*}} = apply [[GET_Y]]() : $@convention(thin) () -> Foo
|
||||
// CHECK: apply [[BAS]]({{%.*}}, {{%.*}}) : $@convention(thin) (@inout Foo, @inout Foo) -> ()
|
||||
// CHECK: [[SET_Y:%.*]] = function_ref @_TF9writebacks1yVS_3Foo : $@convention(thin) (Foo) -> ()
|
||||
// CHECK: apply [[SET_Y]]({{%.*}}) : $@convention(thin) (Foo) -> ()
|
||||
// CHECK: [[SET_X:%.*]] = function_ref @_TF9writebacks1xVS_3Foo : $@convention(thin) (Foo) -> ()
|
||||
// CHECK: apply [[SET_X]]({{%.*}}) : $@convention(thin) (Foo) -> ()
|
||||
|
||||
// Writeback to curried arguments to function that returns a function
|
||||
zim(x: &x)(y: &y)(z: &z)
|
||||
// CHECK: [[ZIM:%.*]] = function_ref @_TF9writeback3zimfT1xRVS_3Foo_FT1yRS0__FT1zRS0__T_ : $@convention(thin) (@inout Foo, @inout Foo) -> @owned @callee_owned (@inout Foo) -> ()
|
||||
// CHECK: [[GET_X:%.*]] = function_ref @_TF9writebackg1xVS_3Foo : $@convention(thin) () -> Foo
|
||||
// CHECK: {{%.*}} = apply [[GET_X]]() : $@convention(thin) () -> Foo
|
||||
// CHECK: [[GET_Y:%.*]] = function_ref @_TF9writebackg1yVS_3Foo : $@convention(thin) () -> Foo
|
||||
// CHECK: {{%.*}} = apply [[GET_Y]]() : $@convention(thin) () -> Foo
|
||||
// CHECK: [[ZIM2:%.*]] = apply [[ZIM]]({{%.*}}, {{%.*}}) : $@convention(thin) (@inout Foo, @inout Foo) -> @owned @callee_owned (@inout Foo) -> ()
|
||||
// CHECK: [[SET_Y:%.*]] = function_ref @_TF9writebacks1yVS_3Foo : $@convention(thin) (Foo) -> ()
|
||||
// CHECK: apply [[SET_Y]]({{%.*}}) : $@convention(thin) (Foo) -> ()
|
||||
// CHECK: [[SET_X:%.*]] = function_ref @_TF9writebacks1xVS_3Foo : $@convention(thin) (Foo) -> ()
|
||||
// CHECK: apply [[SET_X]]({{%.*}}) : $@convention(thin) (Foo) -> ()
|
||||
// CHECK: [[GET_Z:%.*]] = function_ref @_TF9writebackg1zVS_3Foo : $@convention(thin) () -> Foo
|
||||
// CHECK: {{%.*}} = apply [[GET_Z]]() : $@convention(thin) () -> Foo
|
||||
// CHECK: apply [[ZIM2]]({{%.*}}) : $@callee_owned (@inout Foo) -> ()
|
||||
// CHECK: [[SET_Z:%.*]] = function_ref @_TF9writebacks1zVS_3Foo : $@convention(thin) (Foo) -> ()
|
||||
// CHECK: apply [[SET_Z]]({{%.*}}) : $@convention(thin) (Foo) -> ()
|
||||
|
||||
func zang(x x: Foo) {}
|
||||
|
||||
// No writeback for pass-by-value argument
|
||||
|
||||
@@ -80,28 +80,6 @@ func test_auto_closure_without_capture() -> Bool {
|
||||
// CHECK: [[FALSE:%.*]] = struct $Bool ([[FV:%.*]] : $Builtin.Int1)
|
||||
// CHECK: return [[FALSE]]
|
||||
|
||||
@_transparent func test_curried(x: Int)(y: Int) -> Int { // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
return y
|
||||
}
|
||||
|
||||
func call_uncurried(x: Int, y: Int) -> Int {
|
||||
return test_curried(x)(y: y)
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF18mandatory_inlining14call_uncurried
|
||||
// CHECK-NOT: = apply
|
||||
// CHECK: return
|
||||
|
||||
func call_curried(x: Int, y: Int) -> Int {
|
||||
let z = test_curried(x)
|
||||
return z(y: y)
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil hidden @_TF18mandatory_inlining12call_curried
|
||||
// CHECK: = apply
|
||||
// CHECK: = apply
|
||||
// CHECK: return
|
||||
|
||||
infix operator &&& {
|
||||
associativity left
|
||||
precedence 120
|
||||
|
||||
@@ -5,13 +5,13 @@ func doFoo(f: () -> ()) {
|
||||
}
|
||||
|
||||
class Base {
|
||||
// expected-warning@+1 {{curried function declaration syntax will be removed in a future version of Swift; use a single parameter list}}
|
||||
// expected-error@+1 {{curried function declaration syntax has been removed; use a single parameter list}}
|
||||
func foo()() {}
|
||||
func bar() {}
|
||||
}
|
||||
|
||||
class Derived : Base {
|
||||
// expected-warning@+1 {{curried function declaration syntax will be removed in a future version of Swift; use a single parameter list}}
|
||||
// expected-error@+1 {{curried function declaration syntax has been removed; use a single parameter list}}
|
||||
override func foo()() {
|
||||
doFoo(super.foo()) // expected-error {{partial application of 'super' method is not allowed}}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ class Derived : Base {
|
||||
}
|
||||
|
||||
class BaseWithFinal {
|
||||
// expected-warning@+1 {{curried function declaration syntax will be removed in a future version of Swift; use a single parameter list}}
|
||||
// expected-error@+1 {{curried function declaration syntax has been removed; use a single parameter list}}
|
||||
final func foo()() {}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,6 @@
|
||||
@_transparent public func standalone_function(x x: Int32, y: Int32) -> Int32 {
|
||||
return x
|
||||
}
|
||||
@_transparent public func curried_function(x x: Int32)(y: Int32) -> Int32 {
|
||||
return standalone_function(x: x, y: y)
|
||||
}
|
||||
@_transparent public func calls(i i: Int32, j: Int32) {
|
||||
var f1 = curried_function(x: i)
|
||||
f1(y: j);
|
||||
}
|
||||
public func foo() -> Int32 { return 0 }
|
||||
public func runced() -> Bool { return true }
|
||||
|
||||
|
||||
@@ -21,10 +21,6 @@ var raw = testTransparent(x: false)
|
||||
// SIL: store [[RESULT2]] to [[TMP]] : $*Int32
|
||||
var tmp = testBuiltin()
|
||||
|
||||
func test_partial(i: Int32, j: Int32) {
|
||||
calls(i: i, j: j)
|
||||
}
|
||||
|
||||
// SIL-LABEL: sil public_external [transparent] [fragile] @_TF15def_transparent15testTransparentFT1xSb_Sb : $@convention(thin) (Bool) -> Bool {
|
||||
// SIL: bb0(%0 : $Bool):
|
||||
// SIL: return %0 : $Bool
|
||||
|
||||
@@ -258,10 +258,6 @@ protocol subject_containerProtocol1 {
|
||||
|
||||
@objc
|
||||
protocol subject_containerObjCProtocol1 {
|
||||
func func_Curried1()() // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// expected-error@-1 {{method cannot be a member of an @objc protocol because curried functions cannot be represented in Objective-C}}
|
||||
// expected-note@-2 {{inferring '@objc' because the declaration is a member of an '@objc' protocol}}
|
||||
|
||||
func func_FunctionReturn1() -> PlainStruct
|
||||
// expected-error@-1 {{method cannot be a member of an @objc protocol because its result type cannot be represented in Objective-C}}
|
||||
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
|
||||
@@ -689,37 +685,6 @@ class infer_instanceFunc1 {
|
||||
|
||||
@objc func func_TupleStyle2a(a: Int, b: Int, c: Int) {}
|
||||
|
||||
func func_Curried1()() {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// CHECK-LABEL: {{^}} func func_Curried1()() {
|
||||
|
||||
@objc func func_Curried1_()() {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// expected-error@-1 {{method cannot be marked @objc because curried functions cannot be represented in Objective-C}}
|
||||
|
||||
func func_Curried2()(a: Int) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// CHECK-LABEL: {{^}} func func_Curried2()(a: Int) {
|
||||
|
||||
@objc func func_Curried2_()(a: Int) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// expected-error@-1 {{method cannot be marked @objc because curried functions cannot be represented in Objective-C}}
|
||||
|
||||
func func_Curried3()() -> Int {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// CHECK-LABEL: {{^}} func func_Curried3()() -> Int {
|
||||
|
||||
@objc func func_Curried3_()() -> Int {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// expected-error@-1 {{method cannot be marked @objc because curried functions cannot be represented in Objective-C}}
|
||||
|
||||
func func_Curried4()(a: String) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// CHECK-LABEL: {{^}} func func_Curried4()(a: String) {
|
||||
|
||||
@objc func func_Curried4_()(a: String) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// expected-error@-1 {{method cannot be marked @objc because curried functions cannot be represented in Objective-C}}
|
||||
|
||||
func func_Curried5()() -> String {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// CHECK-LABEL: {{^}} func func_Curried5()() -> String {
|
||||
|
||||
@objc func func_Curried5_()() -> String {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// expected-error@-1 {{method cannot be marked @objc because curried functions cannot be represented in Objective-C}}
|
||||
|
||||
|
||||
// Check that we produce diagnostics for every parameter and return type.
|
||||
@objc func func_MultipleDiags(a: PlainStruct, b: PlainEnum) -> protocol<> {}
|
||||
// expected-error@-1 {{method cannot be marked @objc because the type of the parameter 1 cannot be represented in Objective-C}}
|
||||
@@ -1597,50 +1562,30 @@ class infer_class5 : Protocol_ObjC1 {}
|
||||
|
||||
protocol infer_protocol1 {
|
||||
// CHECK-LABEL: {{^}}protocol infer_protocol1 {
|
||||
|
||||
func func_Curried1()() // no-error expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// CHECK: {{^}} func func_Curried1()()
|
||||
|
||||
func nonObjC1()
|
||||
// CHECK: {{^}} func nonObjC1()
|
||||
}
|
||||
|
||||
protocol infer_protocol2 : Protocol_Class1 {
|
||||
// CHECK-LABEL: {{^}}protocol infer_protocol2 : Protocol_Class1 {
|
||||
|
||||
func func_Curried1()() // no-error expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// CHECK: {{^}} func func_Curried1()()
|
||||
|
||||
func nonObjC1()
|
||||
// CHECK: {{^}} func nonObjC1()
|
||||
}
|
||||
|
||||
protocol infer_protocol3 : Protocol_ObjC1 {
|
||||
// CHECK-LABEL: {{^}}protocol infer_protocol3 : Protocol_ObjC1 {
|
||||
|
||||
func func_Curried1()() // no-error expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// CHECK: {{^}} func func_Curried1()()
|
||||
|
||||
func nonObjC1()
|
||||
// CHECK: {{^}} func nonObjC1()
|
||||
}
|
||||
|
||||
protocol infer_protocol4 : Protocol_Class1, Protocol_ObjC1 {
|
||||
// CHECK-LABEL: {{^}}protocol infer_protocol4 : Protocol_Class1, Protocol_ObjC1 {
|
||||
|
||||
func func_Curried1()() // no-error expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// CHECK: {{^}} func func_Curried1()()
|
||||
|
||||
func nonObjC1()
|
||||
// CHECK: {{^}} func nonObjC1()
|
||||
}
|
||||
|
||||
protocol infer_protocol5 : Protocol_ObjC1, Protocol_Class1 {
|
||||
// CHECK-LABEL: {{^}}protocol infer_protocol5 : Protocol_ObjC1, Protocol_Class1 {
|
||||
|
||||
func func_Curried1()() // no-error expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
// CHECK: {{^}} func func_Curried1()()
|
||||
|
||||
func nonObjC1()
|
||||
// CHECK: {{^}} func nonObjC1()
|
||||
}
|
||||
|
||||
@@ -27,21 +27,15 @@ class C1 {
|
||||
|
||||
@warn_unused_result(message="huzzah")
|
||||
static func f2() { }
|
||||
|
||||
@warn_unused_result
|
||||
func curried1()()() { } // expected-warning {{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
}
|
||||
|
||||
func testMethodsNegative(c1: C1) {
|
||||
c1.f1 // expected-error{{expression resolves to an unused function}}
|
||||
c1.curried1() // expected-error{{expression resolves to an unused function}}
|
||||
c1.curried1()() // expected-error{{expression resolves to an unused function}}
|
||||
}
|
||||
|
||||
func testMethodsPositive(c1: C1) {
|
||||
c1.f1() // expected-warning{{result of call to 'f1()' is unused}}
|
||||
C1.f2() // expected-warning{{result of call to 'f2()' is unused: huzzah}}
|
||||
c1.curried1()()() // expected-warning{{result of call to 'curried1()' is unused}}
|
||||
}
|
||||
|
||||
struct Inits1 {
|
||||
|
||||
@@ -49,8 +49,6 @@ func foo(x: @convention(block) (Int) -> Int) {}
|
||||
@_transparent
|
||||
func zim() {}
|
||||
@_transparent
|
||||
func zang()() {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
@_transparent
|
||||
func zung<T>(_: T) {}
|
||||
@_transparent // expected-error{{@_transparent cannot be applied to stored properties}} {{1-15=}}
|
||||
var zippity : Int
|
||||
|
||||
@@ -27,12 +27,6 @@ func returnWithDefault() -> (a: Int, b: Int = 42) { // expected-error{{default a
|
||||
return 5 // expected-error{{cannot convert return expression of type 'Int' to return type '(a: Int, b: Int)'}}
|
||||
}
|
||||
|
||||
// Only the first parameter list of a curried function can have a
|
||||
// default argument.
|
||||
func curried(i: Int = 1) // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
(f : Float = 2) { // expected-error{{default argument is only permitted for a non-curried function parameter}}{{17-20=}}
|
||||
}
|
||||
|
||||
func selectorStyle(i: Int = 1, withFloat f: Float = 2) { }
|
||||
|
||||
// Default arguments of constructors.
|
||||
|
||||
@@ -150,14 +150,14 @@ func unnamed(Int) { } // expected-error{{unnamed parameters must be written with
|
||||
|
||||
// Test fixits on curried functions.
|
||||
func testCurryFixits() {
|
||||
func f1(x: Int)(y: Int) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift; use a single parameter list}} {{17-19=, }}
|
||||
func f1(x: Int)(y: Int) {} // expected-error{{curried function declaration syntax has been removed; use a single parameter list}} {{17-19=, }}
|
||||
func f1a(x: Int, y: Int) {}
|
||||
func f2(x: Int)(y: Int)(z: Int) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift; use a single parameter list}} {{17-19=, }} {{25-27=, }}
|
||||
func f2(x: Int)(y: Int)(z: Int) {} // expected-error{{curried function declaration syntax has been removed; use a single parameter list}} {{17-19=, }} {{25-27=, }}
|
||||
func f2a(x: Int, y: Int, z: Int) {}
|
||||
func f3(x: Int)() {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift; use a single parameter list}} {{17-19=}}
|
||||
func f3(x: Int)() {} // expected-error{{curried function declaration syntax has been removed; use a single parameter list}} {{17-19=}}
|
||||
func f3a(x: Int) {}
|
||||
func f4()(x: Int) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift; use a single parameter list}} {{11-13=}}
|
||||
func f4()(x: Int) {} // expected-error{{curried function declaration syntax has been removed; use a single parameter list}} {{11-13=}}
|
||||
func f4a(x: Int) {}
|
||||
func f5(x: Int)()(y: Int) {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift; use a single parameter list}} {{17-19=}} {{19-21=, }}
|
||||
func f5(x: Int)()(y: Int) {} // expected-error{{curried function declaration syntax has been removed; use a single parameter list}} {{17-19=}} {{19-21=, }}
|
||||
func f5a(x: Int, y: Int) {}
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ struct Subscripts2 {
|
||||
}
|
||||
|
||||
|
||||
func f4(a: Int)(_ b: Int) { } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func f5(a: Int)(b: Int) { } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func f4(a: Int) -> (Int) -> () { return { b in () } }
|
||||
func f5(a: Int) -> (b: Int) -> () { return { b in () } }
|
||||
|
||||
func testFunctions(i: Int, x: X) {
|
||||
f4(i)(i)
|
||||
@@ -78,11 +78,11 @@ func testFunctions(i: Int, x: X) {
|
||||
}
|
||||
|
||||
struct Y {
|
||||
func m0(a: Int)(_ b: Int) { } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func m1(a: Int)(b: Int) { } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func m0(a: Int) -> (Int) -> () { return { b in () } }
|
||||
func m1(a: Int) -> (b: Int) -> () { return { b in () } }
|
||||
|
||||
func m2(a: Int)(_ b: Int, _ c: Int) { } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func m3(a: Int)(b: Int, c2 c: Int) { } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func m2(a: Int) -> (Int, Int) -> () { return { b, c in () } }
|
||||
func m3(a: Int) -> (b: Int, c2: Int) -> () { return { b, c in () } }
|
||||
|
||||
subscript (x: Int) -> Int {
|
||||
get { return x }
|
||||
@@ -115,4 +115,6 @@ func testSubscripts(i: Int, s: String, x: Y) {
|
||||
func +(_ a: String, // expected-warning{{extraneous '_' in parameter: 'a' has no keyword argument name}}{{8-10=}}
|
||||
b b: Double) { } // expected-error{{operator cannot have keyword arguments}} {{8-10=}}
|
||||
|
||||
func +(a: Double, b: String)(_ c: Int)(d e: Int) { } // okay; expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func +(a: Double, b: String) -> (Int) -> (d: Int) -> () {
|
||||
return { c in { e in () } }
|
||||
}
|
||||
|
||||
@@ -11,12 +11,6 @@ func f1(f: () throws -> ()) rethrows { try f() }
|
||||
func f2(f: () -> ()) rethrows { f() } // expected-error {{'rethrows' function must take a throwing function argument}}
|
||||
func f3(f: UndeclaredFunctionType) rethrows { f() } // expected-error {{use of undeclared type 'UndeclaredFunctionType'}}
|
||||
|
||||
func cf1(f: () throws -> ())() rethrows { try f() } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func cf2(f: () -> ())() rethrows { f() } // expected-error {{'rethrows' function must take a throwing function argument}} expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func cf3(f: UndeclaredFunctionType)() rethrows { f() } // expected-error {{use of undeclared type 'UndeclaredFunctionType'}} expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func cf4(f: () -> ())(g: () throws -> ()) rethrows {} // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func cf5() rethrows -> () throws -> () {} // expected-error {{'rethrows' function must take a throwing function argument}}
|
||||
|
||||
/** Protocol conformance checking ********************************************/
|
||||
|
||||
protocol P {
|
||||
|
||||
@@ -39,23 +39,12 @@ var d : () throws -> () throws -> () = curry3Throws
|
||||
|
||||
// Partial application ////////////////////////////////////////////////////////
|
||||
|
||||
func partialApply1(a: Int)(b: Int)(c: Int) throws { } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
|
||||
func partialApply2<T>(a: T)(b: Int)(c: Int) throws { } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
|
||||
protocol Parallelogram {
|
||||
static func partialApply3(a: Int) throws
|
||||
static func partialApply1(a: Int) throws
|
||||
}
|
||||
|
||||
let f11 = partialApply1
|
||||
let f12 = partialApply1(1)
|
||||
let f13 = partialApply1(1)(b: 2)
|
||||
|
||||
let f22 = partialApply2(1)
|
||||
let f23 = partialApply2(1)(b: 2)
|
||||
|
||||
func partialApply4<T: Parallelogram>(t: T) {
|
||||
_ = T.partialApply3
|
||||
func partialApply2<T: Parallelogram>(t: T) {
|
||||
_ = T.partialApply1
|
||||
}
|
||||
|
||||
// Overload resolution/////////////////////////////////////////////////////////
|
||||
@@ -79,8 +68,6 @@ func barT() -> Int { return 0 } // expected-error{{invalid redeclaration of 'bar
|
||||
func fooT(callback: () throws -> Bool) {} //OK
|
||||
func fooT(callback: () -> Bool) {}
|
||||
|
||||
func jerry(i: Int)(j: Int) throws -> Int { return 0 } // (Int) -> (Int) throws -> Int expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
|
||||
// Throwing and non-throwing types are not equivalent.
|
||||
struct X<T> { }
|
||||
func specializedOnFuncType1(x: X<String throws -> Int>) { }
|
||||
|
||||
@@ -53,10 +53,9 @@ protocol P10 {
|
||||
|
||||
// Never inheritable: method with 'Self' in curried position.
|
||||
protocol P11 {
|
||||
func f11()(x: Self) -> Int // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func f11() -> (x: Self) -> Int
|
||||
}
|
||||
|
||||
|
||||
// Class A conforms to everything that can be conformed to by a
|
||||
// non-final class.
|
||||
class A : P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 {
|
||||
@@ -98,7 +97,7 @@ class A : P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 {
|
||||
func f10(arr: [A]) { } // expected-error{{protocol 'P10' requirement 'f10' cannot be satisfied by a non-final class ('A') because it uses 'Self' in a non-parameter, non-result type position}}
|
||||
|
||||
// P11
|
||||
func f11()(x: A) -> Int { return 5 } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func f11() -> (x: A) -> Int { return { x in 5 } }
|
||||
}
|
||||
|
||||
// P9
|
||||
@@ -185,7 +184,7 @@ final class A9 : P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 {
|
||||
func f10(arr: [A9]) { }
|
||||
|
||||
// P11
|
||||
func f11()(x: A9) -> Int { return 5 } // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func f11() -> (x: A9) -> Int { return { x in 5 } }
|
||||
}
|
||||
|
||||
// P9
|
||||
|
||||
@@ -8,10 +8,9 @@ func foo(inout x: Int) {
|
||||
}
|
||||
|
||||
// But not partially applied.
|
||||
func curriedFoo(inout x: Int)(y: Int) -> Int { // expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
return x + y
|
||||
struct C {
|
||||
mutating func f(x: Int) {}
|
||||
}
|
||||
|
||||
var score: Int = 0
|
||||
|
||||
_ = curriedFoo(&score) // expected-error {{partial application of function with 'inout' parameters is not allowed}}
|
||||
var c = C()
|
||||
let x = c.f // expected-error{{partial application of 'mutating' method is not allowed}}
|
||||
|
||||
@@ -141,7 +141,7 @@ var test1b = { 42 }
|
||||
var test1c = { { 42 } }
|
||||
var test1d = { { { 42 } } }
|
||||
|
||||
func test2(a: Int)(b: Int) -> (c: Int) { // expected-error{{cannot create a single-element tuple with an element label}} {{32-35=}} expected-warning{{curried function declaration syntax will be removed in a future version of Swift}}
|
||||
func test2(a: Int, b: Int) -> (c: Int) { // expected-error{{cannot create a single-element tuple with an element label}} {{32-35=}}
|
||||
a+b
|
||||
a+b+c // expected-error{{use of unresolved identifier 'c'}}
|
||||
return a+b
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// RUN: not --crash %target-swift-frontend %s -emit-silgen
|
||||
// RUN: not %target-swift-frontend %s -emit-silgen
|
||||
|
||||
// Distributed under the terms of the MIT license
|
||||
// Test case submitted to project by https://github.com/practicalswift (practicalswift)
|
||||
@@ -1,4 +1,4 @@
|
||||
// RUN: not --crash %target-swift-frontend %s -emit-silgen
|
||||
// RUN: not %target-swift-frontend %s -emit-silgen
|
||||
|
||||
// Distributed under the terms of the MIT license
|
||||
// Test case submitted to project by https://github.com/practicalswift (practicalswift)
|
||||
Reference in New Issue
Block a user