Uh oh!
There was an error while loading. Please reload this page.
Only derive PartialOrd::partial_cmp when also deriving PartialEq - #80050
Only derive PartialOrd::partial_cmp when also deriving PartialEq#80050rylev wants to merge 2 commits into
Conversation
davidtwco
commented
Dec 15, 2020
@bors try @rust-timer queue |
rust-timer
commented
Dec 15, 2020
Awaiting bors try build completion |
bors
commented
Dec 15, 2020
⌛ Trying commit 824df7b with merge 8844bde20c440d85a1729e12c9131a1d032cd3f2... |
bors
commented
Dec 15, 2020
☀️ Try build successful - checks-actions |
rust-timer
commented
Dec 15, 2020
Queued 8844bde20c440d85a1729e12c9131a1d032cd3f2 with parent e261649, future comparison URL. |
rust-timer
commented
Dec 15, 2020
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 |
bjorn3
commented
Dec 15, 2020
Clap has up to 2.2% regressions. Derive has up to ~35% improvements. |
rylev
commented
Dec 15, 2020
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.
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.
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.
petrochenkov
commented
Dec 15, 2020
Is this a legal thing to do for types that have fields with "weird" implementations of |
rylev
commented
Dec 15, 2020
@petrochenkov You're correct. Beyond that, the semantics of deriving |
petrochenkov
commented
Dec 16, 2020
From the zulip thread it looks like the extra time (compared to manual implementation) is spent on type checking the generated methods. |
petrochenkov
commented
Dec 16, 2020
Also, MIR shims will be generated for all methods individually, without relying on |
petrochenkov
commented
Dec 16, 2020
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. |
petrochenkov
commented
Dec 16, 2020
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.timesdo |n|
file.write("pub struct MyType#{n} { pub field: i32 }\n")endend
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? |
petrochenkov
commented
Dec 17, 2020
Ok, closing then. |
This adds the ability to tell whether the user is deriving
PartialEqand if so only derivespartial_cmpwhen derivingPartialOrd. This builds on previous special casing of built-in derive macros which change how derivingCloneis handled when the user is also derivingCopy. Because the full implementation ofPartialOrdis expensive to compile, this leanerPartialOrdmight see some perf gains in code bases that derivePartialOrda 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