Skip to content

Commit 03c609a

Browse files
committed
Auto merge of #155911 - jhpratt:rollup-DOR0YN1, r=jhpratt
Rollup of 9 pull requests Successful merges: - #155381 (Fix a bug in `ChunkedBitSet::subtract`) - #155847 (Don't reload length in String::push) - #155858 (`slice::join`: borrow only once during length calc) - #155879 (enable pipe tests in Miri) - #155905 (Update LLVM to 22.1.4 (again)) - #155247 ([AIX] update linker default to bcdtors) - #155812 ([codex] tests: mark migrated UI tests as check-pass) - #155854 (Rename the diagnostic item for `std::sync::mpsc::Receiver`) - #155882 (Add regression test for #101363)
2 parents 4ddb0b7 + 8759017 commit 03c609a

29 files changed

Lines changed: 86 additions & 95 deletions

File tree

compiler/rustc_index/src/bit_set.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,13 +833,16 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
833833
changed = true;
834834
let num_words = num_words(*chunk_domain_size as usize);
835835
debug_assert!(num_words > 0 && num_words <= CHUNK_WORDS);
836-
let mut tail_mask =
837-
1 << (*chunk_domain_size - ((num_words - 1) * WORD_BITS) as u16) - 1;
836+
// Set `self_chunk_words` to `other_chunk_words`, then invert all bits and
837+
// clear any excess bits in the final word.
838838
let mut self_chunk_words = **other_chunk_words;
839-
for word in self_chunk_words[0..num_words].iter_mut().rev() {
840-
*word = !*word & tail_mask;
841-
tail_mask = Word::MAX;
839+
for word in self_chunk_words[0..num_words].iter_mut() {
840+
*word = !*word;
842841
}
842+
clear_excess_bits_in_final_word(
843+
*chunk_domain_size as usize,
844+
&mut self_chunk_words[..num_words],
845+
);
843846
let self_chunk_ones_count = *chunk_domain_size - *other_chunk_ones_count;
844847
debug_assert_eq!(
845848
self_chunk_ones_count,

compiler/rustc_index/src/bit_set/tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,33 @@ fn chunked_bitset() {
333333
assert_eq!(b10000.count(), 6000);
334334
b10000.assert_valid();
335335
b10000b.assert_valid();
336+
337+
//-----------------------------------------------------------------------
338+
339+
let mut b64 = ChunkedBitSet::<usize>::new_filled(64);
340+
341+
let mut b64b = ChunkedBitSet::<usize>::new_empty(64);
342+
b64b.insert(0);
343+
344+
b64.subtract(&b64b);
345+
assert!(!b64.contains(0));
346+
assert!(b64.contains(10));
347+
assert!(b64.contains(50));
348+
assert!(b64.contains(63));
349+
assert_eq!(
350+
b64.chunks(),
351+
#[rustfmt::skip]
352+
vec![
353+
Mixed {
354+
chunk_domain_size: 64,
355+
ones_count: 63,
356+
words: Rc::new([
357+
0xfffffffffffffffe, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
358+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
359+
])
360+
},
361+
],
362+
);
336363
}
337364

338365
fn with_elements_chunked(elements: &[usize], domain_size: usize) -> ChunkedBitSet<usize> {

compiler/rustc_target/src/spec/targets/powerpc64_ibm_aix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub(crate) fn target() -> Target {
55
base.max_atomic_width = Some(64);
66
base.add_pre_link_args(
77
LinkerFlavor::Unix(Cc::No),
8-
&["-b64", "-bpT:0x100000000", "-bpD:0x110000000", "-bcdtors:all:0:s"],
8+
&["-b64", "-bpT:0x100000000", "-bpD:0x110000000", "-bcdtors:mbr:0:s"],
99
);
1010

1111
Target {

library/alloc/src/str.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,9 @@ macro_rules! copy_slice_and_advance {
135135
//
136136
// This implementation calls `borrow()` multiple times:
137137
// 1. To calculate `reserved_len`, all elements are borrowed once.
138-
// 2. The first element is borrowed again when copied via `extend_from_slice`.
139-
// 3. Subsequent elements are borrowed a second time when building the mapped iterator.
138+
// 2. All elements, except the first, are borrowed a second time when building the mapped iterator.
140139
//
141140
// Risks and Mitigations:
142-
// - If the first element GROWS on the second borrow, the length subtraction underflows.
143-
// We mitigate this by doing a `checked_sub` to panic rather than allowing an underflow
144-
// that fabricates a huge destination slice.
145141
// - If elements 2..N GROW on their second borrow, the target slice bounds set by `checked_sub`
146142
// means that `split_at_mut` inside `copy_slice_and_advance!` will correctly panic.
147143
// - If elements SHRINK on their second borrow, the spare space is never written, and the final
@@ -157,8 +153,10 @@ where
157153
let mut iter = slice.iter();
158154

159155
// the first slice is the only one without a separator preceding it
156+
// we take care to only borrow this once during the length calculation
157+
// to avoid inconsistent Borrow implementations from breaking our assumptions
160158
let first = match iter.next() {
161-
Some(first) => first,
159+
Some(first) => first.borrow().as_ref(),
162160
None => return vec![],
163161
};
164162

@@ -168,21 +166,24 @@ where
168166
// the entire Vec pre-allocated for safety
169167
let reserved_len = sep_len
170168
.checked_mul(iter.len())
169+
.and_then(|n| n.checked_add(first.len()))
171170
.and_then(|n| {
172-
slice.iter().map(|s| s.borrow().as_ref().len()).try_fold(n, usize::checked_add)
171+
// iter starts from the second element as we've already taken the first
172+
// it's cloned so we can reuse the same iterator below
173+
iter.clone().map(|s| s.borrow().as_ref().len()).try_fold(n, usize::checked_add)
173174
})
174175
.expect("attempt to join into collection with len > usize::MAX");
175176

176177
// prepare an uninitialized buffer
177178
let mut result = Vec::with_capacity(reserved_len);
178179
debug_assert!(result.capacity() >= reserved_len);
179180

180-
result.extend_from_slice(first.borrow().as_ref());
181+
result.extend_from_slice(first);
181182

182183
unsafe {
183184
let pos = result.len();
184-
let target_len = reserved_len.checked_sub(pos).expect("inconsistent Borrow implementation");
185-
let target = result.spare_capacity_mut().get_unchecked_mut(..target_len);
185+
debug_assert!(reserved_len >= pos);
186+
let target = result.spare_capacity_mut().get_unchecked_mut(..reserved_len - pos);
186187

187188
// Convert the separator and slices to slices of MaybeUninit
188189
// to simplify implementation in specialize_for_lengths.

library/alloc/src/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ impl String {
14201420

14211421
// SAFETY: Just reserved capacity for at least the length needed to encode `ch`.
14221422
unsafe {
1423-
core::char::encode_utf8_raw_unchecked(ch as u32, self.vec.as_mut_ptr().add(self.len()));
1423+
core::char::encode_utf8_raw_unchecked(ch as u32, self.vec.as_mut_ptr().add(len));
14241424
self.vec.set_len(len + ch_len);
14251425
}
14261426
}

library/alloctests/tests/str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn test_join_for_different_lengths_with_long_separator() {
164164
}
165165

166166
#[test]
167-
fn test_join_issue_80335() {
167+
fn test_join_inconsistent_borrow_shrink() {
168168
use core::borrow::Borrow;
169169
use core::cell::Cell;
170170

@@ -191,12 +191,12 @@ fn test_join_issue_80335() {
191191
}
192192

193193
let arr: [WeirdBorrow; 3] = Default::default();
194-
test_join!("0-0-0", arr, "-");
194+
test_join!("123456-0-0", arr, "-");
195195
}
196196

197197
#[test]
198-
#[should_panic(expected = "inconsistent Borrow implementation")]
199-
fn test_join_inconsistent_borrow() {
198+
#[should_panic(expected = "mid > len")]
199+
fn test_join_inconsistent_borrow_grow() {
200200
use std::borrow::Borrow;
201201
use std::cell::Cell;
202202

library/std/src/io/pipe.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ use crate::sys::{FromInner, IntoInner, pipe as imp};
4040
/// # Example
4141
///
4242
/// ```no_run
43-
/// # #[cfg(miri)] fn main() {}
44-
/// # #[cfg(not(miri))]
4543
/// # fn main() -> std::io::Result<()> {
4644
/// use std::io::{Read, Write, pipe};
4745
/// use std::process::Command;
@@ -126,8 +124,6 @@ impl PipeReader {
126124
/// # Examples
127125
///
128126
/// ```no_run
129-
/// # #[cfg(miri)] fn main() {}
130-
/// # #[cfg(not(miri))]
131127
/// # fn main() -> std::io::Result<()> {
132128
/// use std::fs;
133129
/// use std::io::{pipe, Write};
@@ -185,8 +181,6 @@ impl PipeWriter {
185181
/// # Examples
186182
///
187183
/// ```no_run
188-
/// # #[cfg(miri)] fn main() {}
189-
/// # #[cfg(not(miri))]
190184
/// # fn main() -> std::io::Result<()> {
191185
/// use std::process::Command;
192186
/// use std::io::{pipe, Read};

library/std/src/io/pipe/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::io::{Read, Write, pipe};
22

33
#[test]
4-
#[cfg(all(any(unix, windows), not(miri)))]
54
fn pipe_creation_clone_and_rw() {
65
let (rx, tx) = pipe().unwrap();
76

library/std/src/sync/mpmc/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ pub fn sync_channel<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
297297
/// assert_eq!(3, msg + msg2);
298298
/// ```
299299
#[unstable(feature = "mpmc_channel", issue = "126840")]
300+
#[cfg_attr(not(test), rustc_diagnostic_item = "MpmcSender")]
300301
pub struct Sender<T> {
301302
flavor: SenderFlavor<T>,
302303
}
@@ -722,6 +723,7 @@ impl<T> fmt::Debug for Sender<T> {
722723
/// rx_thread_2.join().unwrap();
723724
/// ```
724725
#[unstable(feature = "mpmc_channel", issue = "126840")]
726+
#[cfg_attr(not(test), rustc_diagnostic_item = "MpmcReceiver")]
725727
pub struct Receiver<T> {
726728
flavor: ReceiverFlavor<T>,
727729
}

library/std/src/sync/mpsc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ use crate::{error, fmt};
173173
/// println!("{}", recv.recv().unwrap()); // Received after 2 seconds
174174
/// ```
175175
#[stable(feature = "rust1", since = "1.0.0")]
176-
#[cfg_attr(not(test), rustc_diagnostic_item = "Receiver")]
176+
#[cfg_attr(not(test), rustc_diagnostic_item = "MpscReceiver")]
177177
pub struct Receiver<T> {
178178
inner: mpmc::Receiver<T>,
179179
}

0 commit comments

Comments
 (0)