I’ve been trying to map out my options for compile time metaprogramming and so far I could not find a supported way of plugging into the compilation with no limitations on the code that is generated.
As far as I can see, type providers allow me to supply types based on very simple input, such as a string, pointing at a schema etc and I wouldn’t be able to generate all constructs of the language such as generic types.
Options for code generation all seem to focus on parallel use of the f# compiler, as in, invoke compiler services, read some metadata from sources, then generate code, but I cannot see a well defined step in the compiling process to plug this behaviour in; similar to what compile time annotation processing supported by Java. I’d have to write a tool and write that in parallel to my code base, which is clunky.
The only project that seems to mention what I have in mind is this one: https://github.com/pezipink/MixinProvider
Its definition pretty much sums up what I’m describing:
The Mixin Provider is essentially a very powerful code generator - it evaluates an F# metaprogram at compile time, and compiles the resulting program to an assembly - or it can inject code into existing F# source files within your projects by using a combination of special dummy injection functions and a metaprogram.
but it is subject to same limitation that I seem to have come across: no point in the compiler’s various phases to invoke a mechanism to do code generation.
Am I missing an approach I could explore? I’d appreciate your confirmation about this indeed being the state of things. Very keen to hear alternatives that I may be missing.
All the best