From ca64815c702162c7c36f165f07462ce32b14d68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 6 Mar 2025 09:16:24 +0000 Subject: [PATCH 1/2] Revert "rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync"" This reverts commit 8eba29ac1015e989e6ba96ff17a75d548afde7ff. --- compiler/rustc_middle/src/ty/context.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index d0aa2b8cbdad3..2d2bbd22b9842 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1327,6 +1327,9 @@ pub struct TyCtxt<'tcx> { gcx: &'tcx GlobalCtxt<'tcx>, } +// Explicitly implement `DynSync` and `DynSend` for `TyCtxt` to short circuit trait resolution. +unsafe impl DynSend for TyCtxt<'_> {} +unsafe impl DynSync for TyCtxt<'_> {} fn _assert_tcx_fields() { sync::assert_dyn_sync::<&'_ GlobalCtxt<'_>>(); sync::assert_dyn_send::<&'_ GlobalCtxt<'_>>(); From 7d6bbe2df788d9c23aef1384bc1c8b240253ae7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 6 Mar 2025 09:21:37 +0000 Subject: [PATCH 2/2] expand comments of `TyCtxt` impl of `DynSync`/`DynSend` so that it doesn't get removed again --- compiler/rustc_middle/src/ty/context.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 2d2bbd22b9842..4013f7b2c8548 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1327,7 +1327,9 @@ pub struct TyCtxt<'tcx> { gcx: &'tcx GlobalCtxt<'tcx>, } -// Explicitly implement `DynSync` and `DynSend` for `TyCtxt` to short circuit trait resolution. +// Explicitly implement `DynSync` and `DynSend` for `TyCtxt` to short circuit trait resolution. Its +// field are asserted to implement these traits below, so this is trivially safe, and it greatly +// speeds-up compilation of this crate and its dependents. unsafe impl DynSend for TyCtxt<'_> {} unsafe impl DynSync for TyCtxt<'_> {} fn _assert_tcx_fields() {