Skip to content

Simplify Encodable derives - #161137

Open
panstromek wants to merge 8 commits into
rust-lang:mainfrom
panstromek:cleanup-encode-macros
Open

Simplify Encodable derives#161137
panstromek wants to merge 8 commits into
rust-lang:mainfrom
panstromek:cleanup-encode-macros

Conversation

@panstromek

@panstromek panstromek commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

View all comments

Few cleanups I found when investigating encoding code.

  • avoid generating match for structs
  • remove second match for enums if it is empty
  • clarify why is the enum matched twice
  • cleanup dead code and style

This is not super impactful but it makes the expanded code simpler, which is nice when you look at it for debugging purposes.
Best reviewed commit by commit

r? nnethercote
(I believe you've looked into this code quite a bit before)

@rustbot rustbot added 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. labels Aug 15, 2026
@panstromek

Copy link
Copy Markdown
Contributor Author

I don't expect much, maybe some little changes in bootstrap.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 15, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 15, 2026
@rust-bors

rust-bors Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: ba8d592 (ba8d592b3bf183de5683c92c8c4a2d3b560b6a0e)
Base parent: 110d7e5 (110d7e55dbd37e65cdc3321a204a9911af35f533)

@panstromek

Copy link
Copy Markdown
Contributor Author

@rust-timer build ba8d592

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (ba8d592): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (primary -0.8%, secondary -0.8%)

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

mean range count
Regressions ❌
(primary)
0.6% [0.6%, 0.6%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.2% [-2.2%, -2.2%] 1
Improvements ✅
(secondary)
-0.8% [-0.8%, -0.7%] 2
All ❌✅ (primary) -0.8% [-2.2%, 0.6%] 2

Cycles

Results (secondary 3.6%)

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
6.1% [1.6%, 10.0%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.7% [-4.5%, -2.9%] 2
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 462.121s -> 459.222s (-0.63%)
Artifact size: 396.97 MiB -> 398.98 MiB (0.51%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 15, 2026
@panstromek
panstromek marked this pull request as ready for review August 15, 2026 21:40
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 15, 2026
Comment thread compiler/rustc_macros/src/serialize.rs Outdated
Comment thread compiler/rustc_macros/src/serialize.rs
@Zalathar

Copy link
Copy Markdown
Member

It would be helpful to add and bless a tests/ui-fulldeps test as the first commit, and then re-bless it to show the effects of each change.

Here's an example of what that might look like:

//@ edition: 2024
//@ check-pass
//@ compile-flags: -Zunpretty=expanded

#![crate_type = "rlib"]
#![feature(rustc_private)]

extern crate rustc_macros;
extern crate rustc_serialize;
extern crate rustc_span;

use rustc_macros::Encodable;

#[derive(Encodable)]
struct UnitStruct;

#[derive(Encodable)]
struct EmptyStruct {}

#[derive(Encodable)]
enum EmptyEnum {}

#[derive(Encodable)]
enum SingleFieldlessEnum {
    A,
}

#[derive(Encodable)]
enum SingleEnum {
    A(u32),
}

#[derive(Encodable)]
enum FieldlessEnum {
    A,
    B,
}

#[derive(Encodable)]
enum PartlyFieldlessEnum {
    A,
    B(u32),
}

@panstromek

Copy link
Copy Markdown
Contributor Author

It would be helpful to add and bless a tests/ui-fulldeps test

That's a good idea, I will do that. I was thinking of posting the diff here to make the changes more visible for the review, but this is much better.

❤️ Thanks a lot for writing down the example, it would probably take me a lot longer to figure out myself.

@Zalathar

Copy link
Copy Markdown
Member

Yeah, I figured it would be a bit mean to just say “please write a ui-fulldeps test”, and from past experience I already had a pretty good idea of what it needs to look like. 😅

@panstromek
panstromek force-pushed the cleanup-encode-macros branch from 4d4cda4 to ca338a7 Compare August 16, 2026 11:23
@rustbot

rustbot commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@panstromek

Copy link
Copy Markdown
Contributor Author

I added the test based on your comment. Not sure if you checked it before posting, but it was actually 100% right, I didn't need to change or debug anything about it 👍

I re-blessed it with each edit to make it clear what it does. The test also made it clear that I didn't handle all unit-like types so I added a case to cover that in the last commit.

@nnethercote nnethercote left a comment

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.

Looks good, just one nit.

View changes since this review

Comment thread compiler/rustc_macros/src/serialize.rs Outdated
@nnethercote nnethercote 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 Aug 17, 2026
@panstromek
panstromek force-pushed the cleanup-encode-macros branch from ca338a7 to 93510b8 Compare August 17, 2026 18:00
@panstromek

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 17, 2026
@rustbot

rustbot commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Error: shortcut handler unexpectedly failed in this comment: failed to add labels

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

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

Labels

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.

5 participants