Repository navigation
reflection: enable tool attributes to be reflectable - #166037
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer The reflection data structures are tied exactly to the implementation cc @oli-obk Some changes occurred in compiler/rustc_attr_ir cc @jdonszelmann, @JonathanBrouwer These commits modify the If this was unintentional then you should revert the changes before this PR is merged. Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred to the CTFE machinery |
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…, r=<try> reflection: enable tool attributes to be reflectable
This comment has been minimized.
This comment has been minimized.
| /// | ||
| /// Tool attributes, with the exception of diagnostic attributes, are not converted into a | ||
| /// parsed form. | ||
| Tool(Box<AttrItem>), |
There was a problem hiding this comment.
I'd prefer if this was implemented by looking up the tool options in the RegisteredTools when needed, rather than re-storing it in every attribute. Is that implementable?
There was a problem hiding this comment.
Tess explained to me that because tool options might differ between crates, it's kinda annoying to find the right ToolOptions that correspond to this attribute, so the implementation in this PR is fine for now
| rustc_ast_pretty = { path = "../rustc_ast_pretty" } | ||
| rustc_data_structures = { path = "../rustc_data_structures" } | ||
| rustc_error_messages = { path = "../rustc_error_messages" } | ||
| rustc_lint_defs = { path = "../rustc_lint_defs" } |
There was a problem hiding this comment.
this is already a transitive dependency through rustc_errors, so this is fine and won't regress bootstrap times :)
This comment has been minimized.
This comment has been minimized.
304cc46 to
e0ac4cc
Compare
|
cc @rust-lang/clippy |
e0ac4cc to
e40ff07
Compare
This comment has been minimized.
This comment has been minimized.
2a06740 to
1f1599d
Compare
|
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. |
This comment has been minimized.
This comment has been minimized.
1f1599d to
cc11ed1
Compare
There was a problem hiding this comment.
If I do #![register_tool(rustfmt(reflect))] is is possible to reflect on it? Since it's already implicitly registered?
Similarly, #![register_tool(diagnostic(reflect))] cannot work since diagnostic attributes are parsed, and do not show up as tool attributes.
Can you also add tests for reflect tools being registered via -Zcrate-attr over command line?
cc11ed1 to
73a18dd
Compare
|
Made it an error when someone reflects on a predefined attribute. If we want to be able to reflect on these attribute later, we would have to plan on dealing with parsed tool attributes like Also added a test for tools registered via |
There was a problem hiding this comment.
|
Reminder, once the PR becomes ready for a review, use |
73a18dd to
48e98b4
Compare
|
@bors r=oli-obk |
…cting-tools, r=oli-obk reflection: enable tool attributes to be reflectable Adds an option to the `register_tool` crate level attribute to allow the option to be reflective. Tool attributes of these registered tools are queryable from a `TypeId` object. Encoded the reflectivity of an attribute in `Attribute::Tool` because the attributes can come from another crate and tools are reflective at the crate level. Addresses the FIXME introduced in rust-lang#165810 Maybe we should run a perf run for it, not sure if the change to `Attribute::Tool` would impact it. r? @oli-obk cc @mejrs
Rollup of 16 pull requests Successful merges: - #166037 (reflection: enable tool attributes to be reflectable) - #165008 (Support `NonNull` pointers as `asm!` input operands) - #165465 (Use `emit_ptr_va_arg` for `va_arg` on M68k) - #166042 (Fix out of scope method suggestion) - #166090 (bootstrap: rebuild LLD when LLVM changes) - #159795 (Introduce `-Z pack-coroutine-layout` flag) - #163556 (arm: only f32 and f64 are valid HFA bases) - #164665 (Add Reference annotations for inline assembly) - #165725 (change target modifier errors to use the diagnostic APIs instead of structs) - #165912 (simplify `fluent_value_from_str_list_sep_by_and`) - #165982 (compiler: Stop special-casing `report_in_external_macro` in `declare_tool_lint!`) - #166006 (Detect method shadowed by another when accessing a field or calling method that isn't found in method chain) - #166083 (Record seeds in the appropriate order) - #166104 (abi/bad-custom.rs: make test run on all editions) - #166124 (platform-support: add amaanq as powerpc64-unknown-linux-gnuelfv2 maintainer) - #166127 (Add tests from failed attempt at implementing `hir::Param` move) Failed merges: - #165094 (reflection: doc attributes from adts, fields, and variants)
…uwer Rollup of 15 pull requests Successful merges: - #166037 (reflection: enable tool attributes to be reflectable) - #165465 (Use `emit_ptr_va_arg` for `va_arg` on M68k) - #166042 (Fix out of scope method suggestion) - #166090 (bootstrap: rebuild LLD when LLVM changes) - #159795 (Introduce `-Z pack-coroutine-layout` flag) - #163556 (arm: only f32 and f64 are valid HFA bases) - #164665 (Add Reference annotations for inline assembly) - #165725 (change target modifier errors to use the diagnostic APIs instead of structs) - #165912 (simplify `fluent_value_from_str_list_sep_by_and`) - #165982 (compiler: Stop special-casing `report_in_external_macro` in `declare_tool_lint!`) - #166006 (Detect method shadowed by another when accessing a field or calling method that isn't found in method chain) - #166083 (Record seeds in the appropriate order) - #166104 (abi/bad-custom.rs: make test run on all editions) - #166124 (platform-support: add amaanq as powerpc64-unknown-linux-gnuelfv2 maintainer) - #166127 (Add tests from failed attempt at implementing `hir::Param` move) Failed merges: - #165094 (reflection: doc attributes from adts, fields, and variants)
Rollup merge of #166037 - Tess4552:reflection-register-reflecting-tools, r=oli-obk reflection: enable tool attributes to be reflectable Adds an option to the `register_tool` crate level attribute to allow the option to be reflective. Tool attributes of these registered tools are queryable from a `TypeId` object. Encoded the reflectivity of an attribute in `Attribute::Tool` because the attributes can come from another crate and tools are reflective at the crate level. Addresses the FIXME introduced in #165810 Maybe we should run a perf run for it, not sure if the change to `Attribute::Tool` would impact it. r? @oli-obk cc @mejrs
Upgrades the Rust toolchain from nightly-2026-11-18 to nightly-2026-11-19. The automated upgrade failed in `cargo build-dev` because of two rustc API changes in this range: - rust-lang/rust#166037 ("reflection: enable tool attributes to be reflectable"): `Attribute::Tool(Box<AttrItem>)` became `Attribute::Tool { item, opts }`. The four matches in `kani_middle/attributes.rs` now bind the `item` field. - rust-lang/rust#164544 (`rustc_intrinsic(llvm = "...")`): `IntrinsicDef::name` is now `Intrinsic::{Rustc(Symbol), Backend { llvm }}`. The `simd_bitmask` check in `kani_middle/intrinsics.rs` now compares against `Intrinsic::Rustc(sym::simd_bitmask)`. Nothing in core/std uses the new `Backend` variant in this nightly, so there is no new handling for it. - `TargetDataLayout::i8_align` was removed: the alignment of `i8` is no longer part of the data layout (`Integer::I8.align` is always 1). The LLBC backend (`codegen_aeneas_llbc/mir_to_ullbc/mod.rs`) now uses `rustc_abi::Integer::I8.align` for the `Bool`, `I8` and `U8` alignments it reports to Charon. No tests change. ### Testing Locally, with CBMC 6.11.0: - `cargo build-dev`, `cargo build-dev -- --features cprover --features llbc`, `./scripts/kani-fmt.sh` and `cargo clippy -p kani-compiler` succeed; `./scripts/kani-llbc-regression.sh` passes. - These suites have no failures: `expected` (562 passed), `cargo-kani` (72), `cargo-ui` (30) and `script-based-pre` (102). - `kani` (655 passed, 2 failed) and `ui` (170 passed, 2 failed) have failures that also occur on `main` in the same local environment: `Quantifiers/typed_variables.rs` and `Quantifiers/arbitrary_range.rs`, and `loop-contracts-synthesis/main_{signed,unsigned}`, which need a `goto-synthesizer` binary that isn't installed locally. - Unit tests for `kani-compiler`, `kani-driver`, `kani_metadata` and `cprover_bindings` pass. Resolves model-checking#5200 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Signed-off-by: Felipe Monteiro <[email protected]>
…uwer Rollup of 15 pull requests Successful merges: - rust-lang/rust#166037 (reflection: enable tool attributes to be reflectable) - rust-lang/rust#165465 (Use `emit_ptr_va_arg` for `va_arg` on M68k) - rust-lang/rust#166042 (Fix out of scope method suggestion) - rust-lang/rust#166090 (bootstrap: rebuild LLD when LLVM changes) - rust-lang/rust#159795 (Introduce `-Z pack-coroutine-layout` flag) - rust-lang/rust#163556 (arm: only f32 and f64 are valid HFA bases) - rust-lang/rust#164665 (Add Reference annotations for inline assembly) - rust-lang/rust#165725 (change target modifier errors to use the diagnostic APIs instead of structs) - rust-lang/rust#165912 (simplify `fluent_value_from_str_list_sep_by_and`) - rust-lang/rust#165982 (compiler: Stop special-casing `report_in_external_macro` in `declare_tool_lint!`) - rust-lang/rust#166006 (Detect method shadowed by another when accessing a field or calling method that isn't found in method chain) - rust-lang/rust#166083 (Record seeds in the appropriate order) - rust-lang/rust#166104 (abi/bad-custom.rs: make test run on all editions) - rust-lang/rust#166124 (platform-support: add amaanq as powerpc64-unknown-linux-gnuelfv2 maintainer) - rust-lang/rust#166127 (Add tests from failed attempt at implementing `hir::Param` move) Failed merges: - rust-lang/rust#165094 (reflection: doc attributes from adts, fields, and variants)
View all comments
Adds an option to the
register_toolcrate level attribute to allow the option to be reflective. Tool attributes of these registered tools are queryable from aTypeIdobject. Encoded the reflectivity of an attribute inAttribute::Toolbecause the attributes can come from another crate and tools are reflective at the crate level.Addresses the FIXME introduced in #165810
Maybe we should run a perf run for it, not sure if the change to
Attribute::Toolwould impact it.r? @oli-obk
cc @mejrs