Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Status Access Violation with constant redefinition #135870

Closed
TheIronBorn opened this issue Jan 22, 2025 · 20 comments
Closed

Internal Status Access Violation with constant redefinition #135870

TheIronBorn opened this issue Jan 22, 2025 · 20 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-compiler-parallel Working group: Parallelizing the compiler

Comments

@TheIronBorn
Copy link

Code

const FOO: usize = 32;
fn bar() {
    const FOO: usize = FOO;
}

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (ed43cbcb8 2025-01-21)
binary: rustc
commit-hash: ed43cbcb882e7c06870abdd9305dc1f17eb9bab9
commit-date: 2025-01-21
host: x86_64-pc-windows-msvc
release: 1.86.0-nightly
LLVM version: 19.1.7

Error output

error: could not compile `testtest` (lib)

Caused by:
process didn't exit successfully: `C:\Users\<username>\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin\clippy-driver.exe C:\Users\<username>\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin\rustc.exe --crate-name testtest --edition=2024 src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -Ctarget-cpu=native -Ztune-cpu=native -Ctarget-feature=+aes -Clink-arg=-fuse-ld=lld -Zthreads=4 --cfg "feature=\"default\"" --check-cfg cfg(docsrs,test) --check-cfg "cfg(feature, values(\"default\", \"rand\"))" -C metadata=10a1d148f727b426 -C extra-filename=-652f9f02f745d5a0 --out-dir C:\Users\<username>\Rust_stuff\misc\testtest\target\debug\deps -C incremental=C:\Users\<username>\Rust_stuff\misc\testtest\target\debug\incremental -L dependency=C:\Users\<username>\Rust_stuff\misc\testtest\target\debug\deps` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
@TheIronBorn TheIronBorn added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 22, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 22, 2025
@bjorn3
Copy link
Member

bjorn3 commented Jan 22, 2025

On the playground both stable and nightly give:

error[E0391]: cycle detected when simplifying constant for the type system `bar::FOO`
 --> src/lib.rs:3:5
  |
3 |     const FOO: usize = FOO;
  |     ^^^^^^^^^^^^^^^^
  |
note: ...which requires const-evaluating + checking `bar::FOO`...
 --> src/lib.rs:3:24
  |
3 |     const FOO: usize = FOO;
  |                        ^^^
  = note: ...which again requires simplifying constant for the type system `bar::FOO`, completing the cycle
  = note: cycle used when running analysis passes on this crate
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

For more information about this error, try `rustc --explain E0391`.
error: could not compile `playground` (lib) due to 1 previous error

@ehuss
Copy link
Contributor

ehuss commented Jan 22, 2025

@bjorn3 there are several non-standard flags in the user's output:
-Ctarget-cpu=native -Ztune-cpu=native -Ctarget-feature=+aes -Clink-arg=-fuse-ld=lld -Zthreads=4

I believe it is the -Zthreads=4 which is causing the error.

@bjorn3
Copy link
Member

bjorn3 commented Jan 22, 2025

Didn't notice that. -Zthreads=4 indeed gives a different result:

https://rust.godbolt.org/z/nqfqqjo8h

