Files
swift-mirror/test/AutoDiff/Serialization/differentiable_function.swift
marcrasi eae4c5eece [AutoDiff upstream] @differentiable function type sema (#30648)
Add type checking for `@differentiable` function types:
- Check that parameters and results conform to `Differentiable`.
- Implicitly conform parameters and results whose types are generic parameters
  to `Differentiable`.
- Upstream most of the differentiable_func_type_type_checking.swift test from
  `tensorflow` branch. A few function conversion tests have not been added
   because they depend on the `@differentiable` function conversion pipeline.

Diagnose gracefully when the `Differentiable` protocol is unavailable because
`_Differentiation` has not been imported.

Resolves TF-823 and TF-1219.
2020-03-26 23:28:02 -07:00

18 lines
861 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -emit-module -parse-as-library -enable-experimental-differentiable-programming -o %t
// RUN: llvm-bcanalyzer %t/differentiable_function.swiftmodule | %FileCheck %s -check-prefix=BCANALYZER
// RUN: %target-sil-opt -disable-sil-linking -enable-sil-verify-all %t/differentiable_function.swiftmodule -enable-experimental-differentiable-programming -o - | %FileCheck %s
// BCANALYZER-NOT: UnknownCode
import _Differentiation
func a(_ f: @differentiable (Float) -> Float) {}
// CHECK: func a(_ f: @differentiable (Float) -> Float)
func b(_ f: @differentiable(linear) (Float) -> Float) {}
// CHECK: func b(_ f: @differentiable(linear) (Float) -> Float)
func c(_ f: @differentiable (Float, @noDerivative Float) -> Float) {}
// CHECK: func c(_ f: @differentiable (Float, @noDerivative Float) -> Float)