Skip to content

Overhaul CfgTrace/CfgAttrTrace handling#159266

Merged
rust-bors[bot] merged 7 commits into
rust-lang:mainfrom
nnethercote:rm-AttrItemKind
Jul 17, 2026
Merged

Overhaul CfgTrace/CfgAttrTrace handling#159266
rust-bors[bot] merged 7 commits into
rust-lang:mainfrom
nnethercote:rm-AttrItemKind

Conversation

@nnethercote

@nnethercote nnethercote commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

View all comments

I noticed that AttrItemKind was a bit clunky and by the time I was finished I had a PR that:

  • removes AttrItemKind;
  • removes sym::cfg_trace and sym::cfg_attr_trace;
  • overhauls how these attributes are handled;
  • changes the terminology used for these attributes;
  • fixes some erroneous comments;
  • and a few other small improvements.

It's a sizeable change but I think it makes things a lot clearer. Details in individual commits.

r? @petrochenkov

@rustbot

rustbot commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

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

cc @ZuseZ4

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 14, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

cc @JonathanBrouwer

The final two commits are opinionated, especially the final one. I do think the new terminology is much better, as explained in the commit logs, but I would appreciate careful checking to make sure I haven't overlooked or misinterpreted anything. In particular, if there are any future plans for handling AST attributes that might be relevant.

@nnethercote

Copy link
Copy Markdown
Contributor 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 Jul 14, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
Overhaul `CfgTrace`/`CfgAttrTrace` handling
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

(Would like to take a look at this as well, might take me a few days to get to it)

@petrochenkov

Copy link
Copy Markdown
Contributor

There's one more PR in flight changing the data in cfg_attr traces - #158980, this PR may depend on it (depending on what it does).

@nnethercote

Copy link
Copy Markdown
Contributor Author

this PR may depend on it

There will be conflicts but I think they will be superficial. That PR is about adding an argument to CfgAttrTrace. This PR moves CfgAttrTrace around but doesn't change what it's doing.

@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 61408d1 (61408d1532b7aa37a3d4bf619a1e7d38a884bb06)
Base parent: 55b6bd8 (55b6bd8ecbed23599e966a04508a8a13cbfe90b3)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (61408d1): comparison URL.

Overall result: ✅ improvements - no action needed

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.

@bors rollup=never rustc-perf
@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.4% [-0.6%, -0.2%] 6
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-0.6%, -0.2%] 6

Max RSS (memory usage)

