Skip to content

Commit 5a7fffe

Browse files
committed
rustc_metadata: use AtomicBool for privateness instead of Lock
1 parent d47dc32 commit 5a7fffe

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use proc_macro::bridge::client::ProcMacro;
4040
use std::iter::TrustedLen;
4141
use std::num::NonZeroUsize;
4242
use std::path::Path;
43+
use std::sync::atomic::{AtomicBool, Ordering};
4344
use std::{io, iter, mem};
4445

4546
pub(super) use cstore_impl::provide;
@@ -114,7 +115,7 @@ pub(crate) struct CrateMetadata {
114115
/// Whether or not this crate should be consider a private dependency.
115116
/// Used by the 'exported_private_dependencies' lint, and for determining
116117
/// whether to emit suggestions that reference this crate.
117-
private_dep: Lock<bool>,
118+
private_dep: AtomicBool,
118119
/// The hash for the host proc macro. Used to support `-Z dual-proc-macro`.
119120
host_hash: Option<Svh>,
120121

@@ -1619,7 +1620,7 @@ impl CrateMetadata {
16191620
dependencies,
16201621
dep_kind: Lock::new(dep_kind),
16211622
source: Lrc::new(source),
1622-
private_dep: Lock::new(private_dep),
1623+
private_dep: AtomicBool::new(private_dep),
16231624
host_hash,
16241625
extern_crate: Lock::new(None),
16251626
hygiene_context: Default::default(),
@@ -1667,8 +1668,11 @@ impl CrateMetadata {
16671668
self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
16681669
}
16691670

1670-
pub(crate) fn update_private_dep(&self, f: impl FnOnce(bool) -> bool) {
1671-
self.private_dep.with_lock(|private_dep| *private_dep = f(*private_dep))
1671+
/// `f` must not perform any I/O or take any locks. It may be called more than once.
1672+
pub(crate) fn update_private_dep(&self, mut f: impl FnMut(bool) -> bool) {
1673+
self.private_dep
1674+
.fetch_update(Ordering::Release, Ordering::Acquire, |private_dep| Some(f(private_dep)))
1675+
.expect("fetch_update only returns Err if `f` returns None`, which it doesn't");
16721676
}
16731677

16741678
pub(crate) fn required_panic_strategy(&self) -> Option<PanicStrategy> {

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,11 @@ provide! { tcx, def_id, other, cdata,
286286

287287
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
288288
is_private_dep => {
289-
let r = *cdata.private_dep.lock();
290-
r
289+
// Parallel compiler needs to synchronize type checking and linting (which use this flag)
290+
// so that they happen strictly crate loading. Otherwise, the full list of available
291+
// impls aren't loaded yet.
292+
use std::sync::atomic::Ordering;
293+
cdata.private_dep.load(Ordering::Acquire)
291294
}
292295
is_panic_runtime => { cdata.root.panic_runtime }
293296
is_compiler_builtins => { cdata.root.compiler_builtins }

0 commit comments

Comments
 (0)