Files
swift-mirror/test/AutoDiff/compiler_crashers_fixed/sr15205-diff-capture.swift
Anton Korobeynikov 91458b4890 Fix several issues related to captured arguments:
- Introduce a workaround while dealing with getLoweredParameterIndices() results:
    it operates on AST and therefore does not take into account captured arguments
    which are "on side" on AST and explicit in SIL
  - Ensure captured arguments (@inout_aliased) are handled in a same way as ordinary
    @inout arguments while generating a pullback type

Fixes SR-15205
2022-02-17 00:04:12 +03:00

37 lines
1.0 KiB
Swift

// RUN: %target-swift-frontend -emit-sil -verify %s
// SR-15205: fix assertions related to captured arguments, they should
// treated as constants
import _Differentiation
func outerFunc(value: inout Float) -> (Float, (Float) -> (Float, Float)) {
@differentiable(reverse, wrt: param)
func innerFunc(param: Float, other: Float) -> Float {
value += param * other
return value * param * 2.0
}
let valAndPullback = valueWithPullback(at: value, 2.0, of: innerFunc)
return (value + valAndPullback.value, valAndPullback.pullback)
}
func outerFunc2(value: inout Float) -> (Float, (Float) -> Float) {
@differentiable(reverse, wrt: param)
func innerFunc(param: Float, other: Float) -> Float {
value += param * other
return value * param * 2.0
}
@differentiable(reverse)
func curriedFunc(param: Float) -> Float {
return innerFunc(param: param, other: 3.0)
}
let valAndPullback = valueWithPullback(at: value, of: curriedFunc)
return (value + valAndPullback.value, valAndPullback.pullback)
}