Skip to content

Rollup of 6 pull requests #94612

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 15 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ dependencies = [
"getopts",
"ignore",
"libc",
"num_cpus",
"once_cell",
"opener",
"pretty_assertions",
Expand Down Expand Up @@ -249,7 +248,6 @@ dependencies = [
"anyhow",
"flate2",
"hex 0.4.2",
"num_cpus",
"rayon",
"serde",
"serde_json",
Expand Down Expand Up @@ -4242,7 +4240,6 @@ name = "rustc_session"
version = "0.0.0"
dependencies = [
"getopts",
"num_cpus",
"rustc_ast",
"rustc_data_structures",
"rustc_errors",
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::pat::Expected;
use super::ty::{AllowPlus, IsAsCast};
use super::ty::{AllowPlus, RecoverQuestionMark};
use super::{
BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions,
SemiColonMode, SeqSep, TokenExpectType, TokenType,
Expand Down Expand Up @@ -1049,9 +1049,9 @@ impl<'a> Parser<'a> {
pub(super) fn maybe_recover_from_question_mark(
&mut self,
ty: P<Ty>,
is_as_cast: IsAsCast,
recover_question_mark: RecoverQuestionMark,
) -> P<Ty> {
if let IsAsCast::Yes = is_as_cast {
if let RecoverQuestionMark::No = recover_question_mark {
return ty;
}
if self.token == token::Question {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/nonterminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<'a> Parser<'a> {
}

NonterminalKind::Ty => {
token::NtTy(self.collect_tokens_no_attrs(|this| this.parse_ty())?)
token::NtTy(self.collect_tokens_no_attrs(|this| this.parse_no_question_mark_recover())?)
}
// this could be handled like a token, since it is one
NonterminalKind::Ident
Expand Down
34 changes: 23 additions & 11 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(super) enum RecoverQPath {
No,
}

pub(super) enum IsAsCast {
pub(super) enum RecoverQuestionMark {
Yes,
No,
}
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<'a> Parser<'a> {
RecoverQPath::Yes,
RecoverReturnSign::Yes,
None,
IsAsCast::No,
RecoverQuestionMark::Yes,
)
}

Expand All @@ -119,7 +119,7 @@ impl<'a> Parser<'a> {
RecoverQPath::Yes,
RecoverReturnSign::Yes,
Some(ty_params),
IsAsCast::No,
RecoverQuestionMark::Yes,
)
}

Expand All @@ -133,7 +133,7 @@ impl<'a> Parser<'a> {
RecoverQPath::Yes,
RecoverReturnSign::Yes,
None,
IsAsCast::No,
RecoverQuestionMark::Yes,
)
}

Expand All @@ -150,7 +150,7 @@ impl<'a> Parser<'a> {
RecoverQPath::Yes,
RecoverReturnSign::Yes,
None,
IsAsCast::No,
RecoverQuestionMark::Yes,
)
}

Expand All @@ -163,9 +163,21 @@ impl<'a> Parser<'a> {
RecoverQPath::Yes,
RecoverReturnSign::Yes,
None,
IsAsCast::Yes,
RecoverQuestionMark::No,
)
}

pub(super) fn parse_no_question_mark_recover(&mut self) -> PResult<'a, P<Ty>> {
self.parse_ty_common(
AllowPlus::Yes,
AllowCVariadic::No,
RecoverQPath::Yes,
RecoverReturnSign::Yes,
None,
RecoverQuestionMark::No,
)
}

/// Parse a type without recovering `:` as `->` to avoid breaking code such as `where fn() : for<'a>`
pub(super) fn parse_ty_for_where_clause(&mut self) -> PResult<'a, P<Ty>> {
self.parse_ty_common(
Expand All @@ -174,7 +186,7 @@ impl<'a> Parser<'a> {
RecoverQPath::Yes,
RecoverReturnSign::OnlyFatArrow,
None,
IsAsCast::No,
RecoverQuestionMark::Yes,
)
}

Expand All @@ -193,7 +205,7 @@ impl<'a> Parser<'a> {
recover_qpath,
recover_return_sign,
None,
IsAsCast::No,
RecoverQuestionMark::Yes,
)?;
FnRetTy::Ty(ty)
} else if recover_return_sign.can_recover(&self.token.kind) {
Expand All @@ -214,7 +226,7 @@ impl<'a> Parser<'a> {
recover_qpath,
recover_return_sign,
None,
IsAsCast::No,
RecoverQuestionMark::Yes,
)?;
FnRetTy::Ty(ty)
} else {
Expand All @@ -229,7 +241,7 @@ impl<'a> Parser<'a> {
recover_qpath: RecoverQPath,
recover_return_sign: RecoverReturnSign,
ty_generics: Option<&Generics>,
is_as_cast: IsAsCast,
recover_question_mark: RecoverQuestionMark,
) -> PResult<'a, P<Ty>> {
let allow_qpath_recovery = recover_qpath == RecoverQPath::Yes;
maybe_recover_from_interpolated_ty_qpath!(self, allow_qpath_recovery);
Expand Down Expand Up @@ -305,7 +317,7 @@ impl<'a> Parser<'a> {
// Try to recover from use of `+` with incorrect priority.
self.maybe_report_ambiguous_plus(allow_plus, impl_dyn_multi, &ty);
self.maybe_recover_from_bad_type_plus(allow_plus, &ty)?;
let ty = self.maybe_recover_from_question_mark(ty, is_as_cast);
let ty = self.maybe_recover_from_question_mark(ty, recover_question_mark);
self.maybe_recover_from_bad_qpath(ty, allow_qpath_recovery)
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ rustc_serialize = { path = "../rustc_serialize" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_span = { path = "../rustc_span" }
rustc_fs_util = { path = "../rustc_fs_util" }
num_cpus = "1.0"
rustc_ast = { path = "../rustc_ast" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ mod parse {
crate fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
match v.and_then(|s| s.parse().ok()) {
Some(0) => {
*slot = ::num_cpus::get();
*slot = std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get);
true
}
Some(i) => {
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sync/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ impl Once {
///
/// [poison]: struct.Mutex.html#poisoning
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
pub fn call_once<F>(&self, f: F)
where
F: FnOnce(),
Expand Down Expand Up @@ -390,6 +391,7 @@ impl Once {
// currently no way to take an `FnOnce` and call it via virtual dispatch
// without some allocation overhead.
#[cold]
#[track_caller]
fn call_inner(&self, ignore_poisoning: bool, init: &mut dyn FnMut(&OnceState)) {
let mut state_and_queue = self.state_and_queue.load(Ordering::Acquire);
loop {
Expand Down
13 changes: 9 additions & 4 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1443,13 +1443,18 @@ impl<T> JoinHandle<T> {
self.0.join()
}

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

Expand Down
15 changes: 9 additions & 6 deletions library/std/src/thread/scoped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
///
/// ```
/// #![feature(scoped_threads)]
/// #![feature(thread_is_running)]
///
/// use std::thread;
///
Expand Down Expand Up @@ -274,7 +273,6 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
///
/// ```
/// #![feature(scoped_threads)]
/// #![feature(thread_is_running)]
///
/// use std::thread;
///
Expand All @@ -289,13 +287,18 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
self.0.join()
}

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

Expand Down
8 changes: 4 additions & 4 deletions library/std/src/thread/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn test_run_basic() {
}

#[test]
fn test_is_running() {
fn test_is_finished() {
let b = Arc::new(Barrier::new(2));
let t = thread::spawn({
let b = b.clone();
Expand All @@ -63,14 +63,14 @@ fn test_is_running() {
});

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

// Unblock the barrier.
b.wait();

// Now check that t.is_running() becomes false within a reasonable time.
// Now check that t.is_finished() becomes true within a reasonable time.
let start = Instant::now();
while t.is_running() {
while !t.is_finished() {
assert!(start.elapsed() < Duration::from_secs(2));
thread::sleep(Duration::from_millis(15));
}
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ test = false
build_helper = { path = "../build_helper" }
cmake = "0.1.38"
filetime = "0.2"
num_cpus = "1.0"
getopts = "0.2.19"
cc = "1.0.69"
libc = "0.2"
Expand Down
14 changes: 7 additions & 7 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ macro_rules! derive_merge {

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

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

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

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

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

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

fn threads_from_config(v: u32) -> u32 {
match v {
0 => num_cpus::get() as u32,
0 => std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32,
n => n,
}
}
2 changes: 1 addition & 1 deletion src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
let j_msg = format!(
"number of jobs to run in parallel; \
defaults to {} (this host's logical CPU count)",
num_cpus::get()
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get)
);
opts.optopt("j", "jobs", &j_msg, "JOBS");
opts.optflag("h", "help", "print this help message");
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,9 @@ impl Build {
/// Returns the number of parallel jobs that have been configured for this
/// build.
fn jobs(&self) -> u32 {
self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32)
self.config.jobs.unwrap_or_else(|| {
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32
})
}

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