Hi compiler experts,
I'm working on differentiable programming in Swift and I'd like advice on implementing robust mangling for compiler-generated derivative functions/thunks. These mangled names will eventually be used in SIL differentiability witness tables.
There are a few components to mangle:
- Name of the original SIL function: a
StringRef
. - Derivative function kind:
jvp
,differential
, etc. - Differentiable parameter indices: a bit vector. (e.g.
wrt_0_1
) - Differentiation result indices: a bit vector. (e.g.
src_0
) - Generic requirements (optional):
ArrayRef<Requirement>
.
Currently, we've been using a hacky scheme, but we'd like to make the scheme robust and implement it in the mangler/demangler.
I took a look at Mangling.rst and ASTMangler
but I'm not sure how to start. Could anyone please help me get started or point to related existing code? Any advice would be appreciated!