@@ -58,7 +58,7 @@ use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
5858 StableVec } ;
5959use arena:: { TypedArena , SyncDroplessArena } ;
6060use rustc_data_structures:: indexed_vec:: IndexVec ;
61- use rustc_data_structures:: sync:: { Lrc , Lock } ;
61+ use rustc_data_structures:: sync:: { self , Lrc , Lock , WorkerLocal } ;
6262use std:: any:: Any ;
6363use std:: borrow:: Borrow ;
6464use std:: cmp:: Ordering ;
@@ -80,14 +80,14 @@ use syntax_pos::Span;
8080use hir;
8181
8282pub struct AllArenas < ' tcx > {
83- pub global : GlobalArenas < ' tcx > ,
83+ pub global : WorkerLocal < GlobalArenas < ' tcx > > ,
8484 pub interner : SyncDroplessArena ,
8585}
8686
8787impl < ' tcx > AllArenas < ' tcx > {
8888 pub fn new ( ) -> Self {
8989 AllArenas {
90- global : GlobalArenas :: new ( ) ,
90+ global : WorkerLocal :: new ( |_| GlobalArenas :: new ( ) ) ,
9191 interner : SyncDroplessArena :: new ( ) ,
9292 }
9393 }
@@ -854,7 +854,7 @@ impl<'a, 'gcx, 'tcx> Deref for TyCtxt<'a, 'gcx, 'tcx> {
854854}
855855
856856pub struct GlobalCtxt < ' tcx > {
857- global_arenas : & ' tcx GlobalArenas < ' tcx > ,
857+ global_arenas : & ' tcx WorkerLocal < GlobalArenas < ' tcx > > ,
858858 global_interners : CtxtInterners < ' tcx > ,
859859
860860 cstore : & ' tcx CrateStoreDyn ,
@@ -1179,6 +1179,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11791179 output_filenames : Arc :: new ( output_filenames. clone ( ) ) ,
11801180 } ;
11811181
1182+ sync:: assert_send_val ( & gcx) ;
1183+
11821184 tls:: enter_global ( gcx, f)
11831185 }
11841186
@@ -1704,7 +1706,7 @@ pub mod tls {
17041706 use ty:: maps;
17051707 use errors:: { Diagnostic , TRACK_DIAGNOSTICS } ;
17061708 use rustc_data_structures:: OnDrop ;
1707- use rustc_data_structures:: sync:: Lrc ;
1709+ use rustc_data_structures:: sync:: { self , Lrc } ;
17081710 use dep_graph:: OpenTask ;
17091711
17101712 /// This is the implicit state of rustc. It contains the current
@@ -1832,6 +1834,10 @@ pub mod tls {
18321834 if context == 0 {
18331835 f ( None )
18341836 } else {
1837+ // We could get a ImplicitCtxt pointer from another thread.
1838+ // Ensure that ImplicitCtxt is Sync
1839+ sync:: assert_sync :: < ImplicitCtxt > ( ) ;
1840+
18351841 unsafe { f ( Some ( & * ( context as * const ImplicitCtxt ) ) ) }
18361842 }
18371843 }
0 commit comments