diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 73e60e1e22e8d..9349c0acc4ae4 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -5950,7 +5950,7 @@ class FuncDecl : public AbstractFunctionDecl { return Bits.FuncDecl.IsStatic; } bool isCallable() const { - return getName().str() == "call" && isInstanceMember(); + return getName().str() == "callAsFunction" && isInstanceMember(); } /// \returns the way 'static'/'class' was spelled in the source. StaticSpellingKind getStaticSpelling() const { diff --git a/include/swift/AST/KnownIdentifiers.def b/include/swift/AST/KnownIdentifiers.def index 43dbd2aacb059..a829f7e883509 100644 --- a/include/swift/AST/KnownIdentifiers.def +++ b/include/swift/AST/KnownIdentifiers.def @@ -32,7 +32,7 @@ IDENTIFIER(ArrayLiteralElement) IDENTIFIER(atIndexedSubscript) IDENTIFIER_(bridgeToObjectiveC) // SWIFT_ENABLE_TENSORFLOW -IDENTIFIER(call) +IDENTIFIER(callAsFunction) IDENTIFIER_WITH_NAME(code_, "_code") IDENTIFIER(CodingKeys) IDENTIFIER(combine) diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index e74c194d9aef8..496ffa38122bd 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -7140,8 +7140,8 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType, }; // SWIFT_ENABLE_TENSORFLOW - // Save the original potentially lvalue function for rewriting call method - // applications. + // Save the original potentially lvalue function for rewriting + // 'callAsFunction' method applications. auto *originalFn = fn; // SWIFT_ENABLE_TENSORFLOW END // The function is always an rvalue. @@ -7291,7 +7291,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType, } // SWIFT_ENABLE_TENSORFLOW - // Handle call method applications. + // Handle 'callAsFunction' method applications. auto &ctx = cs.getASTContext(); TupleExpr *arg = dyn_cast(apply->getArg()); diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index c36ad1dd28d78..dd87e53809153 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -5827,7 +5827,7 @@ ConstraintSystem::simplifyApplicableFnConstraint( auto &ctx = getASTContext(); // Get all call methods of the nominal type. SmallVector callMethods; - auto candidates = lookupMember(desugar2, DeclName(ctx.Id_call)); + auto candidates = lookupMember(desugar2, DeclName(ctx.Id_callAsFunction)); for (auto entry : candidates) { auto callMethod = dyn_cast(entry.getValueDecl()); if (!callMethod) diff --git a/test/Sema/Inputs/call_method_other_module.swift b/test/Sema/Inputs/call_method_other_module.swift index 8ddf37d3fac37..19bec3859611c 100644 --- a/test/Sema/Inputs/call_method_other_module.swift +++ b/test/Sema/Inputs/call_method_other_module.swift @@ -1,13 +1,15 @@ +// SWIFT_ENABLE_TENSORFLOW + public protocol Layer : Differentiable { @differentiable - func call(_ input: Float) -> Float + func callAsFunction(_ input: Float) -> Float } public struct Dense : Differentiable { public init() {} @differentiable - public func call(_ input: Float) -> Float { + public func callAsFunction(_ input: Float) -> Float { return input * 2 } } diff --git a/test/Sema/call_method_generic.swift b/test/Sema/call_method_generic.swift index b07e57d2012d8..e86406180d86d 100644 --- a/test/Sema/call_method_generic.swift +++ b/test/Sema/call_method_generic.swift @@ -1,22 +1,22 @@ // RUN: %target-typecheck-verify-swift protocol P0 { - func call(x: Self) + func callAsFunction(x: Self) } struct ConcreteType { - func call(_ x: T, _ y: U) -> (T, U) { + func callAsFunction(_ x: T, _ y: U) -> (T, U) { return (x, y) } - func call(_ fn: @escaping (T) -> U) -> (T) -> U { + func callAsFunction(_ fn: @escaping (T) -> U) -> (T) -> U { return fn } } let concrete = ConcreteType() _ = concrete(1, 3.0) -_ = concrete(concrete, concrete.call as ([Int], Float) -> ([Int], Float)) +_ = concrete(concrete, concrete.callAsFunction as ([Int], Float) -> ([Int], Float)) func generic(_ x: T, _ y: U) { _ = concrete(x, x) @@ -25,14 +25,14 @@ func generic(_ x: T, _ y: U) { struct GenericType { let collection: T - func call(_ x: U) -> Bool where U == T.Element, U : Equatable { + func callAsFunction(_ x: U) -> Bool where U == T.Element, U : Equatable { return collection.contains(x) } } // Test conditional conformance. extension GenericType where T.Element : Numeric { - func call(initialValue: T.Element) -> T.Element { + func callAsFunction(initialValue: T.Element) -> T.Element { return collection.reduce(initialValue, +) } } diff --git a/test/Sema/call_method_protocol.swift b/test/Sema/call_method_protocol.swift index da7efbbf53e27..1497c615451bb 100644 --- a/test/Sema/call_method_protocol.swift +++ b/test/Sema/call_method_protocol.swift @@ -1,8 +1,8 @@ // RUN: %target-typecheck-verify-swift protocol P0 { - // expected-note @+1 {{protocol requires function 'call()' with type '() -> Missing'; do you want to add a stub?}} - func call() -> Self + // expected-note @+1 {{protocol requires function 'callAsFunction()' with type '() -> Missing'; do you want to add a stub?}} + func callAsFunction() -> Self } func testProtocol(_ x: P0) { _ = x() @@ -12,18 +12,18 @@ func testGeneric(_ x: T) { } protocol P1 { - func call() -> Self + func callAsFunction() -> Self } extension P1 { // expected-note @+1 {{found this candidate}} - func call() -> Self { + func callAsFunction() -> Self { return self } } protocol P2 {} extension P2 { // expected-note @+1 {{found this candidate}} - func call(x: Int, y: Int) -> Int { + func callAsFunction(x: Int, y: Int) -> Int { return x + y } } @@ -32,13 +32,13 @@ extension P2 { struct Missing : P0 {} struct S0 : P0 { @discardableResult - func call() -> S0 { return self } + func callAsFunction() -> S0 { return self } } let s0 = S0() s0() struct S1 : P1 { - func call() -> S1 { return self } + func callAsFunction() -> S1 { return self } } let s1 = S1() @@ -47,13 +47,13 @@ _ = s1()() struct Conforming : P0 & P1 & P2 {} let conforming = Conforming() _ = conforming(x: 1, y: 2) -_ = conforming().call(x:y:)(1, 2) -_ = conforming.call(x:y:) -_ = conforming.call // expected-error {{ambiguous use of 'call'}} +_ = conforming().callAsFunction(x:y:)(1, 2) +_ = conforming.callAsFunction(x:y:) +_ = conforming.callAsFunction // expected-error {{ambiguous use of 'callAsFunction'}} protocol P3 {} extension P3 { - func call() -> Self { return self } + func callAsFunction() -> Self { return self } } struct S3 : P3 {} diff --git a/test/Sema/call_method_simple.swift b/test/Sema/call_method_simple.swift index dea1f055d996a..6d39034d28a61 100644 --- a/test/Sema/call_method_simple.swift +++ b/test/Sema/call_method_simple.swift @@ -1,7 +1,7 @@ // RUN: %target-typecheck-verify-swift struct SimpleCallable { - func call(_ x: Float) -> Float { + func callAsFunction(_ x: Float) -> Float { return x } } @@ -12,20 +12,20 @@ let foo = SimpleCallable() _ = foo(1) _ = foo(foo(1)) -// TODO: Improve this error to match the error using a direct `call` member reference. +// TODO: Improve this error to match the error using a direct `callAsFunction` member reference. // expected-error @+2 {{cannot call value of non-function type 'SimpleCallable'}} // expected-error @+1 {{cannot invoke 'foo' with an argument list of type '(Int, Int)'}} _ = foo(1, 1) // expected-error @+1 {{cannot convert value of type 'SimpleCallable' to specified type '(Float) -> Float'}} let _: (Float) -> Float = foo -// Test direct `call` member references. +// Test direct `callAsFunction` member references. -_ = foo.call(1) -_ = [1, 2, 3].map(foo.call) -_ = foo.call(foo(1)) -_ = foo(foo.call(1)) -let _: (Float) -> Float = foo.call +_ = foo.callAsFunction(1) +_ = [1, 2, 3].map(foo.callAsFunction) +_ = foo.callAsFunction(foo(1)) +_ = foo(foo.callAsFunction(1)) +let _: (Float) -> Float = foo.callAsFunction func callable() -> SimpleCallable { return SimpleCallable() @@ -42,43 +42,43 @@ extension SimpleCallable { _ = foo.foo(1) _ = foo.bar()(1) _ = callable()(1) -_ = [1, 2, 3].map(foo.foo.call) -_ = [1, 2, 3].map(foo.bar().call) -_ = [1, 2, 3].map(callable().call) +_ = [1, 2, 3].map(foo.foo.callAsFunction) +_ = [1, 2, 3].map(foo.bar().callAsFunction) +_ = [1, 2, 3].map(callable().callAsFunction) struct MultipleArgsCallable { - func call(x: Int, y: Float) -> [Int] { + func callAsFunction(x: Int, y: Float) -> [Int] { return [x] } } let bar = MultipleArgsCallable() _ = bar(x: 1, y: 1) -_ = bar.call(x: 1, y: 1) -_ = bar(x: bar.call(x: 1, y: 1)[0], y: 1) -_ = bar.call(x: bar(x: 1, y: 1)[0], y: 1) +_ = bar.callAsFunction(x: 1, y: 1) +_ = bar(x: bar.callAsFunction(x: 1, y: 1)[0], y: 1) +_ = bar.callAsFunction(x: bar(x: 1, y: 1)[0], y: 1) _ = bar(1, 1) // expected-error {{missing argument labels 'x:y:' in call}} struct Extended {} extension Extended { @discardableResult - func call() -> Extended { + func callAsFunction() -> Extended { return self } } var extended = Extended() -extended()().call()() +extended()().callAsFunction()() struct OptionalCallable { - func call() -> OptionalCallable? { + func callAsFunction() -> OptionalCallable? { return self } } var optional = OptionalCallable() -_ = optional()?.call()?() +_ = optional()?.callAsFunction()?() struct Variadic { - func call(_ args: Int...) -> [Int] { + func callAsFunction(_ args: Int...) -> [Int] { return args } } @@ -88,36 +88,36 @@ _ = variadic(1, 2, 3) struct Mutating { var x: Int - mutating func call() { + mutating func callAsFunction() { x += 1 } } func testMutating(_ x: Mutating, _ y: inout Mutating) { _ = x() // expected-error {{cannot use mutating member on immutable value: 'x' is a 'let' constant}} - _ = x.call() // expected-error {{cannot use mutating member on immutable value: 'x' is a 'let' constant}} + _ = x.callAsFunction() // expected-error {{cannot use mutating member on immutable value: 'x' is a 'let' constant}} _ = y() - _ = y.call() + _ = y.callAsFunction() } struct Inout { - func call(_ x: inout Int) { + func callAsFunction(_ x: inout Int) { x += 5 } } func testInout(_ x: Inout, _ arg: inout Int) { x(&arg) - x.call(&arg) + x.callAsFunction(&arg) // TODO: Improve this error to match the error using a direct `call` member reference. // expected-error @+2 {{cannot invoke 'x' with an argument list of type '(Int)'}} // expected-error @+1 {{cannot call value of non-function type 'Inout'}} x(arg) // expected-error @+1 {{passing value of type 'Int' to an inout parameter requires explicit '&'}} - x.call(arg) + x.callAsFunction(arg) } struct Autoclosure { - func call(_ condition: @autoclosure () -> Bool, - _ message: @autoclosure () -> String) { + func callAsFunction(_ condition: @autoclosure () -> Bool, + _ message: @autoclosure () -> String) { if condition() { print(message()) } @@ -129,10 +129,10 @@ func testAutoclosure(_ x: Autoclosure) { } struct Throwing { - func call() throws -> Throwing { + func callAsFunction() throws -> Throwing { return self } - func call(_ f: () throws -> ()) rethrows { + func callAsFunction(_ f: () throws -> ()) rethrows { try f() } } @@ -145,7 +145,7 @@ enum BinaryOperation { case add, subtract, multiply, divide } extension BinaryOperation { - func call(_ lhs: Float, _ rhs: Float) -> Float { + func callAsFunction(_ lhs: Float, _ rhs: Float) -> Float { switch self { case .add: return lhs + rhs case .subtract: return lhs - rhs @@ -157,12 +157,12 @@ extension BinaryOperation { _ = BinaryOperation.add(1, 2) class BaseClass { - func call() -> Self { + func callAsFunction() -> Self { return self } } class SubClass : BaseClass { - override func call() -> Self { + override func callAsFunction() -> Self { return self } } @@ -173,7 +173,7 @@ func testIUO(a: SimpleCallable!, b: MultipleArgsCallable!, c: Extended!, _ = a(1) _ = b(x: 1, y: 1) _ = c() - _ = d()?.call()?() + _ = d()?.callAsFunction()?() _ = e() _ = e(1, 2, 3) // FIXME(TF-444): `mutating func call` and IUO doesn't work. diff --git a/utils/update_checkout/update-checkout-config.json b/utils/update_checkout/update-checkout-config.json index 06391da553cd5..ad4c123cc9d53 100644 --- a/utils/update_checkout/update-checkout-config.json +++ b/utils/update_checkout/update-checkout-config.json @@ -349,7 +349,7 @@ "clang-tools-extra": "swift-DEVELOPMENT-SNAPSHOT-2019-05-26-a", "libcxx": "swift-DEVELOPMENT-SNAPSHOT-2019-05-26-a", "tensorflow": "ebc41609e27dcf0998d8970e77a2e1f53e13ac86", - "tensorflow-swift-apis": "835d1436a01d9261f0467bc2803cc7f6ac56ed80", + "tensorflow-swift-apis": "e9092254c8135202a813a6cab727fbca691010e8", "indexstore-db": "swift-DEVELOPMENT-SNAPSHOT-2019-05-26-a", "sourcekit-lsp": "swift-DEVELOPMENT-SNAPSHOT-2019-05-26-a" }