Skip to content

Commit b3a029f

Browse files
Auto merge of #145785 - samueltardieu:rollup-81jw080, r=<try>
Rollup of 7 pull requests try-job: test-various
2 parents 8df154b + 8ce68c5 commit b3a029f

File tree

9 files changed

+105
-127
lines changed

9 files changed

+105
-127
lines changed

compiler/rustc_middle/src/mir/interpret/allocation/provenance_map.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
120120
}
121121
}
122122

123+
/// Gets the provenances of all bytes (including from pointers) in a range.
124+
pub fn get_range(
125+
&self,
126+
cx: &impl HasDataLayout,
127+
range: AllocRange,
128+
) -> impl Iterator<Item = Prov> {
129+
let ptr_provs = self.range_ptrs_get(range, cx).iter().map(|(_, p)| *p);
130+
let byte_provs = self.range_bytes_get(range).iter().map(|(_, (p, _))| *p);
131+
ptr_provs.chain(byte_provs)
132+
}
133+
123134
/// Attempt to merge per-byte provenance back into ptr chunks, if the right fragments
124135
/// sit next to each other. Return `false` is that is not possible due to partial pointers.
125136
pub fn merge_bytes(&mut self, cx: &impl HasDataLayout) -> bool {

library/core/src/char/methods.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,28 +1872,33 @@ pub const unsafe fn encode_utf8_raw_unchecked(code: u32, dst: *mut u8) {
18721872
// SAFETY: The caller must guarantee that the buffer pointed to by `dst`
18731873
// is at least `len` bytes long.
18741874
unsafe {
1875-
match len {
1876-
1 => {
1877-
*dst = code as u8;
1878-
}
1879-
2 => {
1880-
*dst = (code >> 6 & 0x1F) as u8 | TAG_TWO_B;
1881-
*dst.add(1) = (code & 0x3F) as u8 | TAG_CONT;
1882-
}
1883-
3 => {
1884-
*dst = (code >> 12 & 0x0F) as u8 | TAG_THREE_B;
1885-
*dst.add(1) = (code >> 6 & 0x3F) as u8 | TAG_CONT;
1886-
*dst.add(2) = (code & 0x3F) as u8 | TAG_CONT;
1887-
}
1888-
4 => {
1889-
*dst = (code >> 18 & 0x07) as u8 | TAG_FOUR_B;
1890-
*dst.add(1) = (code >> 12 & 0x3F) as u8 | TAG_CONT;
1891-
*dst.add(2) = (code >> 6 & 0x3F) as u8 | TAG_CONT;
1892-
*dst.add(3) = (code & 0x3F) as u8 | TAG_CONT;
1893-
}
1894-
// SAFETY: `char` always takes between 1 and 4 bytes to encode in UTF-8.
1895-
_ => crate::hint::unreachable_unchecked(),
1875+
if len == 1 {
1876+
*dst = code as u8;
1877+
return;
1878+
}
1879+
1880+
let last1 = (code >> 0 & 0x3F) as u8 | TAG_CONT;
1881+
let last2 = (code >> 6 & 0x3F) as u8 | TAG_CONT;
1882+
let last3 = (code >> 12 & 0x3F) as u8 | TAG_CONT;
1883+
let last4 = (code >> 18 & 0x3F) as u8 | TAG_FOUR_B;
1884+
1885+
if len == 2 {
1886+
*dst = last2 | TAG_TWO_B;
1887+
*dst.add(1) = last1;
1888+
return;
18961889
}
1890+
1891+
if len == 3 {
1892+
*dst = last3 | TAG_THREE_B;
1893+
*dst.add(1) = last2;
1894+
*dst.add(2) = last1;
1895+
return;
1896+
}
1897+
1898+
*dst = last4;
1899+
*dst.add(1) = last3;
1900+
*dst.add(2) = last2;
1901+
*dst.add(3) = last1;
18971902
}
18981903
}
18991904

library/std/src/sync/lazy_lock.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
244244
#[inline]
245245
#[stable(feature = "lazy_cell", since = "1.80.0")]
246246
pub fn force(this: &LazyLock<T, F>) -> &T {
247-
this.once.call_once(|| {
247+
this.once.call_once_force(|state| {
248+
if state.is_poisoned() {
249+
panic_poisoned();
250+
}
251+
248252
// SAFETY: `call_once` only runs this closure once, ever.
249253
let data = unsafe { &mut *this.data.get() };
250254
let f = unsafe { ManuallyDrop::take(&mut data.f) };
@@ -257,8 +261,7 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
257261
// * the closure was called and initialized `value`.
258262
// * the closure was called and panicked, so this point is never reached.
259263
// * the closure was not called, but a previous call initialized `value`.
260-
// * the closure was not called because the Once is poisoned, so this point
261-
// is never reached.
264+
// * the closure was not called because the Once is poisoned, which we handled above.
262265
// So `value` has definitely been initialized and will not be modified again.
263266
unsafe { &*(*this.data.get()).value }
264267
}

library/std/src/sys/fd/unix.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ pub struct FileDesc(OwnedFd);
3737
//
3838
// On Apple targets however, apparently the 64-bit libc is either buggy or
3939
// intentionally showing odd behavior by rejecting any read with a size
40-
// larger than or equal to INT_MAX. To handle both of these the read
41-
// size is capped on both platforms.
40+
// larger than INT_MAX. To handle both of these the read size is capped on
41+
// both platforms.
4242
const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
43-
libc::c_int::MAX as usize - 1
43+
libc::c_int::MAX as usize
4444
} else {
4545
libc::ssize_t::MAX as usize
4646
};

library/std/tests/sync/lazy_lock.rs

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ fn lazy_default() {
3333
assert_eq!(CALLED.load(SeqCst), 1);
3434
}
3535

36-
#[test]
37-
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
38-
fn lazy_poisoning() {
39-
let x: LazyCell<String> = LazyCell::new(|| panic!("kaboom"));
40-
for _ in 0..2 {
41-
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| x.len()));
42-
assert!(res.is_err());
43-
}
44-
}
45-
4636
#[test]
4737
#[cfg_attr(any(target_os = "emscripten", target_os = "wasi"), ignore)] // no threads
4838
fn sync_lazy_new() {
@@ -123,16 +113,6 @@ fn static_sync_lazy_via_fn() {
123113
assert_eq!(xs(), &vec![1, 2, 3]);
124114
}
125115

126-
#[test]
127-
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
128-
fn sync_lazy_poisoning() {
129-
let x: LazyLock<String> = LazyLock::new(|| panic!("kaboom"));
130-
for _ in 0..2 {
131-
let res = panic::catch_unwind(|| x.len());
132-
assert!(res.is_err());
133-
}
134-
}
135-
136116
// Check that we can infer `T` from closure's type.
137117
#[test]
138118
fn lazy_type_inference() {
@@ -145,17 +125,6 @@ fn is_sync_send() {
145125
assert_traits::<LazyLock<String>>();
146126
}
147127

148-
#[test]
149-
#[should_panic = "has previously been poisoned"]
150-
fn lazy_force_mut_panic() {
151-
let mut lazy = LazyLock::<String>::new(|| panic!());
152-
panic::catch_unwind(panic::AssertUnwindSafe(|| {
153-
let _ = LazyLock::force_mut(&mut lazy);
154-
}))
155-
.unwrap_err();
156-
let _ = &*lazy;
157-
}
158-
159128
#[test]
160129
fn lazy_force_mut() {
161130
let s = "abc".to_owned();
@@ -165,3 +134,56 @@ fn lazy_force_mut() {
165134
p.clear();
166135
LazyLock::force_mut(&mut lazy);
167136
}
137+
138+
#[test]
139+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
140+
fn lazy_poisoning() {
141+
let x: LazyCell<String> = LazyCell::new(|| panic!("kaboom"));
142+
for _ in 0..2 {
143+
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| x.len()));
144+
assert!(res.is_err());
145+
}
146+
}
147+
148+
/// Verifies that when a `LazyLock` is poisoned, it panics with the correct error message ("LazyLock
149+
/// instance has previously been poisoned") instead of the underlying `Once` error message.
150+
#[test]
151+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
152+
#[should_panic(expected = "LazyLock instance has previously been poisoned")]
153+
fn lazy_lock_deref_panic() {
154+
let lazy: LazyLock<String> = LazyLock::new(|| panic!("initialization failed"));
155+
156+
// First access will panic during initialization.
157+
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {
158+
let _ = &*lazy;
159+
}));
160+
161+
// Second access should panic with the poisoned message.
162+
let _ = &*lazy;
163+
}
164+
165+
#[test]
166+
#[should_panic(expected = "LazyLock instance has previously been poisoned")]
167+
fn lazy_lock_deref_mut_panic() {
168+
let mut lazy: LazyLock<String> = LazyLock::new(|| panic!("initialization failed"));
169+
170+
// First access will panic during initialization.
171+
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {
172+
let _ = LazyLock::force_mut(&mut lazy);
173+
}));
174+
175+
// Second access should panic with the poisoned message.
176+
let _ = &*lazy;
177+
}
178+
179+
/// Verifies that when the initialization closure panics with a custom message, that message is
180+
/// preserved and not overridden by `LazyLock`.
181+
#[test]
182+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
183+
#[should_panic(expected = "custom panic message from closure")]
184+
fn lazy_lock_preserves_closure_panic_message() {
185+
let lazy: LazyLock<String> = LazyLock::new(|| panic!("custom panic message from closure"));
186+
187+
// This should panic with the original message from the closure.
188+
let _ = &*lazy;
189+
}

