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

Turn Linters', etc. implicit into_iter()s into explicit rules() #5436

Merged
merged 2 commits into from
Jul 3, 2023

Conversation

akx
Copy link
Contributor

@akx akx commented Jun 29, 2023

Summary

As discussed on IRC Discord, this will make it easier for e.g. the docs generation stuff to get all rules for a linter (using all_rules()) instead of just non-nursery ones, and it also makes it more Explicit Is Better Than Implicit to iterate over linter rules.

Grepping for Item = Rule reveals some remaining implicit IntoIterators that I didn't feel were necessarily in scope for this (and honestly, iterating over a RuleSet makes sense).

@akx akx force-pushed the yeet-linter-into-iter branch from 1270d62 to d3dd397 Compare June 29, 2023 08:01
@akx akx marked this pull request as ready for review June 29, 2023 08:08
@github-actions
Copy link
Contributor

github-actions bot commented Jun 29, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      9.2±0.04ms     4.4 MB/sec    1.00      9.3±0.04ms     4.4 MB/sec
formatter/numpy/ctypeslib.py               1.00      2.0±0.01ms     8.2 MB/sec    1.00      2.0±0.01ms     8.2 MB/sec
formatter/numpy/globals.py                 1.00    225.1±1.07µs    13.1 MB/sec    1.00    225.3±1.11µs    13.1 MB/sec
formatter/pydantic/types.py                1.00      4.5±0.02ms     5.7 MB/sec    1.00      4.5±0.02ms     5.7 MB/sec
linter/all-rules/large/dataset.py          1.01     15.9±0.09ms     2.6 MB/sec    1.00     15.7±0.08ms     2.6 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.01      4.0±0.03ms     4.2 MB/sec    1.00      3.9±0.02ms     4.2 MB/sec
linter/all-rules/numpy/globals.py          1.01    510.9±1.56µs     5.8 MB/sec    1.00    507.6±2.01µs     5.8 MB/sec
linter/all-rules/pydantic/types.py         1.01      7.0±0.03ms     3.7 MB/sec    1.00      6.9±0.04ms     3.7 MB/sec
linter/default-rules/large/dataset.py      1.01      8.0±0.03ms     5.1 MB/sec    1.00      8.0±0.05ms     5.1 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1752.3±6.37µs     9.5 MB/sec    1.00   1747.1±6.30µs     9.5 MB/sec
linter/default-rules/numpy/globals.py      1.00    197.5±0.98µs    14.9 MB/sec    1.01    198.8±1.51µs    14.8 MB/sec
linter/default-rules/pydantic/types.py     1.01      3.7±0.01ms     7.0 MB/sec    1.00      3.6±0.01ms     7.1 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.01      9.7±0.36ms     4.2 MB/sec    1.00      9.6±0.31ms     4.2 MB/sec
formatter/numpy/ctypeslib.py               1.00      2.1±0.10ms     8.1 MB/sec    1.00      2.1±0.08ms     8.1 MB/sec
formatter/numpy/globals.py                 1.00   224.5±17.11µs    13.1 MB/sec    1.01   227.1±11.27µs    13.0 MB/sec
formatter/pydantic/types.py                1.01      4.5±0.16ms     5.7 MB/sec    1.00      4.4±0.11ms     5.7 MB/sec
linter/all-rules/large/dataset.py          1.00     15.1±0.56ms     2.7 MB/sec    1.06     16.0±0.61ms     2.5 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.9±0.08ms     4.2 MB/sec    1.06      4.1±0.13ms     4.0 MB/sec
linter/all-rules/numpy/globals.py          1.00   473.6±14.69µs     6.2 MB/sec    1.10   521.3±20.34µs     5.7 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.6±0.20ms     3.9 MB/sec    1.08      7.1±0.26ms     3.6 MB/sec
linter/default-rules/large/dataset.py      1.00      8.0±0.37ms     5.1 MB/sec    1.03      8.2±0.22ms     4.9 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.01  1750.9±61.48µs     9.5 MB/sec    1.00  1730.4±42.40µs     9.6 MB/sec
linter/default-rules/numpy/globals.py      1.01   208.3±10.43µs    14.2 MB/sec    1.00   207.3±11.96µs    14.2 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.8±0.11ms     6.8 MB/sec    1.02      3.8±0.13ms     6.6 MB/sec

},
);
linter_rules_match_arms.extend(quote! {
Linter::#linter => vec![#(#rule_paths,)*].into_iter(),
Copy link
Member

@MichaReiser MichaReiser Jun 29, 2023

Choose a reason for hiding this comment

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

Nit: Not sure if a good idea but using vec creates an allocation for every rules call. Should we instead return a static array? I'm not sure if this is a good idea because it may force Rust to copy the whole array which is rather large.

Another alternative could be to have a static (private) array of all rules somewhere and have rules() return a &'static [Rule] slice.

let rule_len = rule_paths.len();
Suggested change
Linter::#linter => vec![#(#rule_paths,)*].into_iter(),
Linter::#linter => [#(#rule_paths,)*; #rule_len].into_iter(),

I'm also okay having this as a separate PR because the code already used a vec before.

@konstin konstin requested a review from charliermarsh June 29, 2023 08:24
@akx
Copy link
Contributor Author

akx commented Jun 29, 2023

I'll draft this and make the array change suggested by @MichaReiser across the board 👍

EDIT: Okay, maybe we can do that later on, I'm getting a mysterious macro expansion syntax error I don't have the bandwidth for right now 😂

@akx akx marked this pull request as draft June 29, 2023 11:08
@akx akx marked this pull request as ready for review June 29, 2023 11:42
@charliermarsh charliermarsh merged commit 6acc316 into astral-sh:main Jul 3, 2023
@akx akx deleted the yeet-linter-into-iter branch July 4, 2023 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants