Skip to content

Commit ee915c3

Browse files
committed
Auto merge of #95414 - Dylan-DPC:rollup-9hbshd0, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #93787 (parallel_compiler: hide dependencies behind feature) - #95318 (diagnostics: correct generic bounds with doubled colon) - #95328 (Fix yet another Box<T, A> ICE) - #95397 (Link to std::io's platform-specific behavior disclaimer) - #95407 (Inline u8::is_utf8_char_boundary) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 600ec28 + 1f33cd1 commit ee915c3

File tree

23 files changed

+205
-50
lines changed

23 files changed

+205
-50
lines changed

compiler/rustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ features = ['unprefixed_malloc_on_supported_platforms']
1919
jemalloc = ['tikv-jemalloc-sys']
2020
llvm = ['rustc_driver/llvm']
2121
max_level_info = ['rustc_driver/max_level_info']
22+
rustc_use_parallel_compiler = ['rustc_driver/rustc_use_parallel_compiler']

compiler/rustc_codegen_ssa/src/base.rs

+27-25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use crate::{CachedModuleCodegen, CompiledModule, CrateInfo, MemFlags, ModuleCode
1414
use rustc_attr as attr;
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
17+
18+
#[cfg(parallel_compiler)]
1719
use rustc_data_structures::sync::{par_iter, ParallelIterator};
1820
use rustc_hir as hir;
1921
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
@@ -622,34 +624,34 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
622624
// This likely is a temporary measure. Once we don't have to support the
623625
// non-parallel compiler anymore, we can compile CGUs end-to-end in
624626
// parallel and get rid of the complicated scheduling logic.
627+
#[cfg(parallel_compiler)]
625628
let pre_compile_cgus = |cgu_reuse: &[CguReuse]| {
626-
if cfg!(parallel_compiler) {
627-
tcx.sess.time("compile_first_CGU_batch", || {
628-
// Try to find one CGU to compile per thread.
629-
let cgus: Vec<_> = cgu_reuse
630-
.iter()
631-
.enumerate()
632-
.filter(|&(_, reuse)| reuse == &CguReuse::No)
633-
.take(tcx.sess.threads())
634-
.collect();
635-
636-
// Compile the found CGUs in parallel.
637-
let start_time = Instant::now();
638-
639-
let pre_compiled_cgus = par_iter(cgus)
640-
.map(|(i, _)| {
641-
let module = backend.compile_codegen_unit(tcx, codegen_units[i].name());
642-
(i, module)
643-
})
644-
.collect();
645-
646-
(pre_compiled_cgus, start_time.elapsed())
647-
})
648-
} else {
649-
(FxHashMap::default(), Duration::new(0, 0))
650-
}
629+
tcx.sess.time("compile_first_CGU_batch", || {
630+
// Try to find one CGU to compile per thread.
631+
let cgus: Vec<_> = cgu_reuse
632+
.iter()
633+
.enumerate()
634+
.filter(|&(_, reuse)| reuse == &CguReuse::No)
635+
.take(tcx.sess.threads())
636+
.collect();
637+
638+
// Compile the found CGUs in parallel.
639+
let start_time = Instant::now();
640+
641+
let pre_compiled_cgus = par_iter(cgus)
642+
.map(|(i, _)| {
643+
let module = backend.compile_codegen_unit(tcx, codegen_units[i].name());
644+
(i, module)
645+
})
646+
.collect();
647+
648+
(pre_compiled_cgus, start_time.elapsed())
649+
})
651650
};
652651

652+
#[cfg(not(parallel_compiler))]
653+
let pre_compile_cgus = |_: &[CguReuse]| (FxHashMap::default(), Duration::new(0, 0));
654+
653655
let mut cgu_reuse = Vec::new();
654656
let mut pre_compiled_cgus: Option<FxHashMap<usize, _>> = None;
655657
let mut total_codegen_time = Duration::new(0, 0);

compiler/rustc_codegen_ssa/src/mir/place.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
441441
.find(|elem| matches!(elem.1, mir::ProjectionElem::Deref))
442442
{
443443
base = elem.0 + 1;
444-
self.codegen_consume(
444+
let cg_base = self.codegen_consume(
445445
bx,
446446
mir::PlaceRef { projection: &place_ref.projection[..elem.0], ..place_ref },
447-
)
448-
.deref(bx.cx())
447+
);
448+
449+
// a box with a non-zst allocator should not be directly dereferenced
450+
if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 1).is_zst() {
451+
let ptr = cg_base.extract_field(bx, 0).extract_field(bx, 0);
452+
453+
ptr.deref(bx.cx())
454+
} else {
455+
cg_base.deref(bx.cx())
456+
}
449457
} else {
450458
bug!("using operand local {:?} as place", place_ref);
451459
}
@@ -454,10 +462,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
454462
for elem in place_ref.projection[base..].iter() {
455463
cg_base = match elem.clone() {
456464
mir::ProjectionElem::Deref => {
457-
// custom allocators can change box's abi, making it unable to be derefed directly
458-
if cg_base.layout.ty.is_box()
459-
&& matches!(cg_base.layout.abi, Abi::Aggregate { .. } | Abi::Uninhabited)
460-
{
465+
// a box with a non-zst allocator should not be directly dereferenced
466+
if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 1).is_zst() {
461467
let ptr = cg_base.project_field(bx, 0).project_field(bx, 0);
462468

463469
bx.load_operand(ptr).deref(bx.cx())

compiler/rustc_data_structures/Cargo.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ doctest = false
99
[dependencies]
1010
arrayvec = { version = "0.7", default-features = false }
1111
ena = "0.14"
12-
indexmap = { version = "1.8.0", features = ["rustc-rayon"] }
12+
indexmap = { version = "1.8.0" }
1313
tracing = "0.1"
1414
jobserver_crate = { version = "0.1.13", package = "jobserver" }
1515
rustc_serialize = { path = "../rustc_serialize" }
1616
rustc_macros = { path = "../rustc_macros" }
1717
rustc_graphviz = { path = "../rustc_graphviz" }
1818
cfg-if = "0.1.2"
1919
stable_deref_trait = "1.0.0"
20-
rayon = { version = "0.3.2", package = "rustc-rayon" }
21-
rayon-core = { version = "0.3.2", package = "rustc-rayon-core" }
20+
rayon = { version = "0.3.2", package = "rustc-rayon", optional = true }
21+
rayon-core = { version = "0.3.2", package = "rustc-rayon-core", optional = true }
2222
rustc-hash = "1.1.0"
2323
smallvec = { version = "1.6.1", features = ["const_generics", "union", "may_dangle"] }
2424
rustc_index = { path = "../rustc_index", package = "rustc_index" }
@@ -36,3 +36,6 @@ winapi = { version = "0.3", features = ["fileapi", "psapi", "winerror"] }
3636

3737
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
3838
memmap2 = "0.2.1"
39+
40+
[features]
41+
rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "rayon", "rayon-core"]

compiler/rustc_driver/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ winapi = { version = "0.3", features = ["consoleapi", "debugapi", "processenv"]
3939
[features]
4040
llvm = ['rustc_interface/llvm']
4141
max_level_info = ['rustc_log/max_level_info']
42+
rustc_use_parallel_compiler = ['rustc_data_structures/rustc_use_parallel_compiler', 'rustc_interface/rustc_use_parallel_compiler',
43+
'rustc_middle/rustc_use_parallel_compiler']

compiler/rustc_interface/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ doctest = false
1010
libc = "0.2"
1111
libloading = "0.7.1"
1212
tracing = "0.1"
13-
rustc-rayon-core = "0.3.2"
14-
rayon = { version = "0.3.2", package = "rustc-rayon" }
13+
rustc-rayon-core = { version = "0.3.2", optional = true }
14+
rayon = { version = "0.3.2", package = "rustc-rayon", optional = true }
1515
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
1616
rustc_ast = { path = "../rustc_ast" }
1717
rustc_attr = { path = "../rustc_attr" }
@@ -57,3 +57,4 @@ rustc_target = { path = "../rustc_target" }
5757

5858
[features]
5959
llvm = ['rustc_codegen_llvm']
60+
rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler']

compiler/rustc_middle/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ bitflags = "1.2.1"
1212
either = "1.5.0"
1313
gsgdt = "0.1.2"
1414
tracing = "0.1"
15-
rustc-rayon = "0.3.2"
16-
rustc-rayon-core = "0.3.2"
15+
rustc-rayon = { version = "0.3.2", optional = true }
16+
rustc-rayon-core = { version = "0.3.2", optional = true }
1717
polonius-engine = "0.13.0"
1818
rustc_apfloat = { path = "../rustc_apfloat" }
1919
rustc_attr = { path = "../rustc_attr" }
@@ -35,3 +35,6 @@ rustc_session = { path = "../rustc_session" }
3535
rustc_type_ir = { path = "../rustc_type_ir" }
3636
rand = "0.8.4"
3737
rand_xoshiro = "0.6.0"
38+
39+
[features]
40+
rustc_use_parallel_compiler = ["rustc-rayon", "rustc-rayon-core"]

compiler/rustc_parse/src/parser/diagnostics.rs

+28
Original file line numberDiff line numberDiff line change
@@ -2369,6 +2369,34 @@ impl<'a> Parser<'a> {
23692369
Err(err)
23702370
}
23712371

2372+
crate fn maybe_recover_bounds_doubled_colon(&mut self, ty: &Ty) -> PResult<'a, ()> {
2373+
let TyKind::Path(qself, path) = &ty.kind else { return Ok(()) };
2374+
let qself_position = qself.as_ref().map(|qself| qself.position);
2375+
for (i, segments) in path.segments.windows(2).enumerate() {
2376+
if qself_position.map(|pos| i < pos).unwrap_or(false) {
2377+
continue;
2378+
}
2379+
if let [a, b] = segments {
2380+
let (a_span, b_span) = (a.span(), b.span());
2381+
let between_span = a_span.shrink_to_hi().to(b_span.shrink_to_lo());
2382+
if self.span_to_snippet(between_span).as_ref().map(|a| &a[..]) == Ok(":: ") {
2383+
let mut err = self.struct_span_err(
2384+
path.span.shrink_to_hi(),
2385+
"expected `:` followed by trait or lifetime",
2386+
);
2387+
err.span_suggestion(
2388+
between_span,
2389+
"use single colon",
2390+
": ".to_owned(),
2391+
Applicability::MachineApplicable,
2392+
);
2393+
return Err(err);
2394+
}
2395+
}
2396+
}
2397+
Ok(())
2398+
}
2399+
23722400
/// Parse and throw away a parenthesized comma separated
23732401
/// sequence of patterns until `)` is reached.
23742402
fn skip_pat_list(&mut self) -> PResult<'a, ()> {

compiler/rustc_parse/src/parser/generics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ impl<'a> Parser<'a> {
312312
id: ast::DUMMY_NODE_ID,
313313
}))
314314
} else {
315+
self.maybe_recover_bounds_doubled_colon(&ty)?;
315316
self.unexpected()
316317
}
317318
}

