Conversation

Mind is getting blown by multi-stage programming! Does anyone know of any simple examples of it being used as a way of doing offline partial evaluation in compilation? Most of the stuff I see is for run-time code generation. 🤔
3
4
"MetaOCaml is not very suitable for writing offline generators because of CSP [Cross-Stage Persistence]. Our type system introduces residualizable code types to solve the problem."
1
Haven't yet understood this claim, and the pros and cons. Would also really love to see some example implementations of compilers that do offline partial evaluation using this kind of thing (but that might be hoping for too much).
1
1
There is a difference between partial evaluation and supercompilation but I always forget what it is. There was a bunch of supercompilation-related work on GHC a few years back but I assume you're already familiar with that as well. :)
1
1
So the issue is that if you're generating code and the generated code references an arbitrary object on the heap of the code-generator, either (a) the generated code must run in the address space of the generator or (b) you need to know how to serialize that object into syntax.
1
1
I'm kinda wondering, if the code generator is a normal AOT compiler, whether it couldn't "just" dump the memory for such objects almost-as-is into the generated binary as static data. It'd still need to "know where the pointers are", at least, for to fix them up...
1
Maybe there's cases where the graph-closure of the object contains things for which this really is infeasible... like function pointers into the compiler's own code? I dunno. I also suppose this wouldn't be on good terms with cross-compilation. :|
1