Skip to content

Remove deadlock detection for benchmarking #142247

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3167,8 +3167,7 @@ dependencies = [
[[package]]
name = "rustc-rayon-core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f42932dcd3bcbe484b38a3ccf79b7906fac41c02d408b5b1bac26da3416efdb"
source = "git+https://github.com/zetanumbers/rayon?branch=rustc-remove-deadlock-detection#3b8d9c138ab70138c2016d19fbb2801a372614f6"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
Expand Down Expand Up @@ -4330,7 +4329,6 @@ version = "0.0.0"
dependencies = [
"hashbrown",
"parking_lot",
"rustc-rayon-core",
"rustc_abi",
"rustc_ast",
"rustc_attr_data_structures",
Expand Down Expand Up @@ -6584,3 +6582,8 @@ dependencies = [
"quote",
"syn 2.0.101",
]

[[patch.unused]]
name = "rustc-rayon"
version = "0.5.1"
source = "git+https://github.com/zetanumbers/rayon?branch=rustc-remove-deadlock-detection#3b8d9c138ab70138c2016d19fbb2801a372614f6"
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ exclude = [
"obj",
]

[patch.crates-io]
rustc-rayon = { git = "https://github.com/zetanumbers/rayon", branch = "rustc-remove-deadlock-detection" }
rustc-rayon-core = { git = "https://github.com/zetanumbers/rayon", branch = "rustc-remove-deadlock-detection" }

[profile.release.package.rustc-rayon-core]
# The rustc fork of Rayon has deadlock detection code which intermittently
# causes overflows in the CI (see https://github.com/rust-lang/rust/issues/90227)
Expand Down
49 changes: 1 addition & 48 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_session::{EarlyDiagCtxt, Session, filesearch};
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::edition::Edition;
use rustc_span::source_map::SourceMapInputs;
use rustc_span::{SessionGlobals, Symbol, sym};
use rustc_span::{Symbol, sym};
use rustc_target::spec::Target;
use tracing::info;

Expand Down Expand Up @@ -175,13 +175,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
sm_inputs: SourceMapInputs,
f: F,
) -> R {
use std::process;

use rustc_data_structures::defer;
use rustc_data_structures::sync::FromDyn;
use rustc_middle::ty::tls;
use rustc_query_impl::QueryCtxt;
use rustc_query_system::query::{QueryContext, break_query_cycles};

let thread_stack_size = init_stack_size(thread_builder_diag);

Expand All @@ -203,7 +197,6 @@ pub(crate) fn run_in_thread_pool_with_globals<
}

let current_gcx = FromDyn::from(CurrentGcx::new());
let current_gcx2 = current_gcx.clone();

let proxy = Proxy::new();

Expand All @@ -214,46 +207,6 @@ pub(crate) fn run_in_thread_pool_with_globals<
.acquire_thread_handler(move || proxy_.acquire_thread())
.release_thread_handler(move || proxy__.release_thread())
.num_threads(threads)
.deadlock_handler(move || {
// On deadlock, creates a new thread and forwards information in thread
// locals to it. The new thread runs the deadlock handler.

let current_gcx2 = current_gcx2.clone();
let registry = rayon_core::Registry::current();
let session_globals = rustc_span::with_session_globals(|session_globals| {
session_globals as *const SessionGlobals as usize
});
thread::Builder::new()
.name("rustc query cycle handler".to_string())
.spawn(move || {
let on_panic = defer(|| {
eprintln!("internal compiler error: query cycle handler thread panicked, aborting process");
// We need to abort here as we failed to resolve the deadlock,
// otherwise the compiler could just hang,
process::abort();
});

// Get a `GlobalCtxt` reference from `CurrentGcx` as we cannot rely on having a
// `TyCtxt` TLS reference here.
current_gcx2.access(|gcx| {
tls::enter_context(&tls::ImplicitCtxt::new(gcx), || {
tls::with(|tcx| {
// Accessing session globals is sound as they outlive `GlobalCtxt`.
// They are needed to hash query keys containing spans or symbols.
let query_map = rustc_span::set_session_globals_then(unsafe { &*(session_globals as *const SessionGlobals) }, || {
// Ensure there was no errors collecting all active jobs.
// We need the complete map to ensure we find a cycle to break.
QueryCtxt::new(tcx).collect_active_jobs().ok().expect("failed to collect active queries in deadlock handler")
});
break_query_cycles(query_map, &registry);
})
})
});

on_panic.disable();
})
.unwrap();
})
.stack_size(thread_stack_size);

// We create the session globals on the main thread, then create the thread
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_query_system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2024"
[dependencies]
# tidy-alphabetical-start
parking_lot = "0.12"
rustc-rayon-core = { version = "0.5.0" }
rustc_abi = { path = "../rustc_abi" }
rustc_ast = { path = "../rustc_ast" }
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
Expand Down
Loading
Loading