src/bootstrap/src/bin/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,16 @@ fn check_version(config: &Config) -> Option<String> {
198198
Some(ChangeId::Id(id)) if id == latest_change_id => return None,
199199
Some(ChangeId::Ignore) => return None,
200200
Some(ChangeId::Id(id)) => id,
201-
None => {
201+
// The warning is only useful for development, not release tarballs
202+
None if !config.rust_info.is_from_tarball() => {
202203
msg.push_str("WARNING: The `change-id` is missing in the `bootstrap.toml`. This means that you will not be able to track the major changes made to the bootstrap configurations.\n");
203204
msg.push_str("NOTE: to silence this warning, ");
204205
msg.push_str(&format!(
205206
"add `change-id = {latest_change_id}` or `change-id = \"ignore\"` at the top of `bootstrap.toml`"
206207
));
207208
return Some(msg);
208209
}
210+
None => return None,
209211
};
210212

211213
// Always try to use `change-id` from .last-warned-change-id first. If it doesn't exist,

src/bootstrap/src/core/config/config.rs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -327,59 +327,6 @@ pub struct Config {
327327
}
328328

329329
impl Config {
330-
#[cfg_attr(
331-
feature = "tracing",
332-
instrument(target = "CONFIG_HANDLING", level = "trace", name = "Config::default_opts")
333-
)]
334-
pub fn default_opts() -> Config {
335-
#[cfg(feature = "tracing")]
336-
span!(target: "CONFIG_HANDLING", tracing::Level::TRACE, "constructing default config");
337-
338-
Config {
339-
bypass_bootstrap_lock: false,
340-
llvm_optimize: true,
341-
ninja_in_file: true,
342-
llvm_static_stdcpp: false,
343-
llvm_libzstd: false,
344-
backtrace: true,
345-
rust_optimize: RustOptimize::Bool(true),
346-
rust_optimize_tests: true,
347-
rust_randomize_layout: false,
348-
submodules: None,
349-
docs: true,
350-
docs_minification: true,
351-
rust_rpath: true,
352-
rust_strip: false,
353-
channel: "dev".to_string(),
354-
codegen_tests: true,
355-
rust_dist_src: true,
356-
rust_codegen_backends: vec![CodegenBackendKind::Llvm],
357-
deny_warnings: true,
358-
bindir: "bin".into(),
359-
dist_include_mingw_linker: true,
360-
dist_compression_profile: "fast".into(),
361-
362-
stdout_is_tty: std::io::stdout().is_terminal(),
363-
stderr_is_tty: std::io::stderr().is_terminal(),
364-
365-
// set by build.rs
366-
host_target: get_host_target(),
367-
368-
src: {
369-
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
370-
// Undo `src/bootstrap`
371-
manifest_dir.parent().unwrap().parent().unwrap().to_owned()
372-
},
373-
out: PathBuf::from("build"),
374-
375-
// This is needed by codegen_ssa on macOS to ship `llvm-objcopy` aliased to
376-
// `rust-objcopy` to workaround bad `strip`s on macOS.
377-
llvm_tools_enabled: true,
378-
379-
..Default::default()
380-
}
381-
}
382-
383330
pub fn set_dry_run(&mut self, dry_run: DryRun) {
384331
self.exec_ctx.set_dry_run(dry_run);
385332
}

