These have been implemented in Mooncake and previously adopted for Enzyme. The code can be reused for ADTests. - https://github.com/EnzymeAD/Enzyme.jl/pull/1819 - https://github.com/EnzymeAD/Enzyme.jl/pull/2037