Skip to content

Lintcheck maintenance #10445

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

Merged
merged 2 commits into from
Mar 4, 2023
Merged

Conversation

samueltardieu
Copy link
Contributor

Make cargo lintcheck -j 0 use all threads instead of panicking, and cleanup (and shorten) lintcheck's parsing code.

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented Mar 4, 2023

r? @llogiq

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 4, 2023
Copy link
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

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

Do we need the num_cpus dependency here? Otherwise this looks good and I'll gladly r+ it.

// look at the --threads arg, if 0 is passed, use the threads count
if config.max_jobs == 0 {
// automatic choice
config.max_jobs = num_cpus::get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use std::thread::available_parallelism() here and avoid an extra dependency?

Copy link
Contributor Author

@samueltardieu samueltardieu Mar 4, 2023

Choose a reason for hiding this comment

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

Sure. I introduced the dependency in the first commit to keep the same semantics as was there before so that commits were self contained, and didn't think twice about removing it. Done, now in two commits.

@samueltardieu samueltardieu force-pushed the lintcheck-maintenance branch from 151ef5a to f82c64a Compare March 4, 2023 16:22
Using `rayon::current_num_threads()` causes a bug:

```
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value:
  ThreadPoolBuildError { kind: GlobalPoolAlreadyInitialized }',
  src/main.rs:632:10
```

Moreover, using the number of threads and dividing it by 2 wouldn't
return the number of physical threads on modern processors which have
a varying number of threads per core.

It makes little sense to restrict ourselves to physical threads,
especially when, in modern architectures, cores with multiple threads
are often faster (performance) while cores with a unique threads are
often slower (efficient). The Rust runtime will make a better choice.
@samueltardieu samueltardieu force-pushed the lintcheck-maintenance branch from f82c64a to 00dedfa Compare March 4, 2023 16:30
// look at the --threads arg, if 0 is passed, use the threads count
if config.max_jobs == 0 {
// automatic choice
config.max_jobs = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
config.max_jobs = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1);
config.max_jobs = std::thread::available_parallelism().map_or(1, |n| n.get());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. There should be a lint for that.

Neat GitHub interface btw, I didn't know this one.

This makes the code shorter and clearer.

The only incompatible change is that an explicit command-line argument
`--crates-toml=` will take precedence over the `LINTCHECK_TOML`
environment variable.
@samueltardieu samueltardieu force-pushed the lintcheck-maintenance branch from 00dedfa to 79829d8 Compare March 4, 2023 22:17
@llogiq
Copy link
Contributor

llogiq commented Mar 4, 2023

Thank you! And I think there is a lint for that, I'm curious why it didn't trigger during dogfood.

@bors r+

@bors
Copy link
Contributor

bors commented Mar 4, 2023

📌 Commit 79829d8 has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Mar 4, 2023

⌛ Testing commit 79829d8 with merge 78f0f78...

@bors
Copy link
Contributor

bors commented Mar 4, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing 78f0f78 to master...

@bors bors merged commit 78f0f78 into rust-lang:master Mar 4, 2023
@samueltardieu samueltardieu deleted the lintcheck-maintenance branch March 5, 2023 19:18
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