src/tools/clippy/Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ harness = false
6565
name = "dogfood"
6666
harness = false
6767

68-
# quine-mc_cluskey makes up a significant part of the runtime in dogfood
69-
# due to the number of conditions in the clippy_lints crate
70-
# and enabling optimizations for that specific dependency helps a bit
71-
# without increasing total build times.
72-
[profile.dev.package.quine-mc_cluskey]
73-
opt-level = 3
74-
7568
[lints.rust.unexpected_cfgs]
7669
level = "warn"
7770
check-cfg = ['cfg(bootstrap)']

src/tools/miri/src/shims/native_lib/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
242242

243243
match evt {
244244
AccessEvent::Read(_) => {
245-
// FIXME: ProvenanceMap should have something like get_range().
246-
let p_map = alloc.provenance();
247-
for idx in overlap {
248-
// If a provenance was read by the foreign code, expose it.
249-
if let Some((prov, _idx)) = p_map.get_byte(Size::from_bytes(idx), this)
250-
{
251-
this.expose_provenance(prov)?;
252-
}
245+
// If a provenance was read by the foreign code, expose it.
246+
for prov in alloc.provenance().get_range(this, overlap.into()) {
247+
this.expose_provenance(prov)?;
253248
}
254249
}
255250
AccessEvent::Write(_, certain) => {

0 commit comments

Comments
 (0)