Skip to content

incr-comp: thread 'rustc' panicked at 'attempted to read from stolen value: rustc_middle::mir::Body' #108633

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

Closed
Red-exe-Engineer opened this issue Mar 2, 2023 · 4 comments
Labels
A-incr-comp Area: Incremental compilation 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.

Comments

@Red-exe-Engineer
Copy link

Code

use std::io;
use std::io::Write;

fn input(prompt: &str, value: &mut String) {
    print!("{}: ", prompt);

    value.clear();

    io::stdout().flush().unwrap();
    io::stdin().read_line(value).unwrap();

    *value = value.to_lowercase();
}

fn main() {
    let options: Vec<&str> = vec!["rock", "paper", "scissors", "quit"];
    println!("Enter \"quit\" or \"q\" to exit.");

    loop {
        let mut player: String = String::new();

        while player.len() == 0 {
            input("Rock (r), paper (p), scissors (s): ", &mut player);
            print!("\x1B[{}{}{}", "A", " ".repeat(player.len() + 35), "\r");

            if options.contains(&player.as_str()) {
                println!("{}", player);
            }
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.67.1 (d5a82bbd2 2023-02-07)
binary: rustc
commit-hash: d5a82bbd26e1ad8b7401f6a718a9c57c96905483
commit-date: 2023-02-07
host: x86_64-unknown-linux-gnu
release: 1.67.1
LLVM version: 15.0.6

Error output

   Compiling rock_paper_scissors v0.1.0 (/home/dragon/Development/Rust/rock_paper_scissors)
thread 'rustc' panicked at 'attempted to read from stolen value: rustc_middle::mir::Body', compiler/rustc_mir_transform/src/ffi_unwind_calls.rs:50:78
stack backtrace:
   0:     0x7fdd9e7656fa - std::backtrace_rs::backtrace::libunwind::trace::h79937bc171ada62c
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fdd9e7656fa - std::backtrace_rs::backtrace::trace_unsynchronized::h2292bca8571cb919
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fdd9e7656fa - std::sys_common::backtrace::_print_fmt::h9c461f248e4ae90d
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7fdd9e7656fa - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he9fe6bf1a39182e1
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fdd9e7c825e - core::fmt::write::h032658c119c720d7
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/fmt/mod.rs:1208:17
   5:     0x7fdd9e755a85 - std::io::Write::write_fmt::h299fc90dfae41c0d
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/io/mod.rs:1682:15
   6:     0x7fdd9e7654c5 - std::sys_common::backtrace::_print::heb70d25df9937e3f
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7fdd9e7654c5 - std::sys_common::backtrace::print::had745c0a76b8b521
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7fdd9e76820f - std::panicking::default_hook::{{closure}}::h1ea782cdfa2fd097
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:267:22
   9:     0x7fdd9e767f4b - std::panicking::default_hook::h1cc3af63455a163c
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:286:9
  10:     0x7fdda1a60ab1 - <rustc_driver[5c3b90d1fb3964ba]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[e6a29f2585b3d454]::ops::function::FnOnce<(&core[e6a29f2585b3d454]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7fdd9e768a4d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6e4950ba7c0fd82a
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/alloc/src/boxed.rs:2032:9
  12:     0x7fdd9e768a4d - std::panicking::rust_panic_with_hook::h5cafdc4b3bfd5528
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:692:13
  13:     0x7fdd9e7687c9 - std::panicking::begin_panic_handler::{{closure}}::hf31c60f40775892c
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:579:13
  14:     0x7fdd9e765bac - std::sys_common::backtrace::__rust_end_short_backtrace::h28a5c7be595826cd
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:137:18
  15:     0x7fdd9e7684d2 - rust_begin_unwind
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
  16:     0x7fdd9e7c4c43 - core::panicking::panic_fmt::h8fa27a0b37dd98b7
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
  17:     0x7fdd9ff5810f - rustc_mir_transform[6a2c2b2ce0179b78]::ffi_unwind_calls::has_ffi_unwind_calls
  18:     0x7fdda072966d - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::try_load_from_disk_and_cache_in_memory::<rustc_query_impl[e214cefb6de2a99d]::plumbing::QueryCtxt, rustc_span[41a321a6411ba4fa]::def_id::LocalDefId, bool>
  19:     0x7fdda07286da - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::try_execute_query::<rustc_query_impl[e214cefb6de2a99d]::plumbing::QueryCtxt, rustc_query_system[7dbbccfee5a2d054]::query::caches::VecCache<rustc_span[41a321a6411ba4fa]::def_id::LocalDefId, bool>>
  20:     0x7fdda072805c - <rustc_query_impl[e214cefb6de2a99d]::Queries as rustc_middle[83f907612b22699d]::ty::query::QueryEngine>::has_ffi_unwind_calls
  21:     0x7fdda0760b89 - <rustc_query_impl[e214cefb6de2a99d]::queries::has_ffi_unwind_calls as rustc_query_system[7dbbccfee5a2d054]::query::config::QueryConfig<rustc_query_impl[e214cefb6de2a99d]::plumbing::QueryCtxt>>::execute_query
  22:     0x7fdda1251d3e - <rustc_query_system[7dbbccfee5a2d054]::dep_graph::graph::DepGraph<rustc_middle[83f907612b22699d]::dep_graph::dep_node::DepKind>>::exec_cache_promotions::<rustc_middle[83f907612b22699d]::ty::context::TyCtxt>
  23:     0x7fdda1251b48 - <rustc_query_impl[e214cefb6de2a99d]::on_disk_cache::OnDiskCache as rustc_middle[83f907612b22699d]::ty::context::OnDiskCache>::drop_serialized_data
  24:     0x7fdda0c8711a - rustc_data_structures[1026114362f98086]::sync::join::<rustc_incremental[686a60493602ec2b]::persist::save::save_dep_graph::{closure#0}::{closure#2}, rustc_incremental[686a60493602ec2b]::persist::save::save_dep_graph::{closure#0}::{closure#3}, (), ()>
  25:     0x7fdda0c2204a - <rustc_middle[83f907612b22699d]::dep_graph::dep_node::DepKind as rustc_query_system[7dbbccfee5a2d054]::dep_graph::DepKind>::with_deps::<rustc_incremental[686a60493602ec2b]::persist::save::save_dep_graph::{closure#0}, ()>
  26:     0x7fdda0c21dea - <rustc_session[b89b9f24749004e7]::session::Session>::time::<(), <rustc_interface[65dcc5dffb099e04]::interface::Compiler>::enter<rustc_driver[5c3b90d1fb3964ba]::run_compiler::{closure#1}::{closure#2}, core[e6a29f2585b3d454]::result::Result<core[e6a29f2585b3d454]::option::Option<rustc_interface[65dcc5dffb099e04]::queries::Linker>, rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>>::{closure#0}>
  27:     0x7fdda0c208bc - <rustc_interface[65dcc5dffb099e04]::interface::Compiler>::enter::<rustc_driver[5c3b90d1fb3964ba]::run_compiler::{closure#1}::{closure#2}, core[e6a29f2585b3d454]::result::Result<core[e6a29f2585b3d454]::option::Option<rustc_interface[65dcc5dffb099e04]::queries::Linker>, rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>>
  28:     0x7fdda0c1b788 - rustc_span[41a321a6411ba4fa]::with_source_map::<core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>, rustc_interface[65dcc5dffb099e04]::interface::run_compiler<core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>, rustc_driver[5c3b90d1fb3964ba]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  29:     0x7fdda0c1b275 - <scoped_tls[393dd8f8fd825c8d]::ScopedKey<rustc_span[41a321a6411ba4fa]::SessionGlobals>>::set::<rustc_interface[65dcc5dffb099e04]::interface::run_compiler<core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>, rustc_driver[5c3b90d1fb3964ba]::run_compiler::{closure#1}>::{closure#0}, core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>>
  30:     0x7fdda0c1a862 - std[359ab902947f5f0b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[65dcc5dffb099e04]::util::run_in_thread_pool_with_globals<rustc_interface[65dcc5dffb099e04]::interface::run_compiler<core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>, rustc_driver[5c3b90d1fb3964ba]::run_compiler::{closure#1}>::{closure#0}, core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>>
  31:     0x7fdda1313b7a - <<std[359ab902947f5f0b]::thread::Builder>::spawn_unchecked_<rustc_interface[65dcc5dffb099e04]::util::run_in_thread_pool_with_globals<rustc_interface[65dcc5dffb099e04]::interface::run_compiler<core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>, rustc_driver[5c3b90d1fb3964ba]::run_compiler::{closure#1}>::{closure#0}, core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>>::{closure#1} as core[e6a29f2585b3d454]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7fdd9e772803 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb77d8d72ebcf79c4
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/alloc/src/boxed.rs:2000:9
  33:     0x7fdd9e772803 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc08c3353e1568487
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/alloc/src/boxed.rs:2000:9
  34:     0x7fdd9e772803 - std::sys::unix::thread::Thread::new::thread_start::h7168e596cd5e5ce6
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys/unix/thread.rs:108:17
  35:     0x7fdd9e4eabb5 - <unknown>
  36:     0x7fdd9e56cd90 - <unknown>
  37:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: 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: rustc 1.67.1 (d5a82bbd2 2023-02-07) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [has_ffi_unwind_calls] checking if `input` contains FFI-unwind calls
end of query stack
error: could not compile `rock_paper_scissors`
Backtrace

   Compiling rock_paper_scissors v0.1.0 (/home/dragon/Development/Rust/rock_paper_scissors)
thread 'rustc' panicked at 'attempted to read from stolen value: rustc_middle::mir::Body', compiler/rustc_mir_transform/src/ffi_unwind_calls.rs:50:78
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
   2: rustc_mir_transform::ffi_unwind_calls::has_ffi_unwind_calls
   3: rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory::<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::LocalDefId, bool>
   4: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, bool>>
   5: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::has_ffi_unwind_calls
   6: <rustc_query_impl::queries::has_ffi_unwind_calls as rustc_query_system::query::config::QueryConfig<rustc_query_impl::plumbing::QueryCtxt>>::execute_query
   7: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::exec_cache_promotions::<rustc_middle::ty::context::TyCtxt>
   8: <rustc_query_impl::on_disk_cache::OnDiskCache as rustc_middle::ty::context::OnDiskCache>::drop_serialized_data
   9: rustc_data_structures::sync::join::<rustc_incremental::persist::save::save_dep_graph::{closure#0}::{closure#2}, rustc_incremental::persist::save::save_dep_graph::{closure#0}::{closure#3}, (), ()>
  10: <rustc_middle::dep_graph::dep_node::DepKind as rustc_query_system::dep_graph::DepKind>::with_deps::<rustc_incremental::persist::save::save_dep_graph::{closure#0}, ()>
  11: <rustc_session::session::Session>::time::<(), <rustc_interface::interface::Compiler>::enter<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>::{closure#0}>
  12: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  13: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  14: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: 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: rustc 1.67.1 (d5a82bbd2 2023-02-07) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [has_ffi_unwind_calls] checking if `input` contains FFI-unwind calls
end of query stack
error: could not compile `rock_paper_scissors`

@Red-exe-Engineer Red-exe-Engineer 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 Mar 2, 2023
@clubby789
Copy link
Contributor

This might be an incremental bug. Try cargo clean then rebuilding.

@Red-exe-Engineer
Copy link
Author

```rust
use std::io;
use std::io::Write;

fn input(prompt: &str, value: &mut String) {
    print!("{}: ", prompt);

    value.clear();

    io::stdout().flush().unwrap();
    io::stdin().read_line(value).unwrap();

    *value = value.to_lowercase();
}

fn main() {
    let options: Vec<&str> = vec!["rock", "paper", "scissors", "quit"];
    println!("Enter \"quit\" or \"q\" to exit.");

    loop {
        let mut player: String = String::new();

        while player.len() == 0 {
            input("Rock (r), paper (p), scissors (s): ", &mut player);
            print!("\x1B[{}{}{}", "A", " ".repeat(player.len() + 35), "\r");

            if options.contains(&player.as_str()) {
                println!("{}", player);
            }
        }
    }
}

Actually, I got it working and now that I paste the old code it works... Rust just got a hole lot weirder.

@workingjubilee workingjubilee added the A-incr-comp Area: Incremental compilation label Mar 2, 2023
@workingjubilee
Copy link
Member

workingjubilee commented Mar 2, 2023

All compilers have "internal compiler errors" from time to time. These are errors due to input code that the compiler didn't expect and didn't have a more useful response prepared for. In Rust's case they're most often due to "incremental compilation", where you compile some code and the compiler writes some "intermediate artifacts" (files containing partially compiled code and some notes on what is in the files and where they came from) to your filesystem, so that when you next run the compiler, the previous result is reused. However, this requires us to correctly handle something that has dashed many a programmer upon its rocks:

Cache invalidation.

We could remove the incremental compilation features, and thus not produce these occasional errors, but last time we checked, while it would halve the time on some builds, most builds would be 5 times slower. As mentioned, cargo clean fixes most of them, but thank you for reporting!

@workingjubilee workingjubilee changed the title I'm new to Rust, how long might this take to get resolved? incr-comp: thread 'rustc' panicked at 'attempted to read from stolen value: rustc_middle::mir::Body' Mar 2, 2023
@cjgillot
Copy link
Contributor

Marking as fixed by #108820. Please open a new instance of this bug if it appears again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants