From a18e9afe6b242a685f3d16be19cc88e6105e51b3 Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Mon, 7 Oct 2019 15:51:03 -0700 Subject: [PATCH 1/4] Underscore `Differentiable` protocol. Rename `Differentiable` protocol to `_Differentiable`. --- include/swift/AST/KnownProtocols.def | 2 +- lib/AST/Builtins.cpp | 7 +- stdlib/public/core/CMakeLists.txt | 5 +- stdlib/public/core/Differentiable.swift | 66 +++++++++++++++++++ ...iff.swift => DifferentiationSupport.swift} | 59 +++-------------- stdlib/public/core/GroupInfo.json | 7 +- 6 files changed, 85 insertions(+), 61 deletions(-) create mode 100644 stdlib/public/core/Differentiable.swift rename stdlib/public/core/{AutoDiff.swift => DifferentiationSupport.swift} (93%) diff --git a/include/swift/AST/KnownProtocols.def b/include/swift/AST/KnownProtocols.def index 7c3a45c71eccb..65f5aa13b7b97 100644 --- a/include/swift/AST/KnownProtocols.def +++ b/include/swift/AST/KnownProtocols.def @@ -87,7 +87,7 @@ PROTOCOL(TensorGroup) PROTOCOL_(TensorFlowDataTypeCompatible) PROTOCOL(TensorProtocol) PROTOCOL(VectorProtocol) -PROTOCOL(Differentiable) +PROTOCOL_(Differentiable) PROTOCOL(EuclideanDifferentiable) PROTOCOL_(ObjectiveCBridgeable) diff --git a/lib/AST/Builtins.cpp b/lib/AST/Builtins.cpp index 4d7fc1c73fed2..ec69ad75c820e 100644 --- a/lib/AST/Builtins.cpp +++ b/lib/AST/Builtins.cpp @@ -1007,11 +1007,8 @@ static ValueDecl *getAutoDiffApplyAssociatedFunction( // rethrows -> (R, (R.TangentVector) -> ...T.TangentVector) unsigned numGenericParams = 1 + arity; BuiltinGenericSignatureBuilder builder(Context, numGenericParams); - // Look up the Differentiable protocol. - SmallVector diffableProtoLookup; - Context.lookupInSwiftModule("Differentiable", diffableProtoLookup); - assert(diffableProtoLookup.size() == 1); - auto *diffableProto = cast(diffableProtoLookup.front()); + // Get the `Differentiable` protocol. + auto *diffableProto = Context.getProtocol(KnownProtocolKind::Differentiable); // Create type parameters and add conformance constraints. auto fnResultGen = makeGenericParam(arity); builder.addConformanceRequirement(fnResultGen, diffableProto); diff --git a/stdlib/public/core/CMakeLists.txt b/stdlib/public/core/CMakeLists.txt index 7ba29489c6ff9..3b002db032828 100644 --- a/stdlib/public/core/CMakeLists.txt +++ b/stdlib/public/core/CMakeLists.txt @@ -30,8 +30,6 @@ set(SWIFTLIB_ESSENTIAL ASCII.swift Assert.swift AssertCommon.swift - # SWIFT_ENABLE_TENSORFLOW - AutoDiff.swift BidirectionalCollection.swift Bitset.swift Bool.swift @@ -208,6 +206,9 @@ set(SWIFTLIB_SOURCES CollectionDifference.swift CollectionOfOne.swift Diffing.swift + Differentiable.swift + # SWIFT_ENABLE_TENSORFLOW + DifferentiationSupport.swift Mirror.swift PlaygroundDisplay.swift CommandLine.swift diff --git a/stdlib/public/core/Differentiable.swift b/stdlib/public/core/Differentiable.swift new file mode 100644 index 0000000000000..95d7788f82fb1 --- /dev/null +++ b/stdlib/public/core/Differentiable.swift @@ -0,0 +1,66 @@ +//===--- Differentiable.swift ---------------------------------*- swift -*-===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// +// +// This file defines the Differentiable protocol, used by the experimental +// differentiable programming project. Please see forum discussion for more +// information: +// https://forums.swift.org/t/differentiable-programming-mega-proposal/28547 +// +//===----------------------------------------------------------------------===// + +/// A type that mathematically represents a differentiable manifold whose +/// tangent spaces are finite-dimensional. +public protocol _Differentiable { + /// A type representing a differentiable value's derivatives. + /// + /// Mathematically, this is equivalent to the tangent bundle of the + /// differentiable manifold represented by the differentiable type. + associatedtype TangentVector: _Differentiable & AdditiveArithmetic + where TangentVector.TangentVector == TangentVector + + /// Moves `self` along the given direction. In Riemannian geometry, this is + /// equivalent to exponential map, which moves `self` on the geodesic surface + /// along the given tangent vector. + mutating func move(along direction: TangentVector) + + // SWIFT_ENABLE_TENSORFLOW + /// A tangent vector such that `move(along: zeroTangentVector)` will not + /// modify `self`. + /// - Note: `zeroTangentVector` can be `TangentVector.zero` in most cases, + /// but types whose tangent vectors depend on instance properties of `self` + /// need to provide a different implementation. For example, the tangent + /// vector of an `Array` depends on the array's `count`. + @available(*, deprecated, message: """ + `zeroTangentVector` derivation has not been implemented; do not use \ + this property + """) + var zeroTangentVector: TangentVector { get } +} + +public extension _Differentiable where TangentVector == Self { + mutating func move(along direction: TangentVector) { + self += direction + } +} + +public extension _Differentiable { + // This is a temporary solution that allows us to add `zeroTangentVector` + // without implementing derived conformances. This property is marked + // unavailable because it will produce incorrect results when tangent vectors + // depend on instance properties of `self`. + // FIXME: Implement derived conformance and remove this default + // implementation. + var zeroTangentVector: TangentVector { .zero } +} + +// SWIFT_ENABLE_TENSORFLOW +public typealias Differentiable = _Differentiable diff --git a/stdlib/public/core/AutoDiff.swift b/stdlib/public/core/DifferentiationSupport.swift similarity index 93% rename from stdlib/public/core/AutoDiff.swift rename to stdlib/public/core/DifferentiationSupport.swift index 96f595bb6f52f..92c4e11f4d73e 100644 --- a/stdlib/public/core/AutoDiff.swift +++ b/stdlib/public/core/DifferentiationSupport.swift @@ -1,8 +1,8 @@ -//===--- AutoDiff.swift ---------------------------------------*- swift -*-===// +//===--- DifferentiationSupport.swift -------------------------*- swift -*-===// // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -12,7 +12,8 @@ // // SWIFT_ENABLE_TENSORFLOW // -// This file defines support for automatic differentiation. +// This file defines support for differentiable programming and deep learning +// APIs. // //===----------------------------------------------------------------------===// @@ -101,8 +102,9 @@ public extension VectorProtocol { } } -/* Note: These default-implemented operators will slow down type-checking - performance and break existing code. +/* +// Note: These default-implemented operators will slow down type-checking +// performance and break existing code. public extension VectorProtocol { static func + (lhs: Self, rhs: VectorSpaceScalar) -> Self { @@ -149,50 +151,6 @@ public extension VectorProtocol where VectorSpaceScalar : SignedNumeric { } */ -/// A type that mathematically represents a differentiable manifold whose -/// tangent spaces are finite-dimensional. -public protocol Differentiable { - /// A type representing a differentiable value’s derivatives. - /// - /// Mathematically, this is equivalent to the tangent bundle of the - /// differentiable manifold represented by the differentiable type. - associatedtype TangentVector: Differentiable & AdditiveArithmetic - where TangentVector.TangentVector == TangentVector - - /// Moves `self` along the given direction. In Riemannian geometry, this is - /// equivalent to exponential map, which moves `self` on the geodesic surface - /// along the given tangent vector. - mutating func move(along direction: TangentVector) - - /// A tangent vector such that `move(along: zeroTangentVector)` will not - /// modify `self`. - /// - Note: `zeroTangentVector` can be `TangentVector.zero` in most cases, - /// but types whose tangent vectors depend on instance properties of `self` - /// need to provide a different implementation. For example, the tangent - /// vector of an `Array` depends on the array’s `count`. - @available(*, deprecated, message: """ - `zeroTangentVector` derivation has not been implemented; do not use \ - this property - """) - var zeroTangentVector: TangentVector { get } -} - -public extension Differentiable { - // This is a temporary solution that allows us to add `zeroTangentVector` - // without implementing derived conformances. This property is marked - // unavailable because it will produce incorrect results when tangent vectors - // depend on instance properties of `self`. - // FIXME: Implement derived conformance and remove this default - // implementation. - var zeroTangentVector: TangentVector { .zero } -} - -public extension Differentiable where TangentVector == Self { - mutating func move(along direction: TangentVector) { - self += direction - } -} - /// A type that is differentiable in the Euclidean space. /// The type may represent a vector space, or consist of a vector space and some /// other non-differentiable component. @@ -1077,8 +1035,9 @@ public extension Array where Element: Differentiable { } //===----------------------------------------------------------------------===// -// JVP Diagnostics +// JVP diagnostics //===----------------------------------------------------------------------===// + @_silgen_name("_printJVPErrorAndExit") public func _printJVPErrorAndExit() -> Never { fatalError(""" diff --git a/stdlib/public/core/GroupInfo.json b/stdlib/public/core/GroupInfo.json index d374bbd7ec57c..181ae94441f0a 100644 --- a/stdlib/public/core/GroupInfo.json +++ b/stdlib/public/core/GroupInfo.json @@ -171,9 +171,6 @@ "SIMDVector.swift", "SIMDVectorTypes.swift"]} ], - "AutoDiff": [ - "AutoDiff.swift", - ], "Optional": [ "Optional.swift" ], @@ -231,5 +228,9 @@ ], "Result": [ "Result.swift" + ], + "DifferentiableProgramming": [ + "Differentiable.swift", + "DifferentiationSupport.swift" ] } From 30415545f76cf4e98fad07920208c0a1ba9aba46 Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Tue, 8 Oct 2019 12:46:17 -0700 Subject: [PATCH 2/4] Code reordering to match upstream changes. --- include/swift/AST/KnownProtocols.def | 6 ++++-- lib/IRGen/GenMeta.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/swift/AST/KnownProtocols.def b/include/swift/AST/KnownProtocols.def index 65f5aa13b7b97..71bb9de06b330 100644 --- a/include/swift/AST/KnownProtocols.def +++ b/include/swift/AST/KnownProtocols.def @@ -87,14 +87,16 @@ PROTOCOL(TensorGroup) PROTOCOL_(TensorFlowDataTypeCompatible) PROTOCOL(TensorProtocol) PROTOCOL(VectorProtocol) -PROTOCOL_(Differentiable) PROTOCOL(EuclideanDifferentiable) +PROTOCOL(Expression) PROTOCOL_(ObjectiveCBridgeable) PROTOCOL_(DestructorSafeContainer) PROTOCOL(StringInterpolationProtocol) +PROTOCOL_(Differentiable) + EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByArrayLiteral, "Array", false) EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByBooleanLiteral, "BooleanLiteralType", true) EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByDictionaryLiteral, "Dictionary", false) @@ -109,9 +111,9 @@ EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByUnicodeScalarLiteral, "UnicodeScala EXPRESSIBLE_BY_LITERAL_PROTOCOL_(ExpressibleByColorLiteral, "_ColorLiteralType", true) EXPRESSIBLE_BY_LITERAL_PROTOCOL_(ExpressibleByImageLiteral, "_ImageLiteralType", true) EXPRESSIBLE_BY_LITERAL_PROTOCOL_(ExpressibleByFileReferenceLiteral, "_FileReferenceLiteralType", true) +// SWIFT_ENABLE_TENSORFLOW // TODO(TF-735): Implement ExpressibleByQuoteLiteral. // EXPRESSIBLE_BY_LITERAL_PROTOCOL_(ExpressibleByQuoteLiteral, "_QuoteLiteralType", true) -PROTOCOL(Expression) BUILTIN_EXPRESSIBLE_BY_LITERAL_PROTOCOL_(ExpressibleByBuiltinBooleanLiteral) BUILTIN_EXPRESSIBLE_BY_LITERAL_PROTOCOL_(ExpressibleByBuiltinExtendedGraphemeClusterLiteral) diff --git a/lib/IRGen/GenMeta.cpp b/lib/IRGen/GenMeta.cpp index 89961bea1b469..5706d4b31655d 100644 --- a/lib/IRGen/GenMeta.cpp +++ b/lib/IRGen/GenMeta.cpp @@ -4216,7 +4216,7 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) { case KnownProtocolKind::Encodable: case KnownProtocolKind::Decodable: case KnownProtocolKind::StringInterpolationProtocol: - case KnownProtocolKind::Expression: + case KnownProtocolKind::Differentiable: // SWIFT_ENABLE_TENSORFLOW case KnownProtocolKind::AdditiveArithmetic: case KnownProtocolKind::PointwiseMultiplicative: @@ -4227,8 +4227,8 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) { case KnownProtocolKind::TensorFlowDataTypeCompatible: case KnownProtocolKind::TensorProtocol: case KnownProtocolKind::VectorProtocol: - case KnownProtocolKind::Differentiable: case KnownProtocolKind::EuclideanDifferentiable: + case KnownProtocolKind::Expression: return SpecialProtocol::None; } From 144c676c99a1f51d0fef3201174ad687f5e7d03a Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Tue, 8 Oct 2019 13:11:51 -0700 Subject: [PATCH 3/4] Update tests. --- test/AutoDiff/derived_differentiable.swift | 14 +++++++------- test/AutoDiff/differentiable_attr_silgen.swift | 4 ++-- .../differentiable_attr_type_checking.swift | 2 +- .../AutoDiff/differentiable_func_debuginfo.swift | 2 +- .../differentiable_func_type_type_checking.swift | 2 +- .../differentiable_function_silgen.swift | 4 ++-- test/AutoDiff/differentiable_sil_attr.sil | 4 ++-- .../differentiating_attr_type_checking.swift | 6 +++--- test/AutoDiff/silgen_thunking/main.swift | 16 ++++++++-------- test/AutoDiff/subset_parameters_thunk.swift | 8 ++++---- .../transposing_attr_type_checking.swift | 2 +- test/AutoDiff/witness_table_sil.swift | 2 +- test/Sema/class_differentiable.swift | 14 +++++++------- test/Sema/struct_differentiable.swift | 12 ++++++------ 14 files changed, 46 insertions(+), 46 deletions(-) diff --git a/test/AutoDiff/derived_differentiable.swift b/test/AutoDiff/derived_differentiable.swift index ac8e6362e63c8..9b6571620d907 100644 --- a/test/AutoDiff/derived_differentiable.swift +++ b/test/AutoDiff/derived_differentiable.swift @@ -44,7 +44,7 @@ struct TestNoDerivative : EuclideanDifferentiable { // CHECK-AST: var w: Float // CHECK-AST: @noDerivative internal var technicallyDifferentiable: Float // CHECK-AST: internal init(w: Float, technicallyDifferentiable: Float) -// CHECK-AST: internal struct TangentVector : Differentiable, AdditiveArithmetic, ElementaryFunctions, VectorProtocol +// CHECK-AST: internal struct TangentVector : _Differentiable, AdditiveArithmetic, ElementaryFunctions, VectorProtocol // CHECK-AST: internal typealias TangentVector = TestNoDerivative.TangentVector // CHECK-AST: internal var differentiableVectorView: TestNoDerivative.TangentVector { get } @@ -57,7 +57,7 @@ struct TestPointwiseMultiplicative : Differentiable { // CHECK-AST: var w: PointwiseMultiplicativeDummy // CHECK-AST: @noDerivative internal var technicallyDifferentiable: PointwiseMultiplicativeDummy // CHECK-AST: internal init(w: PointwiseMultiplicativeDummy, technicallyDifferentiable: PointwiseMultiplicativeDummy) -// CHECK-AST: internal struct TangentVector : Differentiable, AdditiveArithmetic, PointwiseMultiplicative +// CHECK-AST: internal struct TangentVector : _Differentiable, AdditiveArithmetic, PointwiseMultiplicative // CHECK-AST: internal typealias TangentVector = TestPointwiseMultiplicative.TangentVector @@ -70,14 +70,14 @@ struct TestKeyPathIterable : Differentiable, KeyPathIterable { // CHECK-AST: var w: Float // CHECK-AST: @noDerivative internal var technicallyDifferentiable: Float // CHECK-AST: internal init(w: Float, technicallyDifferentiable: Float) -// CHECK-AST: internal struct TangentVector : Differentiable, AdditiveArithmetic, ElementaryFunctions, VectorProtocol, KeyPathIterable +// CHECK-AST: internal struct TangentVector : _Differentiable, AdditiveArithmetic, ElementaryFunctions, VectorProtocol, KeyPathIterable // CHECK-AST: internal typealias TangentVector = TestKeyPathIterable.TangentVector struct GenericTanMember : Differentiable, AdditiveArithmetic { var x: T.TangentVector } -// CHECK-AST-LABEL: internal struct GenericTanMember : Differentiable, AdditiveArithmetic where T : Differentiable +// CHECK-AST-LABEL: internal struct GenericTanMember : Differentiable, AdditiveArithmetic where T : _Differentiable // CHECK-AST: internal var x: T.TangentVector // CHECK-AST: internal init(x: T.TangentVector) // CHECK-AST: internal typealias TangentVector = GenericTanMember @@ -92,7 +92,7 @@ public struct ConditionallyDifferentiable { extension ConditionallyDifferentiable : Differentiable where T : Differentiable {} // CHECK-AST-LABEL: public struct ConditionallyDifferentiable { -// CHECK-AST: @differentiable(wrt: self where T : Differentiable) +// CHECK-AST: @differentiable(wrt: self where T : _Differentiable) // CHECK-AST: public var x: T // CHECK-AST: internal init(x: T) // CHECK-AST: } @@ -121,7 +121,7 @@ final class AdditiveArithmeticClass : A } } -// CHECK-AST-LABEL: final internal class AdditiveArithmeticClass : AdditiveArithmetic, Differentiable where T : AdditiveArithmetic, T : Differentiable { +// CHECK-AST-LABEL: final internal class AdditiveArithmeticClass : AdditiveArithmetic, Differentiable where T : AdditiveArithmetic, T : _Differentiable { // CHECK-AST: final internal var x: T, y: T -// CHECK-AST: internal struct TangentVector : Differentiable, AdditiveArithmetic +// CHECK-AST: internal struct TangentVector : _Differentiable, AdditiveArithmetic // CHECK-AST: } diff --git a/test/AutoDiff/differentiable_attr_silgen.swift b/test/AutoDiff/differentiable_attr_silgen.swift index 2b9f13e583f87..d617609ded57e 100644 --- a/test/AutoDiff/differentiable_attr_silgen.swift +++ b/test/AutoDiff/differentiable_attr_silgen.swift @@ -30,7 +30,7 @@ public func foo_indir_ret(_ x: Float, _ y: T) -> T { return y } -// CHECK-SIL-LABEL: sil [differentiable source 0 wrt 0, 1 vjp @AD__foo_indir_ret__vjp_src_0_wrt_0_1] [ossa] @foo_indir_ret : $@convention(thin) (Float, @in_guaranteed T) -> @out T { +// CHECK-SIL-LABEL: sil [differentiable source 0 wrt 0, 1 vjp @AD__foo_indir_ret__vjp_src_0_wrt_0_1] [ossa] @foo_indir_ret : $@convention(thin) (Float, @in_guaranteed T) -> @out T { // CHECK-SIL: bb0(%0 : $*T, %1 : $Float, %2 : $*T): @_silgen_name("dfoo_indir_ret") @@ -101,7 +101,7 @@ struct DiffComputedProp : Differentiable & AdditiveArithmetic { // Check that `@differentiable` attribute is transferred from computed property // storage declaration to getter accessor. -// CHECK-AST: struct DiffComputedProp : AdditiveArithmetic & Differentiable { +// CHECK-AST: struct DiffComputedProp : _Differentiable & AdditiveArithmetic { // CHECK-AST-NEXT: var computedProp: Float { get } // CHECK-AST: } diff --git a/test/AutoDiff/differentiable_attr_type_checking.swift b/test/AutoDiff/differentiable_attr_type_checking.swift index 6088a162d32e8..13cb382f0e473 100644 --- a/test/AutoDiff/differentiable_attr_type_checking.swift +++ b/test/AutoDiff/differentiable_attr_type_checking.swift @@ -765,7 +765,7 @@ struct TF_521 { self.imaginary = imaginary } } -// expected-error @+2 {{type 'TF_521' does not conform to protocol 'Differentiable'}} +// expected-error @+2 {{type 'TF_521' does not conform to protocol '_Differentiable'}} // expected-note @+1 {{do you want to add protocol stubs}} extension TF_521: Differentiable where T: Differentiable { // expected-note @+1 {{possibly intended match 'TF_521.TangentVector' does not conform to 'AdditiveArithmetic'}} diff --git a/test/AutoDiff/differentiable_func_debuginfo.swift b/test/AutoDiff/differentiable_func_debuginfo.swift index 87d8b0978bfcc..e766f8d82d8bb 100644 --- a/test/AutoDiff/differentiable_func_debuginfo.swift +++ b/test/AutoDiff/differentiable_func_debuginfo.swift @@ -23,7 +23,7 @@ // Conclusion: mangling coverage is important. // Minimal dummy compiler-known `Differentiable` protocol. -public protocol Differentiable { +public protocol _Differentiable { associatedtype TangentVector } diff --git a/test/AutoDiff/differentiable_func_type_type_checking.swift b/test/AutoDiff/differentiable_func_type_type_checking.swift index 9e85d8344f94e..b6df9a4d9603e 100644 --- a/test/AutoDiff/differentiable_func_type_type_checking.swift +++ b/test/AutoDiff/differentiable_func_type_type_checking.swift @@ -92,7 +92,7 @@ extension Vector: Differentiable where T: Differentiable {} func inferredConformancesGeneric(_: @differentiable (Vector) -> Vector) {} func nondiffVectorFunc(x: Vector) -> Vector {} -// expected-error @+1 {{global function 'inferredConformancesGeneric' requires that 'Int' conform to 'Differentiable}} +// expected-error @+1 {{global function 'inferredConformancesGeneric' requires that 'Int' conform to '_Differentiable}} inferredConformancesGeneric(nondiffVectorFunc) func diffVectorFunc(x: Vector) -> Vector {} diff --git a/test/AutoDiff/differentiable_function_silgen.swift b/test/AutoDiff/differentiable_function_silgen.swift index e1b17af6ff9dd..16ad288847a36 100644 --- a/test/AutoDiff/differentiable_function_silgen.swift +++ b/test/AutoDiff/differentiable_function_silgen.swift @@ -84,5 +84,5 @@ func appliesReabstraction(_ f: @escaping @differentiable (Float) -> Float) { // CHECK-SILGEN: [[REABS_VJP:%.*]] = function_ref @$sS4fIegyd_Iegydo_S4fIegnr_Iegnro_TR : $@convention(thin) (@in_guaranteed Float, @guaranteed @callee_guaranteed (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float) // CHECK-SILGEN: [[NEW_VJP:%.*]] = partial_apply [callee_guaranteed] [[REABS_VJP]]([[VJP_COPY]]) : $@convention(thin) (@in_guaranteed Float, @guaranteed @callee_guaranteed (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float) // CHECK-SILGEN: [[NEW_DIFF_FUNC:%.*]] = differentiable_function [wrt 0] [order 1] [[NEW_ORIG]] : $@callee_guaranteed (@in_guaranteed Float) -> @out Float with {[[NEW_JVP]] : $@callee_guaranteed (@in_guaranteed Float) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float), [[NEW_VJP]] : $@callee_guaranteed (@in_guaranteed Float) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float)} -// CHECK-SILGEN: [[DIFF_API:%.*]] = function_ref @${{.*}}pullback{{.*}}at{{.*}} : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Differentiable, τ_0_1 : Differentiable> (@in_guaranteed τ_0_0, @guaranteed @differentiable @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_1) -> @owned @callee_guaranteed (@in_guaranteed τ_0_1.TangentVector) -> @out τ_0_0.TangentVector -// CHECK-SILGEN: apply [[DIFF_API]]({{.*}}, [[NEW_DIFF_FUNC]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Differentiable, τ_0_1 : Differentiable> (@in_guaranteed τ_0_0, @guaranteed @differentiable @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_1) -> @owned @callee_guaranteed (@in_guaranteed τ_0_1.TangentVector) -> @out τ_0_0.TangentVector +// CHECK-SILGEN: [[DIFF_API:%.*]] = function_ref @${{.*}}pullback{{.*}}at{{.*}} : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : _Differentiable, τ_0_1 : _Differentiable> (@in_guaranteed τ_0_0, @guaranteed @differentiable @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_1) -> @owned @callee_guaranteed (@in_guaranteed τ_0_1.TangentVector) -> @out τ_0_0.TangentVector +// CHECK-SILGEN: apply [[DIFF_API]]({{.*}}, [[NEW_DIFF_FUNC]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : _Differentiable, τ_0_1 : _Differentiable> (@in_guaranteed τ_0_0, @guaranteed @differentiable @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_1) -> @owned @callee_guaranteed (@in_guaranteed τ_0_1.TangentVector) -> @out τ_0_0.TangentVector diff --git a/test/AutoDiff/differentiable_sil_attr.sil b/test/AutoDiff/differentiable_sil_attr.sil index 444ac533f0577..c308cdf0ad79e 100644 --- a/test/AutoDiff/differentiable_sil_attr.sil +++ b/test/AutoDiff/differentiable_sil_attr.sil @@ -16,13 +16,13 @@ entry(%0: $Float, %1: $Float): return undef: $(Float, (Float) -> (Float, Float)) } -// CHECK-LABEL: sil [differentiable source 0 wrt 0, 1 vjp @foo_vjp where T : Differentiable, U : Differentiable, V : Differentiable] @foo +// CHECK-LABEL: sil [differentiable source 0 wrt 0, 1 vjp @foo_vjp where T : _Differentiable, U : _Differentiable, V : _Differentiable] @foo sil [differentiable source 0 wrt 0, 1 vjp @foo_vjp where T : Differentiable, U : Differentiable, V : Differentiable] @foo : $@convention(thin) (@in_guaranteed T, @in_guaranteed U, @in_guaranteed V) -> @out V { entry(%0 : $*V, %1 : $*T, %2 : $*U, %3 : $*V): return undef: $() } -sil @foo_vjp : $@convention(thin) (@in_guaranteed T, @in_guaranteed U, @in_guaranteed V) -> (@out V, @owned @callee_guaranteed (@in_guaranteed V) -> (@out T, @out U)) { +sil @foo_vjp : $@convention(thin) (@in_guaranteed T, @in_guaranteed U, @in_guaranteed V) -> (@out V, @owned @callee_guaranteed (@in_guaranteed V) -> (@out T, @out U)) { bb0(%0 : $*V, %1 : $*T, %2 : $*U, %3 : $*V): return undef: $@callee_guaranteed (@in_guaranteed V) -> (@out T, @out U) } diff --git a/test/AutoDiff/differentiating_attr_type_checking.swift b/test/AutoDiff/differentiating_attr_type_checking.swift index ea70d52308e04..19a28a40e1786 100644 --- a/test/AutoDiff/differentiating_attr_type_checking.swift +++ b/test/AutoDiff/differentiating_attr_type_checking.swift @@ -54,7 +54,7 @@ func jvpGeneric(x: T, y: T) -> (value: T, differential: (T.T func vjpGenericWrongLabel(x: T, y: T) -> (value: T, (T) -> (T, T)) { return (x, { ($0, $0) }) } -// expected-error @+1 {{could not find function 'generic' with expected type ' (x: T) -> T'}} +// expected-error @+1 {{could not find function 'generic' with expected type ' (x: T) -> T'}} @differentiating(generic) func vjpGenericDiffParamMismatch(x: T) -> (value: T, pullback: (T) -> (T, T)) where T == T.TangentVector { return (x, { ($0, $0) }) @@ -120,7 +120,7 @@ func invalidDiffWrtFunction(_ fn: @differentiable(Float) -> Float) -> Float { } // expected-error @+2 {{type 'T' does not conform to protocol 'FloatingPoint'}} -// expected-error @+1 {{could not find function 'foo' with expected type ' (T) -> T'}} +// expected-error @+1 {{could not find function 'foo' with expected type ' (T) -> T'}} @differentiating(foo) func vjpFoo(_ x: T) -> (value: T, pullback: (T.TangentVector) -> (T.TangentVector)) { return (x, { $0 }) @@ -157,7 +157,7 @@ extension Differentiable where Self : AdditiveArithmetic { } extension AdditiveArithmetic where Self : Differentiable, Self == Self.TangentVector { - // expected-error @+1 {{could not find function '+' with expected type ' (Self) -> (Self, Self) -> Self'}} + // expected-error @+1 {{could not find function '+' with expected type ' (Self) -> (Self, Self) -> Self'}} @differentiating(+) func vjpPlusInstanceMethod(x: Self, y: Self) -> (value: Self, pullback: (Self) -> (Self, Self)) { return (x + y, { v in (v, v) }) diff --git a/test/AutoDiff/silgen_thunking/main.swift b/test/AutoDiff/silgen_thunking/main.swift index 610cea38c4c58..17aa79f79c845 100644 --- a/test/AutoDiff/silgen_thunking/main.swift +++ b/test/AutoDiff/silgen_thunking/main.swift @@ -104,29 +104,29 @@ where Dummy: Differentiable & ExpressibleByIntegerLiteral { return (value, { v in (v, 2.0, 3.0) }) } -// CHECK-LABEL: sil hidden [ossa] @AD__$s4main21SelfReorderingGenericV20threeParameterMethodyACyxGqd___qd_0_ts14DifferentiableRd__sAFRd_0_s25ExpressibleByFloatLiteral13TangentVectorRpd__sAgHRpd_0_r0_lF__jvp_src_0_wrt_0_1_2 : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 : ExpressibleByIntegerLiteral><τ_1_0, τ_1_1 where τ_1_0 : Differentiable, τ_1_1 : Differentiable, τ_1_0.TangentVector : ExpressibleByFloatLiteral, τ_1_1.TangentVector : ExpressibleByFloatLiteral> (@in_guaranteed τ_1_0, @in_guaranteed τ_1_1, @in_guaranteed SelfReorderingGeneric<τ_0_0>) -> (@out SelfReorderingGeneric<τ_0_0>, @owned @callee_guaranteed (@in_guaranteed τ_1_0.TangentVector, @in_guaranteed τ_1_1.TangentVector, @in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector) -> @out SelfReorderingGeneric<τ_0_0>.TangentVector) +// CHECK-LABEL: sil hidden [ossa] @AD__$s4main21SelfReorderingGenericV20threeParameterMethodyACyxGqd___qd_0_ts15_DifferentiableRd__sAFRd_0_s25ExpressibleByFloatLiteral13TangentVectorRpd__sAgHRpd_0_r0_lF__jvp_src_0_wrt_0_1_2 : $@convention(method) <τ_0_0 where τ_0_0 : ExpressibleByIntegerLiteral, τ_0_0 : _Differentiable><τ_1_0, τ_1_1 where τ_1_0 : _Differentiable, τ_1_1 : _Differentiable, τ_1_0.TangentVector : ExpressibleByFloatLiteral, τ_1_1.TangentVector : ExpressibleByFloatLiteral> (@in_guaranteed τ_1_0, @in_guaranteed τ_1_1, @in_guaranteed SelfReorderingGeneric<τ_0_0>) -> (@out SelfReorderingGeneric<τ_0_0>, @owned @callee_guaranteed (@in_guaranteed τ_1_0.TangentVector, @in_guaranteed τ_1_1.TangentVector, @in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector) -> @out SelfReorderingGeneric<τ_0_0>.TangentVector) { // CHECK: bb0([[JVP_RESULT:%.*]] : $*SelfReorderingGeneric<τ_0_0>, [[X:%.*]] : $*τ_1_0, [[Y:%.*]] : $*τ_1_1, [[SELF:%.*]] : $*SelfReorderingGeneric<τ_0_0>): -// CHECK: [[JVP:%.*]] = function_ref @$s4main21SelfReorderingGenericV23jvpThreeParameterMethodyACyxG_AC13TangentVectorVyx_GAH_AFQyd__AFQyd_0_tctqd___qd_0_ts14DifferentiableRd__sAKRd_0_s25ExpressibleByFloatLiteralAIRQsAlJRQr0_lF +// CHECK: [[JVP:%.*]] = function_ref @$s4main21SelfReorderingGenericV23jvpThreeParameterMethodyACyxG_AC13TangentVectorVyx_GAH_AFQyd__AFQyd_0_tctqd___qd_0_ts15_DifferentiableRd__sAKRd_0_s25ExpressibleByFloatLiteralAIRQsAlJRQr0_lF // CHECK: [[DF:%.*]] = apply [[JVP]]<τ_0_0, τ_1_0, τ_1_1>([[JVP_RESULT]], [[X]], [[Y]], [[SELF]]) -// CHECK: [[DF_SELF_REORDER_THUNK:%.*]] = function_ref @AD__$s4main21SelfReorderingGenericV13TangentVectorVyx_GADQyd__ADQyd_0_AFIegnnnr_Agh2FIegnnnr_s14DifferentiableRzs27ExpressibleByIntegerLiteralRzsAIRd__sAIRd_0_s0hi5FloatK0AGRQsAkHRQr_0_lTR_differential_self_reordering_thunk +// CHECK: [[DF_SELF_REORDER_THUNK:%.*]] = function_ref @AD__$s4main21SelfReorderingGenericV13TangentVectorVyx_GADQyd__ADQyd_0_AFIegnnnr_Agh2FIegnnnr_s27ExpressibleByIntegerLiteralRzs15_DifferentiableRzsAJRd__sAJRd_0_s0gh5FloatJ0AGRQsAkHRQr_0_lTR_differential_self_reordering_thunk // CHECK: [[THUNKED_DF:%.*]] = partial_apply [callee_guaranteed] [[DF_SELF_REORDER_THUNK]]<τ_0_0, τ_1_0, τ_1_1>([[DF]]) // CHECK: return [[THUNKED_DF]] -// CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @AD__$s4main21SelfReorderingGenericV13TangentVectorVyx_GADQyd__ADQyd_0_AFIegnnnr_Agh2FIegnnnr_s14DifferentiableRzs27ExpressibleByIntegerLiteralRzsAIRd__sAIRd_0_s0hi5FloatK0AGRQsAkHRQr_0_lTR_differential_self_reordering_thunk : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 : ExpressibleByIntegerLiteral><τ_1_0, τ_1_1 where τ_1_0 : Differentiable, τ_1_1 : Differentiable, τ_1_0.TangentVector : ExpressibleByFloatLiteral, τ_1_1.TangentVector : ExpressibleByFloatLiteral> (@in_guaranteed τ_1_0.TangentVector, @in_guaranteed τ_1_1.TangentVector, @in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector, @guaranteed @callee_guaranteed (@in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector, @in_guaranteed τ_1_0.TangentVector, @in_guaranteed τ_1_1.TangentVector) -> @out SelfReorderingGeneric<τ_0_0>.TangentVector) -> @out SelfReorderingGeneric<τ_0_0>.TangentVector +// CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @AD__$s4main21SelfReorderingGenericV13TangentVectorVyx_GADQyd__ADQyd_0_AFIegnnnr_Agh2FIegnnnr_s27ExpressibleByIntegerLiteralRzs15_DifferentiableRzsAJRd__sAJRd_0_s0gh5FloatJ0AGRQsAkHRQr_0_lTR_differential_self_reordering_thunk : $@convention(thin) <τ_0_0 where τ_0_0 : ExpressibleByIntegerLiteral, τ_0_0 : _Differentiable><τ_1_0, τ_1_1 where τ_1_0 : _Differentiable, τ_1_1 : _Differentiable, τ_1_0.TangentVector : ExpressibleByFloatLiteral, τ_1_1.TangentVector : ExpressibleByFloatLiteral> (@in_guaranteed τ_1_0.TangentVector, @in_guaranteed τ_1_1.TangentVector, @in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector, @guaranteed @callee_guaranteed (@in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector, @in_guaranteed τ_1_0.TangentVector, @in_guaranteed τ_1_1.TangentVector) -> @out SelfReorderingGeneric<τ_0_0>.TangentVector) -> @out SelfReorderingGeneric<τ_0_0>.TangentVector { // CHECK: bb0([[DF_RESULT:%.*]] : $*SelfReorderingGeneric<τ_0_0>.TangentVector, [[DX:%.*]] : $*τ_1_0.TangentVector, [[DY:%.*]] : $*τ_1_1.TangentVector, [[DSELF:%.*]] : $*SelfReorderingGeneric<τ_0_0>.TangentVector, [[DF:%.*]] : @guaranteed $@callee_guaranteed (@in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector, @in_guaranteed τ_1_0.TangentVector, @in_guaranteed τ_1_1.TangentVector) -> @out SelfReorderingGeneric<τ_0_0>.TangentVector): // CHECK: {{%.*}} = apply [[DF]]([[DF_RESULT]], [[DSELF]], [[DX]], [[DY]]) // CHECK: [[VOID:%.*]] = tuple () // CHECK: return [[VOID]] -// CHECK-LABEL: sil hidden [ossa] @AD__$s4main21SelfReorderingGenericV20threeParameterMethodyACyxGqd___qd_0_ts14DifferentiableRd__sAFRd_0_s25ExpressibleByFloatLiteral13TangentVectorRpd__sAgHRpd_0_r0_lF__vjp_src_0_wrt_0_1_2 : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 : ExpressibleByIntegerLiteral><τ_1_0, τ_1_1 where τ_1_0 : Differentiable, τ_1_1 : Differentiable, τ_1_0.TangentVector : ExpressibleByFloatLiteral, τ_1_1.TangentVector : ExpressibleByFloatLiteral> (@in_guaranteed τ_1_0, @in_guaranteed τ_1_1, @in_guaranteed SelfReorderingGeneric<τ_0_0>) -> (@out SelfReorderingGeneric<τ_0_0>, @owned @callee_guaranteed (@in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector) -> (@out τ_1_0.TangentVector, @out τ_1_1.TangentVector, @out SelfReorderingGeneric<τ_0_0>.TangentVector)) +// CHECK-LABEL: sil hidden [ossa] @AD__$s4main21SelfReorderingGenericV20threeParameterMethodyACyxGqd___qd_0_ts15_DifferentiableRd__sAFRd_0_s25ExpressibleByFloatLiteral13TangentVectorRpd__sAgHRpd_0_r0_lF__vjp_src_0_wrt_0_1_2 : $@convention(method) <τ_0_0 where τ_0_0 : ExpressibleByIntegerLiteral, τ_0_0 : _Differentiable><τ_1_0, τ_1_1 where τ_1_0 : _Differentiable, τ_1_1 : _Differentiable, τ_1_0.TangentVector : ExpressibleByFloatLiteral, τ_1_1.TangentVector : ExpressibleByFloatLiteral> (@in_guaranteed τ_1_0, @in_guaranteed τ_1_1, @in_guaranteed SelfReorderingGeneric<τ_0_0>) -> (@out SelfReorderingGeneric<τ_0_0>, @owned @callee_guaranteed (@in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector) -> (@out τ_1_0.TangentVector, @out τ_1_1.TangentVector, @out SelfReorderingGeneric<τ_0_0>.TangentVector)) { // CHECK: bb0([[VJP_RESULT:%.*]] : $*SelfReorderingGeneric<τ_0_0>, [[X:%.*]] : $*τ_1_0, [[Y:%.*]] : $*τ_1_1, [[SELF:%.*]] : $*SelfReorderingGeneric<τ_0_0>): -// CHECK: [[VJP:%.*]] = function_ref @$s4main21SelfReorderingGenericV23vjpThreeParameterMethodyACyxG_AC13TangentVectorVyx_G_AFQyd__AFQyd_0_tAHctqd___qd_0_ts14DifferentiableRd__sAKRd_0_s25ExpressibleByFloatLiteralAIRQsAlJRQr0_lF +// CHECK: [[VJP:%.*]] = function_ref @$s4main21SelfReorderingGenericV23vjpThreeParameterMethodyACyxG_AC13TangentVectorVyx_G_AFQyd__AFQyd_0_tAHctqd___qd_0_ts15_DifferentiableRd__sAKRd_0_s25ExpressibleByFloatLiteralAIRQsAlJRQr0_lF // CHECK: [[PB:%.*]] = apply [[VJP]]<τ_0_0, τ_1_0, τ_1_1>([[VJP_RESULT]], [[X]], [[Y]], [[SELF]]) -// CHECK: [[PB_SELF_REORDER_THUNK:%.*]] = function_ref @AD__$s4main21SelfReorderingGenericV13TangentVectorVyx_GAfDQyd__ADQyd_0_Iegnrrr_AfghFIegnrrr_s14DifferentiableRzs27ExpressibleByIntegerLiteralRzsAIRd__sAIRd_0_s0hi5FloatK0AGRQsAkHRQr_0_lTR_pullback_self_reordering_thunk +// CHECK: [[PB_SELF_REORDER_THUNK:%.*]] = function_ref @AD__$s4main21SelfReorderingGenericV13TangentVectorVyx_GAfDQyd__ADQyd_0_Iegnrrr_AfghFIegnrrr_s27ExpressibleByIntegerLiteralRzs15_DifferentiableRzsAJRd__sAJRd_0_s0gh5FloatJ0AGRQsAkHRQr_0_lTR_pullback_self_reordering_thunk // CHECK: [[THUNKED_PB:%.*]] = partial_apply [callee_guaranteed] [[PB_SELF_REORDER_THUNK]]<τ_0_0, τ_1_0, τ_1_1>([[PB]]) // CHECK: return [[THUNKED_PB]] -// CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @AD__$s4main21SelfReorderingGenericV13TangentVectorVyx_GAfDQyd__ADQyd_0_Iegnrrr_AfghFIegnrrr_s14DifferentiableRzs27ExpressibleByIntegerLiteralRzsAIRd__sAIRd_0_s0hi5FloatK0AGRQsAkHRQr_0_lTR_pullback_self_reordering_thunk : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 : ExpressibleByIntegerLiteral><τ_1_0, τ_1_1 where τ_1_0 : Differentiable, τ_1_1 : Differentiable, τ_1_0.TangentVector : ExpressibleByFloatLiteral, τ_1_1.TangentVector : ExpressibleByFloatLiteral> (@in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector, @guaranteed @callee_guaranteed (@in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector) -> (@out SelfReorderingGeneric<τ_0_0>.TangentVector, @out τ_1_0.TangentVector, @out τ_1_1.TangentVector)) -> (@out τ_1_0.TangentVector, @out τ_1_1.TangentVector, @out SelfReorderingGeneric<τ_0_0>.TangentVector) +// CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @AD__$s4main21SelfReorderingGenericV13TangentVectorVyx_GAfDQyd__ADQyd_0_Iegnrrr_AfghFIegnrrr_s27ExpressibleByIntegerLiteralRzs15_DifferentiableRzsAJRd__sAJRd_0_s0gh5FloatJ0AGRQsAkHRQr_0_lTR_pullback_self_reordering_thunk : $@convention(thin) <τ_0_0 where τ_0_0 : ExpressibleByIntegerLiteral, τ_0_0 : _Differentiable><τ_1_0, τ_1_1 where τ_1_0 : _Differentiable, τ_1_1 : _Differentiable, τ_1_0.TangentVector : ExpressibleByFloatLiteral, τ_1_1.TangentVector : ExpressibleByFloatLiteral> (@in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector, @guaranteed @callee_guaranteed (@in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector) -> (@out SelfReorderingGeneric<τ_0_0>.TangentVector, @out τ_1_0.TangentVector, @out τ_1_1.TangentVector)) -> (@out τ_1_0.TangentVector, @out τ_1_1.TangentVector, @out SelfReorderingGeneric<τ_0_0>.TangentVector) { // CHECK: bb0([[X_ADJ:%.*]] : $*τ_1_0.TangentVector, [[Y_ADJ:%.*]] : $*τ_1_1.TangentVector, [[SELF_ADJ:%.*]] : $*SelfReorderingGeneric<τ_0_0>.TangentVector, [[SEED:%.*]] : $*SelfReorderingGeneric<τ_0_0>.TangentVector, [[PB:%.*]] : @guaranteed $@callee_guaranteed (@in_guaranteed SelfReorderingGeneric<τ_0_0>.TangentVector) -> (@out SelfReorderingGeneric<τ_0_0>.TangentVector, @out τ_1_0.TangentVector, @out τ_1_1.TangentVector)): // CHECK: {{%.*}} = apply [[PB]]([[SELF_ADJ]], [[X_ADJ]], [[Y_ADJ]], [[SEED]]) // CHECK: [[VOID:%.*]] = tuple () diff --git a/test/AutoDiff/subset_parameters_thunk.swift b/test/AutoDiff/subset_parameters_thunk.swift index 68fff7e44db66..8521faa117f20 100644 --- a/test/AutoDiff/subset_parameters_thunk.swift +++ b/test/AutoDiff/subset_parameters_thunk.swift @@ -18,12 +18,12 @@ func differentiate_foo_wrt_0(_ x: Float) -> Float { // CHECK: bb0 // CHECK: [[FOO_ORIG:%.*]] = function_ref @{{.*}}foo{{.*}} : $@convention(thin) <τ_0_0 where τ_0_0 : Numeric> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> @out τ_0_0 // CHECK: [[FOO_FLOAT:%.*]] = partial_apply [callee_guaranteed] [[FOO_ORIG]]() : $@convention(thin) <τ_0_0 where τ_0_0 : Numeric> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> @out τ_0_0 -// CHECK: [[FOO_JVP:%.*]] = function_ref @AD__{{.*}}foo{{.*}}__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 : Numeric> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, @in_guaranteed τ_0_0.TangentVector) -> @out τ_0_0.TangentVector) -// CHECK: [[FOO_JVP_FLOAT:%.*]] = partial_apply [callee_guaranteed] [[FOO_JVP]]() : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 : Numeric> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, @in_guaranteed τ_0_0.TangentVector) -> @out τ_0_0.TangentVector) +// CHECK: [[FOO_JVP:%.*]] = function_ref @AD__{{.*}}foo{{.*}}__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Numeric, τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, @in_guaranteed τ_0_0.TangentVector) -> @out τ_0_0.TangentVector) +// CHECK: [[FOO_JVP_FLOAT:%.*]] = partial_apply [callee_guaranteed] [[FOO_JVP]]() : $@convention(thin) <τ_0_0 where τ_0_0 : Numeric, τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, @in_guaranteed τ_0_0.TangentVector) -> @out τ_0_0.TangentVector) // CHECK: [[FOO_JVP_SUBSET_THUNK_THIN:%.*]] = function_ref @AD__orig_{{.*}}foo{{.*}}_src_0_wrt_0_jvp_subset_parameters_thunk : $@convention(thin) (@in_guaranteed Float, @in_guaranteed Float) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float) // CHECK: [[FOO_JVP_SUBSET_THUNK:%.*]] = thin_to_thick_function [[FOO_JVP_SUBSET_THUNK_THIN]] : $@convention(thin) (@in_guaranteed Float, @in_guaranteed Float) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float) to $@callee_guaranteed (@in_guaranteed Float, @in_guaranteed Float) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float) -// CHECK: [[FOO_VJP:%.*]] = function_ref @AD__{{.*}}foo{{.*}}__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 : Numeric> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_0.TangentVector)) -// CHECK: [[FOO_VJP_FLOAT:%.*]] = partial_apply [callee_guaranteed] [[FOO_VJP]]() : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 : Numeric> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_0.TangentVector)) +// CHECK: [[FOO_VJP:%.*]] = function_ref @AD__{{.*}}foo{{.*}}__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Numeric, τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_0.TangentVector)) +// CHECK: [[FOO_VJP_FLOAT:%.*]] = partial_apply [callee_guaranteed] [[FOO_VJP]]() : $@convention(thin) <τ_0_0 where τ_0_0 : Numeric, τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_0.TangentVector)) // CHECK: [[FOO_VJP_SUBSET_THUNK_THIN:%.*]] = function_ref @AD__orig_{{.*}}foo{{.*}}_src_0_wrt_0_vjp_subset_parameters_thunk : $@convention(thin) (@in_guaranteed Float, @in_guaranteed Float) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float) // CHECK: [[FOO_VJP_SUBSET_THUNK:%.*]] = thin_to_thick_function [[FOO_VJP_SUBSET_THUNK_THIN]] : $@convention(thin) (@in_guaranteed Float, @in_guaranteed Float) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float) to $@callee_guaranteed (@in_guaranteed Float, @in_guaranteed Float) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float) // CHECK: [[FOO_DIFF:%.*]] = differentiable_function [wrt 0] [order 1] [[FOO_FLOAT]] : $@callee_guaranteed (@in_guaranteed Float, @in_guaranteed Float) -> @out Float with {[[FOO_JVP_SUBSET_THUNK]] : $@callee_guaranteed (@in_guaranteed Float, @in_guaranteed Float) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float), [[FOO_VJP_SUBSET_THUNK]] : $@callee_guaranteed (@in_guaranteed Float, @in_guaranteed Float) -> (@out Float, @owned @callee_guaranteed (@in_guaranteed Float) -> @out Float)} diff --git a/test/AutoDiff/transposing_attr_type_checking.swift b/test/AutoDiff/transposing_attr_type_checking.swift index 4eb1389604843..897c245260a65 100644 --- a/test/AutoDiff/transposing_attr_type_checking.swift +++ b/test/AutoDiff/transposing_attr_type_checking.swift @@ -179,7 +179,7 @@ func differentGenericConstraint(x: T) } // expected-error @+2 {{type 'T' does not conform to protocol 'BinaryFloatingPoint'}} -// expected-error @+1 {{could not find function 'differentGenericConstraint' with expected type ' (T) -> T'}} +// expected-error @+1 {{could not find function 'differentGenericConstraint' with expected type ' (T) -> T'}} @transposing(differentGenericConstraint, wrt: 0) func differentGenericConstraintT(x: T) -> T where T == T.TangentVector { diff --git a/test/AutoDiff/witness_table_sil.swift b/test/AutoDiff/witness_table_sil.swift index 1ccc33a4b2952..ff4b29088a061 100644 --- a/test/AutoDiff/witness_table_sil.swift +++ b/test/AutoDiff/witness_table_sil.swift @@ -82,7 +82,7 @@ struct S : Proto, VectorProtocol { } // CHECK-LABEL: sil_witness_table hidden S: Proto module witness_table_sil { -// CHECK-NEXT: base_protocol Differentiable: S: Differentiable module witness_table_sil +// CHECK-NEXT: base_protocol _Differentiable: S: _Differentiable module witness_table_sil // CHECK-NEXT: method #Proto.function1!1: (Self) -> (Float, Double) -> Float : @{{.*}}function1 // CHECK-NEXT: method #Proto.function1!1.jvp.1.SSU: (Self) -> (Float, Double) -> Float : @AD__{{.*}}function1{{.*}}_jvp_SSU // CHECK-NEXT: method #Proto.function1!1.vjp.1.SSU: (Self) -> (Float, Double) -> Float : @AD__{{.*}}function1{{.*}}_vjp_SSU diff --git a/test/Sema/class_differentiable.swift b/test/Sema/class_differentiable.swift index a8eaf5f5225cd..1351fba098d38 100644 --- a/test/Sema/class_differentiable.swift +++ b/test/Sema/class_differentiable.swift @@ -473,9 +473,9 @@ final class TangentVectorWB : DummyAdditiveArithmetic, Differentiable { self.b = b } } -// expected-error @+4 {{'Differentiable' requires the types 'VectorSpaceTypeAlias.TangentVector' (aka 'TangentVectorWB') and 'TangentVectorWB.TangentVector' be equivalent}} +// expected-error @+4 {{'_Differentiable' requires the types 'VectorSpaceTypeAlias.TangentVector' (aka 'TangentVectorWB') and 'TangentVectorWB.TangentVector' be equivalent}} // expected-note @+3 {{requirement specified as 'Self.TangentVector' == 'Self.TangentVector.TangentVector' [with Self = VectorSpaceTypeAlias]}} -// expected-error @+2 {{type 'VectorSpaceTypeAlias' does not conform to protocol 'Differentiable'}} +// expected-error @+2 {{type 'VectorSpaceTypeAlias' does not conform to protocol '_Differentiable'}} // expected-note @+1 {{do you want to add protocol stubs?}} final class VectorSpaceTypeAlias : DummyAdditiveArithmetic, Differentiable { var w: Float @@ -487,7 +487,7 @@ final class VectorSpaceTypeAlias : DummyAdditiveArithmetic, Differentiable { self.b = b } } -// expected-error @+2 {{type 'VectorSpaceCustomStruct' does not conform to protocol 'Differentiable'}} +// expected-error @+2 {{type 'VectorSpaceCustomStruct' does not conform to protocol '_Differentiable'}} // expected-note @+1 {{do you want to add protocol stubs?}} final class VectorSpaceCustomStruct : DummyAdditiveArithmetic, Differentiable { var w: Float @@ -546,12 +546,12 @@ extension NoMemberwiseInitializerExtended: Differentiable // Test derived conformances in disallowed contexts. -// expected-error @+3 {{type 'OtherFileNonconforming' does not conform to protocol 'Differentiable'}} -// expected-error @+2 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}} +// expected-error @+3 {{type 'OtherFileNonconforming' does not conform to protocol '_Differentiable'}} +// expected-error @+2 {{implementation of '_Differentiable' cannot be automatically synthesized in an extension in a different file to the type}} // expected-note @+1 {{do you want to add protocol stubs?}} extension OtherFileNonconforming : Differentiable {} -// expected-error @+3 {{type 'GenericOtherFileNonconforming' does not conform to protocol 'Differentiable'}} -// expected-error @+2 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}} +// expected-error @+3 {{type 'GenericOtherFileNonconforming' does not conform to protocol '_Differentiable'}} +// expected-error @+2 {{implementation of '_Differentiable' cannot be automatically synthesized in an extension in a different file to the type}} // expected-note @+1 {{do you want to add protocol stubs?}} extension GenericOtherFileNonconforming : Differentiable {} diff --git a/test/Sema/struct_differentiable.swift b/test/Sema/struct_differentiable.swift index d2d2bd341c94c..7e03f3fa11ab7 100644 --- a/test/Sema/struct_differentiable.swift +++ b/test/Sema/struct_differentiable.swift @@ -325,14 +325,14 @@ public struct TF_269 : TF_269_Layer { // Test manually customizing vector space types. // Thees should fail. Synthesis is semantically unsupported if vector space // types are customized. -// expected-error @+2 {{type 'VectorSpaceTypeAlias' does not conform to protocol 'Differentiable'}} +// expected-error @+2 {{type 'VectorSpaceTypeAlias' does not conform to protocol '_Differentiable'}} // expected-note @+1 {{do you want to add protocol stubs?}} struct VectorSpaceTypeAlias : AdditiveArithmetic, Differentiable { var w: Float var b: Float typealias TangentVector = Simple } -// expected-error @+2 {{type 'VectorSpaceCustomStruct' does not conform to protocol 'Differentiable'}} +// expected-error @+2 {{type 'VectorSpaceCustomStruct' does not conform to protocol '_Differentiable'}} // expected-note @+1 {{do you want to add protocol stubs?}} struct VectorSpaceCustomStruct : AdditiveArithmetic, Differentiable { var w: Float @@ -387,12 +387,12 @@ extension NoMemberwiseInitializerExtended: EuclideanDifferentiable // Test derived conformances in disallowed contexts. -// expected-error @+3 {{type 'OtherFileNonconforming' does not conform to protocol 'Differentiable'}} -// expected-error @+2 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}} +// expected-error @+3 {{type 'OtherFileNonconforming' does not conform to protocol '_Differentiable'}} +// expected-error @+2 {{implementation of '_Differentiable' cannot be automatically synthesized in an extension in a different file to the type}} // expected-note @+1 {{do you want to add protocol stubs?}} extension OtherFileNonconforming : Differentiable {} -// expected-error @+3 {{type 'GenericOtherFileNonconforming' does not conform to protocol 'Differentiable'}} -// expected-error @+2 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}} +// expected-error @+3 {{type 'GenericOtherFileNonconforming' does not conform to protocol '_Differentiable'}} +// expected-error @+2 {{implementation of '_Differentiable' cannot be automatically synthesized in an extension in a different file to the type}} // expected-note @+1 {{do you want to add protocol stubs?}} extension GenericOtherFileNonconforming : Differentiable {} From a3743b7456cfa9013e598fbfc0a23ec0843814ad Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Wed, 9 Oct 2019 11:32:40 -0700 Subject: [PATCH 4/4] Update remaining tests. --- test/AutoDiff/nonvaried_result.swift | 4 ++-- test/Serialization/differentiable_attr.swift | 10 +++++----- test/Serialization/differentiating_attr.swift | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/AutoDiff/nonvaried_result.swift b/test/AutoDiff/nonvaried_result.swift index c45134e5d3467..379691f0711ba 100644 --- a/test/AutoDiff/nonvaried_result.swift +++ b/test/AutoDiff/nonvaried_result.swift @@ -44,7 +44,7 @@ NonVariedResultTests.testWithLeakChecking("SingleBasicBlockGeneric") { expectEqual((0, 0, 0), gradient(at: 3, 4, 5) { simpleGeneric($0, $1, $2) }) } -// CHECK-LABEL: sil hidden [ossa] @AD__${{.*}}simpleGeneric{{.*}}pullback_src_0_wrt_0_1_2 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 == τ_0_0.TangentVector> (@in_guaranteed τ_0_0.TangentVector, @owned _AD__$s4nullyycfU0_13simpleGenericL_yxx_x23DifferentiationUnittest7TrackedVySfGts14DifferentiableRz13TangentVectorsAGPQzRszlF_bb0__PB__src_0_wrt_0_1_2<τ_0_0>) -> (@out τ_0_0.TangentVector, @out τ_0_0.TangentVector, @owned Tracked) { +// CHECK-LABEL: sil hidden [ossa] @AD__${{.*}}simpleGeneric{{.*}}pullback_src_0_wrt_0_1_2 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable, τ_0_0 == τ_0_0.TangentVector> (@in_guaranteed τ_0_0.TangentVector, @owned _AD__$s4nullyycfU0_13simpleGenericL_yxx_x23DifferentiationUnittest7TrackedVySfGts15_DifferentiableRz13TangentVectorsAGPQzRszlF_bb0__PB__src_0_wrt_0_1_2<τ_0_0>) -> (@out τ_0_0.TangentVector, @out τ_0_0.TangentVector, @owned Tracked) { // CHECK: bb0([[DX:%.*]] : $*τ_0_0, [[DY:%.*]] : $*τ_0_0, [[SEED:%.*]] : $*τ_0_0, [[PB_STRUCT:%.*]] : [[PB_STRUCT_TYPE:.*]]): // CHECK: [[ZERO_FN_X:%.*]] = witness_method $τ_0_0, #AdditiveArithmetic.zero!getter.1 : (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // CHECK: [[METATYPE_X:%.*]] = metatype $@thick τ_0_0.Type @@ -150,7 +150,7 @@ NonVariedResultTests.testWithLeakChecking("ComplexGeneric") { expectEqual(0, pullback(at: Tracked(3)) { complexGeneric(10, $0) }(1)) } -// CHECK-LABEL: sil hidden [ossa] @AD__${{.*}}complexGeneric{{.*}}pullback_src_0_wrt_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0.TangentVector, @owned _AD__$s4nullyycfU4_14complexGenericL_yxx_xts14DifferentiableRzlF_bb9__PB__src_0_wrt_1<τ_0_0>) -> @out τ_0_0.TangentVector { +// CHECK-LABEL: sil hidden [ossa] @AD__${{.*}}complexGeneric{{.*}}pullback_src_0_wrt_1 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0.TangentVector, @owned _AD__$s4nullyycfU4_14complexGenericL_yxx_xts15_DifferentiableRzlF_bb9__PB__src_0_wrt_1<τ_0_0>) -> @out τ_0_0.TangentVector { // CHECK: bb0([[DY:%.*]] : $*τ_0_0.TangentVector, [[SEED:%.*]] : $*τ_0_0.TangentVector, [[PB_STRUCT:%.*]] : @owned [[PB_STRUCT_TYPE:.*]]): // CHECK: destroy_value [[PB_STRUCT]] : [[PB_STRUCT_TYPE]] // CHECK: [[ZERO_FN:%.*]] = witness_method $τ_0_0.TangentVector, #AdditiveArithmetic.zero!getter.1 : (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 diff --git a/test/Serialization/differentiable_attr.swift b/test/Serialization/differentiable_attr.swift index b16236684b3a6..7fbed582d96ab 100644 --- a/test/Serialization/differentiable_attr.swift +++ b/test/Serialization/differentiable_attr.swift @@ -52,14 +52,14 @@ struct InstanceMethod : Differentiable { } } -// CHECK: @differentiable(wrt: x where T : Differentiable) +// CHECK: @differentiable(wrt: x where T : _Differentiable) // CHECK-NEXT: func testOnlyWhereClause(x: T) -> T where T : Numeric @differentiable(where T : Differentiable) func testOnlyWhereClause(x: T) -> T { return x } -// CHECK: @differentiable(wrt: x, vjp: vjpTestWhereClause where T : Differentiable) +// CHECK: @differentiable(wrt: x, vjp: vjpTestWhereClause where T : _Differentiable) // CHECK-NEXT: func testWhereClause(x: T) -> T where T : Numeric @differentiable(vjp: vjpTestWhereClause where T : Differentiable) func testWhereClause(x: T) -> T { @@ -73,7 +73,7 @@ func vjpTestWhereClause(x: T) -> (T, (T.TangentVector) -> T.TangentVector) protocol P {} extension P { - // CHECK: @differentiable(wrt: self, vjp: vjpTestWhereClauseMethod where Self : Differentiable) + // CHECK: @differentiable(wrt: self, vjp: vjpTestWhereClauseMethod where Self : _Differentiable) // CHECK-NEXT: func testWhereClauseMethod() -> Self @differentiable(wrt: self, vjp: vjpTestWhereClauseMethod where Self : Differentiable) func testWhereClauseMethod() -> Self { @@ -86,7 +86,7 @@ extension P where Self : Differentiable { } } -// CHECK: @differentiable(wrt: x, vjp: vjpTestWhereClauseMethodTypeConstraint where T : Differentiable, T == T.TangentVector) +// CHECK: @differentiable(wrt: x, vjp: vjpTestWhereClauseMethodTypeConstraint where T : _Differentiable, T == T.TangentVector) // CHECK-NEXT: func testWhereClauseMethodTypeConstraint(x: T) -> T where T : Numeric @differentiable(vjp: vjpTestWhereClauseMethodTypeConstraint where T : Differentiable, T == T.TangentVector) func testWhereClauseMethodTypeConstraint(x: T) -> T { @@ -99,7 +99,7 @@ func vjpTestWhereClauseMethodTypeConstraint(x: T) -> (T, (T) -> T) } extension P { - // CHECK: @differentiable(wrt: self, vjp: vjpTestWhereClauseMethodTypeConstraint where Self : Differentiable, Self == Self.TangentVector) + // CHECK: @differentiable(wrt: self, vjp: vjpTestWhereClauseMethodTypeConstraint where Self : _Differentiable, Self == Self.TangentVector) // CHECK-NEXT: func testWhereClauseMethodTypeConstraint() -> Self @differentiable(wrt: self, vjp: vjpTestWhereClauseMethodTypeConstraint where Self.TangentVector == Self, Self : Differentiable) func testWhereClauseMethodTypeConstraint() -> Self { diff --git a/test/Serialization/differentiating_attr.swift b/test/Serialization/differentiating_attr.swift index ac890d33f7b21..8293f1ab82465 100644 --- a/test/Serialization/differentiating_attr.swift +++ b/test/Serialization/differentiating_attr.swift @@ -35,7 +35,7 @@ func vjpLin(x: Float, y: Float) -> (value: Float, pullback: (Float) -> (Float, F return (x + y, { ($0, $0) }) } -// CHECK: @differentiable(wrt: x, vjp: vjpGeneric where T : Differentiable) +// CHECK: @differentiable(wrt: x, vjp: vjpGeneric where T : _Differentiable) func generic(x: T) -> T { return x }