Skip to content

Implement fast path for derive(PartialOrd) when deriving Ord#155598

Open
makai410 wants to merge 4 commits intorust-lang:mainfrom
makai410:partial-ord
Open

Implement fast path for derive(PartialOrd) when deriving Ord#155598
makai410 wants to merge 4 commits intorust-lang:mainfrom
makai410:partial-ord

Conversation

@makai410
Copy link
Copy Markdown
Member

@makai410 makai410 commented Apr 21, 2026

View all comments

Closes: #155537

Unfortunately, this PR shares the same issue with #124794, which doesn't work when derive(PartialOrd) is before derive(Ord).

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 21, 2026

Changes to the code generated for builtin derived traits.

cc @nnethercote

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 21, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 21, 2026

r? @ShoyuVanilla

rustbot has assigned @ShoyuVanilla.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 72 candidates
  • Random selection from 18 candidates

cx.dcx().span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`");
cx.dcx()
.span_bug(field.span, "not exactly 2 arguments in `derive(PartialOrd)`");
};
Copy link
Copy Markdown
Member Author

@makai410 makai410 Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably a copy-paste curse, so I changed that, not 100% sure though.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@nnethercote
Copy link
Copy Markdown
Contributor

I can review this: r? @nnethercote

cc @theemathas, who has made good comments on similar PRs in the past.

@rustbot rustbot assigned nnethercote and unassigned ShoyuVanilla Apr 21, 2026
Comment thread compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs
@theemathas

This comment has been minimized.

Comment thread tests/ui/deriving/deriving-all-codegen.stdout Outdated
@makai410
Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 22, 2026
Implement fast path for `derive(PartialOrd)` when deriving `Ord`
resolutions: Vec<DeriveResolution>,
helper_attrs: Vec<(usize, IdentKey, Span)>,
// if this list keeps getting extended, we could use `bitflags`,
// something like what [`rustc_type_ir::flags::TypeFlags`] is doing.
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had multiple flags here in the past, and they indeed used flags, and one map in the resolver instead of two containers_deriving_(copy,ord) maps.

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing the context. I was thinking about doing one more round of scanning derives to collect all flags such that it might solve #124794. I don't know if that had been discussed before, and if it did I'd really want to know the reason of why not doing that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more round of scanning derives to collect all flags

If I correctly understand what you are talking about, it's a much worse hack and it cannot work correctly.
We already doing something like that to support deprecation lint legacy_derive_helpers, and that logic is going to be removed soon.

@petrochenkov
Copy link
Copy Markdown
Contributor

Similarly to the existing derive(Clone, Copy) I'd classify this as adding hacks to the expansion infra, and would recommend against this by default, unless there are really strong performance reasons.

Moreover, the Copy hack can be in theory removed in favor of some MIR transform, but for this one it would be harder to do.

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 22, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 22, 2026

💔 Test for f5daf9f failed: CI

@makai410
Copy link
Copy Markdown
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 23, 2026
Implement fast path for `derive(PartialOrd)` when deriving `Ord`
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 23, 2026

☀️ Try build successful (CI)
Build commit: 803fd19 (803fd197cdeec49615d500f71f89872b51cfc6a9, parent: 30837cb66de032fbc8072c8ecbf76c39c5b14478)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (803fd19): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.6% [0.3%, 0.9%] 3
Regressions ❌
(secondary)
0.9% [0.7%, 1.0%] 6
Improvements ✅
(primary)
-0.3% [-0.4%, -0.2%] 17
Improvements ✅
(secondary)
-0.4% [-0.4%, -0.4%] 2
All ❌✅ (primary) -0.2% [-0.4%, 0.9%] 20

Max RSS (memory usage)

Results (primary 0.7%, secondary -3.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.9% [0.5%, 5.7%] 3
Regressions ❌
(secondary)
1.5% [1.5%, 1.5%] 1
Improvements ✅
(primary)
-2.6% [-3.2%, -1.9%] 2
Improvements ✅
(secondary)
-6.3% [-6.5%, -6.1%] 2
All ❌✅ (primary) 0.7% [-3.2%, 5.7%] 5

Cycles

Results (primary 2.8%, secondary 4.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.8% [2.8%, 2.8%] 1
Regressions ❌
(secondary)
4.5% [3.9%, 5.3%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.8% [2.8%, 2.8%] 1

Binary size

Results (primary 0.1%, secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.4%] 46
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 24
Improvements ✅
(primary)
-0.2% [-0.3%, -0.0%] 6
Improvements ✅
(secondary)
-0.1% [-0.4%, -0.0%] 14
All ❌✅ (primary) 0.1% [-0.3%, 0.4%] 52

Bootstrap: 490.44s -> 500.217s (1.99%)
Artifact size: 394.27 MiB -> 394.33 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 23, 2026
@makai410
Copy link
Copy Markdown
Member Author

Hmmm, so the perf result doesn't seem to be a strong performance reason? I'm fine with closing this.

@nnethercote
Copy link
Copy Markdown
Contributor

The change isn't necessarily going to speed up the compiler itself. "Generate tight code for derives" is a good goal in general.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 26, 2026

☔ The latest upstream changes (presumably #155796) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cheap derive(PartialOrd) for non-generic types

8 participants