Skip to content

Commit 1b14fd3

Browse files
committed
Auto merge of #94612 - matthiaskrgr:rollup-2jm5wkr, r=matthiaskrgr
Rollup of 6 pull requests r? `@ghost`
2 parents b4bf56c + b4baef5 commit 1b14fd3

File tree

22 files changed

+112
-62
lines changed

22 files changed

+112
-62
lines changed

Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ dependencies = [
221221
"getopts",
222222
"ignore",
223223
"libc",
224-
"num_cpus",
225224
"once_cell",
226225
"opener",
227226
"pretty_assertions",
@@ -249,7 +248,6 @@ dependencies = [
249248
"anyhow",
250249
"flate2",
251250
"hex 0.4.2",
252-
"num_cpus",
253251
"rayon",
254252
"serde",
255253
"serde_json",
@@ -4242,7 +4240,6 @@ name = "rustc_session"
42424240
version = "0.0.0"
42434241
dependencies = [
42444242
"getopts",
4245-
"num_cpus",
42464243
"rustc_ast",
42474244
"rustc_data_structures",
42484245
"rustc_errors",

compiler/rustc_parse/src/parser/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::pat::Expected;
2-
use super::ty::{AllowPlus, IsAsCast};
2+
use super::ty::{AllowPlus, RecoverQuestionMark};
33
use super::{
44
BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions,
55
SemiColonMode, SeqSep, TokenExpectType, TokenType,
@@ -1049,9 +1049,9 @@ impl<'a> Parser<'a> {
10491049
pub(super) fn maybe_recover_from_question_mark(
10501050
&mut self,
10511051
ty: P<Ty>,
1052-
is_as_cast: IsAsCast,
1052+
recover_question_mark: RecoverQuestionMark,
10531053
) -> P<Ty> {
1054-
if let IsAsCast::Yes = is_as_cast {
1054+
if let RecoverQuestionMark::No = recover_question_mark {
10551055
return ty;
10561056
}
10571057
if self.token == token::Question {

compiler/rustc_parse/src/parser/nonterminal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'a> Parser<'a> {
140140
}
141141

142142
NonterminalKind::Ty => {
143-
token::NtTy(self.collect_tokens_no_attrs(|this| this.parse_ty())?)
143+
token::NtTy(self.collect_tokens_no_attrs(|this| this.parse_no_question_mark_recover())?)
144144
}
145145
// this could be handled like a token, since it is one
146146
NonterminalKind::Ident

compiler/rustc_parse/src/parser/ty.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub(super) enum RecoverQPath {
4444
No,
4545
}
4646

47-
pub(super) enum IsAsCast {
47+
pub(super) enum RecoverQuestionMark {
4848
Yes,
4949
No,
5050
}
@@ -105,7 +105,7 @@ impl<'a> Parser<'a> {
105105
RecoverQPath::Yes,
106106
RecoverReturnSign::Yes,
107107
None,
108-
IsAsCast::No,
108+
RecoverQuestionMark::Yes,
109109
)
110110
}
111111

@@ -119,7 +119,7 @@ impl<'a> Parser<'a> {
119119
RecoverQPath::Yes,
120120
RecoverReturnSign::Yes,
121121
Some(ty_params),
122-
IsAsCast::No,
122+
RecoverQuestionMark::Yes,
123123
)
124124
}
125125

@@ -133,7 +133,7 @@ impl<'a> Parser<'a> {
133133
RecoverQPath::Yes,
134134
RecoverReturnSign::Yes,
135135
None,
136-
IsAsCast::No,
136+
RecoverQuestionMark::Yes,
137137
)
138138
}
139139

@@ -150,7 +150,7 @@ impl<'a> Parser<'a> {
150150
RecoverQPath::Yes,
151151
RecoverReturnSign::Yes,
152152
None,
153-
IsAsCast::No,
153+
RecoverQuestionMark::Yes,
154154
)
155155
}
156156

@@ -163,9 +163,21 @@ impl<'a> Parser<'a> {
163163
RecoverQPath::Yes,
164164
RecoverReturnSign::Yes,
165165
None,
166-
IsAsCast::Yes,
166+
RecoverQuestionMark::No,
167167
)
168168
}
169+
170+
pub(super) fn parse_no_question_mark_recover(&mut self) -> PResult<'a, P<Ty>> {
171+
self.parse_ty_common(
172+
AllowPlus::Yes,
173+
AllowCVariadic::No,
174+
RecoverQPath::Yes,
175+
RecoverReturnSign::Yes,
176+
None,
177+
RecoverQuestionMark::No,
178+
)
179+
}
180+
169181
/// Parse a type without recovering `:` as `->` to avoid breaking code such as `where fn() : for<'a>`
170182
pub(super) fn parse_ty_for_where_clause(&mut self) -> PResult<'a, P<Ty>> {
171183
self.parse_ty_common(
@@ -174,7 +186,7 @@ impl<'a> Parser<'a> {
174186
RecoverQPath::Yes,
175187
RecoverReturnSign::OnlyFatArrow,
176188
None,
177-
IsAsCast::No,
189+
RecoverQuestionMark::Yes,
178190
)
179191
}
180192

@@ -193,7 +205,7 @@ impl<'a> Parser<'a> {
193205
recover_qpath,
194206
recover_return_sign,
195207
None,
196-
IsAsCast::No,
208+
RecoverQuestionMark::Yes,
197209
)?;
198210
FnRetTy::Ty(ty)
199211
} else if recover_return_sign.can_recover(&self.token.kind) {
@@ -214,7 +226,7 @@ impl<'a> Parser<'a> {
214226
recover_qpath,
215227
recover_return_sign,
216228
None,
217-
IsAsCast::No,
229+
RecoverQuestionMark::Yes,
218230
)?;
219231
FnRetTy::Ty(ty)
220232
} else {
@@ -229,7 +241,7 @@ impl<'a> Parser<'a> {
229241
recover_qpath: RecoverQPath,
230242
recover_return_sign: RecoverReturnSign,
231243
ty_generics: Option<&Generics>,
232-
is_as_cast: IsAsCast,
244+
recover_question_mark: RecoverQuestionMark,
233245
) -> PResult<'a, P<Ty>> {
234246
let allow_qpath_recovery = recover_qpath == RecoverQPath::Yes;
235247
maybe_recover_from_interpolated_ty_qpath!(self, allow_qpath_recovery);
@@ -305,7 +317,7 @@ impl<'a> Parser<'a> {
305317
// Try to recover from use of `+` with incorrect priority.
306318
self.maybe_report_ambiguous_plus(allow_plus, impl_dyn_multi, &ty);
307319
self.maybe_recover_from_bad_type_plus(allow_plus, &ty)?;
308-
let ty = self.maybe_recover_from_question_mark(ty, is_as_cast);
320+
let ty = self.maybe_recover_from_question_mark(ty, recover_question_mark);
309321
self.maybe_recover_from_bad_qpath(ty, allow_qpath_recovery)
310322
}
311323

compiler/rustc_session/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ rustc_serialize = { path = "../rustc_serialize" }
1515
rustc_data_structures = { path = "../rustc_data_structures" }
1616
rustc_span = { path = "../rustc_span" }
1717
rustc_fs_util = { path = "../rustc_fs_util" }
18-
num_cpus = "1.0"
1918
rustc_ast = { path = "../rustc_ast" }
2019
rustc_lint_defs = { path = "../rustc_lint_defs" }

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ mod parse {
551551
crate fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
552552
match v.and_then(|s| s.parse().ok()) {
553553
Some(0) => {
554-
*slot = ::num_cpus::get();
554+
*slot = std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get);
555555
true
556556
}
557557
Some(i) => {

library/std/src/sync/once.rs

+2
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ impl Once {
256256
///
257257
/// [poison]: struct.Mutex.html#poisoning
258258
#[stable(feature = "rust1", since = "1.0.0")]
259+
#[track_caller]
259260
pub fn call_once<F>(&self, f: F)
260261
where
261262
F: FnOnce(),
@@ -390,6 +391,7 @@ impl Once {
390391
// currently no way to take an `FnOnce` and call it via virtual dispatch
391392
// without some allocation overhead.
392393
#[cold]
394+
#[track_caller]
393395
fn call_inner(&self, ignore_poisoning: bool, init: &mut dyn FnMut(&OnceState)) {
394396
let mut state_and_queue = self.state_and_queue.load(Ordering::Acquire);
395397
loop {

library/std/src/thread/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1443,13 +1443,18 @@ impl<T> JoinHandle<T> {
14431443
self.0.join()
14441444
}
14451445

1446-
/// Checks if the associated thread is still running its main function.
1446+
/// Checks if the associated thread has finished running its main function.
14471447
///
1448-
/// This might return `false` for a brief moment after the thread's main
1448+
/// This might return `true` for a brief moment after the thread's main
14491449
/// function has returned, but before the thread itself has stopped running.
1450+
/// However, once this returns `true`, [`join`][Self::join] can be expected
1451+
/// to return quickly, without blocking for any significant amount of time.
1452+
///
1453+
/// This function does not block. To block while waiting on the thread to finish,
1454+
/// use [`join`][Self::join].
14501455
#[unstable(feature = "thread_is_running", issue = "90470")]
1451-
pub fn is_running(&self) -> bool {
1452-
Arc::strong_count(&self.0.packet) > 1
1456+
pub fn is_finished(&self) -> bool {
1457+
Arc::strong_count(&self.0.packet) == 1
14531458
}
14541459
}
14551460

library/std/src/thread/scoped.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
240240
///
241241
/// ```
242242
/// #![feature(scoped_threads)]
243-
/// #![feature(thread_is_running)]
244243
///
245244
/// use std::thread;
246245
///
@@ -274,7 +273,6 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
274273
///
275274
/// ```
276275
/// #![feature(scoped_threads)]
277-
/// #![feature(thread_is_running)]
278276
///
279277
/// use std::thread;
280278
///
@@ -289,13 +287,18 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
289287
self.0.join()
290288
}
291289

292-
/// Checks if the associated thread is still running its main function.
290+
/// Checks if the associated thread has finished running its main function.
293291
///
294-
/// This might return `false` for a brief moment after the thread's main
292+
/// This might return `true` for a brief moment after the thread's main
295293
/// function has returned, but before the thread itself has stopped running.
294+
/// However, once this returns `true`, [`join`][Self::join] can be expected
295+
/// to return quickly, without blocking for any significant amount of time.
296+
///
297+
/// This function does not block. To block while waiting on the thread to finish,
298+
/// use [`join`][Self::join].
296299
#[unstable(feature = "thread_is_running", issue = "90470")]
297-
pub fn is_running(&self) -> bool {
298-
Arc::strong_count(&self.0.packet) > 1
300+
pub fn is_finished(&self) -> bool {
301+
Arc::strong_count(&self.0.packet) == 1
299302
}
300303
}
301304

library/std/src/thread/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn test_run_basic() {
5252
}
5353

5454
#[test]
55-
fn test_is_running() {
55+
fn test_is_finished() {
5656
let b = Arc::new(Barrier::new(2));
5757
let t = thread::spawn({
5858
let b = b.clone();
@@ -63,14 +63,14 @@ fn test_is_running() {
6363
});
6464

6565
// Thread is definitely running here, since it's still waiting for the barrier.
66-
assert_eq!(t.is_running(), true);
66+
assert_eq!(t.is_finished(), false);
6767

6868
// Unblock the barrier.
6969
b.wait();
7070

71-
// Now check that t.is_running() becomes false within a reasonable time.
71+
// Now check that t.is_finished() becomes true within a reasonable time.
7272
let start = Instant::now();
73-
while t.is_running() {
73+
while !t.is_finished() {
7474
assert!(start.elapsed() < Duration::from_secs(2));
7575
thread::sleep(Duration::from_millis(15));
7676
}

src/bootstrap/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ test = false
3737
build_helper = { path = "../build_helper" }
3838
cmake = "0.1.38"
3939
filetime = "0.2"
40-
num_cpus = "1.0"
4140
getopts = "0.2.19"
4241
cc = "1.0.69"
4342
libc = "0.2"

src/bootstrap/config.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ macro_rules! derive_merge {
387387

388388
derive_merge! {
389389
/// TOML representation of various global build decisions.
390-
#[derive(Deserialize, Default, Clone)]
390+
#[derive(Deserialize, Default)]
391391
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
392392
struct Build {
393393
build: Option<String>,
@@ -434,7 +434,7 @@ derive_merge! {
434434

435435
derive_merge! {
436436
/// TOML representation of various global install decisions.
437-
#[derive(Deserialize, Default, Clone)]
437+
#[derive(Deserialize)]
438438
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
439439
struct Install {
440440
prefix: Option<String>,
@@ -449,7 +449,7 @@ derive_merge! {
449449

450450
derive_merge! {
451451
/// TOML representation of how the LLVM build is configured.
452-
#[derive(Deserialize, Default)]
452+
#[derive(Deserialize)]
453453
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
454454
struct Llvm {
455455
skip_rebuild: Option<bool>,
@@ -483,7 +483,7 @@ derive_merge! {
483483
}
484484

485485
derive_merge! {
486-
#[derive(Deserialize, Default, Clone)]
486+
#[derive(Deserialize)]
487487
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
488488
struct Dist {
489489
sign_folder: Option<String>,
@@ -510,7 +510,7 @@ impl Default for StringOrBool {
510510

511511
derive_merge! {
512512
/// TOML representation of how the Rust build is configured.
513-
#[derive(Deserialize, Default)]
513+
#[derive(Deserialize)]
514514
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
515515
struct Rust {
516516
optimize: Option<bool>,
@@ -565,7 +565,7 @@ derive_merge! {
565565

566566
derive_merge! {
567567
/// TOML representation of how each build target is configured.
568-
#[derive(Deserialize, Default)]
568+
#[derive(Deserialize)]
569569
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
570570
struct TomlTarget {
571571
cc: Option<String>,
@@ -1187,7 +1187,7 @@ fn set<T>(field: &mut T, val: Option<T>) {
11871187

11881188
fn threads_from_config(v: u32) -> u32 {
11891189
match v {
1190-
0 => num_cpus::get() as u32,
1190+
0 => std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32,
11911191
n => n,
11921192
}
11931193
}

src/bootstrap/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
208208
let j_msg = format!(
209209
"number of jobs to run in parallel; \
210210
defaults to {} (this host's logical CPU count)",
211-
num_cpus::get()
211+
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get)
212212
);
213213
opts.optopt("j", "jobs", &j_msg, "JOBS");
214214
opts.optflag("h", "help", "print this help message");

src/bootstrap/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,9 @@ impl Build {
922922
/// Returns the number of parallel jobs that have been configured for this
923923
/// build.
924924
fn jobs(&self) -> u32 {
925-
self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32)
925+
self.config.jobs.unwrap_or_else(|| {
926+
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32
927+
})
926928
}
927929

928930
fn debuginfo_map_to(&self, which: GitRepo) -> Option<String> {

0 commit comments

Comments
 (0)