compiler/rustc_query_impl/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ doctest = false
88

99
[dependencies]
1010
measureme = "10.0.0"
11-
rustc-rayon-core = "0.3.2"
11+
rustc-rayon-core = { version = "0.3.2", optional = true }
1212
rustc_ast = { path = "../rustc_ast" }
1313
rustc_data_structures = { path = "../rustc_data_structures" }
1414
rustc_errors = { path = "../rustc_errors" }
@@ -20,3 +20,6 @@ rustc_query_system = { path = "../rustc_query_system" }
2020
rustc_serialize = { path = "../rustc_serialize" }
2121
rustc_session = { path = "../rustc_session" }
2222
rustc_span = { path = "../rustc_span" }
23+
24+
[features]
25+
rustc_use_parallel_compiler = ["rustc-rayon-core", "rustc_query_system/rustc_use_parallel_compiler"]

compiler/rustc_query_system/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ doctest = false
99
[dependencies]
1010
rustc_arena = { path = "../rustc_arena" }
1111
tracing = "0.1"
12-
rustc-rayon-core = "0.3.2"
12+
rustc-rayon-core = { version = "0.3.2", optional = true }
1313
rustc_ast = { path = "../rustc_ast" }
1414
rustc_data_structures = { path = "../rustc_data_structures" }
1515
rustc_errors = { path = "../rustc_errors" }
@@ -23,3 +23,6 @@ rustc_span = { path = "../rustc_span" }
2323
rustc_target = { path = "../rustc_target" }
2424
parking_lot = "0.11"
2525
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
26+
27+
[features]
28+
rustc_use_parallel_compiler = ["rustc-rayon-core"]

