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. 🤔
Conversation
There's this paper about static staging: cs.utexas.edu/users/mckinley
That said, it isn't clear to me what the difference is between typed macros and static staging -- syntactic flexibility vs rigidity?
2
1
Replying to
I think there is some correspondence, but I don't know. The annoying thing about full spectrum dependent types is that you lose the phase information that is present in traditional languages, so it's hard to compile things like type parameters and constant parameters efficiently.
Replying to
Languages like D, C++ and Zig, Rust etc. get around this with constexpr and monomorphized type parameters, but it always seems rather tacked-on, and you can't seem to get the full expressiveness of dependent types then if you ever need that.
2
Ah, I think I see what you're saying. Have some partial evaluation and do specialization at run time based on the types passed. Is that right? A JIT would solve the problem, no? Is the question about partial evaluation to reduce JITting overhead? Not sure where staging comes in.
1
Show replies
Yeah, I think you need to use something other than the 'use count'. I believe McBride was talking about this in his presentation on 'Worldly Type Systems' - it's taken a long time for me to realise that he was talking about multi-stage programming here:
2
1
Show replies


