Repository navigation
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.T-langRelevant to the language teamRelevant to the language teamT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
Description
(none exhaustive) list of libcore::num, which should be a const fn:
feature = const_int_rotate-
rotate_leftAdd more const int ops #53697 -- stabilized -
rotate_rightAdd more const int ops #53697 -- stabilized
-
feature = const_checked_int_methods-
checked_add[1] Make more arithmetic functions unstably const #68809 -
checked_sub[1] Make more arithmetic functions unstably const #68809 -
checked_mul[1] Make more arithmetic functions unstably const #68809 -
checked_div[1] Make more arithmetic functions unstably const #68809 -
checked_rem[1] Make more arithmetic functions unstably const #68809 -
checked_neg[1] Make more arithmetic functions unstably const #68809 -
checked_shl[1] Make more arithmetic functions unstably const #68809 -
checked_shr[1] Make more arithmetic functions unstably const #68809 -
checked_abs[1] Make more arithmetic functions unstably const #68809
-
feature = const_saturating_int_methods-
saturating_addMakesaturating_addandsaturating_subconstfunctions #58246 -
saturating_subMakesaturating_addandsaturating_subconstfunctions #58246 -
saturating_mul[1] Make more arithmetic functions unstably const #68809
-
feature = const_int_wrapping-
wrapping_addAdd more const int ops #53697 -- stabilized -
wrapping_subAdd more const int ops #53697 -- stabilized -
wrapping_mulAdd more const int ops #53697 -- stabilized -
wrapping_div[1] Make more arithmetic functions unstably const #68809 -
wrapping_rem[1] Make more arithmetic functions unstably const #68809 -
wrapping_negMake overflowing and wrapping negation const #58044 -- stabilized -
wrapping_shlAdd more const int ops #53697 -- stabilized -
wrapping_shrAdd more const int ops #53697 -- stabilized -
wrapping_absMakeabs,wrapping_abs,overflowing_absconst functions #63786 -- stabilized in 1.39
-
feature = const_int_overflowing-
overflowing_addAdd more const int ops #53697 -
overflowing_subAdd more const int ops #53697 -
overflowing_mulAdd more const int ops #53697 -
overflowing_div[1] Make more arithmetic functions unstably const #68809 -
overflowing_rem[1] Make more arithmetic functions unstably const #68809 -
overflowing_negMake overflowing and wrapping negation const #58044 -- stabilized -
overflowing_shlAdd more const int ops #53697 -
overflowing_shrAdd more const int ops #53697 -
overflowing_absMakeabs,wrapping_abs,overflowing_absconst functions #63786 -- stabilized in 1.39
-
feature = const_euclidean_int_methods-
checked_div_euc[1] Make more arithmetic functions unstably const #68809 -
checked_mod_euc[1] Make more arithmetic functions unstably const #68809 -
wrapping_div_euc[1] Make more arithmetic functions unstably const #68809 -
wrapping_mod_euc[1] Make more arithmetic functions unstably const #68809 -
overflowing_div_euc[1] Make more arithmetic functions unstably const #68809 -
overflowing_mod_euc[1] Make more arithmetic functions unstably const #68809
-
feature = const_int_pow-
pow[1, 2] Make integer exponentiation methods unstably const #68978 -
is_power_of_twomake is_power_of_two a const function #65092 -
next_power_of_two[1] Make integer exponentiation methods unstably const #68978 -
checked_pow[1] Make integer exponentiation methods unstably const #68978 -
checked_next_power_of_two[1] Make integer exponentiation methods unstably const #68978 -
saturating_pow[1, 2] Make integer exponentiation methods unstably const #68978 -
wrapping_pow[1, 2] Make integer exponentiation methods unstably const #68978 -
wrapping_next_power_of_two[1] Make integer exponentiation methods unstably const #68978 -
overflowing_pow[1, 2] Make integer exponentiation methods unstably const #68978
-
feature = const_int_sign-
absMakeabs,wrapping_abs,overflowing_absconst functions #63786 -- stabilized in 1.39 -
signumMakei*::signumaconst fn. #61635 -
is_positiveAdd more const int ops #53697 -- stabilized -
is_negativeAdd more const int ops #53697 -- stabilized
-
feature = const_int_conversion-
to_be_bytesAdd more const int ops #53697 -
to_le_bytesAdd more const int ops #53697 -
to_ne_bytesAdd more const int ops #53697 -
from_be_bytesAdd more const int ops #53697 -
from_le_bytesAdd more const int ops #53697 -
from_ne_bytesAdd more const int ops #53697 -
reverse_bitsAdd more const int ops #53697
-
feature = const_nonzero_int_methods-
NonZero*::new[1] Makenum::NonZeroX::newan unstableconst fn#68976
-
- Requires conditionals. Tracking Issue: Tracking issue for RFC 2342, "Allow
ifandmatchin constants" #49146 (implemented on nightly) - Requires loops. Tracking Issue: Tracking issue for RFC 2344, "Allow
loopin constant evaluation" #52000 (implemented on nightly)
This issue has been assigned to @9999years via this comment.
Reacted by mark, 🏴☠️ 💪📎 , Diana, hugecheese, Charles Samborski, runiq, Virgiel, Ron Lobo, İrem, Simon and 8 more
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.T-langRelevant to the language teamRelevant to the language teamT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
Activity
TheDarkula commentedon Aug 30, 2018
transmute()just got merged. You can start on your last block now :)TimDiekmann commentedon Aug 31, 2018
@TheDarkula Thank you, I'll start implementing them as soon as #53699 is merged.
TimDiekmann commentedon Aug 31, 2018
Added rest of
const_int_conversionto #53697TimDiekmann commentedon Sep 1, 2018
I'm currently rebasing #53697 and testing. Then the first bunch should be ready to merge.
Auto merge of #53697 - Cyres:const-fn-int-ops, r=oli-obk
mjbshaw commentedon Dec 31, 2018
Adding a comment here so I don't have to hunt for the following related issue: #51267 is the tracking issue for
feature = const_int_ops, which tracks:count_zeros-- stabilizedcount_ones-- stabilizedleading_zeros-- stabilizedtrailing_zeros-- stabilizedLokathor commentedon Jan 13, 2019
wrapping_neg isn't on the list here it seems (though overflowing_neg is)
ecstatic-morse commentedon Jun 8, 2019
It's possible to make a great number of these
constwithout conditional statements being legal inconst fnby using indexing (e.g.[x, -x][(x < 0) as usize]). However, it's a bad idea because the technique results in much less efficient generated code. You can check this by viewing ASM in the previous link. I'm posting this to avoid duplication of effort in case someone else has the same idea.mark-i-m commentedon Jun 8, 2019
In fact, we are already doing that to make
Vec::new()aconst fn😛rust/src/liballoc/raw_vec.rs
Lines 51 to 63 in d132f54
ecstatic-morse commentedon Jun 8, 2019
@mark-i-m That's probably where I first saw this technique!
My point was that making a similar modification would likely slow down these arithmetic operations considerably. The use in
Vec::newcan be eliminated via const-propagation post-monomorphization, but that optimization doesn't apply here.38 remaining items
Rollup merge of rust-lang#68978 - ecstatic-morse:const-int-pow, r=oli…
Rollup merge of rust-lang#68978 - ecstatic-morse:const-int-pow, r=oli…
tspiteri commentedon Feb 21, 2020
I think that the
{to,from}_{be,le,ne}_bytesmethods should be made const in stable. While it is true that currently the implementation depends on e.g.transmute, that is a hidden implementation detail, and they could already be implemented as const stably with e.g.b[3] << 24 | b[2] << 16 | b[1] << 8 | b[0]. Of course, I'm not suggesting that the implementation itself should be changed, just that it should not stop them from being marked const in stable.jhpratt commentedon May 3, 2020
Would a PR making
.rem_euclidaconst fnon stable be accepted? It could be trivially implemented as((x % y) + y) % y. This reasoning has been used for other methods in the past.tspiteri commentedon May 3, 2020
@jhpratt
It doesn't give the same results for negative y.
3.rem_euclid(-2) == 1, but((3 % (-2)) + (-2)) % (-2) == -1. This could be solved by usingy.abs().But it would overflow for example when
x == i32::MAX - 1 && y == i32::MAX.myrrlyn commentedon May 7, 2020
Can we stabilize the
const_int_conversiongate, or is there a standing issue preventing stabilization? As has been mentioned upthread, these functions have equivalentconst-able expressions, but as they are still unstable, these must be copied into each crate that needs them. This copying is bug-prone, so stabilization would reduce duplication and the possibility of error production.tspiteri commentedon May 7, 2020
@myrrlyn It's already stabilized in beta.
Razican commentedon Sep 10, 2020
Hello, as far as I can tell, both [1] and [2] are now stable, right? so there is no extra blocking issue to implement/stabilize those, right? Is there something that can be done to get them stabilized?
tspiteri commentedon Sep 10, 2020
@Razican Most of [1] were marked stable in #73858, so they will be stabilized in 1.47. The PR did not include division and remainder because they can panic, so maybe they need another footnote.
To stabilize the rest that can be stabilized (the
powfunctions I think), someone needs to write a PR, which will then need to be approved, pass through FCP, and get merged.jhpratt commentedon Jan 13, 2021
#80962 is up to stabilize all remaining methods mentioned at the top of this issue. The diagnostic on nightly is functionally the same as already-stable equivalents (
5 % 0vs5.rem_euclid(0), for example).Auto merge of rust-lang#80962 - jhpratt:const_int_fn-stabilization, r…