Skip to content

Commit 87e5848

Browse files
committed
Auto merge of #156285 - JonathanBrouwer:rollup-bxLhwFA, r=JonathanBrouwer
Rollup of 4 pull requests Successful merges: - #149468 (Skipping borrowck because of trivial const) - #152487 (core: drop unmapped ZSTs in array `map`) - #153759 (Add a suite of ChunkedBitSet union/subtract/intersect test scenarios) - #156198 (Add `sync` option to `-Z threads` to force synchronization on one thread)
2 parents ffccab6 + 79792ff commit 87e5848

19 files changed

Lines changed: 292 additions & 61 deletions

File tree

compiler/rustc_borrowck/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ fn mir_borrowck(
115115
def: LocalDefId,
116116
) -> Result<&FxIndexMap<LocalDefId, ty::DefinitionSiteHiddenType<'_>>, ErrorGuaranteed> {
117117
assert!(!tcx.is_typeck_child(def.to_def_id()));
118+
if tcx.is_trivial_const(def) {
119+
debug!("Skipping borrowck because of trivial const");
120+
let opaque_types = Default::default();
121+
return Ok(tcx.arena.alloc(opaque_types));
122+
}
118123
let (input_body, _) = tcx.mir_promoted(def);
119124
debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
120125

compiler/rustc_codegen_cranelift/patches/0027-sysroot_tests-128bit-atomic-operations.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ index 1e336bf..35e6f54 100644
1616
+++ b/coretests/tests/lib.rs
1717
@@ -2,4 +2,3 @@
1818
// tidy-alphabetical-start
19+
#![cfg_attr(not(panic = "abort"), feature(reentrant_lock))]
1920
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
2021
#![feature(array_ptr_get)]
2122
#![feature(array_try_from_fn)]
@@ -36,4 +37,3 @@ index b735957..ea728b6 100644
3637
#[cfg(target_has_atomic = "ptr")]
3738
--
3839
2.26.2.7.g19db9cfb68
39-

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,14 +776,14 @@ pub fn codegen_crate<B: ExtraBackendMethods>(backend: B, tcx: TyCtxt<'_>) -> Ong
776776
// This likely is a temporary measure. Once we don't have to support the
777777
// non-parallel compiler anymore, we can compile CGUs end-to-end in
778778
// parallel and get rid of the complicated scheduling logic.
779-
let mut pre_compiled_cgus = if tcx.sess.threads() > 1 {
779+
let mut pre_compiled_cgus = if let Some(threads) = tcx.sess.threads() {
780780
tcx.sess.time("compile_first_CGU_batch", || {
781781
// Try to find one CGU to compile per thread.
782782
let cgus: Vec<_> = cgu_reuse
783783
.iter()
784784
.enumerate()
785785
.filter(|&(_, reuse)| reuse == &CguReuse::No)
786-
.take(tcx.sess.threads())
786+
.take(threads)
787787
.collect();
788788

789789
// Compile the found CGUs in parallel.

compiler/rustc_index/src/bit_set/tests.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,116 @@ fn chunked_bitset() {
362362
);
363363
}
364364

365+
/// Additional helper methods for testing.
366+
impl ChunkedBitSet<usize> {
367+
/// Creates a new `ChunkedBitSet` containing all `i` for which `fill_fn(i)` is true.
368+
fn fill_with(domain_size: usize, fill_fn: impl Fn(usize) -> bool) -> Self {
369+
let mut this = ChunkedBitSet::new_empty(domain_size);
370+
for i in 0..domain_size {
371+
if fill_fn(i) {
372+
this.insert(i);
373+
}
374+
}
375+
this
376+
}
377+
378+
/// Asserts that for each `i` in `0..self.domain_size()`, `self.contains(i) == expected_fn(i)`.
379+
#[track_caller]
380+
fn assert_filled_with(&self, expected_fn: impl Fn(usize) -> bool) {
381+
for i in 0..self.domain_size() {
382+
let expected = expected_fn(i);
383+
assert_eq!(self.contains(i), expected, "i = {i}");
384+
}
385+
}
386+
}
387+
388+
#[test]
389+
fn chunked_bulk_ops() {
390+
struct ChunkedBulkOp {
391+
name: &'static str,
392+
op_fn: fn(&mut ChunkedBitSet<usize>, &ChunkedBitSet<usize>) -> bool,
393+
spec_fn: fn(fn(usize) -> bool, fn(usize) -> bool, usize) -> bool,
394+
}
395+
let ops = &[
396+
ChunkedBulkOp {
397+
name: "union",
398+
op_fn: ChunkedBitSet::union,
399+
spec_fn: |fizz, buzz, i| fizz(i) || buzz(i),
400+
},
401+
ChunkedBulkOp {
402+
name: "subtract",
403+
op_fn: ChunkedBitSet::subtract,
404+
spec_fn: |fizz, buzz, i| fizz(i) && !buzz(i),
405+
},
406+
ChunkedBulkOp {
407+
name: "intersect",
408+
op_fn: ChunkedBitSet::intersect,
409+
spec_fn: |fizz, buzz, i| fizz(i) && buzz(i),
410+
},
411+
];
412+
413+
let domain_sizes = [
414+
CHUNK_BITS / 7, // Smaller than a full chunk.
415+
CHUNK_BITS,
416+
(CHUNK_BITS + CHUNK_BITS / 7), // Larger than a full chunk.
417+
];
418+
419+
for ChunkedBulkOp { name, op_fn, spec_fn } in ops {
420+
for domain_size in domain_sizes {
421+
// If false, use different values for LHS and RHS, to test "fizz op buzz".
422+
// If true, use identical values, to test "fizz op fizz".
423+
for identical in [false, true] {
424+
// If false, make a clone of LHS before doing the op.
425+
// This covers optimizations that depend on whether chunk words are shared or not.
426+
for unique in [false, true] {
427+
// Print the current test case, so that we can see which one failed.
428+
println!(
429+
"Testing op={name}, domain_size={domain_size}, identical={identical}, unique={unique} ..."
430+
);
431+
432+
let fizz_fn = |i| i % 3 == 0;
433+
let buzz_fn = if identical { fizz_fn } else { |i| i % 5 == 0 };
434+
435+
// Check that `fizz op buzz` gives the expected results.
436+
chunked_bulk_ops_test_inner(
437+
domain_size,
438+
unique,
439+
fizz_fn,
440+
buzz_fn,
441+
op_fn,
442+
|i| spec_fn(fizz_fn, buzz_fn, i),
443+
);
444+
}
445+
}
446+
}
447+
}
448+
}
449+
450+
fn chunked_bulk_ops_test_inner(
451+
domain_size: usize,
452+
unique: bool,
453+
fizz_fn: impl Fn(usize) -> bool + Copy,
454+
buzz_fn: impl Fn(usize) -> bool + Copy,
455+
op_fn: impl Fn(&mut ChunkedBitSet<usize>, &ChunkedBitSet<usize>) -> bool,
456+
expected_fn: impl Fn(usize) -> bool + Copy,
457+
) {
458+
// Create two bitsets, "fizz" (LHS) and "buzz" (RHS).
459+
let mut fizz = ChunkedBitSet::fill_with(domain_size, fizz_fn);
460+
let buzz = ChunkedBitSet::fill_with(domain_size, buzz_fn);
461+
462+
// If requested, clone `fizz` so that its word Rcs are not uniquely-owned.
463+
let _cloned = (!unique).then(|| fizz.clone());
464+
465+
// Perform the op (e.g. union/subtract/intersect), and verify that the
466+
// mutated LHS contains exactly the expected values.
467+
let changed = op_fn(&mut fizz, &buzz);
468+
fizz.assert_filled_with(expected_fn);
469+
470+
// Verify that the "changed" return value is correct.
471+
let should_change = (0..domain_size).any(|i| fizz_fn(i) != expected_fn(i));
472+
assert_eq!(changed, should_change);
473+
}
474+
365475
fn with_elements_chunked(elements: &[usize], domain_size: usize) -> ChunkedBitSet<usize> {
366476
let mut s = ChunkedBitSet::new_empty(domain_size);
367477
for &e in elements {

compiler/rustc_interface/src/interface.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
385385
trace!("run_compiler");
386386

387387
// Set parallel mode before thread pool creation, which will create `Lock`s.
388-
rustc_data_structures::sync::set_dyn_thread_safe_mode(config.opts.unstable_opts.threads > 1);
388+
rustc_data_structures::sync::set_dyn_thread_safe_mode(
389+
config.opts.unstable_opts.threads.is_some(),
390+
);
389391

390392
// Check jobserver before run_in_thread_pool_with_globals, which call jobserver::acquire_thread
391393
let early_dcx = EarlyDiagCtxt::new(config.opts.error_format);
@@ -407,7 +409,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
407409
util::run_in_thread_pool_with_globals(
408410
&early_dcx,
409411
config.opts.edition,
410-
config.opts.unstable_opts.threads,
412+
config.opts.unstable_opts.threads.unwrap_or(1),
411413
&config.extra_symbols,
412414
SourceMapInputs { file_loader, path_mapping, hash_kind, checksum_hash_kind },
413415
|current_gcx, jobserver_proxy| {

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ fn test_unstable_options_tracking_hash() {
734734
untracked!(span_debug, true);
735735
untracked!(span_free_formats, true);
736736
untracked!(temps_dir, Some(String::from("abc")));
737-
untracked!(threads, 99);
737+
untracked!(threads, Some(99));
738738
untracked!(time_llvm_passes, true);
739739
untracked!(time_passes, true);
740740
untracked!(time_passes_format, TimePassesFormat::Json);

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2465,7 +2465,7 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
24652465
return;
24662466
};
24672467

2468-
if tcx.sess.threads() != 1 {
2468+
if tcx.sess.threads().is_some() {
24692469
// Prefetch some queries used by metadata encoding.
24702470
// This is not necessary for correctness, but is only done for performance reasons.
24712471
// It can be removed if it turns out to cause trouble or be detrimental to performance.

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl DepGraphData {
629629
let ok = match color {
630630
DepNodeColor::Unknown => true,
631631
DepNodeColor::Red => false,
632-
DepNodeColor::Green(..) => sess.threads() > 1, // Other threads may mark this green
632+
DepNodeColor::Green(..) => sess.threads().is_some(), // Other threads may mark this green
633633
};
634634
if !ok {
635635
panic!("{}", msg())

compiler/rustc_mir_transform/src/trivial_const.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ where
5959
return None;
6060
}
6161

62+
if !tcx.opaque_types_defined_by(def).is_empty() {
63+
return None;
64+
}
65+
6266
let body = body_provider();
6367

6468
if body.has_opaque_types() {

compiler/rustc_query_impl/src/execution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ fn try_execute_query<'tcx, C: QueryCache, const INCR: bool>(
294294
// re-executing the query since `try_start` only checks that the query is not currently
295295
// executing, but another thread may have already completed the query and stores it result
296296
// in the query cache.
297-
if tcx.sess.threads() > 1 {
297+
if tcx.sess.threads().is_some() {
298298
if let Some((value, index)) = query.cache.lookup(&key) {
299299
tcx.prof.query_cache_hit(index.into());
300300
return (value, Some(index));

0 commit comments

Comments
 (0)