Monomorphize generic functions · Issue #1736 · rust-lang/rust (original) (raw)

There is consensus that we should at least experiment with generating single-type instances of generic functions. So if you have map<T, U> and you call it on <int, int>, the compiler can compile a version specifically for those types, and if you then call it on <@int, (float, float)>, it can generate another version.

We can reuse generated functions for similar types. For example, since generics can't look 'into' types, types like int and uint could be passed to the same version of a function without problems. We also store tydescs in boxes now, so a single version could be used for all @ types, and simply look inside the box if it needs to call free or compare glue on them.

This is related to the project of cross-crate inlining. To monomorphize a function, you also need some representation of its code.