You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking issue for const_size_of_val and const_align_of_val #46571
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).
Reacted by Stepan Koltsov, lolbinarycat, orzogc and José Luis Cruz
I believe this is currently blocked on miri becoming the primary/only CTFE provider.
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?
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 const fn len() on [T] and str though.
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.
pubunsafefnstrlen(muts:*constc_char) -> usize{letmut n = 0;while*s != 0{// <-- loop & deref
n += 1;
s = s.offset(1);// <-- raw pointer offset}return n
}
@davidtwco so just to be sure, you are fine with moving ahead here with const stabilization, and do not think this will adversely affect the future of your RFC or the entire unsized types / extern type / only-runtime-sized type situation?
@davidtwco so just to be sure, you are fine with moving ahead here with const stabilization, and do not think this will adversely affect the future of your RFC or the entire unsized types / extern type / only-runtime-sized type situation?
I think it should be okay for this to proceed. As long as this can be changed to ~const ?Sized backwards compatibly, and I believe it can be, then it wouldn't interfere with the current proposal.
If that bound is equivalent to ~const ValueSized then yeah that should work -- whatever transition deals with existing size_of_val calls outside const should be able to also deal with size_of_val calls inside const.
This does require const traits though, so the new hierarchy couldn't be stabilized until const traits are stable. But const traits are already a core part of that story so I assume that is anyway the case.
Activity
Gankra commentedon Dec 7, 2017
I believe this is currently blocked on miri becoming the primary/only CTFE provider.
Gankra commentedon Dec 7, 2017
cc @eddyb @oli-obk
oli-obk commentedon Dec 7, 2017
I think this is possible without miri const eval, but it would be wasteful to implement in old ctfe
Gankra commentedon Dec 7, 2017
Yeah I consider "the people who would implement/review this are able but unwilling" to be a blocker
polarathene commentedon Apr 27, 2018
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?
oli-obk commentedon Apr 27, 2018
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
Gankra commentedon May 9, 2018
i'm implementing this
kennytm commentedon May 9, 2018
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
const fn len()on[T]andstrthough.whitequark commentedon May 9, 2018
Why isn't it possible to implement strlen in Rust instead?
oli-obk commentedon May 9, 2018
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
kennytm commentedon May 9, 2018
It also requires dereferencing a raw pointer and offset it, which probably needs the unsafe guideline.
steveklabnik commentedon Sep 22, 2019
Triage: looks like the original PR didn't get merged. We've been making more and more stuff
const fn, what's the current status here?oli-obk commentedon Sep 22, 2019
@Gankra #63770 solves your problem, albeit not with
size_of_val33 remaining items
RalfJung commentedon Nov 27, 2024
@davidtwco so just to be sure, you are fine with moving ahead here with const stabilization, and do not think this will adversely affect the future of your RFC or the entire unsized types / extern type / only-runtime-sized type situation?
davidtwco commentedon Dec 2, 2024
I think it should be okay for this to proceed. As long as this can be changed to
~const ?Sizedbackwards compatibly, and I believe it can be, then it wouldn't interfere with the current proposal.RalfJung commentedon Dec 2, 2024
If that bound is equivalent to
~const ValueSizedthen yeah that should work -- whatever transition deals with existingsize_of_valcalls outside const should be able to also deal withsize_of_valcalls inside const.This does require const traits though, so the new hierarchy couldn't be stabilized until const traits are stable. But const traits are already a core part of that story so I assume that is anyway the case.
RalfJung commentedon Dec 2, 2024
Stabilization PR is up: #133762
Rollup merge of rust-lang#133762 - RalfJung:const-size-of-val, r=work…
Rollup merge of rust-lang#133762 - RalfJung:const-size-of-val, r=work…
Rollup merge of rust-lang#133762 - RalfJung:const-size-of-val, r=work…
Rollup merge of rust-lang#133762 - RalfJung:const-size-of-val, r=work…
Unrolled build for rust-lang#133762
Rollup merge of #133762 - RalfJung:const-size-of-val, r=workingjubilee
Rollup merge of rust-lang#133762 - RalfJung:const-size-of-val, r=work…