-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix compiler panic with a large number of threads #132355
Conversation
r? @SparrowLii since this is probably parallel frontend stuff |
That makes sense, thanks! |
Please squash into one commit, this only touches 3 lines. |
818099c
to
ef30dab
Compare
@fmease All good now? |
Yes, thanks! @bors r=SparrowLii |
Please no? This should have some warning when max value actually reached. |
Hmm... maybe? How to emit a warning for such a thing in the compiler? |
Probably parsing can be left as it is, and actual max value checked here rust/compiler/rustc_session/src/session.rs Lines 819 to 821 in 298c746
and emit_warn here (or early_warn )? Probably someone will suggest correct method.
|
@bors r- |
I would add this warning on parsing. I think I just need to revert to the first version and add this warning in else. @fmease @SparrowLii What do you think? |
Better place: rust/compiler/rustc_session/src/config.rs Lines 2463 to 2465 in 298c746
|
So. Should I use std::thread::available_parallelism() to determinate the proper value? |
Maybe apply min value after that match in |
92d06b4
to
67e6b4b
Compare
Maybe this makes more sense? |
This comment has been minimized.
This comment has been minimized.
More like pub fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
let ret = match v.and_then(|s| s.parse().ok()) {
Some(0) => {
*slot = std::thread::available_parallelism().map_or(1, NonZero::<usize>::get);
true
}
Some(i) => {
*slot = i;
true
}
None => false,
};
// We want to cap the number of threads here to avoid large numbers like 999999 and compiler panics.
// This solution was suggested here https://github.com/rust-lang/rust/issues/117638#issuecomment-1800925067
*slot = slot.clone().min(MAX_THREADS_CAP);
ret
} and left things in config.rs as in previous try with simple warning. |
67e6b4b
to
7591eb6
Compare
@klensy Done. |
@rustbot review for official reviewer |
@bors r+ rollup |
Fix compiler panic with a large number of threads Hi, This PR is an attempt to fix the problem described here rust-lang#117638 using the solution suggested in this comment rust-lang#117638 (comment) Best regards, Michal
Wouldn't we want to be able to use more threads on future machines? I feel having this limit hard-coded could pose a problem, or maybe I'm missing something? |
When you use it like -Zthreads=0, then you should have a value from std::thread::available_parallelism() In one iteration of the PR I also tried to use it for Some(i) match, but @klensy suggested a different solution. |
The way it was implemented, value was taken from available_parallelism() but still warned that it was capped at 256, even if it actually don't. |
I tested it on my machine and it was capped properly to 6. |
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#132153 (Stabilise `const_char_encode_utf16`.) - rust-lang#132355 (Fix compiler panic with a large number of threads) - rust-lang#132486 (No need to instantiate binder in `confirm_async_closure_candidate`) - rust-lang#132594 (Subtree update of `rust-analyzer`) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#132355 (Fix compiler panic with a large number of threads) - rust-lang#132486 (No need to instantiate binder in `confirm_async_closure_candidate`) - rust-lang#132544 (Use backticks instead of single quotes for library feature names in diagnostics) - rust-lang#132559 (find the generic container rather than simply looking up for the assoc with const arg) - rust-lang#132579 (add rustc std workspace crate sources) - rust-lang#132583 (Suggest creating unary tuples when types don't match a trait) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#132355 - practicalrs:fix_117638, r=SparrowLii Fix compiler panic with a large number of threads Hi, This PR is an attempt to fix the problem described here rust-lang#117638 using the solution suggested in this comment rust-lang#117638 (comment) Best regards, Michal
@SparrowLii @matthiaskrgr Can #117638 be closed now? |
Hi,
This PR is an attempt to fix the problem described here #117638 using the solution suggested in this comment #117638 (comment)
Best regards,
Michal