thread 'rustc query cycle handler' panicked at compiler/rustc_query_system/src/query/job.rs:502:9:
deadlock detected as we're unable to find a query cycle to break
current query map:
{}
stack backtrace:
   0:     0x7a4ec02fa8ca - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hd3f7dde65eadb8f5
   1:     0x7a4ec0a12da6 - core::fmt::write::h03821e8dd27929da
   2:     0x7a4ec19846d1 - std::io::Write::write_fmt::h28497d2928023bec
   3:     0x7a4ec02fa722 - std::sys::backtrace::BacktraceLock::print::h113e8531332c9d1a
   4:     0x7a4ec02fcba2 - std::panicking::default_hook::{{closure}}::h511fb590fa3e0372
   5:     0x7a4ec02fca2a - std::panicking::default_hook::h9dd552201bc7892d
   6:     0x7a4ebf45ad0b - std[99f071fb7bf80049]::panicking::update_hook::<alloc[8b0936adf4c1bb8e]::boxed::Box<rustc_driver_impl[520997e00060abd5]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7a4ec02fd723 - std::panicking::rust_panic_with_hook::hdf22da07ff72d33d
   8:     0x7a4ec02fd41a - std::panicking::begin_panic_handler::{{closure}}::h6388cd95efa89156
   9:     0x7a4ec02fada9 - std::sys::backtrace::__rust_end_short_backtrace::ha958cfab6971d37c
  10:     0x7a4ec02fd0dd - rust_begin_unwind
  11:     0x7a4ebcfa9690 - core::panicking::panic_fmt::hba7dd8f296a53b9a
  12:     0x7a4ebfe994aa - rustc_query_system[3ed4f24c27dcb839]::query::job::break_query_cycles
  13:     0x7a4ebf4515cc - std[99f071fb7bf80049]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[686a4ed24023fb80]::util::run_in_thread_pool_with_globals<rustc_interface[686a4ed24023fb80]::interface::run_compiler<(), rustc_driver_impl[520997e00060abd5]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#2}::{closure#1}, ()>
  14:     0x7a4ebf462938 - <<std[99f071fb7bf80049]::thread::Builder>::spawn_unchecked_<rustc_interface[686a4ed24023fb80]::util::run_in_thread_pool_with_globals<rustc_interface[686a4ed24023fb80]::interface::run_compiler<(), rustc_driver_impl[520997e00060abd5]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#2}::{closure#1}, ()>::{closure#1} as core[fe4dc82ac4f8e512]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  15:     0x7a4ec185352b - std::sys::pal::unix::thread::Thread::new::thread_start::h3a1166e57f630f50
  16:     0x7a4ebba94ac3 - <unknown>
  17:     0x7a4ebbb26850 - <unknown>
  18:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/app/rustc-ice-2025-01-22T15_12_31-1.txt` to your bug report

note: compiler flags: -C debuginfo=2 -C llvm-args=--x86-asm-syntax=intel --crate-type rlib -Z threads=4

query stack during panic:
end of query stack
query cycle handler thread panicked, aborting process
error: rustc interrupted by SIGSEGV, printing backtrace

/opt/compiler-explorer/rust-nightly/lib/librustc_driver-51e8a964a3a70cd7.so(+0x367f363)[0x7a4ebf47f363]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7a4ebba42520]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x178)[0x7a4ebba28898]
/opt/compiler-explorer/rust-nightly/lib/librustc_driver-51e8a964a3a70cd7.so(+0x2ad801a)[0x7a4ebe8d801a]
/opt/compiler-explorer/rust-nightly/lib/librustc_driver-51e8a964a3a70cd7.so(+0x44f89da)[0x7a4ec02f89da]
/opt/compiler-explorer/rust-nightly/lib/librustc_driver-51e8a964a3a70cd7.so(_RINvNtNtCsddpJ6axtn8j_3std3sys9backtrace28___rust_begin_short_backtraceNCNCINvNtCs8XNBdZ1EPrU_15rustc_interface4util31run_in_thread_pool_with_globalsNCINvNtB1g_9interface12run_compileruNCNvCs72GnytMAHAL_17rustc_driver_impl12run_compiler0Es_0uEs0_0s_0uEB31_+0x79)[0x7a4ebf451619]
/opt/compiler-explorer/rust-nightly/lib/librustc_driver-51e8a964a3a70cd7.so(+0x3662938)[0x7a4ebf462938]
/opt/compiler-explorer/rust-nightly/lib/librustc_driver-51e8a964a3a70cd7.so(+0x5a5352b)[0x7a4ec185352b]
/lib/x86_64-linux-gnu/libc.so.6(+0x94ac3)[0x7a4ebba94ac3]
/lib/x86_64-linux-gnu/libc.so.6(+0x126850)[0x7a4ebbb26850]

note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
Program terminated with signal: SIGSEGV
Compiler returned: 139

@ehuss
Copy link
Contributor

ehuss commented Jan 22, 2025

Another oddity is that I get SIGSEGV on aarch64-apple-darwin and STATUS_ACCESS_VIOLATION on x86_64-pc-windows-msvc, but I get the deadlock detection on x86_64-apple-darwin.

@cyrgani
Copy link
Contributor

cyrgani commented Jan 22, 2025

Reduction (rustc -Zthreads=2):

const FOO: usize = FOO;

Bisection:

searched nightlies: from nightly-2024-12-16 to nightly-2025-01-22
regressed nightly: nightly-2024-12-18
searched commit range: 6d9f6ae...a4cb3c8
regressed commit: 978c659

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2024-12-16 --script run.sh 

@rustbot label:S-has-mcve WG-compiler-parallel S-has-bisection

@rustbot rustbot added S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue WG-compiler-parallel Working group: Parallelizing the compiler labels Jan 22, 2025
@lqd
Copy link
Member

lqd commented Jan 22, 2025

That bisects to removing driver queries? @bjorn3

@bjorn3
Copy link
Member

bjorn3 commented Jan 22, 2025

That PR touched some code around handling of fatal error when they were emitted from inside a TyCtxt.

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 22, 2025
@lqd
Copy link
Member

lqd commented Jan 23, 2025

@bjorn3 That's unfortunate because it may mean error handling has regressed under -Zthreads>1? Does cg_clif depend on that PR (both the repo and the in-tree rev)? In case we'd need to take a look at a revert. (A revert does fix this issue for me locally)

@bjorn3
Copy link
Member

bjorn3 commented Jan 24, 2025

I've bisected #134302 and the crash is introduced by 6545a2d. The commit that I actually suspected (618d4c3) was from the earlier PR #133567 instead.

@bjorn3
Copy link
Member

bjorn3 commented Jan 24, 2025

Reduced revert to fix this issue (will update as I minimize it)
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 2d76f6ec7d6..564b8e0f49a 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -1349,6 +1349,33 @@ pub struct GlobalCtxt<'tcx> {
 
     /// Stores memory for globals (statics/consts).
     pub(crate) alloc_map: Lock<interpret::AllocMap<'tcx>>,
+
+    current_gcx: CurrentGcx,
+}
+
+impl<'tcx> GlobalCtxt<'tcx> {
+    /// Installs `self` in a `TyCtxt` and `ImplicitCtxt` for the duration of
+    /// `f`.
+    pub fn enter<F, R>(&'tcx self, f: F) -> R
+    where
+        F: FnOnce(TyCtxt<'tcx>) -> R,
+    {
+        let icx = tls::ImplicitCtxt::new(self);
+
+        // Reset `current_gcx` to `None` when we exit.
+        let _on_drop = defer(move || {
+            *self.current_gcx.value.write() = None;
+        });
+
+        // Set this `GlobalCtxt` as the current one.
+        {
+            let mut guard = self.current_gcx.value.write();
+            assert!(guard.is_none(), "no `GlobalCtxt` is currently set");
+            *guard = Some(self as *const _ as *const ());
+        }
+
+        tls::enter_context(&icx, || f(icx.tcx))
+    }
 }
 
 /// This is used to get a reference to a `GlobalCtxt` if one is available.
@@ -1539,23 +1566,10 @@ pub fn create_global_ctxt<T>(
             canonical_param_env_cache: Default::default(),
             data_layout,
             alloc_map: Lock::new(interpret::AllocMap::new()),
+            current_gcx,
         });
 
-        let icx = tls::ImplicitCtxt::new(&gcx);
-
-        // Reset `current_gcx` to `None` when we exit.
-        let _on_drop = defer(|| {
-            *current_gcx.value.write() = None;
-        });
-
-        // Set this `GlobalCtxt` as the current one.
-        {
-            let mut guard = current_gcx.value.write();
-            assert!(guard.is_none(), "no `GlobalCtxt` is currently set");
-            *guard = Some(&gcx as *const _ as *const ());
-        }
-
-        tls::enter_context(&icx, || f(icx.tcx))
+        gcx.enter(f)
     }
 
     /// Obtain all lang items of this crate and all dependencies (recursively)

@bjorn3
Copy link
Member

bjorn3 commented Jan 24, 2025

This is the minimal change that will fix this crash. Somehow inlining GlobalCtxt::enter is enough to cause this crash again. The crash happens inside the deadlock_handler, which uses current_gcx.

diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 2d76f6ec7d6..564b8e0f49a 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -1349,6 +1349,33 @@ pub struct GlobalCtxt<'tcx> {
 
     /// Stores memory for globals (statics/consts).
     pub(crate) alloc_map: Lock<interpret::AllocMap<'tcx>>,
+
+    current_gcx: CurrentGcx,
+}
+
+impl<'tcx> GlobalCtxt<'tcx> {
+    /// Installs `self` in a `TyCtxt` and `ImplicitCtxt` for the duration of
+    /// `f`.
+    pub fn enter<F, R>(&'tcx self, f: F) -> R
+    where
+        F: FnOnce(TyCtxt<'tcx>) -> R,
+    {
+        let icx = tls::ImplicitCtxt::new(self);
+
+        // Reset `current_gcx` to `None` when we exit.
+        let _on_drop = defer(move || {
+            *self.current_gcx.value.write() = None;
+        });
+
+        // Set this `GlobalCtxt` as the current one.
+        {
+            let mut guard = self.current_gcx.value.write();
+            assert!(guard.is_none(), "no `GlobalCtxt` is currently set");
+            *guard = Some(self as *const _ as *const ());
+        }
+
+        tls::enter_context(&icx, || f(icx.tcx))
+    }
 }
 
 /// This is used to get a reference to a `GlobalCtxt` if one is available.
@@ -1539,23 +1566,10 @@ pub fn create_global_ctxt<T>(
             canonical_param_env_cache: Default::default(),
             data_layout,
             alloc_map: Lock::new(interpret::AllocMap::new()),
+            current_gcx,
         });
 
-        let icx = tls::ImplicitCtxt::new(&gcx);
-
-        // Reset `current_gcx` to `None` when we exit.
-        let _on_drop = defer(|| {
-            *current_gcx.value.write() = None;
-        });
-
-        // Set this `GlobalCtxt` as the current one.
-        {
-            let mut guard = current_gcx.value.write();
-            assert!(guard.is_none(), "no `GlobalCtxt` is currently set");
-            *guard = Some(&gcx as *const _ as *const ());
-        }
-
-        tls::enter_context(&icx, || f(icx.tcx))
+        gcx.enter(f)
     }
 
     /// Obtain all lang items of this crate and all dependencies (recursively)

@lqd
Copy link
Member

lqd commented Jan 24, 2025

I think we should probably land it. When working on the parallel queries tests and rustc-rayon, the crash above sometimes showed up as failures to get the ImplicitCtxt from tls, so the minimization makes a lot of sense for the errors I was seeing as well as this issue.

@bjorn3
Copy link
Member

bjorn3 commented Jan 24, 2025

I guess. It is just weird that inlining GlobalCtxt::enter without any other changes is enough to cause the crash.

@lqd
Copy link
Member

lqd commented Jan 24, 2025

For sure. Something unobvious and fragile is going on.

@bjorn3
Copy link
Member

bjorn3 commented Jan 24, 2025

Likely not related to this crash, but when trying to run rustc in miri I found UB with -Zthreads=2:

error: Undefined Behavior: trying to retag from <4532432> for SharedReadWrite permission at alloc1866067[0x8], but that tag does not exist in the borrow stack for this location
--> /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/internal.rs:549:9
|
549 | &*local_ptr
| ^^^^^^^^^^^
| |
| trying to retag from <4532432> for SharedReadWrite permission at alloc1866067[0x8], but that tag does not exist in the borrow stack for this location
| this error occurs as part of retag at alloc1866067[0x0..0x180]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <4532432> was created by a SharedReadWrite retag at offsets [0x0..0x8]
--> /home/gh-bjorn3/rust/compiler/rustc_interface/src/util.rs:199:29
|
199 | ... thread.run()
| ^^^^^^^^^^^^
= note: BACKTRACE (of the first span) on thread `rustc`:
= note: inside `<crossbeam_epoch::internal::Local as crossbeam_epoch::sync::list::IsElement<crossbeam_epoch::internal::Local>>::element_of` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/internal.rs:549:9: 549:20
= note: inside `<crossbeam_epoch::sync::list::Iter<'_, crossbeam_epoch::internal::Local, crossbeam_epoch::internal::Local> as std::iter::Iterator>::next` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/sync/list.rs:290:37: 290:53
= note: inside `crossbeam_epoch::internal::Global::try_advance` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/internal.rs:235:22: 235:45
= note: inside `crossbeam_epoch::internal::Global::collect` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/internal.rs:200:28: 200:51
= note: inside `crossbeam_epoch::internal::Local::pin` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/internal.rs:435:17: 435:46
= note: inside `crossbeam_epoch::collector::LocalHandle::pin` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/collector.rs:81:18: 81:37
= note: inside closure at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/default.rs:40:26: 40:38
= note: inside closure at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/default.rs:60:23: 60:27
= note: inside `std::thread::LocalKey::<crossbeam_epoch::collector::LocalHandle>::try_with::<{closure@crossbeam_epoch::default::with_handle<{closure@crossbeam_epoch::default::pin::{closure#0}}, crossbeam_epoch::guard::Guard>::{closure#0}}, crossbeam_epoch::guard::Guard>` at /home/gh-bjorn3/.rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:316:12: 316:27
= note: inside `crossbeam_epoch::default::with_handle::<{closure@crossbeam_epoch::default::pin::{closure#0}}, crossbeam_epoch::guard::Guard>` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/default.rs:59:5: 60:28
= note: inside `crossbeam_epoch::default::pin` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-epoch-0.9.18/src/default.rs:40:5: 40:39
= note: inside `crossbeam_deque::deque::Stealer::<rayon_core::job::JobRef>::steal` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-deque-0.8.6/src/deque.rs:646:22: 646:34
= note: inside `rayon_core::registry::WorkerThread::take_local_job` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustc-rayon-core-0.5.0/src/registry.rs:827:19: 827:39
= note: inside `rayon_core::registry::WorkerThread::find_work` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustc-rayon-core-0.5.0/src/registry.rs:889:9: 889:30
= note: inside `rayon_core::registry::WorkerThread::wait_until_cold` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustc-rayon-core-0.5.0/src/registry.rs:860:32: 860:48
= note: inside `rayon_core::registry::WorkerThread::wait_until::<rayon_core::latch::CountLatch>` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustc-rayon-core-0.5.0/src/registry.rs:845:13: 845:40
= note: inside `rayon_core::registry::main_loop` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustc-rayon-core-0.5.0/src/registry.rs:991:5: 991:49
= note: inside `rayon_core::registry::ThreadBuilder::run` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustc-rayon-core-0.5.0/src/registry.rs:55:18: 55:33
note: inside closure
--> /home/gh-bjorn3/rust/compiler/rustc_interface/src/util.rs:199:29
|
199 | ... thread.run()
| ^^^^^^^^^^^^
= note: inside `scoped_tls::ScopedKey::<rustc_span::SessionGlobals>::set::<{closure@rustc_interface::util::run_in_thread_pool_with_globals<{closure@rustc_interface::interface::run_compiler<(), {closure@rustc_driver::run_compiler::{closure#0}}>::{closure#1}}, ()>::{closure#3}::{closure#0}::{closure#0}::{closure#0}}, ()>` at /home/gh-bjorn3/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/scoped-tls-1.0.1/src/lib.rs:137:9: 137:12
note: inside `rustc_span::set_session_globals_then::<(), {closure@rustc_interface::util::run_in_thread_pool_with_globals<{closure@rustc_interface::interface::run_compiler<(), {closure@rustc_driver::run_compiler::{closure#0}}>::{closure#1}}, ()>::{closure#3}::{closure#0}::{closure#0}::{closure#0}}>`
--> /home/gh-bjorn3/rust/compiler/rustc_span/src/lib.rs:148:5
|
148 | SESSION_GLOBALS.set(session_globals, f)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
--> /home/gh-bjorn3/rust/compiler/rustc_interface/src/util.rs:198:25
|
198 | / rustc_span::set_session_globals_then(session_globals.into_inner(), || {
199 | | thread.run()
200 | | })
| |__________________________^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

