Skip to content

rustc_builtin_macros cleanup, part 8 - #163485

Open
cyrgani wants to merge 18 commits into
rust-lang:mainfrom
cyrgani:builtin-macros-8
Open

cyrgani wants to merge 18 commits into
rust-lang:mainfrom
cyrgani:builtin-macros-8

Conversation

@cyrgani

@cyrgani cyrgani commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

This PR is roughly split into four parts:

  • The first few commits add helpers to ExtCtxt to both construct some common AST elements in an easier way. They also change some Ident arguments to Symbol to avoid the annoying call-site pattern of repeating the span (cx.some_method(span, Ident::new(name, span), ...)).
  • The next few commits focus on the derive infrastructure cleanup a bit.
  • The further following commits make Path construction faster and remove the new_path remnant of the old local path version.
  • The last four commits are two changes where I am not sure which option is nicer:
    • We can either remove path_std! and pathvec! entirely or utilize them in the whole crate. Both solutions seem better than the current mixed situation.
    • I added the old Substructure back in use the type name instead of Self in constructor paths again #163863 to fix the regression without thinking much about whether it is actually needed. We can either remove it again or use it to also store the &Item which the derive is applied to, which allows removing combine_substructure, but reduces the flexibility a bit.

Previous PR: #163389

r? @nnethercote

@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 Sep 29, 2026
@jieyouxu

Copy link
Copy Markdown
Member

@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 Sep 29, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 29, 2026
[PERF] `rustc_builtin_macros` cleanup, part 8
Comment thread compiler/rustc_expand/src/base.rs Outdated
@rust-bors

rust-bors Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 0bcf40d (0bcf40dc0c6b1a2253f428ebaa94e0e54aa98617)
Base parent: b46c90c (b46c90c5619a16a0c7e4d0f4e9e1ad4db4cf106e)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (0bcf40d): comparison URL.

Overall result: ✅ improvements - 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

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.2%] 7
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 0.7%, secondary 2.1%)

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

mean range count
Regressions ❌
(primary)
2.2% [2.2%, 2.2%] 1
Regressions ❌
(secondary)
3.6% [3.4%, 3.8%] 3
Improvements ✅
(primary)
-0.9% [-0.9%, -0.9%] 1
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) 0.7% [-0.9%, 2.2%] 2

Cycles

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

Binary size

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

Bootstrap: 491.711s -> 491.207s (-0.10%)
Artifact size: 406.38 MiB -> 406.39 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 29, 2026
@rust-bors

This comment has been minimized.

cyrgani added 17 commits October 9, 2026 08:33
These are especially useful for constructing types and paths referring to primitives.
It is only used in one place and it's easier to do the check directly in `debug.rs`.
Several small changes to remove some unhelpful helpers.
As I understand it, this would only be needed if the crate defining the derive macros (which is `core`) was using edition 2015.
Since `core` uses edition 2024, there is in this case no difference between global and local and we can skip the leading `::`.
Previously, `std_path` converted the given `&[Symbol]` to a `Vec<Ident>` by prepending a `$crate::` and mapping each `Symbol` to an `Ident`.
This commit changes the functions that previously took `Vec<Ident>` to directly take `Path` instead, and updates `std_path` to also directly return a `Path`. This allows directly prepending the `$crate::` to the resulting `segments`.
It also allows constructing a `Path` from `&[Ident]` instead of `Vec<Ident>`.
`new_path` is just a obsolete trivial wrapper around `cx.std_path_all` now.
TODO: is this actually worth it? maybe we should remove the macros entirely instead?
Passing around `type_ident` everywhere is what the old code did as well, but it's actually only needed in two places.
This reverts commit c28f2fece8497fb2119e17a47188c6ab1dc5da7b.
(This revert only exists to make the diff for the next commit clearer and will be removed before merging.)
This leads to `CombineSubstructureFunc` becoming a `fn`, allows some cleanups and requires restructuring `From` a bit.
It also means that it is no longer easily possible to generate the dummy method body after encountering an error, so the code just skips generating anything.
@cyrgani cyrgani changed the title [PERF] rustc_builtin_macros cleanup, part 8 rustc_builtin_macros cleanup, part 8 Oct 9, 2026
@cyrgani
cyrgani marked this pull request as ready for review October 9, 2026 12:23
@rustbot

rustbot commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

@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 Oct 9, 2026
use crate::{deriving, diagnostics};

pub(crate) struct TraitDef<'a> {
pub(crate) struct TraitDef<> {

@cyrgani cyrgani Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh, it looks like rustfmt skips formatting a struct with a default field entirely

View changes since the review

This branch has not been deployed

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants