[SR-9849] LoadableByAddress fails to handle functions that return a closure in a tuple · Issue #52260 · apple/swift · GitHub illustrates a problem that we ran into while working on figuring out how the autodiff feature inter-operates with this LoadableByAddress IRGen pass.
My understanding of this pass is that it maps function types to pass large values by address.
For context, a differentiable function (original) also binds additional associated functions (like vjp) that can be extracted at runtime.
original: (T) -> R
vjp: (T) -> (R, (R.CotangentVector) -> T.CotangentVector)
Thus far, we've been updating the autodiff functions identically whenever the original function goes through some transformation (like abstraction thunks). However, because the types do not match, original and vjp can be transformed differently in the LoadableByAddress IRGen pass. This leads to our tensorflow branch version of LoadableByAddress to try and cast between functions that pass via different conventions.
Any thoughts on what would be the proper resolution to this would be appreciated.