And another one without -Zthreads=1:

error: Undefined Behavior: attempting a read access using <8984379> at alloc2631991[0x10], but that tag does not exist in the borrow stack for this location
    --> /home/gh-bjorn3/rust/compiler/rustc_data_structures/src/flat_map_in_place.rs:72:5
     |
72   |     flat_map_in_place!();
     |     ^^^^^^^^^^^^^^^^^^^^
     |     |
     |     attempting a read access using <8984379> at alloc2631991[0x10], but that tag does not exist in the borrow stack for this location
     |     this error occurs as part of an access at alloc2631991[0x10..0x18]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <8984379> would have been created here, but this is a zero-size retag ([0x10..0x10]) so the tag in question does not exist anywhere
    --> /home/gh-bjorn3/rust/compiler/rustc_data_structures/src/flat_map_in_place.rs:72:5
     |
72   |     flat_map_in_place!();
     |     ^^^^^^^^^^^^^^^^^^^^
     = note: BACKTRACE (of the first span) on thread `rustc`:
     = note: inside `<thin_vec::ThinVec<rustc_ast::ptr::P<rustc_ast::ast::Item>> as rustc_data_structures::flat_map_in_place::FlatMapInPlace<rustc_ast::ptr::P<rustc_ast::ast::Item>>>::flat_map_in_place::<{closure@rustc_ast::mut_visit::walk_crate<rustc_expand::expand::InvocationCollector<'_, '_>>::{closure#0}}, smallvec::SmallVec<[rustc_ast::ptr::P<rustc_ast::ast::Item>; 1]>>` at /home/gh-bjorn3/rust/compiler/rustc_data_structures/src/flat_map_in_place.rs:31:29: 31:65
