Skip to content

Commit c30186c

Browse files
committed
Double check that the deadlock handler doesn't get overwritten
1 parent e2bee64 commit c30186c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

compiler/rustc_interface/src/interface.rs

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ pub struct Compiler {
4343
pub compiler_for_deadlock_handler: Arc<AtomicPtr<()>>,
4444
}
4545

46+
impl !Sync for Compiler {}
47+
impl !rustc_data_structures::sync::DynSync for Compiler {}
48+
4649
/// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`.
4750
pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec<String>) -> Cfg {
4851
cfgs.into_iter()

compiler/rustc_interface/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(let_chains)]
55
#![feature(thread_spawn_unchecked)]
66
#![feature(try_blocks)]
7+
#![feature(negative_impls)]
78

89
#[macro_use]
910
extern crate tracing;

compiler/rustc_interface/src/queries.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ impl<'tcx> Queries<'tcx> {
161161
&self.hir_arena,
162162
);
163163

164-
self.compiler
164+
let old = self
165+
.compiler
165166
.compiler_for_deadlock_handler
166-
.store(qcx as *const _ as *mut _, Ordering::Relaxed);
167+
.swap(qcx as *const _ as *mut _, Ordering::Relaxed);
168+
assert!(old.is_null());
167169

168170
qcx.enter(|tcx| {
169171
let feed = tcx.feed_local_crate();
@@ -321,6 +323,7 @@ impl Compiler {
321323
// is accessing the `GlobalCtxt`.
322324
self.compiler_for_deadlock_handler.store(std::ptr::null_mut(), Ordering::Relaxed);
323325
});
326+
assert!(self.compiler_for_deadlock_handler.load(Ordering::Relaxed).is_null());
324327
let queries = Queries::new(self);
325328
let ret = f(&queries);
326329

0 commit comments

Comments
 (0)