Skip to content

Commit 9ea6a18

Browse files
committed
Auto merge of #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 ec1f21c + 54492fe commit 9ea6a18

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ 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+
#[cfg(parallel_compiler)]
43+
use rustc_data_structures::sync::{self, DynSend, DynSync};
4244
use rustc_data_structures::sync::{FreezeReadGuard, Lock, WorkerLocal};
4345
use rustc_data_structures::unord::UnordSet;
4446
use rustc_errors::{
@@ -552,6 +554,16 @@ pub struct TyCtxt<'tcx> {
552554
gcx: &'tcx GlobalCtxt<'tcx>,
553555
}
554556

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

0 commit comments

Comments
 (0)