Files
swift-mirror/test/AutoDiff/compiler_crashers_fixed/sr14290-missing-debug-scopes-in-pullback-trampoline.swift
Pavel Prokofyev 841618ea70 [AutoDiff] Use correct debug scope for pullback trampoline block.
Fixes:
[[SR-14290]: SIL verification fails when differentiating a function of [[Double]]](rdar://74876596)
[[SR-14298]: [AutoDiff] SIL verification failed: non-contiguous lexical scope at -Onone](rdar://75032457)
2021-04-20 12:10:54 -07:00

46 lines
1.3 KiB
Swift

// RUN: %target-build-swift %s
// RUN: %target-swift-frontend -c -g -Xllvm -verify-di-holes=true %s
// rdar://74876596 ([SR-14290]: SIL verification fails when differentiating a function of [[Double]])
import _Differentiation
let values: [[Double]] = [[0, 0], [0, 0]]
let const = 1.12345
let result = add(const, to: values)
@differentiable(reverse)
func add(_ const: Double, to values: [[Double]]) -> [[Double]] {
var result = values
for i in withoutDerivative(at: values.indices) {
for j in withoutDerivative(at: values.indices) {
result.updated(at: i, j, with: values[i][j] + const)
}
}
return result
}
extension Array where Element == [Double] {
@differentiable(reverse)
mutating func updated(at i: Int, _ j: Int, with newValue: Double) {
self[i][j] = newValue
}
@derivative(of: updated)
mutating func vjpUpdated(at i: Int, _ j: Int, with newValue: Double)
-> (value: Void, pullback: (inout TangentVector) -> (Double.TangentVector)) {
self.updated(at: i, j, with: newValue)
func pullback(dSelf: inout TangentVector) -> (Double.TangentVector) {
let dElement = dSelf[i][j]
dSelf.base[i].base[j] = 0
return dElement
}
let value: Void = ()
return (value, pullback)
}
}