Rollup merge of #153776 - zetanumbers:curry-howard-dyn-thread-safe, r=JonathanBrouwer

Remove redundant `is_dyn_thread_safe` checks

Refactor uses of `FromDyn` to reduce number of redundant `is_dyn_thread_safe` checks by replacing `FromDyn::from` with `check_dyn_thread_safe` in tandem with existing `FromDyn::derive` so that the users would avoid redundancy in the future.

PR is split up into multiple commits for an easier review.
This commit is contained in:
Jonathan Brouwer
2026-03-20 13:24:24 +01:00
committed by GitHub
4 changed files with 90 additions and 79 deletions
+4 -5
View File
@@ -183,7 +183,6 @@ pub(crate) fn run_in_thread_pool_with_globals<
use std::process;
use rustc_data_structures::defer;
use rustc_data_structures::sync::FromDyn;
use rustc_middle::ty::tls;
use rustc_query_impl::break_query_cycles;
@@ -191,7 +190,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
let registry = sync::Registry::new(std::num::NonZero::new(threads).unwrap());
if !sync::is_dyn_thread_safe() {
let Some(proof) = sync::check_dyn_thread_safe() else {
return run_in_thread_with_globals(
thread_stack_size,
edition,
@@ -204,9 +203,9 @@ pub(crate) fn run_in_thread_pool_with_globals<
f(current_gcx, jobserver_proxy)
},
);
}
};
let current_gcx = FromDyn::from(CurrentGcx::new());
let current_gcx = proof.derive(CurrentGcx::new());
let current_gcx2 = current_gcx.clone();
let proxy = Proxy::new();
@@ -278,7 +277,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
// `Send` in the parallel compiler.
rustc_span::create_session_globals_then(edition, extra_symbols, Some(sm_inputs), || {
rustc_span::with_session_globals(|session_globals| {
let session_globals = FromDyn::from(session_globals);
let session_globals = proof.derive(session_globals);
builder
.build_scoped(
// Initialize each new worker thread when created.