-
Notifications
You must be signed in to change notification settings - Fork 13k
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
CTFE: select different code for compile-time vs run-time #80489
Comments
Some of the discussion from #79684
|
This feature should be mostly for cases where the logic is equivalent but run-time still has different code, e.g. using SIMD. And it can be used for debug assertions that should only be run at runtime (that was what triggered the discussion in the previous PR).
Hm, wouldn't it be better if the CTFE logic also existed as Rust code, instead of having to implement it manually in the interpreter? |
That's not possible in some cases. Take |
In particular, if the CTFE version cannot be implemented in Rust, we can easily add an intrinsic there -- no need to have another "selection" mechanism. |
If we make it an intrinsic, we can't write the runtime version in Rust. Or am I misunderstanding what you mean by another selection mechanism? I want us to have the following schemes in the end:
|
We make the const part an intrinsic. Like const_select!(runtime_code_in_rust(), ctfe_intrinsic()); So I think the underlying primitive should be one that simply takes Rust/MIR bodies both for the runtime and CTFE versions. That is most expressive and allows encoding the other cases. |
Closing in favor of #124625. |
During #79684 I bumped into a problem that led @oli-obk and me on to a discussion. I am still not quite sure about what we discussed(the smart ideas were not mine). Please correct me on the things I have gotten wrong and I will update this post. I believe the gist of it is:
Some functions, like
align_offset
contains code that is impossible to evaluate in a const context, but the functionality does exist in miri. One potential solution for makingalign_offset
a const fn would be to add an attribute, say#[rustc_const_intrinsic]
that would make the function look like aconst fn
from the outside but would still be allowed to contain non-const code. When the function is called during runtime the contents of the function is executed as expected. However if called in a const context, the const evaluator would catch the call and instead invoke its special logic.The text was updated successfully, but these errors were encountered: