Skip to content

Commit

Permalink
Auto merge of #117681 - Zoxc:tcx-sync, r=compiler-errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Dec 8, 2023
2 parents f967532 + 365aaa8 commit 2d2f1b2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{FreezeReadGuard, Lock, WorkerLocal};
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, WorkerLocal};
#[cfg(parallel_compiler)]
use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_data_structures::unord::UnordSet;
use rustc_errors::{
DecorateLint, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
Expand Down Expand Up @@ -553,6 +555,16 @@ pub struct TyCtxt<'tcx> {
gcx: &'tcx GlobalCtxt<'tcx>,
}

// Explicitly implement `DynSync` and `DynSend` for `TyCtxt` to short circuit trait resolution.
#[cfg(parallel_compiler)]
unsafe impl DynSend for TyCtxt<'_> {}
#[cfg(parallel_compiler)]
unsafe impl DynSync for TyCtxt<'_> {}
fn _assert_tcx_fields() {
sync::assert_dyn_sync::<&'_ GlobalCtxt<'_>>();
sync::assert_dyn_send::<&'_ GlobalCtxt<'_>>();
}

impl<'tcx> Deref for TyCtxt<'tcx> {
type Target = &'tcx GlobalCtxt<'tcx>;
#[inline(always)]
Expand Down

0 comments on commit 2d2f1b2

Please sign in to comment.