-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Only derive PartialOrd::partial_cmp when also deriving PartialEq #80050
Conversation
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 824df7b with merge 8844bde20c440d85a1729e12c9131a1d032cd3f2... |
☀️ Try build successful - checks-actions |
Queued 8844bde20c440d85a1729e12c9131a1d032cd3f2 with parent e261649, future comparison URL. |
Finished benchmarking try commit (8844bde20c440d85a1729e12c9131a1d032cd3f2): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
Clap has up to 2.2% regressions. Derive has up to ~35% improvements. |
Hmm... big wins in the derive benchmark as expected but a small regression in clap benchmarks which I didn't expect. I'll have to investigate. |
pub enum BuiltinDerive { | ||
Copy, | ||
PartialEq, | ||
} |
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.
We actually had this enum in the past, but it was represented as bitflags.
See #65892 where it was removed.
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.
Oh wow, I didn't realize! I was considering using bitflags, but I didn't want to add a dependency to rustc_expand
. I can make this change if we don't close the PR.
Is this a legal thing to do for types that have fields with "weird" implementations of |
@petrochenkov You're correct. Beyond that, the semantics of deriving |
From the zulip thread it looks like the extra time (compared to manual implementation) is spent on type checking the generated methods. |
Also, MIR shims will be generated for all methods individually, without relying on |
It's pretty sad that we have to pull things that are perfectly implementable as a (macro) library into the compiler proper due to performance. C++ is going into the same direction though. |
By the way, does |
@petrochenkov I totally agree that this is less than ideal, and it would be nice if derives were just fast enough, but due to derives needing to handle so many different inputs correctly, they're bound to generate code that is more expensive to compile than hand written versions.
File.open('src/lib.rs', 'w') do |file|
0..10_000.times do |n|
file.write("pub struct MyType#{n} { pub field: i32 }\n")
end
end
There's definitely some wiggle room beyond "just making compilation in general faster, will make derives faster". I manually implemented @petrochenkov since this PR's proposed mechanism won't work, I propose we close this PR and open an issue to track built-in derive performance. Thoughts? |
Ok, closing then. |
This adds the ability to tell whether the user is deriving
PartialEq
and if so only derivespartial_cmp
when derivingPartialOrd
. This builds on previous special casing of built-in derive macros which change how derivingClone
is handled when the user is also derivingCopy
. Because the full implementation ofPartialOrd
is expensive to compile, this leanerPartialOrd
might see some perf gains in code bases that derivePartialOrd
a lot. For instance, this increases the derive perf benchmark from rustc-perf by ~45% on my machine.This has the aided side effect of making some diagnostics a little less noisy.
r? @petrochenkov