-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Generate less code when deriving #31972
Comments
Seem like good ideas in general. Why do you assume that omitting Do we have a derive-heavy crate somewhere that'd be good for compile-time and runtime benchmarks? |
ne just uses !eq, but gt uses a slightly more complicated expression based on the return value of partial_cmp. |
Does it make sense to derive an implementation of |
@ollie27 if we don't call |
While it's technically observable we have a rule " |
While I agree this was not a convincing argument over at #31414 so I recommend we keep this PR small :) |
Why do we even have two methods then? @ollie27 I agree with your observation. And isn't it so that any fast path to either proving equality or nonequality (whichever is easier), is applicable in both .eq and .ne? |
Yeah, if there's a fast path for one then the fast path for the other is just negating the output. I don't think there's ever a reason to override |
performance testing for leftover cases seems to indicate this is mostly a wash on real-world code so closing this. |
Here are some ideas for generating less code when deriving. All of these break down with generic fields, since then we have to fall back to the current general scheme.
PartialEq
For C-like enums, only produce
eq
and notne
. The default ne calls eq and is always enough. Edit: implemented in #31977.PartialOrd
For C-like enums only produce
partial_cmp
and not the four other methods lt, le, gt, ge. This needs an experiment to see if onlypartial_cmp
is good enough. Maybe another of the single methods can be enough, too.PartialOrd, Ord
togetherWhen there are no generic parameters, simply call
.cmp()
in.partial_cmp()
.cc @durka
The text was updated successfully, but these errors were encountered: