[AutoDiff] DifferentiabilityWitnessFunctionInst stores pointer to witness (#27919)
We want the `DifferentiabilityWitnessFunctionInst` to store a pointer to the witness because this makes the instruction data structure smaller and simpler, and makes misuse (e.g. referencing a witness that's not declared in the SIL module) harder.
This PR mostly preserves the existing SIL syntax & rules. The changes are:
* `sil_differentiability_witness` declarations are now required to come before `differentiability_witness_function` instructions that reference them, so that we don't have to add "forward declaration" logic for them.
* `sil_differentiability_witness` constraints now look like `<τ_0_0 where τ_0_0 : _Differentiable>` instead of `[where T : _Differentiable]`. This allows me to share parsing logic between the `sil_differentiability_witness` constraints and the `differentiability_witness_function`, which simplifies the code and also avoids a problem [1].
This PR changes the `DifferentiabilityWitnessFunctionInst` serialization format to store the witness mangled name rather than the original function name plus indices and generic constraints.
Detailed outline of changes:
* Datastructure & utility changes:
* `DifferentiabilityWitnessFunctionInst` now contains a `SILDifferentiabilityWitness*` instead of a pointer to original function, indices, and generic signature. (credit to @dan-zheng, I just copied these changes from his commit)
* Added functions in `SILModule` for looking up `SILDifferentiabilityWitness*` because parsing and deserialization need to find the right `SILDifferentiabilityWitness*` to put in the inst.
* SIL printing changes:
* Print `sil_differentiability_witness` declarations before function declarations
* Print `<T where T ...>` instead of `[where T ...]` in `sil_differentiability_witness` declarations.
* SIL parsing changes:
* Factor out a common `parseSILDifferentiabilityWitnessConfigAndFunction`, and use this for parsing both `sil_differentiability_witness` and `differentiability_witness_function`. This simplifies the code and avoids the problem [1].
* When parsing a `differentiability_witness_function`, look for the `SILDifferentiabilityWitness*` in the module.
* Bugfix in ParseStmt so that it can parse `sil_differentiability_witness` declarations that come at the beginning of the file.
* Serialization changes:
* Deleted `SILInstDifferentiabilityWitnessFunctionLayout` from the serialization format, because the `DifferentiabilityWitnessFunctionInst` now fits into the `SILOneOperandLayout`.
* Changed serialization to serialize `DifferentiabilityWitnessFunctionInst` a `SILOneOperandLayout` with the mangled witness name.
* Changed deserialization to deserialize `DifferentiabilityWitnessFunctionInst` by reading the name and deserializing the corresponding witness.
* Changed deserialization to treat declaration-only witnesses as "fully deserialized". Otherwise it tries to deserialize them twice and the module doesn't like having duplicate witnesses.
[1] The avoided problem: The previous code for parsing `sil_differentiability_witness` constraints of the form `[where T : _Differentiable]` fails to handle the case where the original function is declaration-only, because the code assumes that there is a generic environment, and declaration-only functions do not have a generic environment. Rather than fixing this code, it seemed better to delete it and use the existing code that parses `differentiability_witness_function` constraints, which does not suffer from this problem.