Skip to content

Conversation

samueltardieu
Copy link
Member

@samueltardieu samueltardieu commented May 18, 2025

This patch series makes heavy use of interned symbols when matching against known method names:

  • the first commit reorders the current list of symbols in clippy_utils::sym
  • the second commit adds symbol reordering and order checking to clippy dev fmt / clippy dev fmt --check
  • the third commit converts many uses of string matching during linting to symbols matching

The symbols are kept as-is (not rendered as strings) as much as possible to avoid needing locking the interner as much as possible. Static strings have been kept when they are only used when emitting a diagnostic, as there is no benefit in using interned strings for de-interning them right after.

changelog: none

r? @Alexendoo

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 18, 2025
@samueltardieu samueltardieu force-pushed the more-symbols-less-strings branch 2 times, most recently from 124cab7 to e422ed7 Compare May 18, 2025 22:02
Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

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

All the symbol changes look ok. Just notes on the formatting code.

}

/// Format the symbols list
fn fmt_syms(check: bool) -> Result<(), Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you switch this to use uitils::FileUpdater. Would be something like

FileUpdater::default().update_file_checked(
    "clippy dev fmt",
    mode,
    path,
    update_text_region_fn("start", "end", |dst| write_dst),
)

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know FileUpdater, nice!

line.strip_suffix(',').unwrap_or(line).trim_end()
})
.collect::<Vec<_>>();
lines.sort_by_cached_key(|a| a.to_uppercase());
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the order doesn't really matter, only that there is one, I would just sort normally. x.py tidy also sorts via a normal comparison.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@samueltardieu samueltardieu force-pushed the more-symbols-less-strings branch from e422ed7 to 16087ca Compare May 19, 2025 17:33
@rustbot

This comment has been minimized.

@Jarcho Jarcho self-assigned this May 19, 2025
@samueltardieu samueltardieu force-pushed the more-symbols-less-strings branch from 16087ca to e16801e Compare May 19, 2025 20:48
@samueltardieu
Copy link
Member Author

Rebased

@samueltardieu samueltardieu requested a review from Jarcho May 19, 2025 20:52
Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

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

Thank you.

@Jarcho Jarcho added this pull request to the merge queue May 19, 2025
Merged via the queue into rust-lang:master with commit b87e90b May 19, 2025
11 checks passed
@samueltardieu samueltardieu deleted the more-symbols-less-strings branch May 19, 2025 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants