[AutoDiff] Eliminate SIL linking from differentiation. (#21973)
* [AutoDiff] Eliminate SIL linking from differentiation.
The differentiation pass no longer depends on SerializedSILLoader to link
JVP/VJP functions or witness tables.
Background: the differentiation pass guarantees that JVP/VJPs exist for
`@differentiable` functions defined in a module. If the original function
has public linkage, then JVP/VJPs also have public linkage.
If JVP/VJPs cannot be found in the current module for a given original
function, create an empty declaration to them with public external linkage.
No deserialization is necessary.
A similar technique has been used for witness methods: we emit
`witness_method` instructions rather than loading witness tables.
Defensive explicit loading of witness tables is removed.
---
This enables differentiation of functions from other modules without requiring
that JVP/VJPS be `@inlinable`. This is necessary for library development.
Joint work with @rxwei.
* Declare `declareExternalAssociatedFunction` helper function.
Address comments by @rxwei.
* Minor edits.
Address comments by @rxwei and @slavapestov.
* Clean up differentiation tasks when error occurs. Fix crasher.