Allow generic foreign functions.

Generic extern functions written in Rust have their names mangled, as well as their internal clownshoe __rust_abi functions. This allows e.g. specific monomorphizations of these functions to be used as callbacks.

Closes #12502.
Add new tests for extern and foreign fns and name mangling.