Skip to content
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

Allow drivers to supply a list of extra symbols to intern #138682

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Alexendoo
Copy link
Member

Allows adding new symbols as consts in external drivers, desirable in Clippy so we can use them in patterns to replace code like

if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned")

The Clippy change adds a couple symbols as a demo, the exact clippy_utils API and replacing other usages can be done on the Clippy side to minimise sync conflicts

@rustbot
Copy link
Collaborator

rustbot commented Mar 19, 2025

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 19, 2025
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Mar 19, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

@blyxyas
Copy link
Member

blyxyas commented Mar 19, 2025

This will help a lot when having symbols on Clippy. We usually just batched these and submitted a PR to add 3 or 4 symbols at a time.

Strong +1 ! 👀

@bors
Copy link
Contributor

bors commented Mar 20, 2025

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

Interner::prefill(&[
#prefill_stream
])
pub(crate) fn fresh(extra: &[&'static str]) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend keeping fresh() but naming a new method for this. Perhaps new_with_extra_preinterned_symbols?

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed it to with_extra_symbols and added some docs

There's only one callsite so the current fresh would be unused

@@ -298,7 +298,7 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
let preinterned_symbols_count = entries.len();
let output = quote! {
const SYMBOL_DIGITS_BASE: u32 = #symbol_digits_base;
const PREINTERNED_SYMBOLS_COUNT: u32 = #preinterned_symbols_count;
pub const PREINTERNED_SYMBOLS_COUNT: u32 = #preinterned_symbols_count;
Copy link
Member

Choose a reason for hiding this comment

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

This needs a better name and we should document what it really means. Perhaps something like

Suggested change
pub const PREINTERNED_SYMBOLS_COUNT: u32 = #preinterned_symbols_count;
/// The number of predefined symbols; this is the the first index for
/// extra pre-interned symbols in an Interner created via
/// `new_with_extra_preinterned_symbols`.
pub const PREDEFINED_SYMBOLS_COUNT: u32 = #predefined_symbols_count;

@rustbot rustbot 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 Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants