Skip to content

Commit

Permalink
Auto merge of #117435 - SparrowLii:nightly_parallel, r=oli-obk,davidtwco
Browse files Browse the repository at this point in the history
enable parallel rustc front end in nightly builds

Refers to the [MCP](rust-lang/compiler-team#681), this pr does:
1. Enable the parallel front end in nightly builds, and keep the default number of threads as 1. Then users can use the parallel rustc front end via -Z threads=n option.

2. Set it up to serial front end for beta/stable builds via bootstrap.

3. Switch over the alt builders from parallel rustc to serial, so we have artifacts without parallel to test against the artifacts with parallel.

r? `@oli-obk`

cc `@cjgillot` `@nnethercote` `@bjorn3` `@Kobzol`
  • Loading branch information
bors committed Nov 6, 2023
2 parents fcca978 + f2a40e9 commit f9b6446
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3005,9 +3005,9 @@ dependencies = [

[[package]]
name = "portable-atomic"
version = "1.4.2"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f32154ba0af3a075eefa1eda8bb414ee928f62303a54ea85b8d6638ff1a6ee9e"
checksum = "3bccab0e7fd7cc19f820a1c8c91720af652d0c88dc9664dd72aef2614f04af3b"

[[package]]
name = "ppv-lite86"
Expand Down Expand Up @@ -3734,6 +3734,7 @@ dependencies = [
"measureme",
"memmap2",
"parking_lot 0.12.1",
"portable-atomic",
"rustc-hash",
"rustc-rayon",
"rustc-rayon-core",
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ features = [
memmap2 = "0.2.1"
# tidy-alphabetical-end

[target.'cfg(any(target_arch = "powerpc", target_arch = "mips"))'.dependencies]
portable-atomic = "1.5.1"

[features]
# tidy-alphabetical-start
rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "rustc-rayon", "rustc-rayon-core"]
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_data_structures/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ cfg_match! {
[std::sync::atomic::AtomicUsize]
[std::sync::atomic::AtomicU8]
[std::sync::atomic::AtomicU32]
[std::sync::atomic::AtomicU64]
[std::backtrace::Backtrace]
[std::io::Error]
[std::fs::File]
Expand All @@ -148,6 +147,18 @@ cfg_match! {
[crate::owned_slice::OwnedSlice]
);

// PowerPC and MIPS platforms with 32-bit pointers do not
// have AtomicU64 type.
#[cfg(not(any(target_arch = "powerpc", target_arch = "mips")))]
already_sync!(
[std::sync::atomic::AtomicU64]
);

#[cfg(any(target_arch = "powerpc", target_arch = "mips"))]
already_sync!(
[portable_atomic::AtomicU64]
);

macro_rules! impl_dyn_sync {
($($($attr: meta)* [$ty: ty where $($generics2: tt)*])*) => {
$(unsafe impl<$($generics2)*> DynSync for $ty {})*
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,15 @@ cfg_match! {

pub use std::sync::OnceLock;

pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32, AtomicU64};
pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32};

// PowerPC and MIPS platforms with 32-bit pointers do not
// have AtomicU64 type.
#[cfg(not(any(target_arch = "powerpc", target_arch = "mips")))]
pub use std::sync::atomic::AtomicU64;

#[cfg(any(target_arch = "powerpc", target_arch = "mips"))]
pub use portable_atomic::AtomicU64;

pub use std::sync::Arc as Lrc;
pub use std::sync::Weak as Weak;
Expand Down
11 changes: 6 additions & 5 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#
# If `change-id` does not match the version that is currently running,
# `x.py` will prompt you to update it and check the related PR for more details.
change-id = 116998
change-id = 117435

# =============================================================================
# Tweaking how LLVM is compiled
Expand Down Expand Up @@ -553,10 +553,11 @@ change-id = 116998
# Whether to always use incremental compilation when building rustc
#incremental = false

# Build a multi-threaded rustc
# FIXME(#75760): Some UI tests fail when this option is enabled.
# NOTE: This option is NOT SUPPORTED. See #48685.
#parallel-compiler = false
# Build a multi-threaded rustc. This allows users to use parallel rustc
# via the unstable option `-Z threads=n`.
# Since stable/beta channels only allow using stable features,
# `parallel-compiler = false` should be set for these channels.
#parallel-compiler = true

# The default linker that will be hard-coded into the generated
# compiler for targets that don't specify a default linker explicitly
Expand Down
5 changes: 4 additions & 1 deletion src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ impl Config {
config.bindir = "bin".into();
config.dist_include_mingw_linker = true;
config.dist_compression_profile = "fast".into();
config.rustc_parallel = true;

config.stdout_is_tty = std::io::stdout().is_terminal();
config.stderr_is_tty = std::io::stderr().is_terminal();
Expand Down Expand Up @@ -1429,7 +1430,9 @@ impl Config {
set(&mut config.use_lld, rust.use_lld);
set(&mut config.lld_enabled, rust.lld);
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
config.rustc_parallel = rust.parallel_compiler.unwrap_or(false);
config.rustc_parallel = rust
.parallel_compiler
.unwrap_or(config.channel == "dev" || config.channel == "nightly");
config.rustc_default_linker = rust.default_linker;
config.musl_root = rust.musl_root.map(PathBuf::from);
config.save_toolstates = rust.save_toolstates.map(PathBuf::from);
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const LLD_FILE_NAMES: &[&str] = &["ld.lld", "ld64.lld", "lld-link", "wasm-ld"];
///
/// If you make any major changes (such as adding new values or changing default values), please
/// ensure that the associated PR ID is added to the end of this list.
pub const CONFIG_CHANGE_HISTORY: &[usize] = &[115898, 116998];
pub const CONFIG_CHANGE_HISTORY: &[usize] = &[115898, 116998, 117435];

/// Extra --check-cfg to add when building
/// (Mode restriction, config name, config values (if any))
Expand Down
4 changes: 2 additions & 2 deletions src/ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then
if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"
elif [ "$DEPLOY_ALT" != "" ]; then
if [ "$NO_PARALLEL_COMPILER" = "" ]; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.parallel-compiler"
if [ "$ALT_PARALLEL_COMPILER" = "" ]; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.parallel-compiler=false"
fi
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-assertions"
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.verify-llvm-ir"
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
"perf-event-open-sys",
"pin-project-lite",
"polonius-engine",
"portable-atomic", // dependency for platforms doesn't support `AtomicU64` in std
"ppv-lite86",
"proc-macro-hack",
"proc-macro2",
Expand Down

0 comments on commit f9b6446

Please sign in to comment.