Skip to content

Commit 2d2f1b2

Browse files
committed
Auto merge of rust-lang#117681 - Zoxc:tcx-sync, r=compiler-errors
Explicitly implement `DynSync` and `DynSend` for `TyCtxt` This is an attempt to short circuit trait resolution. It should get a perf run for bootstrap impact.
2 parents f967532 + 365aaa8 commit 2d2f1b2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

compiler/rustc_middle/src/ty/context.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ use rustc_data_structures::profiling::SelfProfilerRef;
3939
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
4040
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4141
use rustc_data_structures::steal::Steal;
42-
use rustc_data_structures::sync::{FreezeReadGuard, Lock, WorkerLocal};
42+
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, WorkerLocal};
43+
#[cfg(parallel_compiler)]
44+
use rustc_data_structures::sync::{DynSend, DynSync};
4345
use rustc_data_structures::unord::UnordSet;
4446
use rustc_errors::{
4547
DecorateLint, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
@@ -553,6 +555,16 @@ pub struct TyCtxt<'tcx> {
553555
gcx: &'tcx GlobalCtxt<'tcx>,
554556
}
555557

558+
// Explicitly implement `DynSync` and `DynSend` for `TyCtxt` to short circuit trait resolution.
559+
#[cfg(parallel_compiler)]
560+
unsafe impl DynSend for TyCtxt<'_> {}
561+
#[cfg(parallel_compiler)]
562+
unsafe impl DynSync for TyCtxt<'_> {}
563+
fn _assert_tcx_fields() {
564+
sync::assert_dyn_sync::<&'_ GlobalCtxt<'_>>();
565+
sync::assert_dyn_send::<&'_ GlobalCtxt<'_>>();
566+
}
567+
556568
impl<'tcx> Deref for TyCtxt<'tcx> {
557569
type Target = &'tcx GlobalCtxt<'tcx>;
558570
#[inline(always)]

0 commit comments

Comments
 (0)