anza-xyz / move

Move compiler targeting llvm supported backends
https://discord.gg/wFgfjG9J
Apache License 2.0
108 stars 34 forks source link

Implement the simplest generic function #60

Closed brson closed 1 year ago

brson commented 1 year ago

Probably we want to monomorphise generics.

It would be nice to do this in two passes: before translating functions discover all the instantiations of generic functions, do type substitutions, emit their declarations and cache them in a way the callers can retrieve; then translate the type-substituted functions along with all the non-generic functions.

If it's not possible to discover all the instances ahead of time, then we can emit and cache them at the same time as emitting their callers.

Just get the most basic thing working as a proof of concept. I don't know the best patterns for monomorphization so it may help to study the rust compiler for a while to see how they are doing it now.

brson commented 1 year ago

I marked this help wanted, but it's not easy.

ksolana commented 1 year ago

It makes sense to monomorphize on the primitive types in the first iteration and then take it from there. The general case of instantiating on aggregate types may become tricky so that can be postponed to later stages.

References:

We could also do it the C++ way of name mangling the functions based on operators and have a final 'link' step to resolve the symbols.