note: inside `rustc_ast::mut_visit::walk_crate::<rustc_expand::expand::InvocationCollector<'_, '_>>`
    --> /home/gh-bjorn3/rust/compiler/rustc_ast/src/mut_visit.rs:1412:5
     |
1412 |     items.flat_map_in_place(|item| vis.flat_map_item(item));
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `<rustc_ast::ast::Crate as rustc_expand::expand::InvocationCollectorNode>::walk::<rustc_expand::expand::InvocationCollector<'_, '_>>`
    --> /home/gh-bjorn3/rust/compiler/rustc_expand/src/expand.rs:1579:9
     |
1579 |         walk_crate(visitor, self)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
    --> /home/gh-bjorn3/rust/compiler/rustc_expand/src/expand.rs:2085:61
     |
2085 |                     assign_id!(self, node.node_id_mut(), || node.walk(self))
     |                                                             ^^^^^^^^^^^^^^^
note: inside `rustc_expand::expand::InvocationCollector::<'_, '_>::visit_node::<rustc_ast::ast::Crate>`
    --> /home/gh-bjorn3/rust/compiler/rustc_expand/src/expand.rs:2085:21
     |
2085 |                     assign_id!(self, node.node_id_mut(), || node.walk(self))
     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `<rustc_expand::expand::InvocationCollector<'_, '_> as rustc_ast::mut_visit::MutVisitor>::visit_crate`
    --> /home/gh-bjorn3/rust/compiler/rustc_expand/src/expand.rs:2176:9
     |
