Skip to content

Commit bc0170a

Browse files
committed
Add a workaround for parallel rustc crashing when there are delayed bugs
This doesn't fix the root cause of this crash, but at least stops it from happening for the time being.
1 parent 48ef38d commit bc0170a

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,33 @@ pub struct GlobalCtxt<'tcx> {
13491349

13501350
/// Stores memory for globals (statics/consts).
13511351
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+
}
13521379
}
13531380

13541381
/// This is used to get a reference to a `GlobalCtxt` if one is available.
@@ -1539,23 +1566,11 @@ impl<'tcx> TyCtxt<'tcx> {
15391566
canonical_param_env_cache: Default::default(),
15401567
data_layout,
15411568
alloc_map: Lock::new(interpret::AllocMap::new()),
1569+
current_gcx,
15421570
});
15431571

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)
15591574
}
15601575

15611576
/// Obtain all lang items of this crate and all dependencies (recursively)

0 commit comments

Comments
 (0)