-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Constify Eq, Ord, PartialOrd #144847
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
base: master
Are you sure you want to change the base?
Constify Eq, Ord, PartialOrd #144847
Conversation
r? @ibraheemdev rustbot has assigned @ibraheemdev. Use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Squash this into one commit please @rustbot author |
Reminder, once the PR becomes ready for a review, use |
@rustbot ready |
Not a review but just a question as I don't know the contexts very well 😅 |
This comment has been minimized.
This comment has been minimized.
Fair enough, I've added |
Sorry for taking a long time to review this. I'm actually somewhat uncomfortable by the scope of this PR. Could you please limit the number of types that this adds const impls for to just types that seem relevant for const programming? Specifically, things like:
Don't seem really relevant here. I think this constification could probably just stick to constifying some impls for built-in types and other important types, and not just try to constify everything that can be constified in the standard library. Also, since this adds new bounds to things, let's run a perf test. @bors2 try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Constify Eq, Ord, PartialOrd
@rustbot author |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (755ce71): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.2%, secondary 3.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.4%, secondary 1.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.1%, secondary -0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 470.205s -> 469.279s (-0.20%) |
I've removed some of these; I left arrays, As for perf, I'm not sure how to read it and if something needs to be done? The largest changes seem to be oscillating for some time before this commit, so it may be unrelated? |
#143949 also caused some minor perf regressions, but so far nobody from wg-const-eval has commented on whether this is considered acceptable or not. Right now my understanding is that the goal is to constify everything, but there may need to be some changes with consteval since my suspicion is that the built-in stuff to allow these operators to work even without trait impls on primitives may now be slower with the const trait impls present and enabled. |
@rustbot ready |
@@ -1012,7 +1023,7 @@ pub trait Ord: Eq + PartialOrd<Self> + PointeeSized { | |||
#[rustc_diagnostic_item = "cmp_ord_max"] | |||
fn max(self, other: Self) -> Self | |||
where | |||
Self: Sized, | |||
Self: Sized + [const] Destruct + [const] PartialOrd, |
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.
Isn't [const] PartialOrd implied from the super trait bounds?
pub const fn min_by<T: [const] Destruct, F: [const] FnOnce(&T, &T) -> Ordering>( | ||
v1: T, | ||
v2: T, | ||
compare: F, |
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.
How come F doesn't need a Destruct bound?
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.
I'm not sure? I've added const and then fixed the error messages until it compiled.
Adds
#[const_trait]
and impls forEq
,Ord
,PartialOrd
. Impl for some other traits (e.g., slices and arrays) are blocked mainly on const closures (#106003).For TypeId Ord we need const pointer comparison (#53020)
Tracking issue #143800