mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
For some values we cannot compute types for differentiation (for example, tangent vector type), so it is better to diagnose them earlier. Otherwise we hit assertions when generating code for such invalid values. The LIT test is a reduced reproducer from the issue #66996. Before the patch the compiler crashed while trying to get a tangent vector type for the following value (partial_apply): %54 = function_ref @$s4null1o2ffSdAA1FV_tFSdyKXEfu0_ : $@convention(thin) @substituted <τ_0_0> (@inout_aliasable Double) -> (@out τ_0_0, @error any Error) for <Double> %55 = partial_apply [callee_guaranteed] %54(%2) : $@convention(thin) @substituted <τ_0_0> (@inout_aliasable Double) -> (@out τ_0_0, @error any Error) for <Double> Now we emit a diagnostic instead. The patch resolves issues #66996 and #63331
21 lines
548 B
Swift
21 lines
548 B
Swift
// RUN: %target-swift-frontend -emit-sil -verify %s
|
|
|
|
import _Differentiation
|
|
|
|
// expected-error @+1 {{function is not differentiable}}
|
|
@differentiable(reverse)
|
|
// expected-note @+1 {{when differentiating this function definition}}
|
|
func o(ff: F) -> Double {
|
|
var y = ff.i?.first { $0 >= 0.0 } ?? 0.0
|
|
while 0.0 < y {
|
|
// expected-note @+1 {{expression is not differentiable}}
|
|
y = ff.g() ?? y
|
|
}
|
|
return y
|
|
}
|
|
|
|
public struct F: Differentiable {
|
|
@noDerivative var i: [Double]? {return nil}
|
|
func g() -> Double? {return nil}
|
|
}
|