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

Check for MSRV attributes in late passes using the HIR #13821

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

Conversation

Alexendoo
Copy link
Member

Closes #13169

Late lints now use a parent iter to check for #[clippy::msrv] attributes instead of keeping track with extract_msrv_attr. This is required for incremental lints since they run per module instead of per crate so don't visit all the necessary attributes

As a basic optimisation if no #[clippy::msrv] attributes are discovered in early passes the HIR access is skipped completely and just the configured MSRV is used, for most code bases this will be the case

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented Dec 12, 2024

r? @y21

rustbot has assigned @y21.
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 the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 12, 2024
@blyxyas blyxyas added the performance-project For issues and PRs related to the Clippy Performance Project label Dec 13, 2024
Copy link
Member

@blyxyas blyxyas left a comment

Choose a reason for hiding this comment

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

Could you separate these changes into two or three commits? A commit or two for the change itself, and another commit updating the rest of the files to adhere to the new MSRV system.

This would ease review.

Thanks for tackling the issue!

@Alexendoo Alexendoo force-pushed the late-pass-msrv-rework branch from 0b1f5c8 to 507e6f0 Compare December 13, 2024 17:40
@bors
Copy link
Contributor

bors commented Dec 15, 2024

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

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

Generally looks good to me. I still have some comments (and questions), though not all necessarily blockers

Also, not really related to this PR, but is there anywhere to read more about specifics of incremental lints that you mentioned? (I'm curious how that will work e.g. for some of the lints that keep state across modules or delay their warnings)

Comment on lines -11 to +26
pass: &'a str,
pass: Pass,
Copy link
Member

Choose a reason for hiding this comment

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

This is a nice cleanup 👍

Comment on lines -118 to 116
if self.msrv.current().is_none() {
if self.msrv.current(cx).is_none() {
// If there is no MSRV, then no need to check anything...
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

It's probably worth delaying this check to run after some of the HIR tree checks now that it potentially does a lot more work? (Relevant in a few more places throughout the modified files where this is the first check in e.g. check_expr but I'm trying to keep it in one place).

I don't know of any use case for actually using these outside of the test suite, but for projects that do use this, it seems like that could get pretty expensive to iterate parent nodes for every expression in the common path

Comment on lines +70 to +72
/// `#[clippy::msrv]` attributes are rarely used outside of Clippy's test suite, as a basic
/// optimization we can skip traversing the HIR in [`Msrv::meets`] if we never saw an MSRV attribute
/// during the early lint passes
Copy link
Member

Choose a reason for hiding this comment

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

Could this break if the user allows all early lints (eg -Aclippy::all -Wclippy::some_lint) and all early lint passes get filtered out such that there is nothing to update the static? If I remember right only late lint passes are filtered out, so I guess not (at the moment), but I don't know if that could break in the future?

@blyxyas
Copy link
Member

blyxyas commented Dec 19, 2024

I've been working on getting this benchmarks to be done & analyzing them for about 2 days.

Here's the results.db file for rustc-perf (.tar.gz), use cargo run --bin site on a rustc-perf clone to view all results.

Everything perf-wise seems correct, the optimization is working as expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance-project For issues and PRs related to the Clippy Performance Project 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.

[Project Goal, Help Wanted] Optimizing MSRV attribute collection
5 participants