swift
e0789daf - Add builtin functions that construct a `@differentiable` or `@differentiable(linear)` function from component functons. (#28467)

Commit
5 years ago
Add builtin functions that construct a `@differentiable` or `@differentiable(linear)` function from component functons. (#28467) Add builtin functions that construct a `@differentiable` or `@differentiable(linear)` function from component functons. * `Builtin.differentiableFunction_*` Takes an original function, a JVP function and a VJP function and returns a `@differentiable` function. Pseudo-declaration: ```swift func differentiableFunction_arity{arity}[_throws]?{throws}<T...{arity}, U>( _ original: __owned @escaping (T...{arity}) {throws}? -> U, _ jvp: __owned @escaping (T...{arity}) {throws}? -> (value: U, differential: (T.TangentVector...{arity}) -> U.TangentVector), _ vjp: __owned @escaping (T...{arity}) {throws}? -> (value: U, pullback: (U.TangentVector) -> (T.TangentVector...{arity})) ) -> @differentiable (T...{arity}) {throws}? -> U where T...{arity} : Differentiable, U : Differentiable ``` * `Builtin.linearFunction_*` Takes an original function and a transpose function and returns a `@differentiable` function. Pseudo-declaration: ```swift func linearFunction_arity{arity}[_throws]?{throws}<T...{arity}, U>( _ original: __owned @escaping (T...{arity}) {throws}? -> U, _ transpose: __owned @escaping (U.TangentVector) {throws}? -> (T.TangentVector...{arity}) ) -> @differentiable (T...{arity}) {throws}? -> U where T...{arity} : Differentiable & AdditiveArithmetic, U : Differentiable & AdditiveArithmetic ``` These builtins will be used to write unit tests for `@differentiable` and `@differentiable(linear)` function types that do not necessarily depend on the differentiation transform. TODO: - SR-11848: For robustness, we need SIL FileCheck tests for all AD builtins. These have not been added for `Builtin.autodiffApply*`, so I'm leaving this as a future task. - SR-11847: Update `differentiableFunction(from:)` to use `Builtin.differentiableFunction*` in its implementation. - SR-11849: Disallow non-top-level derivative registration. Resolves SR-11846.
Author
Parents
  • include/swift/AST
    • File
      AutoDiff.h
    • File
      Builtins.def
    • File
      KnownIdentifiers.def
  • lib
    • AST
      • File
        AutoDiff.cpp
      • File
        Builtins.cpp
    • SIL
      • File
        SILModule.cpp
    • SILGen
      • File
        SILGenBuiltin.cpp
    • SILOptimizer/Mandatory
      • File
        Differentiation.cpp
  • test/AutoDiff
    • File
      builtin_differentiable_function_constructor.swift