From 2a7837262f67887b7e5908181000d36036dc5485 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 25 Mar 2022 13:53:03 -0700 Subject: [PATCH 1/9] diagnostics: correct generic bounds with doubled colon Fixes #95208 --- .../rustc_parse/src/parser/diagnostics.rs | 28 +++++++++++++++++++ compiler/rustc_parse/src/parser/generics.rs | 1 + .../generics/issue-95208-ignore-qself.fixed | 11 ++++++++ .../ui/generics/issue-95208-ignore-qself.rs | 11 ++++++++ .../generics/issue-95208-ignore-qself.stderr | 10 +++++++ src/test/ui/generics/issue-95208.fixed | 11 ++++++++ src/test/ui/generics/issue-95208.rs | 11 ++++++++ src/test/ui/generics/issue-95208.stderr | 10 +++++++ 8 files changed, 93 insertions(+) create mode 100644 src/test/ui/generics/issue-95208-ignore-qself.fixed create mode 100644 src/test/ui/generics/issue-95208-ignore-qself.rs create mode 100644 src/test/ui/generics/issue-95208-ignore-qself.stderr create mode 100644 src/test/ui/generics/issue-95208.fixed create mode 100644 src/test/ui/generics/issue-95208.rs create mode 100644 src/test/ui/generics/issue-95208.stderr diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index b5b628a3f55bd..534fd0d4816dd 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -2369,6 +2369,34 @@ impl<'a> Parser<'a> { Err(err) } + crate fn maybe_recover_bounds_doubled_colon(&mut self, ty: &Ty) -> PResult<'a, ()> { + let TyKind::Path(qself, path) = &ty.kind else { return Ok(()) }; + let qself_position = qself.as_ref().map(|qself| qself.position); + for (i, segments) in path.segments.windows(2).enumerate() { + if qself_position.map(|pos| i < pos).unwrap_or(false) { + continue; + } + if let [a, b] = segments { + let (a_span, b_span) = (a.span(), b.span()); + let between_span = a_span.shrink_to_hi().to(b_span.shrink_to_lo()); + if self.span_to_snippet(between_span).as_ref().map(|a| &a[..]) == Ok(":: ") { + let mut err = self.struct_span_err( + path.span.shrink_to_hi(), + "expected `:` followed by trait or lifetime", + ); + err.span_suggestion( + between_span, + "use single colon", + ": ".to_owned(), + Applicability::MachineApplicable, + ); + return Err(err); + } + } + } + Ok(()) + } + /// Parse and throw away a parenthesized comma separated /// sequence of patterns until `)` is reached. fn skip_pat_list(&mut self) -> PResult<'a, ()> { diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index d625080dee4fd..29fe2b761018e 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -312,6 +312,7 @@ impl<'a> Parser<'a> { id: ast::DUMMY_NODE_ID, })) } else { + self.maybe_recover_bounds_doubled_colon(&ty)?; self.unexpected() } } diff --git a/src/test/ui/generics/issue-95208-ignore-qself.fixed b/src/test/ui/generics/issue-95208-ignore-qself.fixed new file mode 100644 index 0000000000000..608b4a20fbc86 --- /dev/null +++ b/src/test/ui/generics/issue-95208-ignore-qself.fixed @@ -0,0 +1,11 @@ +// run-rustfix + +#[allow(unused)] +struct Struct(T); + +impl Struct where ::Item: std::fmt::Display { +//~^ ERROR expected `:` followed by trait or lifetime +//~| HELP use single colon +} + +fn main() {} diff --git a/src/test/ui/generics/issue-95208-ignore-qself.rs b/src/test/ui/generics/issue-95208-ignore-qself.rs new file mode 100644 index 0000000000000..da7efd576d1cf --- /dev/null +++ b/src/test/ui/generics/issue-95208-ignore-qself.rs @@ -0,0 +1,11 @@ +// run-rustfix + +#[allow(unused)] +struct Struct(T); + +impl Struct where ::Item:: std::fmt::Display { +//~^ ERROR expected `:` followed by trait or lifetime +//~| HELP use single colon +} + +fn main() {} diff --git a/src/test/ui/generics/issue-95208-ignore-qself.stderr b/src/test/ui/generics/issue-95208-ignore-qself.stderr new file mode 100644 index 0000000000000..acbc1300d00fd --- /dev/null +++ b/src/test/ui/generics/issue-95208-ignore-qself.stderr @@ -0,0 +1,10 @@ +error: expected `:` followed by trait or lifetime + --> $DIR/issue-95208-ignore-qself.rs:6:88 + | +LL | impl Struct where ::Item:: std::fmt::Display { + | --- ^ + | | + | help: use single colon: `:` + +error: aborting due to previous error + diff --git a/src/test/ui/generics/issue-95208.fixed b/src/test/ui/generics/issue-95208.fixed new file mode 100644 index 0000000000000..a0b1e886ca268 --- /dev/null +++ b/src/test/ui/generics/issue-95208.fixed @@ -0,0 +1,11 @@ +// run-rustfix + +#[allow(unused)] +struct Struct(T); + +impl Struct where T: std::fmt::Display { +//~^ ERROR expected `:` followed by trait or lifetime +//~| HELP use single colon +} + +fn main() {} diff --git a/src/test/ui/generics/issue-95208.rs b/src/test/ui/generics/issue-95208.rs new file mode 100644 index 0000000000000..0e3083484ff15 --- /dev/null +++ b/src/test/ui/generics/issue-95208.rs @@ -0,0 +1,11 @@ +// run-rustfix + +#[allow(unused)] +struct Struct(T); + +impl Struct where T:: std::fmt::Display { +//~^ ERROR expected `:` followed by trait or lifetime +//~| HELP use single colon +} + +fn main() {} diff --git a/src/test/ui/generics/issue-95208.stderr b/src/test/ui/generics/issue-95208.stderr new file mode 100644 index 0000000000000..559527663e8a8 --- /dev/null +++ b/src/test/ui/generics/issue-95208.stderr @@ -0,0 +1,10 @@ +error: expected `:` followed by trait or lifetime + --> $DIR/issue-95208.rs:6:46 + | +LL | impl Struct where T:: std::fmt::Display { + | --- ^ + | | + | help: use single colon: `:` + +error: aborting due to previous error + From 46dadfc1422ce98f4814441154d5fa765caeffe9 Mon Sep 17 00:00:00 2001 From: DrMeepster <19316085+DrMeepster@users.noreply.github.com> Date: Fri, 25 Mar 2022 23:14:30 -0700 Subject: [PATCH 2/9] widen special case on deref to all non-zst allocators --- compiler/rustc_codegen_ssa/src/mir/place.rs | 6 ++---- src/test/ui/box/issue-95036.rs | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/box/issue-95036.rs diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index 2b8fa3be56dd5..12cdc2b2c7d3d 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -454,10 +454,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { for elem in place_ref.projection[base..].iter() { cg_base = match elem.clone() { mir::ProjectionElem::Deref => { - // custom allocators can change box's abi, making it unable to be derefed directly - if cg_base.layout.ty.is_box() - && matches!(cg_base.layout.abi, Abi::Aggregate { .. } | Abi::Uninhabited) - { + // a box with a non-zst allocator should not be directly dereferenced + if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 0).is_zst() { let ptr = cg_base.project_field(bx, 0).project_field(bx, 0); bx.load_operand(ptr).deref(bx.cx()) diff --git a/src/test/ui/box/issue-95036.rs b/src/test/ui/box/issue-95036.rs new file mode 100644 index 0000000000000..e062599d74c29 --- /dev/null +++ b/src/test/ui/box/issue-95036.rs @@ -0,0 +1,10 @@ +// compile-flags: -O +// compile-pass + +#![feature(allocator_api, bench_black_box)] + +pub fn main() { + let mut node = Box::new_in([5u8], &std::alloc::Global); + node[0] = 7u8; + std::hint::black_box(node); +} From e9f08e709d471988fcf163779dec430cdcbf1193 Mon Sep 17 00:00:00 2001 From: DrMeepster <19316085+DrMeepster@users.noreply.github.com> Date: Fri, 25 Mar 2022 23:46:37 -0700 Subject: [PATCH 3/9] fix wrong header command --- src/test/ui/box/issue-95036.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/box/issue-95036.rs b/src/test/ui/box/issue-95036.rs index e062599d74c29..e55a10af3d67f 100644 --- a/src/test/ui/box/issue-95036.rs +++ b/src/test/ui/box/issue-95036.rs @@ -1,5 +1,5 @@ // compile-flags: -O -// compile-pass +// build-pass #![feature(allocator_api, bench_black_box)] From ece64ed3f56f811f2122dc3dcbff85bf47f8fee3 Mon Sep 17 00:00:00 2001 From: DrMeepster <19316085+DrMeepster@users.noreply.github.com> Date: Sat, 26 Mar 2022 00:08:51 -0700 Subject: [PATCH 4/9] check the the right field --- compiler/rustc_codegen_ssa/src/mir/place.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index 12cdc2b2c7d3d..be8b0f3c99125 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -455,7 +455,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { cg_base = match elem.clone() { mir::ProjectionElem::Deref => { // a box with a non-zst allocator should not be directly dereferenced - if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 0).is_zst() { + if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 1).is_zst() { let ptr = cg_base.project_field(bx, 0).project_field(bx, 0); bx.load_operand(ptr).deref(bx.cx()) From 09ccc63624f627e44f13c480c934b4d28a845258 Mon Sep 17 00:00:00 2001 From: DrMeepster <19316085+DrMeepster@users.noreply.github.com> Date: Sun, 27 Mar 2022 13:35:29 -0700 Subject: [PATCH 5/9] fix other source of box deref --- compiler/rustc_codegen_ssa/src/mir/place.rs | 14 +++++++++++--- src/test/ui/box/issue-95036.rs | 12 ++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index be8b0f3c99125..17cfb6c5dfb54 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -441,11 +441,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { .find(|elem| matches!(elem.1, mir::ProjectionElem::Deref)) { base = elem.0 + 1; - self.codegen_consume( + let cg_base = self.codegen_consume( bx, mir::PlaceRef { projection: &place_ref.projection[..elem.0], ..place_ref }, - ) - .deref(bx.cx()) + ); + + // a box with a non-zst allocator should not be directly dereferenced + if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 1).is_zst() { + let ptr = cg_base.extract_field(bx, 0).extract_field(bx, 0); + + ptr.deref(bx.cx()) + } else { + cg_base.deref(bx.cx()) + } } else { bug!("using operand local {:?} as place", place_ref); } diff --git a/src/test/ui/box/issue-95036.rs b/src/test/ui/box/issue-95036.rs index e55a10af3d67f..c2d4275aa49d3 100644 --- a/src/test/ui/box/issue-95036.rs +++ b/src/test/ui/box/issue-95036.rs @@ -3,8 +3,20 @@ #![feature(allocator_api, bench_black_box)] +#[inline(never)] +pub fn by_ref(node: &mut Box<[u8; 1], &std::alloc::Global>) { + node[0] = 9u8; +} + pub fn main() { let mut node = Box::new_in([5u8], &std::alloc::Global); node[0] = 7u8; + + std::hint::black_box(node); + + let mut node = Box::new_in([5u8], &std::alloc::Global); + + by_ref(&mut node); + std::hint::black_box(node); } From d55854d484f64e7a2b570e28ff1250112b6578e2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 27 Mar 2022 20:58:16 -0700 Subject: [PATCH 6/9] Link to std::io's platform-specific behavior disclaimer --- library/std/src/env.rs | 8 ++++++-- library/std/src/time.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 05f08c498e683..f03d298d8699d 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -25,9 +25,11 @@ use crate::sys::os as os_imp; /// /// # Platform-specific behavior /// -/// This function currently corresponds to the `getcwd` function on Unix +/// This function [currently] corresponds to the `getcwd` function on Unix /// and the `GetCurrentDirectoryW` function on Windows. /// +/// [currently]: crate::io#platform-specific-behavior +/// /// # Errors /// /// Returns an [`Err`] if the current working directory value is invalid. @@ -56,11 +58,13 @@ pub fn current_dir() -> io::Result { /// /// # Platform-specific behavior /// -/// This function currently corresponds to the `chdir` function on Unix +/// This function [currently] corresponds to the `chdir` function on Unix /// and the `SetCurrentDirectoryW` function on Windows. /// /// Returns an [`Err`] if the operation fails. /// +/// [currently]: crate::io#platform-specific-behavior +/// /// # Examples /// /// ``` diff --git a/library/std/src/time.rs b/library/std/src/time.rs index 2f8eb557b4f74..708e4064e06f3 100644 --- a/library/std/src/time.rs +++ b/library/std/src/time.rs @@ -101,7 +101,9 @@ pub use core::time::FromFloatSecsError; /// ``` /// /// # Underlying System calls -/// Currently, the following system calls are being used to get the current time using `now()`: +/// +/// The following system calls are [currently] being used by `now()` to find out +/// the current time: /// /// | Platform | System call | /// |-----------|----------------------------------------------------------------------| @@ -113,6 +115,7 @@ pub use core::time::FromFloatSecsError; /// | WASI | [__wasi_clock_time_get (Monotonic Clock)] | /// | Windows | [QueryPerformanceCounter] | /// +/// [currently]: crate::io#platform-specific-behavior /// [QueryPerformanceCounter]: https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter /// [`insecure_time` usercall]: https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.insecure_time /// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode @@ -203,7 +206,8 @@ pub struct Instant(time::Instant); /// For example, on Windows the time is represented in 100 nanosecond intervals whereas Linux /// can represent nanosecond intervals. /// -/// Currently, the following system calls are being used to get the current time using `now()`: +/// The following system calls are [currently] being used by `now()` to find out +/// the current time: /// /// | Platform | System call | /// |-----------|----------------------------------------------------------------------| @@ -215,6 +219,7 @@ pub struct Instant(time::Instant); /// | WASI | [__wasi_clock_time_get (Realtime Clock)] | /// | Windows | [GetSystemTimePreciseAsFileTime] / [GetSystemTimeAsFileTime] | /// +/// [currently]: crate::io#platform-specific-behavior /// [`insecure_time` usercall]: https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.insecure_time /// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode /// [gettimeofday]: https://man7.org/linux/man-pages/man2/gettimeofday.2.html From 78fbcca3e10b6671ca54bd4c01cb84b3f6f13cf3 Mon Sep 17 00:00:00 2001 From: klensy Date: Tue, 8 Feb 2022 22:21:16 +0300 Subject: [PATCH 7/9] use cfg attribute instead of macro --- compiler/rustc_codegen_ssa/src/base.rs | 52 +++++++++++++------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 0b31e4b558261..010560248054e 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -14,6 +14,8 @@ use crate::{CachedModuleCodegen, CompiledModule, CrateInfo, MemFlags, ModuleCode use rustc_attr as attr; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; + +#[cfg(parallel_compiler)] use rustc_data_structures::sync::{par_iter, ParallelIterator}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; @@ -622,34 +624,34 @@ pub fn codegen_crate( // This likely is a temporary measure. Once we don't have to support the // non-parallel compiler anymore, we can compile CGUs end-to-end in // parallel and get rid of the complicated scheduling logic. + #[cfg(parallel_compiler)] let pre_compile_cgus = |cgu_reuse: &[CguReuse]| { - if cfg!(parallel_compiler) { - tcx.sess.time("compile_first_CGU_batch", || { - // Try to find one CGU to compile per thread. - let cgus: Vec<_> = cgu_reuse - .iter() - .enumerate() - .filter(|&(_, reuse)| reuse == &CguReuse::No) - .take(tcx.sess.threads()) - .collect(); - - // Compile the found CGUs in parallel. - let start_time = Instant::now(); - - let pre_compiled_cgus = par_iter(cgus) - .map(|(i, _)| { - let module = backend.compile_codegen_unit(tcx, codegen_units[i].name()); - (i, module) - }) - .collect(); - - (pre_compiled_cgus, start_time.elapsed()) - }) - } else { - (FxHashMap::default(), Duration::new(0, 0)) - } + tcx.sess.time("compile_first_CGU_batch", || { + // Try to find one CGU to compile per thread. + let cgus: Vec<_> = cgu_reuse + .iter() + .enumerate() + .filter(|&(_, reuse)| reuse == &CguReuse::No) + .take(tcx.sess.threads()) + .collect(); + + // Compile the found CGUs in parallel. + let start_time = Instant::now(); + + let pre_compiled_cgus = par_iter(cgus) + .map(|(i, _)| { + let module = backend.compile_codegen_unit(tcx, codegen_units[i].name()); + (i, module) + }) + .collect(); + + (pre_compiled_cgus, start_time.elapsed()) + }) }; + #[cfg(not(parallel_compiler))] + let pre_compile_cgus = |_: &[CguReuse]| (FxHashMap::default(), Duration::new(0, 0)); + let mut cgu_reuse = Vec::new(); let mut pre_compiled_cgus: Option> = None; let mut total_codegen_time = Duration::new(0, 0); From 008fc79dcd821b08a1ab64f5fba40dcc4bcd3aee Mon Sep 17 00:00:00 2001 From: klensy Date: Fri, 11 Feb 2022 23:25:14 +0300 Subject: [PATCH 8/9] Propagate `parallel_compiler` feature through rustc crates. Turned off feature gives change of builded crates: 238 -> 224. --- compiler/rustc/Cargo.toml | 1 + compiler/rustc_data_structures/Cargo.toml | 9 ++++++--- compiler/rustc_driver/Cargo.toml | 2 ++ compiler/rustc_interface/Cargo.toml | 5 +++-- compiler/rustc_middle/Cargo.toml | 7 +++++-- compiler/rustc_query_impl/Cargo.toml | 5 ++++- compiler/rustc_query_system/Cargo.toml | 5 ++++- src/bootstrap/compile.rs | 2 ++ src/bootstrap/lib.rs | 14 +++++++++----- 9 files changed, 36 insertions(+), 14 deletions(-) diff --git a/compiler/rustc/Cargo.toml b/compiler/rustc/Cargo.toml index 696c003a587ac..b642e891956cb 100644 --- a/compiler/rustc/Cargo.toml +++ b/compiler/rustc/Cargo.toml @@ -19,3 +19,4 @@ features = ['unprefixed_malloc_on_supported_platforms'] jemalloc = ['tikv-jemalloc-sys'] llvm = ['rustc_driver/llvm'] max_level_info = ['rustc_driver/max_level_info'] +rustc_use_parallel_compiler = ['rustc_driver/rustc_use_parallel_compiler'] diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml index b82e97172614b..7cc8b5c20339a 100644 --- a/compiler/rustc_data_structures/Cargo.toml +++ b/compiler/rustc_data_structures/Cargo.toml @@ -9,7 +9,7 @@ doctest = false [dependencies] arrayvec = { version = "0.7", default-features = false } ena = "0.14" -indexmap = { version = "1.8.0", features = ["rustc-rayon"] } +indexmap = { version = "1.8.0" } tracing = "0.1" jobserver_crate = { version = "0.1.13", package = "jobserver" } rustc_serialize = { path = "../rustc_serialize" } @@ -17,8 +17,8 @@ rustc_macros = { path = "../rustc_macros" } rustc_graphviz = { path = "../rustc_graphviz" } cfg-if = "0.1.2" stable_deref_trait = "1.0.0" -rayon = { version = "0.3.2", package = "rustc-rayon" } -rayon-core = { version = "0.3.2", package = "rustc-rayon-core" } +rayon = { version = "0.3.2", package = "rustc-rayon", optional = true } +rayon-core = { version = "0.3.2", package = "rustc-rayon-core", optional = true } rustc-hash = "1.1.0" smallvec = { version = "1.6.1", features = ["const_generics", "union", "may_dangle"] } rustc_index = { path = "../rustc_index", package = "rustc_index" } @@ -36,3 +36,6 @@ winapi = { version = "0.3", features = ["fileapi", "psapi", "winerror"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] memmap2 = "0.2.1" + +[features] +rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "rayon", "rayon-core"] diff --git a/compiler/rustc_driver/Cargo.toml b/compiler/rustc_driver/Cargo.toml index 872f946bf7d91..fd2ca5beadea3 100644 --- a/compiler/rustc_driver/Cargo.toml +++ b/compiler/rustc_driver/Cargo.toml @@ -39,3 +39,5 @@ winapi = { version = "0.3", features = ["consoleapi", "debugapi", "processenv"] [features] llvm = ['rustc_interface/llvm'] max_level_info = ['rustc_log/max_level_info'] +rustc_use_parallel_compiler = ['rustc_data_structures/rustc_use_parallel_compiler', 'rustc_interface/rustc_use_parallel_compiler', + 'rustc_middle/rustc_use_parallel_compiler'] diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index e31119c12921d..29d1cd0e05467 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -10,8 +10,8 @@ doctest = false libc = "0.2" libloading = "0.7.1" tracing = "0.1" -rustc-rayon-core = "0.3.2" -rayon = { version = "0.3.2", package = "rustc-rayon" } +rustc-rayon-core = { version = "0.3.2", optional = true } +rayon = { version = "0.3.2", package = "rustc-rayon", optional = true } smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } rustc_ast = { path = "../rustc_ast" } rustc_attr = { path = "../rustc_attr" } @@ -57,3 +57,4 @@ rustc_target = { path = "../rustc_target" } [features] llvm = ['rustc_codegen_llvm'] +rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler'] diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index 9cfc5f5b444df..cd281ea5b38ae 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -12,8 +12,8 @@ bitflags = "1.2.1" either = "1.5.0" gsgdt = "0.1.2" tracing = "0.1" -rustc-rayon = "0.3.2" -rustc-rayon-core = "0.3.2" +rustc-rayon = { version = "0.3.2", optional = true } +rustc-rayon-core = { version = "0.3.2", optional = true } polonius-engine = "0.13.0" rustc_apfloat = { path = "../rustc_apfloat" } rustc_attr = { path = "../rustc_attr" } @@ -35,3 +35,6 @@ rustc_session = { path = "../rustc_session" } rustc_type_ir = { path = "../rustc_type_ir" } rand = "0.8.4" rand_xoshiro = "0.6.0" + +[features] +rustc_use_parallel_compiler = ["rustc-rayon", "rustc-rayon-core"] diff --git a/compiler/rustc_query_impl/Cargo.toml b/compiler/rustc_query_impl/Cargo.toml index f1899a6fb2b07..b7502c4b1e23b 100644 --- a/compiler/rustc_query_impl/Cargo.toml +++ b/compiler/rustc_query_impl/Cargo.toml @@ -8,7 +8,7 @@ doctest = false [dependencies] measureme = "10.0.0" -rustc-rayon-core = "0.3.2" +rustc-rayon-core = { version = "0.3.2", optional = true } rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } @@ -20,3 +20,6 @@ rustc_query_system = { path = "../rustc_query_system" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } + +[features] +rustc_use_parallel_compiler = ["rustc-rayon-core", "rustc_query_system/rustc_use_parallel_compiler"] diff --git a/compiler/rustc_query_system/Cargo.toml b/compiler/rustc_query_system/Cargo.toml index 79f791eb7545f..8a35121f90cdb 100644 --- a/compiler/rustc_query_system/Cargo.toml +++ b/compiler/rustc_query_system/Cargo.toml @@ -9,7 +9,7 @@ doctest = false [dependencies] rustc_arena = { path = "../rustc_arena" } tracing = "0.1" -rustc-rayon-core = "0.3.2" +rustc-rayon-core = { version = "0.3.2", optional = true } rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } @@ -23,3 +23,6 @@ rustc_span = { path = "../rustc_span" } rustc_target = { path = "../rustc_target" } parking_lot = "0.11" smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } + +[features] +rustc_use_parallel_compiler = ["rustc-rayon-core"] diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index e030e0bc1cf80..00fc1f0434252 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -689,6 +689,8 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS } if builder.config.rustc_parallel { + // keep in sync with `bootstrap/lib.rs:Build::rustc_features` + // `cfg` option for rustc, `features` option for cargo, for conditional compilation cargo.rustflag("--cfg=parallel_compiler"); cargo.rustdocflag("--cfg=parallel_compiler"); } diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 41e2e976162de..8f076ad914d9a 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -729,12 +729,16 @@ impl Build { /// Gets the space-separated set of activated features for the compiler. fn rustc_features(&self, kind: Kind) -> String { - let mut features = String::new(); + let mut features = vec![]; if self.config.jemalloc { - features.push_str("jemalloc"); + features.push("jemalloc"); } if self.config.llvm_enabled() || kind == Kind::Check { - features.push_str(" llvm"); + features.push("llvm"); + } + // keep in sync with `bootstrap/compile.rs:rustc_cargo_env` + if self.config.rustc_parallel { + features.push("rustc_use_parallel_compiler"); } // If debug logging is on, then we want the default for tracing: @@ -743,10 +747,10 @@ impl Build { // if its unset, if debug_assertions is on, then debug_logging will also be on // as well as tracing *ignoring* this feature when debug_assertions is on if !self.config.rust_debug_logging { - features.push_str(" max_level_info"); + features.push("max_level_info"); } - features + features.join(" ") } /// Component directory that Cargo will produce output into (e.g. From 12c085a05729f6f795cc854032f99cdb9b833946 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Mon, 28 Mar 2022 18:37:11 +0200 Subject: [PATCH 9/9] Inline u8::is_utf8_char_boundary --- library/core/src/num/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index dca8ffa4e2c89..c09f642d9696c 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -809,6 +809,7 @@ impl u8 { ascii::escape_default(self) } + #[inline] pub(crate) const fn is_utf8_char_boundary(self) -> bool { // This is bit magic equivalent to: b < 128 || b >= 192 (self as i8) >= -0x40