Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

const_allocate intrinsic: what should it do at runtime? #93935

Open
RalfJung opened this issue Feb 12, 2022 · 5 comments
Open

const_allocate intrinsic: what should it do at runtime? #93935

RalfJung opened this issue Feb 12, 2022 · 5 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...)

Comments

@RalfJung
Copy link
Member

We have a const_allocate intrinsic to perform heap allocations during CTFE. It should not be called during runtime, but we do have to generate some code for that case. Currently, we make it return NULL.

I think calling this at runtime is always an error, so we shouldn't just silently continue execution. We should either panic or abort. (The codegen backend already knows how to do both of these things, so this should not be very hard to implement.)

@rust-lang/wg-const-eval what do you think?

@RalfJung RalfJung added the A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) label Feb 12, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Feb 12, 2022

Seems reasonable. I am still hoping we can just not generate code for these intrinsics at all, but considering the extra effort that requires, we can just turn them into aborts and thus force everyone to use const_eval_select and handle the runtime case explicitly.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 12, 2022

Maybe i'll just take this opportunity and implement #93145 instead, so backends just get MIR instead of having to hand-roll some logic for each backend

@RalfJung
Copy link
Member Author

We already have a MIR pass that lowers some intrinsics away, you might just add these there.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 12, 2022

That happens for CTFE MIR, too, so that's not ideal 😆. We'd need an additional pass just for optimized mir.

@fee1-dead
Copy link
Member

That happens for CTFE MIR, too, so that's not ideal 😆. We'd need an additional pass just for optimized mir.

I think we should do this. const_eval_select would work in a MIR pass as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...)
Projects
None yet
Development

No branches or pull requests

3 participants