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
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
@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
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
@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
Copy link
Collaborator

The job aarch64-gnu-llvm-19-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
failures:

---- [incremental] tests/incremental/hashes/function_interfaces.rs stdout ----

error in revision `cfail2`: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/incremental/hashes/function_interfaces.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "cfail2" "--check-cfg" "cfg(test,FALSE,cfail1,cfail2,cfail3,cfail4,cfail5,cfail6)" "-C" "incremental=/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/function_interfaces/function_interfaces.inc" "-Z" "incremental-verify-ich" "-O" "--error-format" "json" "--json" "future-incompat" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/function_interfaces" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "query-dep-graph" "-O" "-Zincremental-ignore-spans"
stdout: none
--- stderr -------------------------------
error: `opt_hir_owner_nodes(no_mangle)` should be clean but is not
##[error]  --> /checkout/tests/incremental/hashes/function_interfaces.rs:282:1
   |
LL | pub fn no_mangle() {}
   | ^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error
------------------------------------------


---- [incremental] tests/incremental/hashes/inherent_impls.rs stdout ----

error in revision `cfail2`: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/incremental/hashes/inherent_impls.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "cfail2" "--check-cfg" "cfg(test,FALSE,cfail1,cfail2,cfail3,cfail4,cfail5,cfail6)" "-C" "incremental=/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/inherent_impls/inherent_impls.inc" "-Z" "incremental-verify-ich" "-O" "--error-format" "json" "--json" "future-incompat" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/inherent_impls" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "query-dep-graph" "-O" "-Zincremental-ignore-spans"
stdout: none
--- stderr -------------------------------
error: `opt_hir_owner_nodes(Foo::add_no_mangle_to_method)` should be clean but is not
##[error]  --> /checkout/tests/incremental/hashes/inherent_impls.rs:678:5
   |
LL |     pub fn add_no_mangle_to_method(&self) { }
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error
------------------------------------------


---- [incremental] tests/incremental/hashes/statics.rs stdout ----

error in revision `cfail2`: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/incremental/hashes/statics.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "cfail2" "--check-cfg" "cfg(test,FALSE,cfail1,cfail2,cfail3,cfail4,cfail5,cfail6)" "-C" "incremental=/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/statics/statics.inc" "-Z" "incremental-verify-ich" "-O" "--error-format" "json" "--json" "future-incompat" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/statics" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "query-dep-graph" "-O" "-Zincremental-ignore-spans"
stdout: none
--- stderr -------------------------------
error: `opt_hir_owner_nodes(STATIC_NO_MANGLE)` should be clean but is not
##[error]  --> /checkout/tests/incremental/hashes/statics.rs:69:1
   |
LL | static STATIC_NO_MANGLE: u8 = 0;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error
------------------------------------------


---- [incremental] tests/incremental/hashes/trait_impls.rs stdout ----

error in revision `cfail2`: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/incremental/hashes/trait_impls.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "cfail2" "--check-cfg" "cfg(test,FALSE,cfail1,cfail2,cfail3,cfail4,cfail5,cfail6)" "-C" "incremental=/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/trait_impls/trait_impls.inc" "-Z" "incremental-verify-ich" "-O" "--error-format" "json" "--json" "future-incompat" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/trait_impls" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "query-dep-graph" "-O" "-Zincremental-ignore-spans"
stdout: none
--- stderr -------------------------------
error: `opt_hir_owner_nodes(<Foo as AddNoMangleToMethod>::add_no_mangle_to_method)` should be clean but is not
##[error]  --> /checkout/tests/incremental/hashes/trait_impls.rs:586:5
   |
LL |     fn add_no_mangle_to_method(&self) { }
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants