Based on my very limited understanding of ppx, I don’t think it’s possible to perform function inlining or apply standard compiler simplifications using a ppx rewriter.
Is my understanding correct? Would this be possible with a compiler plugin?
You can get some manual control over inlining using flambda.
I don’t know enough about ppx to say, but inlining seems like it should be possible.
You are right; ppx is a purely syntactic pass over the parsetree before it has been typechecked so it does not easily have access to the type of information that you would need in order to perform this kind of transformation.
There is no officially supported compiler plugin API, so it is not clear what a “compiler plugin” would be. Of course you can always use
compiler-libs to create a custom compiler driver to instrument the compiler in different ways but, depending on what you want to do, doing this will require some (or a lot) of knowledge about the compiler internals, so it may not be as straightforward as it sounds.