Files
swift-mirror/test/AutoDiff/SILOptimizer/param_thunk_tuple.swift
Andrew Savonichev 5abb580b3d [AutoDiff] Fix return type of subset parameters thunk function (#67487)
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)
2023-07-25 11:36:00 -07:00

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
}