2176 |         self.visit_node(node)
     |         ^^^^^^^^^^^^^^^^^^^^^
note: inside `rustc_expand::expand::AstFragment::mut_visit_with::<rustc_expand::expand::InvocationCollector<'_, '_>>`
    --> /home/gh-bjorn3/rust/compiler/rustc_expand/src/expand.rs:172:1
     |
172  | / ast_fragments! {
173  | |     Expr(P<ast::Expr>) { "expression"; one fn visit_expr; fn visit_expr; fn make_expr; }
174  | |     Pat(P<ast::Pat>) { "pattern"; one fn visit_pat; fn visit_pat; fn make_pat; }
175  | |     Ty(P<ast::Ty>) { "type"; one fn visit_ty; fn visit_ty; fn make_ty; }
...    |
230  | |     Crate(ast::Crate) { "crate"; one fn visit_crate; fn visit_crate; fn make_crate; }
231  | | }
     | |_^
note: inside `rustc_expand::expand::MacroExpander::<'_, '_>::collect_invocations`
    --> /home/gh-bjorn3/rust/compiler/rustc_expand/src/expand.rs:597:13
     |
597  |             fragment.mut_visit_with(&mut collector);
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `rustc_expand::expand::MacroExpander::<'_, '_>::fully_expand_fragment`
    --> /home/gh-bjorn3/rust/compiler/rustc_expand/src/expand.rs:432:13
     |
432  |             self.collect_invocations(input_fragment, &[]);
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `rustc_expand::expand::MacroExpander::<'_, '_>::expand_crate`
    --> /home/gh-bjorn3/rust/compiler/rustc_expand/src/expand.rs:419:21
     |
419  |         let krate = self.fully_expand_fragment(AstFragment::Crate(krate)).make_crate();
     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
    --> /home/gh-bjorn3/rust/compiler/rustc_interface/src/passes.rs:198:50
     |
198  |         let krate = sess.time("expand_crate", || ecx.monotonic_expander().expand_crate(krate));
     |                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `rustc_data_structures::profiling::VerboseTimingGuard::<'_>::run::<rustc_ast::ast::Crate, {closure@rustc_interface::passes::configure_and_expand::{closure#1}::{closure#2}}>`
    --> /home/gh-bjorn3/rust/compiler/rustc_data_structures/src/profiling.rs:753:9
     |
753  |         f()
     |         ^^^
note: inside `rustc_session::utils::<impl rustc_session::session::Session>::time::<rustc_ast::ast::Crate, {closure@rustc_interface::passes::configure_and_expand::{closure#1}::{closure#2}}>`
    --> /home/gh-bjorn3/rust/compiler/rustc_session/src/utils.rs:16:9
     |
16   |         self.prof.verbose_generic_activity(what).run(f)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
    --> /home/gh-bjorn3/rust/compiler/rustc_interface/src/passes.rs:198:21
     |
198  |         let krate = sess.time("expand_crate", || ecx.monotonic_expander().expand_crate(krate));
     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `rustc_data_structures::profiling::VerboseTimingGuard::<'_>::run::<rustc_ast::ast::Crate, {closure@rustc_interface::passes::configure_and_expand::{closure#1}}>`
    --> /home/gh-bjorn3/rust/compiler/rustc_data_structures/src/profiling.rs:753:9
     |
753  |         f()
     |         ^^^
note: inside `rustc_session::utils::<impl rustc_session::session::Session>::time::<rustc_ast::ast::Crate, {closure@rustc_interface::passes::configure_and_expand::{closure#1}}>`
    --> /home/gh-bjorn3/rust/compiler/rustc_session/src/utils.rs:16:9
     |
16   |         self.prof.verbose_generic_activity(what).run(f)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `rustc_interface::passes::configure_and_expand`
    --> /home/gh-bjorn3/rust/compiler/rustc_interface/src/passes.rs:148:13
     |
148  |       krate = sess.time("macro_expand_crate", || {
     |  _____________^
...    |
221  | |         krate
222  | |     });
     | |______^
note: inside `rustc_interface::passes::resolver_for_lowering_raw`
    --> /home/gh-bjorn3/rust/compiler/rustc_interface/src/passes.rs:616:17
     |
616  |     let krate = configure_and_expand(krate, &pre_configured_attrs, &mut resolver);
     |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
    --> /home/gh-bjorn3/rust/compiler/rustc_query_impl/src/lib.rs:224:1
     |
224  | rustc_middle::rustc_query_append! { define_queries! }
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: this error originates in the macro `flat_map_in_place` which comes from the expansion of the macro `rustc_middle::rustc_query_append` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Rustc patches to run under miri
diff --git a/Cargo.lock b/Cargo.lock
index 10889139e8d..659730136a9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1947,8 +1947,6 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
 [[package]]
 name = "jobserver"
 version = "0.1.32"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
 dependencies = [
  "libc",
 ]
