-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Re-enable debug checks in copy[_nonoverlapping]
#90012
Comments
@rustbot claim |
@oli-obk Did you intend to nominate this for lang, or for libs? |
kinda both: lang: for whether const_eval_select is ok in general |
As the assigned reviewer on #90041, and per some of the discussion in today's T-libs meeting, it feels like it would be good to have a more thorough writeup from @oli-obk or someone else on wg-const-eval about what is being asked here. In particular, "lang: for whether const_eval_select is ok in general" seems like a question best asked with a considerable amount of context lacking in this issue, perhaps even RFC-like text targeted at the T-lang audience. While I'm not on T-lang, I definitely couldn't make a decision without that document on what the requirements for its usage should be, and this currently doesn't place it into that context. It also seems like the question is better suited to a tracking issue (or perhaps ideally the PR adding it, rather than this issue), but that's a separate question. I imagine a similar level of context would be helpful on the libs side as well, but again, not on that team either. |
Thanks for the very kind way of informing me that I was writing useless comments again. I should know better, I do know better, but idk... Anyway: The
There are no plans to expose such behaviour to users at present, this is solely for libstd/libcore implementations. The intrinsic itself (from a runtime perspective) is a trivial type-safe function and completely written in safe Rust code. Its sole magicness comes from being a lang-item that const evaluation intercepts and then chooses to behave differently on. The intrinsic is documented at https://doc.rust-lang.org/nightly/std/intrinsics/fn.const_eval_select.html T-langDo we want to use such behaviour in an easily accessible way in std? Up to now we hid each such case behind a custom intrinsic for just that specific case. Now we have a generic mean to do so. Furthermore, but not relevant this issue, we could in the future, instead of implementing intrinsics like T-libsAssuming T-lang has no concerns, are you willing to stabilize some const fns that are impossible to stabilize without this. The main concern is that if we ever want to back out of |
Correction: the const eval machinery does not do pointer alignment checks (Cc #63085). But if those checks are optional anyway (as is the case here, since these used to be debug assertions), then that is okay. |
Note that this does not really save code, since Miri still needs to implement the intrinsics (it will run the run-time path, not the compile-time path). So I am not sure I like this proposal -- having the intrinsic shared between CTFE and Miri gives a lot of coverage to the Miri core engine intrinsic implementation that we would not otherwise get. These comments would probably better fit some const_eval_select tracking issue though? |
We discussed this in today's @rust-lang/lang meeting. We don't have any issue with adding these checks to Also, as general guidance, nobody in the lang team meeting felt that non-observable uses of |
@oli-obk We discussed your question in the libs meeting just now. We're happy with 'low risk' usages of this intrinsic in the standard library, even in stable functions. What counts as 'low risk' we'll leave up to @rust-lang/wg-const-eval, since y'all can best judge what the alternative would look like if |
…arts, r=oli-obk Make `core::slice::from_raw_parts[_mut]` const Responses to rust-lang#90012 seem to allow `@rust-lang/wg-const-eval` to decide on use of `const_eval_select`, so we can make `core::slice::from_raw_parts[_mut]` const :) --- This PR marks the following APIs as const: ```rust // core::slice pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T]; pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T]; ``` --- Resolves rust-lang#90011 r? `@oli-obk`
…arts, r=oli-obk Make `core::slice::from_raw_parts[_mut]` const Responses to rust-lang#90012 seem to allow ``@rust-lang/wg-const-eval`` to decide on use of `const_eval_select`, so we can make `core::slice::from_raw_parts[_mut]` const :) --- This PR marks the following APIs as const: ```rust // core::slice pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T]; pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T]; ``` --- Resolves rust-lang#90011 r? ``@oli-obk``
#79684 removed
debug_assert!
fromintrinsic::copy[_nonoverlapping]
to make itconst
:rust/library/core/src/intrinsics.rs
Lines 2045 to 2049 in 5dab47d
rust/library/core/src/intrinsics.rs
Lines 2130 to 2131 in 5dab47d
We can't do these checks at compile-time, since
is_aligned_and_not_null
, for example, involves ptr->int cast to check the alignment:rust/library/core/src/intrinsics.rs
Lines 1950 to 1952 in 5dab47d
So, as the FIXME suggests, we should enable the checks only at runtime. Recently
const_eval_select
intrinsic was implemented, it allows for exactly this use case - running different code in CTFE and runtime.cc @rust-lang/lang, @rust-lang/libs and @rust-lang/wg-const-eval (it seems like use of
const_eval_select
requires approval of all of the above teams)@rustbot label +T-lang +T-libs +A-const-eval +A-const-fn
The text was updated successfully, but these errors were encountered: