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.
This commit is contained in:
parent
48ef38d350
commit
bc0170a43b
1 changed files with 30 additions and 15 deletions
|
@ -1349,6 +1349,33 @@ pub struct GlobalCtxt<'tcx> {
|
||||||
|
|
||||||
/// Stores memory for globals (statics/consts).
|
/// Stores memory for globals (statics/consts).
|
||||||
pub(crate) alloc_map: Lock<interpret::AllocMap<'tcx>>,
|
pub(crate) alloc_map: Lock<interpret::AllocMap<'tcx>>,
|
||||||
|
|
||||||
|
current_gcx: CurrentGcx,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> GlobalCtxt<'tcx> {
|
||||||
|
/// Installs `self` in a `TyCtxt` and `ImplicitCtxt` for the duration of
|
||||||
|
/// `f`.
|
||||||
|
pub fn enter<F, R>(&'tcx self, f: F) -> R
|
||||||
|
where
|
||||||
|
F: FnOnce(TyCtxt<'tcx>) -> R,
|
||||||
|
{
|
||||||
|
let icx = tls::ImplicitCtxt::new(self);
|
||||||
|
|
||||||
|
// Reset `current_gcx` to `None` when we exit.
|
||||||
|
let _on_drop = defer(move || {
|
||||||
|
*self.current_gcx.value.write() = None;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set this `GlobalCtxt` as the current one.
|
||||||
|
{
|
||||||
|
let mut guard = self.current_gcx.value.write();
|
||||||
|
assert!(guard.is_none(), "no `GlobalCtxt` is currently set");
|
||||||
|
*guard = Some(self as *const _ as *const ());
|
||||||
|
}
|
||||||
|
|
||||||
|
tls::enter_context(&icx, || f(icx.tcx))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is used to get a reference to a `GlobalCtxt` if one is available.
|
/// This is used to get a reference to a `GlobalCtxt` if one is available.
|
||||||
|
@ -1539,23 +1566,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
canonical_param_env_cache: Default::default(),
|
canonical_param_env_cache: Default::default(),
|
||||||
data_layout,
|
data_layout,
|
||||||
alloc_map: Lock::new(interpret::AllocMap::new()),
|
alloc_map: Lock::new(interpret::AllocMap::new()),
|
||||||
|
current_gcx,
|
||||||
});
|
});
|
||||||
|
|
||||||
let icx = tls::ImplicitCtxt::new(&gcx);
|
// This is a separate function to work around a crash with parallel rustc (#135870)
|
||||||
|
gcx.enter(f)
|
||||||
// Reset `current_gcx` to `None` when we exit.
|
|
||||||
let _on_drop = defer(|| {
|
|
||||||
*current_gcx.value.write() = None;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set this `GlobalCtxt` as the current one.
|
|
||||||
{
|
|
||||||
let mut guard = current_gcx.value.write();
|
|
||||||
assert!(guard.is_none(), "no `GlobalCtxt` is currently set");
|
|
||||||
*guard = Some(&gcx as *const _ as *const ());
|
|
||||||
}
|
|
||||||
|
|
||||||
tls::enter_context(&icx, || f(icx.tcx))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtain all lang items of this crate and all dependencies (recursively)
|
/// Obtain all lang items of this crate and all dependencies (recursively)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue