mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The patch resolves #67402. When the original function has a tuple result type, we should append thunkedLinearMap as the last element of the tuple to match the function declaration. Before this patch, the compiler used to wrap the original result tuple and thunkedLinearMap into another tuple, and caused the verifier error. Before the patch: return %{{.*}} : $((Float, Double), @callee_guaranteed (Float) -> X.TangentVector) After the patch: return %{{.*}} : $(Float, Double, @callee_guaranteed (Float) -> X.TangentVector)
34 lines
1.1 KiB
Swift
34 lines
1.1 KiB
Swift
// RUN: %target-swift-frontend -emit-sil %s | %FileCheck %s
|
|
|
|
// Verify the result type of a subset parameters thunk matches the declaration:
|
|
//
|
|
// CHECK: // autodiff subset parameters thunk for forward-mode derivative from f(x:)
|
|
// CHECK-NEXT: sil shared [transparent] [thunk] @$s17param_thunk_tuple{{.*}} : $@convention(thin) (X)
|
|
// CHECK-SAME: -> (Float, Double, @owned @callee_guaranteed (X.TangentVector) -> Float)
|
|
// CHECK: return
|
|
// CHECK-SAME: %{{.*}} : $(Float, Double, @callee_guaranteed (X.TangentVector) -> Float)
|
|
//
|
|
// CHECK: // autodiff subset parameters thunk for reverse-mode derivative from f(x:)
|
|
// CHECK-NEXT: sil shared [transparent] [thunk] @$s17param_thunk_tuple{{.*}} : $@convention(thin) (X)
|
|
// CHECK-SAME: -> (Float, Double, @owned @callee_guaranteed (Float) -> X.TangentVector)
|
|
// CHECK: return
|
|
// CHECK-SAME: %{{.*}} : $(Float, Double, @callee_guaranteed (Float) -> X.TangentVector)
|
|
|
|
import _Differentiation
|
|
|
|
struct X: Differentiable {
|
|
var a: Float
|
|
var b: Double
|
|
}
|
|
|
|
@differentiable(reverse)
|
|
func f(x: X) -> (Float, Double) {
|
|
(x.a, x.b)
|
|
}
|
|
|
|
@differentiable(reverse)
|
|
func g1(x: X) -> Float {
|
|
f(x: x).0
|
|
}
|
|
|