-
Notifications
You must be signed in to change notification settings - Fork 13.9k
More const int functions #66884
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
More const int functions #66884
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @KodrAus (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
|
|
r? @oli-obk |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
f1860ae to
cb7e9be
Compare
cb7e9be to
fdc0011
Compare
|
Accidentally got marked as a coauthor on like 200 commits (I'm not great at |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/libcore/option.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You show this function works in constants, but this should not be possible. It's not for min_const_fn, just for the const_fn feature gate, but still: We seem to have lost a qualification check somewhere along the line. cc @ecstatic-morse the function call to f should not work without -Zunleash-the-miri-inside-of-you
For this PR, please undo all constifications for functions that take generic things with trait bounds (other than Sized), these require rust-lang/rfcs#2632 first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outside of core, the equivalent code is rejected. Any idea what's going on here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted constification for these functions in 99a885e -- should I leave this conversation unresolved why we work out why they weren't rejected, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh!? Even with the const_fn feature gate it still errors... that is worrysome. Yea leave it unresolved. I'll try to create a non-core repro
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
OK, the PR is complete / ready for merge. Should I split the |
src/libcore/option.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect_failed is not const fn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
Most of the tests had to be deleted; the various power_of_two functions use `intrinsics::ctlz_nonzero` internally, so they can't be made const before rust-lang#66275 is merged.
With rust-lang#49146 merged, these can be const; see rust-lang#53718.
With rust-lang#49146 merged, these can be const; see rust-lang#53718.
With rust-lang#49146 merged, these can be const; see rust-lang#53718.
The implementation of rem_euclid for signed integers was const, but I'd forgotten to mark rem_euclid on unsigned integers as const as well, hence the failing test.
const fns with generic trait bounds aren't allowed yet; from @oli-obk: > please undo all constifications for functions that take generic things > with trait bounds (other than Sized), these require > rust-lang/rfcs#2632 first
Option.flatten relies on Option.and_then, which has a generic trait bound and can't be const yet. From @oli-obk: > please undo all constifications for functions that take generic things > with trait bounds (other than Sized), these require > rust-lang/rfcs#2632 first
7c59460 to
8c1f726
Compare
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
- New boostrap compiler! Delete the non-const bootstrap copies of the fns. - Factor the assert_same_const! macro to src/test/ui/consts/auxiliary/const_assert_lib.rs and apply the fix Oli suggested, > In order to prevent promotion from making this test useless because > it ends up promoting the assert argument
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
| None => Ok(None), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you lost a closing bracket
|
☔ The latest upstream changes (presumably #67560) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Please remove the |
|
Ping from triage - |
|
Pinging again from triage - |
|
Sorry for the long delay on this -- life's been especially hectic recently. I'll see what I can do here but might not be able to get to this until this weekend or the next. Is that okay? Willing to just close this if that's easier for folks. Apologies again, I don't want to hold anyone up here. |
|
@9999years Would it be okay if I took this over, but added you as a co-author? This shouldn't require any |
|
Go for it! Do I need to assign it to you or anything?
…On Mon, Feb 3, 2020, at 3:10 PM, ecstatic-morse wrote:
@9999years <https://github.com/9999years> Would it be okay if I took this over, but added you as a co-author? This shouldn't require any `#[cfg(bootstrap)]` anymore, just adding `const` to things. By giving each class of functions a name, you've already done most of the work.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#66884?email_source=notifications&email_token=ADU2KODOXNLDYMJKZS6J7ZTRBB22BA5CNFSM4JTEGUMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKVHDDQ#issuecomment-581595534>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADU2KOGXAVWM6ZCUZVK6WRTRBB22BANCNFSM4JTEGUMA>.
|
|
@9999years. Nah, I'll take care of it. |
|
Closed in favor of #68809. Thanks @ecstatic-morse! |
… r=oli-obk Make more arithmetic functions unstably const This is a smaller version of rust-lang#66884 (thanks @9999years) that constifies many of the arithmetic functions on integer primitives from rust-lang#53718 that were blocked on rust-lang#49146. This makes the following things unstably const. - `feature = const_int_unchecked_arith` - `intrinsics::unchecked_add` - `intrinsics::unchecked_sub` - `intrinsics::unchecked_mul` - `intrinsics::unchecked_div` - `intrinsics::unchecked_rem` - `feature = const_checked_int_methods` - `checked_add` - `checked_sub` - `checked_mul` - `checked_div` (Uses `intrinsics::unchecked_div` internally) - `checked_rem` (Uses `intrinsics::unchecked_rem` internally) - `checked_neg` - `checked_shl` - `checked_shr` - `checked_abs` - `feature = const_saturating_int_methods` - `saturating_mul` - `saturating_neg` (Uses `intrinsics::unchecked_sub` internally) - `saturating_abs` (Uses `intrinsics::unchecked_sub` internally) - `feature = const_wrapping_int_methods` - `wrapping_div` - `wrapping_rem` - `feature = const_overflowing_int_methods` - `overflowing_div` - `overflowing_rem` - `feature = const_euclidean_int_methods` - `checked_div_euclid` - `checked_rem_euclid` - `wrapping_div_euclid` - `wrapping_rem_euclid` - `overflowing_div_euclid` - `overflowing_rem_euclid` Exponentiation and operations on the `NonZero` types are left to a later PR. r? @oli-obk cc @rust-lang/wg-const-eval @rust-lang/libs
Constifies the int arithmetic functions from #53718 that were blocked on #49146.
feature = const_int_checkedchecked_addchecked_subchecked_mulUseschecked_divintrinsics::unchecked_divinternally.Useschecked_remintrinsics::unchecked_reminternally; needs Organize intrinsics promotion checks #66275.checked_negchecked_shlchecked_shrchecked_absfeature = const_int_saturating/feature = const_saturating_int_methodssaturating_mulsaturating_negsaturating_absfeature = const_int_wrappingwrapping_divwrapping_remfeature = const_int_overflowingoverflowing_divoverflowing_remfeature = const_int_euclideanchecked_div_euclidchecked_rem_euclidwrapping_div_euclidwrapping_rem_euclidoverflowing_div_euclidoverflowing_rem_euclidfeature = const_int_powUsesnext_power_of_twointrinsics::ctlz_nonzerointernally; needs Organize intrinsics promotion checks #66275.Ditto.checked_next_power_of_twoDitto.wrapping_next_power_of_twoUseschecked_powwhile; needs Tracking issue for RFC 2344, "Allowloopin constant evaluation" #52000?feature = const_int_nonzeroNonZero*::new(implementation inmacro_rules! nonzero_integers)I converted some of the
Optionfunctions as well; this is a new#![feature], should it be in a different PR?feature = const_optionis_some,is_noneas_refexpectunwrap_or,Requires Calling methods on generic parameters of const fns rfcs#2632 to use functional interfaces (in specific, trait bounds on generic fns).unwrap_or_elseok_or,ok_or_elseand,and_thenfilteror,or_elsexortransposecc @oli-obk, who has kindly been helping me start work on this on Twitter! 🙂