Skip to content

Move attribute validation from rustc_parse to rustc_attr_parsing #143963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

JonathanBrouwer
Copy link
Contributor

@JonathanBrouwer JonathanBrouwer commented Jul 15, 2025

This moves the old attribute validation from rustc_parse to rustc_attr_parsing.
This PR is easiest to review commit-by-commit.

This is part 1 of 2, of a fix for #143940, the perfomance regression caused by #143460.
This PR does not yet fix the performance regression but does the refactoring work to prepare for fixing it. After all these changes there should be no functional change to the compiler, other than some re-ordering of the errors.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Jul 15, 2025
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jul 15, 2025

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

@JonathanBrouwer JonathanBrouwer force-pushed the rework-illformed-attr branch 2 times, most recently from 78e9f18 to 89169bd Compare July 20, 2025 14:16
@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer JonathanBrouwer force-pushed the rework-illformed-attr branch 2 times, most recently from b166f19 to 6b0c356 Compare July 20, 2025 16:05
@JonathanBrouwer JonathanBrouwer changed the title Rework illformed attribute check for unparsed attributes Move attribute validation from rustc_parse to rustc_attr_parsing Jul 20, 2025
@JonathanBrouwer JonathanBrouwer force-pushed the rework-illformed-attr branch from 6b0c356 to 4091a29 Compare July 20, 2025 16:13
id: S::Id,
emit_lint: &mut impl FnMut(AttributeLint<S::Id>),
) {
let builtin_attr_info = attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR still gets safety information of attributes from BUILTIN_ATTRIBUTE_MAP.
The BUILTIN_ATTRIBUTES global duplicates quite some information (templates, encode cross crate, duplicate logic) from the new parsers. Is the long term goal to remove this global? If yes, I can also make a new match statement somewhere to store this information

@JonathanBrouwer
Copy link
Contributor Author

@rustbot ready
r? @jdonszelmann

I don't expect this PR to have a performance effect but it should definitely get a perf run. Could you do this?

@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 Jul 20, 2025
@JonathanBrouwer JonathanBrouwer marked this pull request as ready for review July 20, 2025 16:21
@rustbot
Copy link
Collaborator

rustbot commented Jul 20, 2025

jdonszelmann is currently at their maximum review capacity.
They may take a while to respond.

@rustbot
Copy link
Collaborator

rustbot commented Jul 20, 2025

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer
Copy link
Contributor Author

Ok now how did I break incremental compilation?...
@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 20, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 20, 2025
Signed-off-by: Jonathan Brouwer <[email protected]>
@JonathanBrouwer JonathanBrouwer force-pushed the rework-illformed-attr branch from 4091a29 to cff21c0 Compare July 20, 2025 18:52
@@ -278,7 +278,7 @@ pub fn no_mangle() {}
#[rustc_clean(cfg = "cfail3")]
#[rustc_clean(cfg = "cfail5")]
#[rustc_clean(cfg = "cfail6")]
#[no_mangle]
#[unsafe(no_mangle)]
Copy link
Contributor Author

@JonathanBrouwer JonathanBrouwer Jul 20, 2025

Choose a reason for hiding this comment

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

These changes are needed because the "this should be unsafe" lint (in edition <2021) is now produced by the attribute parsing system, and therefore stored in

pub delayed_lints: DelayedLints,

One version of this test produces the lint (which matters, even though it is allowed, because it is stored as mentioned above), the other one does not. The easy solution is to make both versions not produce the lint, by adding unsafe

@JonathanBrouwer
Copy link
Contributor Author

@rustbot ready

@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 Jul 20, 2025
@lqd
Copy link
Member

lqd commented Jul 20, 2025

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jul 20, 2025

⌛ Trying commit cff21c0 with merge 52b9195

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jul 20, 2025
Move attribute validation from `rustc_parse` to `rustc_attr_parsing`

This moves the old attribute validation from `rustc_parse` to `rustc_attr_parsing`.
This PR is easiest to review commit-by-commit.

This is part 1 of 2, of a fix for #143940, the perfomance regression caused by #143460.
This PR does not yet fix the performance regression but does the refactoring work to prepare for fixing it. After all these changes there should be no functional change to the compiler, other than some re-ordering of the errors.
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 20, 2025
@rust-bors
Copy link

rust-bors bot commented Jul 20, 2025

☀️ Try build successful (CI)
Build commit: 52b9195 (52b9195b91b08cb00498bb639b8628073eff4113, parent: 0864097cd31ee30f5081ba588a5c9820c2c6fc71)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (52b9195): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@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.3% [0.2%, 0.5%] 15
Regressions ❌
(secondary)
0.4% [0.2%, 0.4%] 7
Improvements ✅
(primary)
-0.4% [-0.5%, -0.2%] 9
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 1
All ❌✅ (primary) 0.1% [-0.5%, 0.5%] 24

Max RSS (memory usage)

Results (primary 0.9%, 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.2% [1.8%, 2.6%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.7% [-1.7%, -1.7%] 1
Improvements ✅
(secondary)
-3.7% [-5.8%, -1.7%] 7
All ❌✅ (primary) 0.9% [-1.7%, 2.6%] 3

Cycles

Results (primary 2.6%, 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)
2.6% [2.4%, 2.7%] 3
Regressions ❌
(secondary)
3.6% [2.2%, 5.2%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.6% [2.4%, 2.7%] 3

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 466.613s -> 465.542s (-0.23%)
Artifact size: 374.57 MiB -> 374.61 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 Jul 20, 2025
@JonathanBrouwer
Copy link
Contributor Author

Hm I don't like that, I'm gonna see if I can figure out what is causing that. It's all incremental related so I think it might be the lint stashing

@bors
Copy link
Collaborator

bors commented Jul 21, 2025

☔ The latest upstream changes (presumably #144269) 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
A-attributes Area: Attributes (`#[…]`, `#![…]`) perf-regression Performance regression. 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.

7 participants