@@ -1349,6 +1349,33 @@ pub struct GlobalCtxt<'tcx> {
1349
1349
1350
1350
/// Stores memory for globals (statics/consts).
1351
1351
pub ( crate ) alloc_map : Lock < interpret:: AllocMap < ' tcx > > ,
1352
+
1353
+ current_gcx : CurrentGcx ,
1354
+ }
1355
+
1356
+ impl < ' tcx > GlobalCtxt < ' tcx > {
1357
+ /// Installs `self` in a `TyCtxt` and `ImplicitCtxt` for the duration of
1358
+ /// `f`.
1359
+ pub fn enter < F , R > ( & ' tcx self , f : F ) -> R
1360
+ where
1361
+ F : FnOnce ( TyCtxt < ' tcx > ) -> R ,
1362
+ {
1363
+ let icx = tls:: ImplicitCtxt :: new ( self ) ;
1364
+
1365
+ // Reset `current_gcx` to `None` when we exit.
1366
+ let _on_drop = defer ( move || {
1367
+ * self . current_gcx . value . write ( ) = None ;
1368
+ } ) ;
1369
+
1370
+ // Set this `GlobalCtxt` as the current one.
1371
+ {
1372
+ let mut guard = self . current_gcx . value . write ( ) ;
1373
+ assert ! ( guard. is_none( ) , "no `GlobalCtxt` is currently set" ) ;
1374
+ * guard = Some ( self as * const _ as * const ( ) ) ;
1375
+ }
1376
+
1377
+ tls:: enter_context ( & icx, || f ( icx. tcx ) )
1378
+ }
1352
1379
}
1353
1380
1354
1381
/// This is used to get a reference to a `GlobalCtxt` if one is available.
@@ -1539,23 +1566,11 @@ impl<'tcx> TyCtxt<'tcx> {
1539
1566
canonical_param_env_cache : Default :: default ( ) ,
1540
1567
data_layout,
1541
1568
alloc_map : Lock :: new ( interpret:: AllocMap :: new ( ) ) ,
1569
+ current_gcx,
1542
1570
} ) ;
1543
1571
1544
- let icx = tls:: ImplicitCtxt :: new ( & gcx) ;
1545
-
1546
- // Reset `current_gcx` to `None` when we exit.
1547
- let _on_drop = defer ( || {
1548
- * current_gcx. value . write ( ) = None ;
1549
- } ) ;
1550
-
1551
- // Set this `GlobalCtxt` as the current one.
1552
- {
1553
- let mut guard = current_gcx. value . write ( ) ;
1554
- assert ! ( guard. is_none( ) , "no `GlobalCtxt` is currently set" ) ;
1555
- * guard = Some ( & gcx as * const _ as * const ( ) ) ;
1556
- }
1557
-
1558
- tls:: enter_context ( & icx, || f ( icx. tcx ) )
1572
+ // This is a separate function to work around a crash with parallel rustc (#135870)
1573
+ gcx. enter ( f)
1559
1574
}
1560
1575
1561
1576
/// Obtain all lang items of this crate and all dependencies (recursively)
0 commit comments