From 52b97b2a5fdee5378205e8fd59ccbd7cbd9e728d Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Wed, 16 Oct 2019 21:24:35 +0000 Subject: [PATCH 1/5] [AutoDiff] Move stdlib sources to stdlib/public/core/Differentiation. Move differentiable-programming-related stdlib sources to `stdlib/public/core/Differentiation`. Related master branch PR: https://github.com/apple/swift/pull/27511. master branch will have a `_Differentiation` support library containing the `Differentiable` protocol and related APIs. On tensorflow branch, the Swift source files in `stdlib/public/core/Differentiation` will be directly built as part of swiftCore for simplicity. Swift for TensorFlow users can continue to use the `Differentiable` protocol and related APIs without adding `import _Differentiation`. Rename `protocol _Differentiable` back to `protocol Differentiable`. --- include/swift/AST/KnownIdentifiers.def | 1 + include/swift/AST/KnownProtocols.def | 2 +- stdlib/public/Differentiation/CMakeLists.txt | 25 +++++++ .../Differentiation/Differentiable.swift | 70 +++++++++++++++++++ .../DifferentiationSupport.swift | 0 stdlib/public/core/CMakeLists.txt | 9 ++- test/CMakeLists.txt | 6 ++ .../differentiable_protocol.swift | 34 +++++++++ test/lit.cfg | 5 ++ test/lit.site.cfg.in | 3 + 10 files changed, 151 insertions(+), 4 deletions(-) create mode 100644 stdlib/public/Differentiation/CMakeLists.txt create mode 100644 stdlib/public/Differentiation/Differentiable.swift rename stdlib/public/{core => Differentiation}/DifferentiationSupport.swift (100%) create mode 100644 test/Differentiation/differentiable_protocol.swift diff --git a/include/swift/AST/KnownIdentifiers.def b/include/swift/AST/KnownIdentifiers.def index 409ee932a7d4e..8bdf490861aa1 100644 --- a/include/swift/AST/KnownIdentifiers.def +++ b/include/swift/AST/KnownIdentifiers.def @@ -53,6 +53,7 @@ IDENTIFIER(decode) IDENTIFIER(decodeIfPresent) IDENTIFIER(Decoder) IDENTIFIER(decoder) +IDENTIFIER_(Differentiation) IDENTIFIER(dynamicallyCall) IDENTIFIER(dynamicMember) IDENTIFIER(Element) diff --git a/include/swift/AST/KnownProtocols.def b/include/swift/AST/KnownProtocols.def index 4729f4a21b8fe..dc0d18c63a1ff 100644 --- a/include/swift/AST/KnownProtocols.def +++ b/include/swift/AST/KnownProtocols.def @@ -93,7 +93,7 @@ PROTOCOL_(DestructorSafeContainer) PROTOCOL(StringInterpolationProtocol) -PROTOCOL_(Differentiable) +PROTOCOL(Differentiable) EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByArrayLiteral, "Array", false) EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByBooleanLiteral, "BooleanLiteralType", true) diff --git a/stdlib/public/Differentiation/CMakeLists.txt b/stdlib/public/Differentiation/CMakeLists.txt new file mode 100644 index 0000000000000..13c04cf240949 --- /dev/null +++ b/stdlib/public/Differentiation/CMakeLists.txt @@ -0,0 +1,25 @@ +#===--- CMakeLists.txt - Differentiable programming support library ------===# +# +# 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 +# +#===----------------------------------------------------------------------===# + +# SWIFT_ENABLE_TENSORFLOW +# NOTE: This CMakeLists.txt file is currently used only on master branch, not +# on tensorflow branch. Instead, on tensorflow branch, the Swift source files +# in this directory are directly built as part of swiftCore: see +# stdlib/public/core/CMakeLists.txt. +# SWIFT_ENABLE_TENSORFLOW END + +add_swift_target_library(swift_Differentiation ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB + Differentiable.swift + + SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} + LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" + INSTALL_IN_COMPONENT stdlib) diff --git a/stdlib/public/Differentiation/Differentiable.swift b/stdlib/public/Differentiation/Differentiable.swift new file mode 100644 index 0000000000000..635005d750974 --- /dev/null +++ b/stdlib/public/Differentiation/Differentiable.swift @@ -0,0 +1,70 @@ +//===--- 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. This API is not stable and subject to +// change. +// +// Please see forum discussion for more information about the differentiable +// programming project: +// 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 } + // SWIFT_ENABLE_TENSORFLOW END +} + +public extension Differentiable where TangentVector == Self { + @_alwaysEmitIntoClient + mutating func move(along direction: TangentVector) { + self += direction + } +} + +// SWIFT_ENABLE_TENSORFLOW +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 END diff --git a/stdlib/public/core/DifferentiationSupport.swift b/stdlib/public/Differentiation/DifferentiationSupport.swift similarity index 100% rename from stdlib/public/core/DifferentiationSupport.swift rename to stdlib/public/Differentiation/DifferentiationSupport.swift diff --git a/stdlib/public/core/CMakeLists.txt b/stdlib/public/core/CMakeLists.txt index 4930bf184174a..03f7a0a428305 100644 --- a/stdlib/public/core/CMakeLists.txt +++ b/stdlib/public/core/CMakeLists.txt @@ -197,15 +197,16 @@ set(SWIFTLIB_ESSENTIAL_GYB_SOURCES UnsafeRawBufferPointer.swift.gyb ) +# SWIFT_ENABLE_TENSORFLOW # Compile differentiable programming sources only if enabled. set(SWIFTLIB_DIFFERENTIABLE_PROGRAMMING_SOURCES) if(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING) list(APPEND SWIFTLIB_DIFFERENTIABLE_PROGRAMMING_SOURCES - Differentiable.swift - # SWIFT_ENABLE_TENSORFLOW - DifferentiationSupport.swift) + ../Differentiation/Differentiable.swift + ../Differentiation/DifferentiationSupport.swift) message(STATUS "Differentiable programming standard library additions enabled.") endif() +# SWIFT_ENABLE_TENSORFLOW END # The complete list of sources in the core standard library. Includes # all the essential sources listed above. @@ -225,7 +226,9 @@ set(SWIFTLIB_SOURCES VarArgs.swift Zip.swift "${SWIFT_SOURCE_DIR}/stdlib/linker-support/magic-symbols-for-install-name.c" + # SWIFT_ENABLE_TENSORFLOW ${SWIFTLIB_DIFFERENTIABLE_PROGRAMMING_SOURCES} + # SWIFT_ENABLE_TENSORFLOW END ) set(SWIFTLIB_GYB_SOURCES diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c6124ace9467a..be185d0afa507 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -134,9 +134,11 @@ normalize_boolean_spelling(SWIFT_AST_VERIFIER) normalize_boolean_spelling(SWIFT_ASAN_BUILD) normalize_boolean_spelling(SWIFT_BUILD_SYNTAXPARSERLIB) normalize_boolean_spelling(SWIFT_ENABLE_SOURCEKIT_TESTS) +normalize_boolean_spelling(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING) # SWIFT_ENABLE_TENSORFLOW normalize_boolean_spelling(SWIFT_ENABLE_TENSORFLOW) normalize_boolean_spelling(SWIFT_ENABLE_TENSORFLOW_GPU) +# SWIFT_ENABLE_TENSORFLOW END is_build_type_optimized("${SWIFT_STDLIB_BUILD_TYPE}" SWIFT_OPTIMIZED) set(profdata_merge_worker @@ -317,6 +319,10 @@ _Block_release(void) { }\n") list(APPEND LIT_ARGS "--xunit-xml-output=${SWIFT_TEST_RESULTS_DIR}/lit-tests.xml") + if(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING) + list(APPEND LIT_ARGS "--param" "differentiable_programming") + endif() + foreach(test_subset ${TEST_SUBSETS}) set(directories) set(dependencies ${test_dependencies}) diff --git a/test/Differentiation/differentiable_protocol.swift b/test/Differentiation/differentiable_protocol.swift new file mode 100644 index 0000000000000..5a80784801b33 --- /dev/null +++ b/test/Differentiation/differentiable_protocol.swift @@ -0,0 +1,34 @@ +// RUN: %target-typecheck-verify-swift +// REQUIRES: differentiable_programming + +import _Differentiation + +// Test conformances. + +struct Wrapper { + var value: T +} +extension Wrapper: Equatable where T: Equatable {} +extension Wrapper: AdditiveArithmetic where T: AdditiveArithmetic { + static var zero: Self { + Wrapper(value: T.zero) + } + static func + (lhs: Self, rhs: Self) -> Self { + return Wrapper(value: lhs.value + rhs.value) + } + static func - (lhs: Self, rhs: Self) -> Self { + return Wrapper(value: lhs.value + rhs.value) + } +} +extension Wrapper: Differentiable where T: Differentiable { + typealias TangentVector = Wrapper + mutating func move(along direction: TangentVector) { + value.move(along: direction.value) + } +} + +// Test conformances for standard library types. + +extension Float: Differentiable { + public typealias TangentVector = Self +} diff --git a/test/lit.cfg b/test/lit.cfg index fd1c59fdc3803..418b0ed1d1147 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -345,6 +345,10 @@ swift_version = lit_config.params.get('swift-version', lit_config.note('Compiling with -swift-version ' + swift_version) config.swift_test_options = '-swift-version ' + swift_version +differentiable_programming = lit_config.params.get('differentiable_programming', None) +if differentiable_programming is not None: + config.available_features.add('differentiable_programming') + # SWIFT_ENABLE_TENSORFLOW swift_tensorflow_test_run_extra_options = '' swift_tensorflow_extra_options = '' @@ -363,6 +367,7 @@ else: config.substitutions.append( ('%filecheck-tensorflow-extra-options', '') ) config.substitutions.append( ('%swift-tensorflow-extra-options', swift_tensorflow_extra_options) ) config.substitutions.append( ('%swift-tensorflow-test-run-extra-options', swift_tensorflow_test_run_extra_options) ) +# SWIFT_ENABLE_TENSORFLOW END test_options = os.environ.get('SWIFT_TEST_OPTIONS') if test_options: diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in index 31a1c93ee1b72..6bc4febaf9c4c 100644 --- a/test/lit.site.cfg.in +++ b/test/lit.site.cfg.in @@ -126,6 +126,9 @@ if '@SWIFT_INCLUDE_TOOLS@' == 'TRUE': if "@SWIFT_SOURCEKIT_USE_INPROC_LIBRARY@" == "TRUE": config.available_features.add('sourcekit_use_inproc_library') +if "@SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING@" == "TRUE": + config.available_features.add('differentiable_programming') + # Let the main config do the real work. if config.test_exec_root is None: config.test_exec_root = os.path.dirname(os.path.realpath(__file__)) From 74ec8e26e4641de62dc18eb5c864f07b7fb8891f Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Tue, 5 Nov 2019 15:08:33 -0800 Subject: [PATCH 2/5] Update tests. --- test/AutoDiff/derived_differentiable.swift | 14 +++++++------- ...differentiability_witness_function_inst.sil | 8 ++++---- test/AutoDiff/differentiable_attr_silgen.swift | 4 ++-- .../differentiable_attr_type_checking.swift | 2 +- .../differentiable_func_debuginfo.swift | 2 +- ...ifferentiable_func_type_type_checking.swift | 2 +- .../differentiable_function_inst_lowered.sil | 4 ++-- .../differentiable_function_silgen.swift | 4 ++-- test/AutoDiff/differentiable_sil_attr.sil | 4 ++-- .../differentiating_attr_type_checking.swift | 6 +++--- test/AutoDiff/nonvaried_result.swift | 4 ++-- .../AutoDiff/sil_differentiability_witness.sil | 12 ++++++------ .../sil_differentiability_witness_silgen.swift | 6 +++--- test/AutoDiff/silgen_thunking/main.swift | 18 +++++++++--------- 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 ++++++------ test/Serialization/differentiable_attr.swift | 10 +++++----- test/Serialization/differentiating_attr.swift | 2 +- 21 files changed, 70 insertions(+), 70 deletions(-) diff --git a/test/AutoDiff/derived_differentiable.swift b/test/AutoDiff/derived_differentiable.swift index 7aee5ee3281e7..0491fd0a1eeb1 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 +// CHECK-AST: internal struct TangentVector : Differentiable, AdditiveArithmetic, ElementaryFunctions // 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/differentiability_witness_function_inst.sil b/test/AutoDiff/differentiability_witness_function_inst.sil index 73bc560e356cc..9255e2c5f839f 100644 --- a/test/AutoDiff/differentiability_witness_function_inst.sil +++ b/test/AutoDiff/differentiability_witness_function_inst.sil @@ -76,8 +76,8 @@ bb0: // CHECK: {{%.*}} = differentiability_witness_function [vjp] [parameters 0 1] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float // CHECK: {{%.*}} = differentiability_witness_function [jvp] [parameters 0] [results 0] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float) // CHECK: {{%.*}} = differentiability_witness_function [vjp] [parameters 0 1] [results 0 1] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float) -// CHECK: {{%.*}} = differentiability_witness_function [jvp] [parameters 0] [results 0] <τ_0_0 where τ_0_0 : _Differentiable> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 -// CHECK: {{%.*}} = differentiability_witness_function [vjp] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : AdditiveArithmetic, τ_0_0 : _Differentiable> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 +// CHECK: {{%.*}} = differentiability_witness_function [jvp] [parameters 0] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 +// CHECK: {{%.*}} = differentiability_witness_function [vjp] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : AdditiveArithmetic, τ_0_0 : Differentiable> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 // CHECK: } // CHECK-LABEL: sil @test_transpose_witnesses : $@convention(thin) () -> () { @@ -86,7 +86,7 @@ bb0: // CHECK: {{%.*}} = differentiability_witness_function [transpose] [parameters 0 1] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float // CHECK: {{%.*}} = differentiability_witness_function [transpose] [parameters 0] [results 0] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float) // CHECK: {{%.*}} = differentiability_witness_function [transpose] [parameters 0 1] [results 0 1] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float) -// CHECK: {{%.*}} = differentiability_witness_function [transpose] [parameters 0] [results 0] <τ_0_0 where τ_0_0 : _Differentiable> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 -// CHECK: {{%.*}} = differentiability_witness_function [transpose] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : _Differentiable, τ_0_0 == τ_0_0.TangentVector> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 +// CHECK: {{%.*}} = differentiability_witness_function [transpose] [parameters 0] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 +// CHECK: {{%.*}} = differentiability_witness_function [transpose] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 == τ_0_0.TangentVector> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 // CHECK: return undef : $() // CHECK: } diff --git a/test/AutoDiff/differentiable_attr_silgen.swift b/test/AutoDiff/differentiable_attr_silgen.swift index d617609ded57e..2b9f13e583f87 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 : _Differentiable & AdditiveArithmetic { +// CHECK-AST: struct DiffComputedProp : AdditiveArithmetic & Differentiable { // 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 3140fcbcca1a2..16dedde5ee6b6 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 e766f8d82d8bb..87d8b0978bfcc 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 0177876a972a0..2fa2e2c40e216 100644 --- a/test/AutoDiff/differentiable_func_type_type_checking.swift +++ b/test/AutoDiff/differentiable_func_type_type_checking.swift @@ -102,7 +102,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_inst_lowered.sil b/test/AutoDiff/differentiable_function_inst_lowered.sil index 5d06ad15ebfa9..1e8126ba86e27 100644 --- a/test/AutoDiff/differentiable_function_inst_lowered.sil +++ b/test/AutoDiff/differentiable_function_inst_lowered.sil @@ -9,14 +9,14 @@ sil_stage lowered import Swift import Builtin -struct Large : _Differentiable { +struct Large : Differentiable { @_hasStorage @noDerivative let a: Float { get } @_hasStorage @noDerivative let b: Float { get } @_hasStorage @noDerivative let c: Float { get } @_hasStorage @noDerivative let d: Float { get } @_hasStorage @noDerivative let e: Float { get } init(a: Float, b: Float, c: Float, d: Float, e: Float) - struct TangentVector : _Differentiable, AdditiveArithmetic { + struct TangentVector : Differentiable, AdditiveArithmetic { init() typealias TangentVector = Large.TangentVector static var zero: Large.TangentVector { get } diff --git a/test/AutoDiff/differentiable_function_silgen.swift b/test/AutoDiff/differentiable_function_silgen.swift index 03bc23ec7a7e8..7f32e9dae3a21 100644 --- a/test/AutoDiff/differentiable_function_silgen.swift +++ b/test/AutoDiff/differentiable_function_silgen.swift @@ -111,5 +111,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 [parameters 0] [[NEW_ORIG]] : $@callee_guaranteed (@in_guaranteed Float) -> @out Float with_derivative {[[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 c308cdf0ad79e..444ac533f0577 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 a9c15adff158b..0b34f931fce29 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/nonvaried_result.swift b/test/AutoDiff/nonvaried_result.swift index 379691f0711ba..c45134e5d3467 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_x23DifferentiationUnittest7TrackedVySfGts15_DifferentiableRz13TangentVectorsAGPQzRszlF_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_x23DifferentiationUnittest7TrackedVySfGts14DifferentiableRz13TangentVectorsAGPQzRszlF_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_xts15_DifferentiableRzlF_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_xts14DifferentiableRzlF_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/AutoDiff/sil_differentiability_witness.sil b/test/AutoDiff/sil_differentiability_witness.sil index 7257a8b606b5b..9d80756724428 100644 --- a/test/AutoDiff/sil_differentiability_witness.sil +++ b/test/AutoDiff/sil_differentiability_witness.sil @@ -66,15 +66,15 @@ bb0(%0 : $*τ_0_0, %1 : $*τ_0_0, %2 : $Float): return undef : $@callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float) } -sil_differentiability_witness hidden [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : _Differentiable> @generic : $@convention(thin) (@in_guaranteed T, Float) -> @out T { - jvp: @AD__generic__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector) - vjp: @AD__generic__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float)) +sil_differentiability_witness hidden [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @generic : $@convention(thin) (@in_guaranteed T, Float) -> @out T { + jvp: @AD__generic__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector) + vjp: @AD__generic__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float)) } // CHECK-LABEL: // differentiability witness for generic -// CHECK: sil_differentiability_witness hidden [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : _Differentiable> @generic : $@convention(thin) (@in_guaranteed T, Float) -> @out T { -// CHECK: jvp: @AD__generic__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector) -// CHECK: vjp: @AD__generic__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float)) +// CHECK: sil_differentiability_witness hidden [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @generic : $@convention(thin) (@in_guaranteed T, Float) -> @out T { +// CHECK: jvp: @AD__generic__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector) +// CHECK: vjp: @AD__generic__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float)) // CHECK: } // Test SIL differentiability witness for bodiless original function, with defined jvp/vjp. diff --git a/test/AutoDiff/sil_differentiability_witness_silgen.swift b/test/AutoDiff/sil_differentiability_witness_silgen.swift index 51a5a6494f629..a0fa9342d02ff 100644 --- a/test/AutoDiff/sil_differentiability_witness_silgen.swift +++ b/test/AutoDiff/sil_differentiability_witness_silgen.swift @@ -66,9 +66,9 @@ func generic_vjp(_ x: T, _ y: Float) -> ( } // CHECK-LABEL: // differentiability witness for generic(_:_:) -// CHECK-NEXT: sil_differentiability_witness hidden [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : _Differentiable> @$s36sil_differentiability_witness_silgen7genericyxx_SftlF : $@convention(thin) (@in_guaranteed T, Float) -> @out T { -// CHECK-NEXT: jvp: @AD__$s36sil_differentiability_witness_silgen7genericyxx_SftlF__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector) -// CHECK-NEXT: vjp: @AD__$s36sil_differentiability_witness_silgen7genericyxx_SftlF__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float)) +// CHECK-NEXT: sil_differentiability_witness hidden [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @$s36sil_differentiability_witness_silgen7genericyxx_SftlF : $@convention(thin) (@in_guaranteed T, Float) -> @out T { +// CHECK-NEXT: jvp: @AD__$s36sil_differentiability_witness_silgen7genericyxx_SftlF__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector) +// CHECK-NEXT: vjp: @AD__$s36sil_differentiability_witness_silgen7genericyxx_SftlF__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float)) // CHECK-NEXT: } public struct Foo: Differentiable { diff --git a/test/AutoDiff/silgen_thunking/main.swift b/test/AutoDiff/silgen_thunking/main.swift index cc05c4477cd68..3236b8698a907 100644 --- a/test/AutoDiff/silgen_thunking/main.swift +++ b/test/AutoDiff/silgen_thunking/main.swift @@ -19,7 +19,7 @@ func vjpNoReabstraction(_ x: T) -> (T, (T.TangentVector) -> T return (x, { $0 }) } // Find the non-`[transparent]` SILGen thunk. -// CHECK-LABEL: sil hidden [thunk] [always_inline] [ossa] @AD__$s4main15noReabstractionyxxs15_DifferentiableRzlF__vjp_src_0_wrt_0 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> @out τ_0_0.TangentVector) +// CHECK-LABEL: sil hidden [thunk] [always_inline] [ossa] @AD__$s4main15noReabstractionyxxs14DifferentiableRzlF__vjp_src_0_wrt_0 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> @out τ_0_0.TangentVector) var DerivativeSILGenThunkTests = TestSuite("DerivativeSILGenThunks") @@ -115,29 +115,29 @@ where Dummy: Differentiable & ExpressibleByIntegerLiteral { return (value, { v in (v, 2.0, 3.0) }) } -// CHECK-LABEL: sil hidden [always_inline] [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-LABEL: sil hidden [always_inline] [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: 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_ts15_DifferentiableRd__sAKRd_0_s25ExpressibleByFloatLiteralAIRQsAlJRQr0_lF +// CHECK: [[JVP:%.*]] = function_ref @$s4main21SelfReorderingGenericV23jvpThreeParameterMethodyACyxG_AC13TangentVectorVyx_GAH_AFQyd__AFQyd_0_tctqd___qd_0_ts14DifferentiableRd__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_s27ExpressibleByIntegerLiteralRzs15_DifferentiableRzsAJRd__sAJRd_0_s0gh5FloatJ0AGRQsAkHRQr_0_lTR_differential_self_reordering_thunk +// 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: [[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_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-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: 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 [always_inline] [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-LABEL: sil hidden [always_inline] [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: 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_ts15_DifferentiableRd__sAKRd_0_s25ExpressibleByFloatLiteralAIRQsAlJRQr0_lF +// CHECK: [[VJP:%.*]] = function_ref @$s4main21SelfReorderingGenericV23vjpThreeParameterMethodyACyxG_AC13TangentVectorVyx_G_AFQyd__AFQyd_0_tAHctqd___qd_0_ts14DifferentiableRd__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_s27ExpressibleByIntegerLiteralRzs15_DifferentiableRzsAJRd__sAJRd_0_s0gh5FloatJ0AGRQsAkHRQr_0_lTR_pullback_self_reordering_thunk +// 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: [[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_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-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: 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 102a439fcceb3..5d565d8fbc2b7 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 : 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:%.*]] = 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_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 : 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:%.*]] = 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_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 [parameters 0] [[FOO_FLOAT]] : $@callee_guaranteed (@in_guaranteed Float, @in_guaranteed Float) -> @out Float with_derivative {[[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 ad7ae023f5199..b1838b6da1422 100644 --- a/test/AutoDiff/transposing_attr_type_checking.swift +++ b/test/AutoDiff/transposing_attr_type_checking.swift @@ -181,7 +181,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 3cf254673def6..3caec4edfb47b 100644 --- a/test/AutoDiff/witness_table_sil.swift +++ b/test/AutoDiff/witness_table_sil.swift @@ -82,7 +82,7 @@ struct S : Proto, AdditiveArithmetic { } // 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.SSU: (Self) -> (Float, Double) -> Float : @AD__{{.*}}function1{{.*}}_jvp_SSU // CHECK-NEXT: method #Proto.function1!1.vjp.SSU: (Self) -> (Float, Double) -> Float : @AD__{{.*}}function1{{.*}}_vjp_SSU diff --git a/test/Sema/class_differentiable.swift b/test/Sema/class_differentiable.swift index 1351fba098d38..a8eaf5f5225cd 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 7e03f3fa11ab7..d2d2bd341c94c 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 {} diff --git a/test/Serialization/differentiable_attr.swift b/test/Serialization/differentiable_attr.swift index 7fbed582d96ab..b16236684b3a6 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 8293f1ab82465..ac890d33f7b21 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 } From 174a0fd738729e47dc0520084a9e595bf37e2395 Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Tue, 5 Nov 2019 17:29:15 -0800 Subject: [PATCH 3/5] Create empty `_Differentiation` module on tensorflow branch. This allows us to avoid `#if canImport(_Differentiation)` checks in upstreamed AutoDiff tests. --- stdlib/public/CMakeLists.txt | 6 +++++ stdlib/public/Differentiation/CMakeLists.txt | 11 +++++---- stdlib/public/Differentiation/Empty.swift | 3 +++ .../differentiable_protocol.swift | 24 ++++++++++++++----- 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 stdlib/public/Differentiation/Empty.swift rename test/{Differentiation => AutoDiff}/differentiable_protocol.swift (66%) diff --git a/stdlib/public/CMakeLists.txt b/stdlib/public/CMakeLists.txt index 945c141782adc..f7afacc73fde4 100644 --- a/stdlib/public/CMakeLists.txt +++ b/stdlib/public/CMakeLists.txt @@ -63,6 +63,12 @@ if(SWIFT_BUILD_STDLIB) add_subdirectory(SwiftOnoneSupport) endif() +# Build differentiable programming support library only if enabled. +if(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING AND SWIFT_BUILD_STDLIB) + message(STATUS "Building Swift differentiable programming support library.") + add_subdirectory(Differentiation) +endif() + # SWIFT_ENABLE_TENSORFLOW if(SWIFT_BUILD_STDLIB) add_subdirectory(Python) diff --git a/stdlib/public/Differentiation/CMakeLists.txt b/stdlib/public/Differentiation/CMakeLists.txt index 13c04cf240949..1aaccee69b333 100644 --- a/stdlib/public/Differentiation/CMakeLists.txt +++ b/stdlib/public/Differentiation/CMakeLists.txt @@ -11,14 +11,17 @@ #===----------------------------------------------------------------------===# # SWIFT_ENABLE_TENSORFLOW -# NOTE: This CMakeLists.txt file is currently used only on master branch, not -# on tensorflow branch. Instead, on tensorflow branch, the Swift source files +# NOTE: A non-empty `_Differentiation` module is currently created only on +# master branch, not on tensorflow branch. +# +# Instead, on tensorflow branch, the differentiation-related Swift source files # in this directory are directly built as part of swiftCore: see -# stdlib/public/core/CMakeLists.txt. +# stdlib/public/core/CMakeLists.txt. The `_Differentiation` module is created +# empty to avoid `#if canImport(_Differentiation)` guards in tests. # SWIFT_ENABLE_TENSORFLOW END add_swift_target_library(swift_Differentiation ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB - Differentiable.swift + Empty.swift SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" diff --git a/stdlib/public/Differentiation/Empty.swift b/stdlib/public/Differentiation/Empty.swift new file mode 100644 index 0000000000000..8160c5769bd86 --- /dev/null +++ b/stdlib/public/Differentiation/Empty.swift @@ -0,0 +1,3 @@ +// SWIFT_ENABLE_TENSORFLOW +// Empty Swift file, only for tensorflow branch. +// See explanation in stdlib/public/Differentiation/CMakeLists.txt. diff --git a/test/Differentiation/differentiable_protocol.swift b/test/AutoDiff/differentiable_protocol.swift similarity index 66% rename from test/Differentiation/differentiable_protocol.swift rename to test/AutoDiff/differentiable_protocol.swift index 5a80784801b33..5c7f6190ccda6 100644 --- a/test/Differentiation/differentiable_protocol.swift +++ b/test/AutoDiff/differentiable_protocol.swift @@ -5,6 +5,24 @@ import _Differentiation // Test conformances. +struct FloatWrapper { + var value: Float +} +extension FloatWrapper: AdditiveArithmetic { + static var zero: Self { + FloatWrapper(value: Float.zero) + } + static func + (lhs: Self, rhs: Self) -> Self { + return FloatWrapper(value: lhs.value + rhs.value) + } + static func - (lhs: Self, rhs: Self) -> Self { + return FloatWrapper(value: lhs.value + rhs.value) + } +} +extension FloatWrapper: Differentiable { + public typealias TangentVector = Self +} + struct Wrapper { var value: T } @@ -26,9 +44,3 @@ extension Wrapper: Differentiable where T: Differentiable { value.move(along: direction.value) } } - -// Test conformances for standard library types. - -extension Float: Differentiable { - public typealias TangentVector = Self -} From 443bbd2af6c9b5c4949027b0dea166cc47e8814b Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Wed, 6 Nov 2019 09:21:01 -0800 Subject: [PATCH 4/5] Remove unused Differentiable.swift. stdlib/public/core/Differentiable.swift has been replaced with stdlib/public/Differentiation/Differentiable.swift. --- stdlib/public/core/Differentiable.swift | 66 ------------------------- 1 file changed, 66 deletions(-) delete mode 100644 stdlib/public/core/Differentiable.swift diff --git a/stdlib/public/core/Differentiable.swift b/stdlib/public/core/Differentiable.swift deleted file mode 100644 index 95d7788f82fb1..0000000000000 --- a/stdlib/public/core/Differentiable.swift +++ /dev/null @@ -1,66 +0,0 @@ -//===--- 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 From 01ecd70a6de4643ca5cce219dcc3482b025a4d6c Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Wed, 6 Nov 2019 09:22:05 -0800 Subject: [PATCH 5/5] Work around SR-11723. Split `extension SIMD${n}: Differentiable & EuclideanDifferentiable` into two separate extensions to work around .swiftinterface error. Fixes validation-test/ParseableInterface/verify_stdlib.swift on macOS. --- stdlib/public/core/SIMDVectorTypes.swift.gyb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stdlib/public/core/SIMDVectorTypes.swift.gyb b/stdlib/public/core/SIMDVectorTypes.swift.gyb index efd88372f5b2c..4ab44db2013ea 100644 --- a/stdlib/public/core/SIMDVectorTypes.swift.gyb +++ b/stdlib/public/core/SIMDVectorTypes.swift.gyb @@ -192,12 +192,17 @@ extension SIMD${n} where Scalar: BinaryFloatingPoint { // SWIFT_ENABLE_TENSORFLOW extension SIMD${n} : AdditiveArithmetic where Scalar : FloatingPoint {} -extension SIMD${n} : Differentiable & EuclideanDifferentiable - where Scalar : EuclideanDifferentiable & BinaryFloatingPoint, +extension SIMD${n} : Differentiable + where Scalar : Differentiable & BinaryFloatingPoint, Scalar.TangentVector : BinaryFloatingPoint { public typealias TangentVector = SIMD${n} } +extension SIMD${n} : EuclideanDifferentiable + where Scalar : EuclideanDifferentiable & BinaryFloatingPoint, + Scalar.TangentVector : BinaryFloatingPoint { +} + extension SIMD${n} where Scalar : EuclideanDifferentiable & BinaryFloatingPoint, Scalar.TangentVector : BinaryFloatingPoint {