@@ -2258,8 +2256,6 @@ dependencies = [
 [[package]]
 name = "memchr"
 version = "2.7.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
 
 [[package]]
 name = "memmap2"
diff --git a/Cargo.toml b/Cargo.toml
index b773030b4ca..7f6a71f11e1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -93,3 +93,7 @@ codegen-units = 1
 # FIXME: LTO cannot be enabled for binaries in a workspace
 # <https://github.com/rust-lang/cargo/issues/9330>
 # lto = true
+
+[patch.crates-io]
+jobserver = { path = "jobserver-0.1.32" }
+memchr = { path = "memchr-2.7.4" }
diff --git a/compiler/rustc_data_structures/src/flat_map_in_place.rs b/compiler/rustc_data_structures/src/flat_map_in_place.rs
index e66b00b7557..9e8aabebc40 100644
--- a/compiler/rustc_data_structures/src/flat_map_in_place.rs
+++ b/compiler/rustc_data_structures/src/flat_map_in_place.rs
@@ -1,4 +1,4 @@
-use std::ptr;
+use std::{mem, ptr};
 
 use smallvec::{Array, SmallVec};
 use thin_vec::ThinVec;
@@ -69,5 +69,55 @@ impl<T, A: Array<Item = T>> FlatMapInPlace<T> for SmallVec<A> {
 }
 
 impl<T> FlatMapInPlace<T> for ThinVec<T> {
-    flat_map_in_place!();
+    fn flat_map_in_place<F, I>(&mut self, mut f: F)
+    where
+        F: FnMut(T) -> I,
+        I: IntoIterator<Item = T>,
+    {
+        struct LeakGuard<'a, T>(&'a mut ThinVec<T>);
+
+        impl<'a, T> Drop for LeakGuard<'a, T> {
+            fn drop(&mut self) {
+                unsafe {
+                    self.0.set_len(0); // make sure we just leak elements in case of panic
+                }
+            }
+        }
+
+        let this = LeakGuard(self);
+
+        let mut read_i = 0;
+        let mut write_i = 0;
+        unsafe {
+            while read_i < this.0.len() {
+                // move the read_i'th item out of the vector and map it
+                // to an iterator
+                let e = ptr::read(this.0.as_ptr().add(read_i));
+                let iter = f(e).into_iter();
+                read_i += 1;
+
+                for e in iter {
+                    if write_i < read_i {
+                        ptr::write(this.0.as_mut_ptr().add(write_i), e);
+                        write_i += 1;
+                    } else {
+                        // If this is reached we ran out of space
+                        // in the middle of the vector.
+                        // However, the vector is in a valid state here,
+                        // so we just do a somewhat inefficient insert.
+                        this.0.insert(write_i, e);
+
+                        read_i += 1;
+                        write_i += 1;
+                    }
+                }
+            }
+
+            // write_i tracks the number of actually written new items.
+            this.0.set_len(write_i);
+
+            // The ThinVec is in a sane state again. Prevent the LeakGuard from leaking the data.
+            mem::forget(this);
+        }
+    }
 }
diff --git a/compiler/rustc_data_structures/src/memmap.rs b/compiler/rustc_data_structures/src/memmap.rs
index c7f66b2fee8..d64a5862f4e 100644
--- a/compiler/rustc_data_structures/src/memmap.rs
+++ b/compiler/rustc_data_structures/src/memmap.rs
@@ -3,13 +3,13 @@
 use std::ops::{Deref, DerefMut};
 
 /// A trivial wrapper for [`memmap2::Mmap`] (or `Vec<u8>` on WASM).
-#[cfg(not(target_arch = "wasm32"))]
+#[cfg(not(any(miri, target_arch = "wasm32")))]
 pub struct Mmap(memmap2::Mmap);
 
-#[cfg(target_arch = "wasm32")]
+#[cfg(any(miri, target_arch = "wasm32"))]
 pub struct Mmap(Vec<u8>);
 
-#[cfg(not(target_arch = "wasm32"))]
+#[cfg(not(any(miri, target_arch = "wasm32")))]
 impl Mmap {
     /// # Safety
     ///
@@ -29,7 +29,7 @@ pub unsafe fn map(file: File) -> io::Result<Self> {
     }
 }
 
