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
Make size_of_val a const fn (and stabilize it as such) #46571
Comments
I believe this is currently blocked on miri becoming the primary/only CTFE provider. |
I think this is possible without miri const eval, but it would be wasteful to implement in old ctfe |
Yeah I consider "the people who would implement/review this are able but unwilling" to be a blocker |
Where can that status be followed? If such a transition were quite a while out, would it be possible to support with only miri and/or feature flag of some kind? |
Miri is here. So it's mostly a matter of opening a PR by copying over the code from https://github.com/solson/miri/blob/master/miri/intrinsic.rs#L501 |
i'm implementing this |
Making these functions const would greatly interfere with custom DST. Custom DSTs will need the user to implement some custom functions to derive the size. Thus, semantically, making size_of_val const would mean custom DST now need to depend on the postponed rust-lang/rfcs#2337. Implementation-wise, if we want to support size_of_val for a thin CStr, we would need a const strlen, which means Miri would need to support some selected FFI functions (outside wasm), and also need to perform loop and dereference raw pointers (for wasm target). Therefore I'm 👎 to making size_of_val and align_of_val const until we have a concrete plan on custom DST. I don't mind having a |
Why isn't it possible to implement strlen in Rust instead? |
This is done for wasm, but as noted, that would require loops, which have an RFC, but it's not been accepted yet: rust-lang/rfcs#2344 and additionally requires branches, which have an accepted RFC, but no implementation yet |
It also requires dereferencing a raw pointer and offset it, which probably needs the unsafe guideline. pub unsafe fn strlen(mut s: *const c_char) -> usize {
let mut n = 0;
while *s != 0 { // <-- loop & deref
n += 1;
s = s.offset(1); // <-- raw pointer offset
}
return n
} |
Triage: looks like the original PR didn't get merged. We've been making more and more stuff |
…l, r=oli-obk Make `mem::size_of_val` and `mem::align_of_val` unstably const Implements rust-lang#46571 but does not stabilize it. I wanted this while working on something today. The only reason not to immediately stabilize are concerns around [custom DSTs](rust-lang#46571 (comment)). That proposal has made zero progress in the last two years and const eval is rich enough to support pretty much any user-defined `len` function as long as nightly features are allowed (`raw_ptr_deref`). Currently, this raises a `const_err` lint when passed an `extern type`. r? @oli-obk cc @rust-lang/wg-const-eval
Just recording here that these functions being |
It would be useful for macros to be able to do things like:
I believe the rust-objc devs would like something like this to properly set up statics containing messageSend selectors (which are magically processed by the objc runtime by putting them in the right linker sections).
The text was updated successfully, but these errors were encountered: