Skip to content

Commit 53923c7

Browse files
authored
Rollup merge of rust-lang#136580 - bjorn3:miri_fixes, r=lqd
Couple of changes to run rustc in miri This is not the full set of patches required to run rustc in miri, but it is the fast majority of the changes to rustc itself. There is also a change to the jobserver crate necessary and on arm64 a change to the memchr crate. Running rustc in miri has already found some UB: rust-lang#136579 cc rust-lang#135870 (comment)
2 parents 9315bdc + e27495c commit 53923c7

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

compiler/rustc_data_structures/src/memmap.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use std::io;
33
use std::ops::{Deref, DerefMut};
44

55
/// A trivial wrapper for [`memmap2::Mmap`] (or `Vec<u8>` on WASM).
6-
#[cfg(not(target_arch = "wasm32"))]
6+
#[cfg(not(any(miri, target_arch = "wasm32")))]
77
pub struct Mmap(memmap2::Mmap);
88

9-
#[cfg(target_arch = "wasm32")]
9+
#[cfg(any(miri, target_arch = "wasm32"))]
1010
pub struct Mmap(Vec<u8>);
1111

12-
#[cfg(not(target_arch = "wasm32"))]
12+
#[cfg(not(any(miri, target_arch = "wasm32")))]
1313
impl Mmap {
1414
/// # Safety
1515
///
@@ -29,7 +29,7 @@ impl Mmap {
2929
}
3030
}
3131

32-
#[cfg(target_arch = "wasm32")]
32+
#[cfg(any(miri, target_arch = "wasm32"))]
3333
impl Mmap {
3434
#[inline]
3535
pub unsafe fn map(mut file: File) -> io::Result<Self> {
@@ -56,13 +56,13 @@ impl AsRef<[u8]> for Mmap {
5656
}
5757
}
5858

59-
#[cfg(not(target_arch = "wasm32"))]
59+
#[cfg(not(any(miri, target_arch = "wasm32")))]
6060
pub struct MmapMut(memmap2::MmapMut);
6161

62-
#[cfg(target_arch = "wasm32")]
62+
#[cfg(any(miri, target_arch = "wasm32"))]
6363
pub struct MmapMut(Vec<u8>);
6464

65-
#[cfg(not(target_arch = "wasm32"))]
65+
#[cfg(not(any(miri, target_arch = "wasm32")))]
6666
impl MmapMut {
6767
#[inline]
6868
pub fn map_anon(len: usize) -> io::Result<Self> {
@@ -82,7 +82,7 @@ impl MmapMut {
8282
}
8383
}
8484

85-
#[cfg(target_arch = "wasm32")]
85+
#[cfg(any(miri, target_arch = "wasm32"))]
8686
impl MmapMut {
8787
#[inline]
8888
pub fn map_anon(len: usize) -> io::Result<Self> {

compiler/rustc_data_structures/src/stack.rs

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ const STACK_PER_RECURSION: usize = 16 * 1024 * 1024; // 16MB
1717
///
1818
/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
1919
#[inline]
20+
#[cfg(not(miri))]
2021
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
2122
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
2223
}
24+
25+
/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations
26+
/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit
27+
/// from this.
28+
///
29+
/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
30+
#[cfg(miri)]
31+
#[inline]
32+
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
33+
f()
34+
}

compiler/rustc_driver_impl/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ pub mod pretty;
8989
#[macro_use]
9090
mod print;
9191
mod session_diagnostics;
92-
#[cfg(all(unix, any(target_env = "gnu", target_os = "macos")))]
92+
#[cfg(all(not(miri), unix, any(target_env = "gnu", target_os = "macos")))]
9393
mod signal_handler;
9494

95-
#[cfg(not(all(unix, any(target_env = "gnu", target_os = "macos"))))]
95+
#[cfg(not(all(not(miri), unix, any(target_env = "gnu", target_os = "macos"))))]
9696
mod signal_handler {
9797
/// On platforms which don't support our signal handler's requirements,
9898
/// simply use the default signal handler provided by std.
@@ -1474,7 +1474,7 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
14741474
/// Install our usual `ctrlc` handler, which sets [`rustc_const_eval::CTRL_C_RECEIVED`].
14751475
/// Making this handler optional lets tools can install a different handler, if they wish.
14761476
pub fn install_ctrlc_handler() {
1477-
#[cfg(not(target_family = "wasm"))]
1477+
#[cfg(all(not(miri), not(target_family = "wasm")))]
14781478
ctrlc::set_handler(move || {
14791479
// Indicate that we have been signaled to stop, then give the rest of the compiler a bit of
14801480
// time to check CTRL_C_RECEIVED and run its own shutdown logic, but after a short amount

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ impl HumanEmitter {
17651765

17661766
let column_width = if let Some(width) = self.diagnostic_width {
17671767
width.saturating_sub(code_offset)
1768-
} else if self.ui_testing {
1768+
} else if self.ui_testing || cfg!(miri) {
17691769
DEFAULT_COLUMN_WIDTH
17701770
} else {
17711771
termize::dimensions()

0 commit comments

Comments
 (0)