-#[cfg(target_arch = "wasm32")]
+#[cfg(any(miri, target_arch = "wasm32"))]
 impl Mmap {
     #[inline]
     pub unsafe fn map(mut file: File) -> io::Result<Self> {
@@ -56,13 +56,13 @@ fn as_ref(&self) -> &[u8] {
     }
 }
 
-#[cfg(not(target_arch = "wasm32"))]
+#[cfg(not(any(miri, target_arch = "wasm32")))]
 pub struct MmapMut(memmap2::MmapMut);
 
-#[cfg(target_arch = "wasm32")]
+#[cfg(any(miri, target_arch = "wasm32"))]
 pub struct MmapMut(Vec<u8>);
 
-#[cfg(not(target_arch = "wasm32"))]
+#[cfg(not(any(miri, target_arch = "wasm32")))]
 impl MmapMut {
     #[inline]
     pub fn map_anon(len: usize) -> io::Result<Self> {
@@ -82,7 +82,7 @@ pub fn make_read_only(self) -> std::io::Result<Mmap> {
     }
 }
 
-#[cfg(target_arch = "wasm32")]
+#[cfg(any(miri, target_arch = "wasm32"))]
 impl MmapMut {
     #[inline]
     pub fn map_anon(len: usize) -> io::Result<Self> {
diff --git a/compiler/rustc_data_structures/src/stack.rs b/compiler/rustc_data_structures/src/stack.rs
index 3d6d0003483..d00cce7effc 100644
--- a/compiler/rustc_data_structures/src/stack.rs
+++ b/compiler/rustc_data_structures/src/stack.rs
@@ -18,5 +18,5 @@
 /// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
 #[inline]
 pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
-    stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
+    f() //stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
 }
diff --git a/compiler/rustc_driver/Cargo.toml b/compiler/rustc_driver/Cargo.toml
index ae9712ad66d..81a113fe3f8 100644
--- a/compiler/rustc_driver/Cargo.toml
+++ b/compiler/rustc_driver/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.0.0"
 edition = "2021"
 
 [lib]
-crate-type = ["dylib"]
+#crate-type = ["dylib"]
 
 [dependencies]
 # tidy-alphabetical-start
diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs
index 20be2144609..41da6c6c0ca 100644
--- a/compiler/rustc_driver_impl/src/lib.rs
+++ b/compiler/rustc_driver_impl/src/lib.rs
@@ -89,10 +89,10 @@
 #[macro_use]
 mod print;
 mod session_diagnostics;
-#[cfg(all(unix, any(target_env = "gnu", target_os = "macos")))]
+#[cfg(all(not(miri), unix, any(target_env = "gnu", target_os = "macos")))]
 mod signal_handler;
 
-#[cfg(not(all(unix, any(target_env = "gnu", target_os = "macos"))))]
+#[cfg(not(all(not(miri), unix, any(target_env = "gnu", target_os = "macos"))))]
 mod signal_handler {
     /// On platforms which don't support our signal handler's requirements,
     /// simply use the default signal handler provided by std.
@@ -1474,7 +1474,7 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
 /// Install our usual `ctrlc` handler, which sets [`rustc_const_eval::CTRL_C_RECEIVED`].
 /// Making this handler optional lets tools can install a different handler, if they wish.
 pub fn install_ctrlc_handler() {
-    #[cfg(not(target_family = "wasm"))]
+    #[cfg(all(not(miri), not(target_family = "wasm")))]
     ctrlc::set_handler(move || {
         // Indicate that we have been signaled to stop, then give the rest of the compiler a bit of
         // time to check CTRL_C_RECEIVED and run its own shutdown logic, but after a short amount
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs
index 984b8104f53..529d118cdd4 100644
--- a/compiler/rustc_interface/src/util.rs
+++ b/compiler/rustc_interface/src/util.rs
@@ -247,6 +247,7 @@ pub fn get_codegen_backend(
             }
             #[cfg(feature = "llvm")]
             "llvm" => rustc_codegen_llvm::LlvmCodegenBackend::new,
+            "dummy" => DummyCodegenBackend::new,
             backend_name => get_codegen_sysroot(early_dcx, sysroot, backend_name),
         }
     });
@@ -257,6 +258,44 @@ pub fn get_codegen_backend(
     unsafe { load() }
 }
 
+struct DummyCodegenBackend;
+
+impl DummyCodegenBackend {
+    fn new() -> Box<dyn CodegenBackend> {
+        Box::new(DummyCodegenBackend)
+    }
+}
+
+impl CodegenBackend for DummyCodegenBackend {
+    fn locale_resource(&self) -> &'static str {
+        ""
+    }
+
+    fn codegen_crate<'tcx>(
+        &self,
+        tcx: rustc_middle::ty::TyCtxt<'tcx>,
+        metadata: rustc_metadata::EncodedMetadata,
+        need_metadata_module: bool,
+    ) -> Box<dyn std::any::Any> {
+        todo!()
+    }
+
+    fn join_codegen(
+        &self,
+        ongoing_codegen: Box<dyn std::any::Any>,
+        sess: &Session,
+        outputs: &OutputFilenames,
+    ) -> (
+        rustc_codegen_ssa::CodegenResults,
+        rustc_data_structures::fx::FxIndexMap<
+            rustc_middle::dep_graph::WorkProductId,
+            rustc_middle::dep_graph::WorkProduct,
+        >,
+    ) {
+        todo!()
+    }
+}
+
 // This is used for rustdoc, but it uses similar machinery to codegen backend
 // loading, so we leave the code here. It is potentially useful for other tools
 // that want to invoke the rustc binary while linking to rustc as well.
diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs
index ec83761da4a..bbda7c213db 100644
--- a/compiler/rustc_session/src/filesearch.rs
+++ b/compiler/rustc_session/src/filesearch.rs
@@ -63,7 +63,10 @@ fn current_dll_path() -> Result<PathBuf, String> {
     use std::ffi::{CStr, OsStr};
     use std::os::unix::prelude::*;
 
-    #[cfg(not(target_os = "aix"))]
+    #[cfg(miri)]
+    return Err("must manually specify --sysroot in miri".to_owned());
+
+    #[cfg(all(not(miri), not(target_os = "aix")))]
     unsafe {
         let addr = current_dll_path as usize as *mut _;
         let mut info = std::mem::zeroed();
@@ -160,8 +163,7 @@ fn current_dll_path() -> Result<PathBuf, String> {
 
 pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
     let target = crate::config::host_tuple();
-    let mut sysroot_candidates: SmallVec<[PathBuf; 2]> =
-        smallvec![get_or_default_sysroot().expect("Failed finding sysroot")];
+    let mut sysroot_candidates: SmallVec<[PathBuf; 2]> = smallvec![];
     let path = current_dll_path().and_then(|s| try_canonicalize(s).map_err(|e| e.to_string()));
     if let Ok(dll) = path {
         // use `parent` twice to chop off the file name and then also the

Where jobserver is slightly patched to avoid a direct pipe2 syscall and with the fcntl call removed. Running miri is done using CFG_COMPILER_HOST_TRIPLE=aarch64-unknown-linux-gnu RUSTC_INSTALL_BINDIR=bin CFG_RELEASE_CHANNEL=dev CFG_RELEASE="1.100.0" RUSTFLAGS="--check-cfg cfg(bootstrap)" RUSTC_BOOTSTRAP=1 MIRIFLAGS="-Zmiri-disable-isolation" time cargo +nightly miri run --manifest-path compiler/rustc/Cargo.toml -- --sysroot build/host/stage1 - -Zcodegen-backend=dummy with an existing sysroot in build/host/stage1.

@davidv1992
Copy link
Contributor

The first (-Zthreads=2) is due to crossbeam-epoch not working under stacked borrows. Based on their CI this seems to be a concious choice. Unfortunately, the rust compiler doesn't really want to work with miri in tree borrow mode since it does some integer-pointer casts.

jhpratt added a commit to jhpratt/rust that referenced this issue Jan 27, 2025
…mulacrum

Upgrade elsa to the newest version.

This was locked to 1.7.1 because of an error in the elsa release process that has since been fixed. Upgrading has the advantage that the elsa code runs properly in miri, at least with tree borrows.

This was spawned from rust-lang#135870 (comment)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 27, 2025
…rash, r=lqd

Add a workaround for parallel rustc crashing when there are delayed bugs

This doesn't fix the root cause of this crash, but at least stops it from happening for the time being.

Workaround for rust-lang#135870
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 27, 2025
Rollup merge of rust-lang#135988 - bjorn3:workaround_parallel_rustc_crash, r=lqd

Add a workaround for parallel rustc crashing when there are delayed bugs

This doesn't fix the root cause of this crash, but at least stops it from happening for the time being.

Workaround for rust-lang#135870
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 29, 2025
Upgrade elsa to the newest version.

This was locked to 1.7.1 because of an error in the elsa release process that has since been fixed. Upgrading has the advantage that the elsa code runs properly in miri, at least with tree borrows.

This was spawned from rust-lang#135870 (comment)
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 1, 2025
Upgrade elsa to the newest version.

This was locked to 1.7.1 because of an error in the elsa release process that has since been fixed. Upgrading has the advantage that the elsa code runs properly in miri, at least with tree borrows.

This was spawned from rust-lang#135870 (comment)
@lqd
Copy link
Member

lqd commented Feb 3, 2025

@TheIronBorn this should be fixed on nightly by now, thanks to #135988.
I'll close this as fixed, but feel free to reopen if it happens again.

Thanks for opening an issue!

@lqd lqd closed this as completed Feb 3, 2025
@lqd lqd marked this as a duplicate of #136453 Feb 3, 2025
@bjorn3
Copy link
Member

bjorn3 commented Feb 3, 2025

I intentionally left this issue open as my PR is just a workaround and not a root cause fix.

@lqd
Copy link
Member

lqd commented Feb 3, 2025

I know. The root cause is unfixed but this issue is fixed. Duplicates are being opened though, and don't see this as fixed.

Please open a dedicated issue to fix the root cause, and mention it in the wg-parallel-rustc tracking issues.

@bjorn3
Copy link
Member

bjorn3 commented Feb 3, 2025

Opened #136499

bors added a commit to rust-lang-ci/rust that referenced this issue Feb 5, 2025
Upgrade elsa to the newest version.

This was locked to 1.7.1 because of an error in the elsa release process that has since been fixed. Upgrading has the advantage that the elsa code runs properly in miri, at least with tree borrows.

This was spawned from rust-lang#135870 (comment)
compiler-errors pushed a commit to compiler-errors/rust that referenced this issue Feb 5, 2025
Upgrade elsa to the newest version.

This was locked to 1.7.1 because of an error in the elsa release process that has since been fixed. Upgrading has the advantage that the elsa code runs properly in miri, at least with tree borrows.

This was spawned from rust-lang#135870 (comment)
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this issue Feb 6, 2025
Upgrade elsa to the newest version.

This was locked to 1.7.1 because of an error in the elsa release process that has since been fixed. Upgrading has the advantage that the elsa code runs properly in miri, at least with tree borrows.

This was spawned from rust-lang/rust#135870 (comment)
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Feb 6, 2025
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)
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Feb 6, 2025
Upgrade elsa to the newest version.

This was locked to 1.7.1 because of an error in the elsa release process that has since been fixed. Upgrading has the advantage that the elsa code runs properly in miri, at least with tree borrows.

This was spawned from rust-lang/rust#135870 (comment)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 6, 2025
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)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 6, 2025
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)
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 7, 2025
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)
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Feb 10, 2025
Upgrade elsa to the newest version.

This was locked to 1.7.1 because of an error in the elsa release process that has since been fixed. Upgrading has the advantage that the elsa code runs properly in miri, at least with tree borrows.

This was spawned from rust-lang/rust#135870 (comment)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 27, 2025
Fix UB in ThinVec::flat_map_in_place

`thin_vec.as_ptr()` goes through the `Deref` impl of `ThinVec`, which will not allow access to any memory as we did call `set_len(0)` first.

Found in the process of investigating rust-lang#135870.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 27, 2025
Fix UB in ThinVec::flat_map_in_place

`thin_vec.as_ptr()` goes through the `Deref` impl of `ThinVec`, which will not allow access to any memory as we did call `set_len(0)` first.

Found in the process of investigating rust-lang#135870.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 27, 2025
Fix UB in ThinVec::flat_map_in_place

`thin_vec.as_ptr()` goes through the `Deref` impl of `ThinVec`, which will not allow access to any memory as we did call `set_len(0)` first.

Found in the process of investigating rust-lang#135870.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 28, 2025
Rollup merge of rust-lang#136579 - bjorn3:fix_thinvec_ext_ub, r=BoxyUwU

Fix UB in ThinVec::flat_map_in_place

`thin_vec.as_ptr()` goes through the `Deref` impl of `ThinVec`, which will not allow access to any memory as we did call `set_len(0)` first.

Found in the process of investigating rust-lang#135870.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-compiler-parallel Working group: Parallelizing the compiler
Projects
None yet
Development

No branches or pull requests

8 participants