library/core/src/num/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ impl u8 {
809809
ascii::escape_default(self)
810810
}
811811

812+
#[inline]
812813
pub(crate) const fn is_utf8_char_boundary(self) -> bool {
813814
// This is bit magic equivalent to: b < 128 || b >= 192
814815
(self as i8) >= -0x40

library/std/src/env.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ use crate::sys::os as os_imp;
2525
///
2626
/// # Platform-specific behavior
2727
///
28-
/// This function currently corresponds to the `getcwd` function on Unix
28+
/// This function [currently] corresponds to the `getcwd` function on Unix
2929
/// and the `GetCurrentDirectoryW` function on Windows.
3030
///
31+
/// [currently]: crate::io#platform-specific-behavior
32+
///
3133
/// # Errors
3234
///
3335
/// Returns an [`Err`] if the current working directory value is invalid.
@@ -56,11 +58,13 @@ pub fn current_dir() -> io::Result<PathBuf> {
5658
///
5759
/// # Platform-specific behavior
5860
///
59-
/// This function currently corresponds to the `chdir` function on Unix
61+
/// This function [currently] corresponds to the `chdir` function on Unix
6062
/// and the `SetCurrentDirectoryW` function on Windows.
6163
///
6264
/// Returns an [`Err`] if the operation fails.
6365
///
66+
/// [currently]: crate::io#platform-specific-behavior
67+
///
6468
/// # Examples
6569
///
6670
/// ```

library/std/src/time.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ pub use core::time::FromFloatSecsError;
101101
/// ```
102102
///
103103
/// # Underlying System calls
104-
/// Currently, the following system calls are being used to get the current time using `now()`:
104+
///
105+
/// The following system calls are [currently] being used by `now()` to find out
106+
/// the current time:
105107
///
106108
/// | Platform | System call |
107109
/// |-----------|----------------------------------------------------------------------|
@@ -113,6 +115,7 @@ pub use core::time::FromFloatSecsError;
113115
/// | WASI | [__wasi_clock_time_get (Monotonic Clock)] |
114116
/// | Windows | [QueryPerformanceCounter] |
115117
///
118+
/// [currently]: crate::io#platform-specific-behavior
116119
/// [QueryPerformanceCounter]: https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter
117120
/// [`insecure_time` usercall]: https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.insecure_time
118121
/// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode
@@ -203,7 +206,8 @@ pub struct Instant(time::Instant);
203206
/// For example, on Windows the time is represented in 100 nanosecond intervals whereas Linux
204207
/// can represent nanosecond intervals.
205208
///
206-
/// Currently, the following system calls are being used to get the current time using `now()`:
209+
/// The following system calls are [currently] being used by `now()` to find out
210+
/// the current time:
207211
///
208212
/// | Platform | System call |
209213
/// |-----------|----------------------------------------------------------------------|
@@ -215,6 +219,7 @@ pub struct Instant(time::Instant);
215219
/// | WASI | [__wasi_clock_time_get (Realtime Clock)] |
216220
/// | Windows | [GetSystemTimePreciseAsFileTime] / [GetSystemTimeAsFileTime] |
217221
///
222+
/// [currently]: crate::io#platform-specific-behavior
218223
/// [`insecure_time` usercall]: https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.insecure_time
219224
/// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode
220225
/// [gettimeofday]: https://man7.org/linux/man-pages/man2/gettimeofday.2.html

src/bootstrap/compile.rs

+2
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
689689
}
690690

691691
if builder.config.rustc_parallel {
692+
// keep in sync with `bootstrap/lib.rs:Build::rustc_features`
693+
// `cfg` option for rustc, `features` option for cargo, for conditional compilation
692694
cargo.rustflag("--cfg=parallel_compiler");
693695
cargo.rustdocflag("--cfg=parallel_compiler");
694696
}

src/bootstrap/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -729,12 +729,16 @@ impl Build {
729729

730730
/// Gets the space-separated set of activated features for the compiler.
731731
fn rustc_features(&self, kind: Kind) -> String {
732-
let mut features = String::new();
732+
let mut features = vec![];
733733
if self.config.jemalloc {
734-
features.push_str("jemalloc");
734+
features.push("jemalloc");
735735
}
736736
if self.config.llvm_enabled() || kind == Kind::Check {
737-
features.push_str(" llvm");
737+
features.push("llvm");
738+
}
739+
// keep in sync with `bootstrap/compile.rs:rustc_cargo_env`
740+
if self.config.rustc_parallel {
741+
features.push("rustc_use_parallel_compiler");
738742
}
739743

740744
// If debug logging is on, then we want the default for tracing:
@@ -743,10 +747,10 @@ impl Build {
743747
// if its unset, if debug_assertions is on, then debug_logging will also be on
744748
// as well as tracing *ignoring* this feature when debug_assertions is on
745749
if !self.config.rust_debug_logging {
746-
features.push_str(" max_level_info");
750+
features.push("max_level_info");
747751
}
748752

749-
features
753+
features.join(" ")
750754
}
751755

752756
/// Component directory that Cargo will produce output into (e.g.

src/test/ui/box/issue-95036.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// compile-flags: -O
2+
// build-pass
3+
4+
#![feature(allocator_api, bench_black_box)]
5+
6+
#[inline(never)]
7+
pub fn by_ref(node: &mut Box<[u8; 1], &std::alloc::Global>) {
8+
node[0] = 9u8;
9+
}
10+
11+
pub fn main() {
12+
let mut node = Box::new_in([5u8], &std::alloc::Global);
13+
node[0] = 7u8;
14+
15+
std::hint::black_box(node);
16+
17+
let mut node = Box::new_in([5u8], &std::alloc::Global);
18+
19+
by_ref(&mut node);
20+
21+
std::hint::black_box(node);
22+
}

0 commit comments

Comments
 (0)