So I find myself occasionally wanting staged compilation -- does anyone know of a system that provides that for Rust?
Can you describe what that is in broad strokes?
Sorry, I should have filled in. Staged compilation, aka https://en.wikipedia.org/wiki/Multi-stage_programming, is a technique where some part of the code is itself generated by code. In this case, I'm actually hoping for the "partial evaluation" aspect of it, where you can have expensive computations with relatively compact outputs be computed at compile-time and then inserted into the final executable. May have overlaps with #t-compiler/const-eval.
@JP Sugarbroad There's an ongoing effort to making const eval more powerful. What kind of things do you have in mind?
@Oli I don't think const eval, with the current approach, can ever be as good as staged compilation. See https://anydsl.github.io/Impala.html for a nice example of what staged compilation can do (even with a Rust-inspired syntax^^)
oh... I misunderstood what was desired
staged compilation seems trivial as a MirPass
it's essentially just const propagation
I thought const stuff couldn't allocate?
just like the compiler cannot do partial evaluation, it cannot allocate inside constants. That's not an inherent show stopper though. https://github.com/solson/miri can do heap allocations just fine
once we have figured out https://github.com/rust-rfcs/const-eval/pull/8 (which will allow writing
Drop impls), we can think about allocations in constants
we could technically do so even before that, but it seems needlessly complex to do so
@Oli Nice! Okay, I'll keep an eye out for that. Full staged compilation does require the ability to execute pretty much arbitrary code, though, and then reconstruct the resulting value in the final object.
The other thing to note is that staged compilation usually doesn't require tagging like const eval does. Is there any plan to infer const-ness?
@Oli I have no idea how you think staged compilation can be trivial^^
its const propagation on steroids
needs symbolic miri at the least
or rather, something symbolic.
it doesnt need tons of other stuff miri does
I don't understand... why can't you just copy the MIR of a function, remove an argument, and initialize the corresponding variable with the constant?
staged compilation is about guaranteed compile-time unrolling
like, if you have a staged loop, if it is annotated as such, it should be guaranteed to be unrolled
oh, guarantees, well yea :D that's a different story