|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-emit-sil -Xllvm -debug-only=differentiation -emit-module -module-name M -emit-module-path %t/M.swiftmodule 2>&1 %s | %FileCheck %s |
| 3 | + |
| 4 | +// The original function Tensor.subscriptIndexPath() is not marked as @differentiable. As a result, no explicit differentiable witness is generated for it. |
| 5 | +// However, the witness is generated as a side effect of providing a derivative via @derivative(of: subscriptIndexPath) on _vjpSubscriptIndexPath. |
| 6 | +// Since _vjpSubscriptIndexPath is not emitted when -emit-module is used, we need to ensure we still generate a wittness. |
| 7 | + |
| 8 | +import _Differentiation |
| 9 | + |
| 10 | +// CHECK-LABEL: differentiability witness for Tensor.subscriptIndexPath() |
| 11 | +// CHECK: sil_differentiability_witness [serialized] [reverse] [parameters 0] [results 0] @$s1M6TensorV18subscriptIndexPathACyF : $@convention(method) (Tensor) -> Tensor { |
| 12 | +// CHECK: vjp: @$s1M6TensorV18subscriptIndexPathACyFTJrSpSr : $@convention(method) (Tensor) -> (Tensor, @owned @callee_guaranteed (Tensor) -> Tensor) |
| 13 | + |
| 14 | +// CHECK-LABEL: reverse-mode derivative of Tensor.subscriptIndexPath() |
| 15 | +// CHECK: sil [thunk] [always_inline] [ossa] @$s1M6TensorV18subscriptIndexPathACyFTJrSpSr : $@convention(method) (Tensor) -> (Tensor, @owned @callee_guaranteed (Tensor) -> Tensor) { |
| 16 | +// CHECK: function_ref Tensor._vjpSubscriptIndexPath() |
| 17 | +// CHECK: function_ref @$s1M6TensorV22_vjpSubscriptIndexPathAC5value_A2Cc8pullbacktyF : $@convention(method) (Tensor) -> (Tensor, @owned @callee_guaranteed (Tensor) -> Tensor) |
| 18 | + |
| 19 | +public struct Tensor: Differentiable & AdditiveArithmetic { |
| 20 | + @inlinable |
| 21 | + func subscriptIndexPath() -> Tensor { |
| 22 | + fatalError() |
| 23 | + } |
| 24 | + |
| 25 | + @inlinable |
| 26 | + @differentiable(reverse, wrt: self) |
| 27 | + func subscriptRanges() -> Tensor { |
| 28 | + subscriptIndexPath() |
| 29 | + } |
| 30 | + |
| 31 | + @usableFromInline |
| 32 | + @derivative(of: subscriptIndexPath) |
| 33 | + func _vjpSubscriptIndexPath() -> ( |
| 34 | + value: Tensor, pullback: (Tensor) -> Tensor |
| 35 | + ) { |
| 36 | + fatalError() |
| 37 | + } |
| 38 | +} |
0 commit comments