Results (primary 4.4%, 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)
4.4% [4.4%, 4.4%] 1
Regressions ❌
(secondary)
1.7% [1.0%, 3.5%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.4% [-4.7%, -4.1%] 2
All ❌✅ (primary) 4.4% [4.4%, 4.4%] 1

Cycles

Results (secondary -5.0%)

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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.0% [-5.0%, -5.0%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 489.277s -> 489.827s (0.11%)
Artifact size: 389.95 MiB -> 389.32 MiB (-0.16%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 14, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

Some tiny perf wins? Wasn't the goal here, but I'll take it :)

Comment thread compiler/rustc_ast/src/ast.rs Outdated
Comment thread compiler/rustc_ast/src/attr/mod.rs Outdated
Comment thread compiler/rustc_ast/src/attr/mod.rs
Comment thread compiler/rustc_ast/src/attr/mod.rs Outdated
@petrochenkov

Copy link
Copy Markdown
Contributor

I like all the changes here, including the last commits.

(Most of the code refactored here was added during the rustc_attr_parsing migration, previously the cfg trace attributes were just regular normal attributes with a weird non-identifier name and emptied tokens).

@petrochenkov petrochenkov 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 Jul 14, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

I added a commit that addresses @petrochenkov's comments. Now waiting for @JonathanBrouwer's feedback, which might take a few days.

@rust-log-analyzer

This comment has been minimized.

@nnethercote

Copy link
Copy Markdown
Contributor Author

The job pr-check-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Caused by a network failure:

fatal: unable to access 'https://github.com/rust-lang-nursery/rust-toolstate.git/': Failed to connect to github.com port 443 after 133489 ms

@rust-bors

This comment has been minimized.

@petrochenkov petrochenkov 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 Jul 15, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

r=me
r? @JonathanBrouwer

Once `sym::ignore` has been matched, the attribute can't be a
`DocComment` and trying to match one is pointless.
To explain some things that weren't obvious to me.
`AttrItem` currently contains an `AttrItemKind` which is either `Parsed`
or `Unparsed`. In the `Parsed` case the surrounding `AttrItem` is
basically fake, with a meaningless `unsafety` field, a synthetic
(non-ident) symbol, and an empty `tokens`.

This commit moves `Parsed` up one level to become a new variant of
`AttrKind`. It no longer needs to pretend to be an `AttrKind::Normal`,
and makes a number of things simpler:
- No `unparsed_ref` calls needed.
- Replaces the `attr_into_trace` and `Attribute::replace_args` mess with
  the much simpler `convert_normal_to_parsed`.

The commit converts a numberof non-exhaustive `AttrKind` matches (those
that don't involve matching a single attribute) to exhaustive, for
future-proofing. It uses `unreachable!` on all the `AttrKind::Parsed`
cases that aren't hit by the full test suite.
This commit pushes further than the previous one, relying more heavily
on looking directly at `AttrKind::Parsed` to handle various cases.

Note that the removed clippy code was actually dead.
AST attributes use "early parsed"/"parsed" terminology to refer to the
`CfgTrace` and `CfgAttrTrace` attributes. I think this terminology is
meant to echo the terminology used for HIR attributes, i.e.
`hir::Attribute::{Parsed,Unparsed}`, probably because
`hir::Attribute::Parsed` is used for attributes that aren't stored in a
token-based form.

But this naming is misleading. "Early parsed" attributes aren't parsed
at all because they are inserted by the compiler and cannot be written
in source code. There are also two comments that claim that these
attributes are kept in parsed form "so they don't have to be reparsed
every time they're used, for performance", which is simply incorrect.

This commit renames these as "synthetic" attributes, which better
reflects their nature. The commit also fixes the incorrect comments.

Note that `is_parsed_attribute` is unchanged, because it refers to the
HIR attribute meaning. (And the removal of the synthetic attributes from
it in the previous commit is now more obviously correct.)
@rustbot

rustbot commented Jul 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.

@JonathanBrouwer JonathanBrouwer 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.

This makes the code significantly nicer, all commits are also welcome by me, thanks a lot for changing it :)

@bors r=petrochenkov,JonathanBrouwer rollup=never note=perf

View changes since this review

@rust-bors

rust-bors Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit fa56a01 has been approved by petrochenkov,JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 17, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 17, 2026
@rust-bors

rust-bors Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: petrochenkov,JonathanBrouwer
Duration: 3h 18m 29s
Pushing 656ccbe to main...

@rust-bors
rust-bors Bot merged commit 656ccbe into rust-lang:main Jul 17, 2026
14 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor
What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 4a9d536 (parent) -> 656ccbe (this PR)

Test differences

Show 130 test diffs

130 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 656ccbe796ff98def9b555c118e1620c5389e3b2 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-msvc-2: 1h 42m -> 2h 20m (+36.9%)
  2. i686-gnu-nopt-1: 2h 20m -> 1h 29m (-36.1%)
  3. dist-apple-various: 1h 36m -> 2h 11m (+36.1%)
  4. x86_64-msvc-ext3: 1h 23m -> 1h 52m (+34.2%)
  5. dist-powerpc64le-linux-musl: 1h 41m -> 1h 10m (-30.8%)
  6. dist-i686-mingw: 2h 48m -> 2h 3m (-26.6%)
  7. dist-ohos-armv7: 58m 27s -> 1h 13m (+26.4%)
  8. i686-msvc-2: 1h 59m -> 1h 28m (-26.2%)
  9. dist-arm-linux-musl: 1h 16m -> 1h 36m (+25.3%)
  10. dist-x86_64-linux-alt: 1h 53m -> 2h 21m (+25.1%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (656ccbe): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -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.4% [-0.6%, -0.2%] 11
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) -0.4% [-0.6%, -0.2%] 11

Max RSS (memory usage)

Results (primary 4.5%, secondary -3.4%)

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

mean range count
Regressions ❌
(primary)
4.5% [2.8%, 6.7%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-5.6%, -1.7%] 3
All ❌✅ (primary) 4.5% [2.8%, 6.7%] 3

Cycles

Results (secondary 2.0%)

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)
8.0% [8.0%, 8.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.0% [-4.0%, -4.0%] 1
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.0%, 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.0% [0.0%, 0.1%] 42
Regressions ❌
(secondary)
0.0% [0.0%, 0.1%] 23
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [0.0%, 0.1%] 42

Bootstrap: 491.028s -> 490.561s (-0.10%)
Artifact size: 389.42 MiB -> 390.05 MiB (0.16%)

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) merged-by-bors This PR was explicitly merged by bors. T-clippy Relevant to the Clippy team. 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