Stream: general

Topic: staged compilation

JP Sugarbroad (Nov 22 2018 at 19:01, on Zulip):

So I find myself occasionally wanting staged compilation -- does anyone know of a system that provides that for Rust?

Jake Goulding (Nov 22 2018 at 21:42, on Zulip):

Can you describe what that is in broad strokes?

JP Sugarbroad (Nov 22 2018 at 22:01, on Zulip):

Sorry, I should have filled in. Staged compilation, aka, 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.

centril (Nov 23 2018 at 07:07, on Zulip):

@RalfJ :wave:

oli (Nov 23 2018 at 09:50, on Zulip):

@JP Sugarbroad There's an ongoing effort to making const eval more powerful. What kind of things do you have in mind?

RalfJ (Nov 23 2018 at 09:56, on Zulip):

@Oli I don't think const eval, with the current approach, can ever be as good as staged compilation. See for a nice example of what staged compilation can do (even with a Rust-inspired syntax^^)

oli (Nov 23 2018 at 13:19, on Zulip):

oh... I misunderstood what was desired

oli (Nov 23 2018 at 13:20, on Zulip):

staged compilation seems trivial as a MirPass

oli (Nov 23 2018 at 13:20, on Zulip):

it's essentially just const propagation

JP Sugarbroad (Nov 23 2018 at 16:53, on Zulip):

I thought const stuff couldn't allocate?

oli (Nov 23 2018 at 16:56, on Zulip):

just like the compiler cannot do partial evaluation, it cannot allocate inside constants. That's not an inherent show stopper though. can do heap allocations just fine

oli (Nov 23 2018 at 16:57, on Zulip):

once we have figured out (which will allow writing const Drop impls), we can think about allocations in constants

oli (Nov 23 2018 at 16:57, on Zulip):

we could technically do so even before that, but it seems needlessly complex to do so

JP Sugarbroad (Nov 23 2018 at 19:05, on Zulip):

@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.

JP Sugarbroad (Nov 23 2018 at 19:06, on Zulip):

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?

RalfJ (Nov 23 2018 at 21:58, on Zulip):

@Oli I have no idea how you think staged compilation can be trivial^^

RalfJ (Nov 23 2018 at 21:58, on Zulip):

its const propagation on steroids

RalfJ (Nov 23 2018 at 21:59, on Zulip):

needs symbolic miri at the least

RalfJ (Nov 23 2018 at 22:00, on Zulip):

or rather, something symbolic.

RalfJ (Nov 23 2018 at 22:00, on Zulip):

it doesnt need tons of other stuff miri does

oli (Nov 24 2018 at 10:38, on Zulip):

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?

RalfJ (Nov 24 2018 at 10:50, on Zulip):

staged compilation is about guaranteed compile-time unrolling

RalfJ (Nov 24 2018 at 10:50, on Zulip):

like, if you have a staged loop, if it is annotated as such, it should be guaranteed to be unrolled

oli (Nov 24 2018 at 11:06, on Zulip):

oh, guarantees, well yea :D that's a different story

Last update: Jul 16 2020 at 15:10UTC