Skip to content

Commit 1d3799e

Browse files
committed
rustc_metadata: use AtomicBool for privateness instead of Lock
1 parent 827a181 commit 1d3799e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use proc_macro::bridge::client::ProcMacro;
3838
use std::iter::TrustedLen;
3939
use std::num::NonZeroUsize;
4040
use std::path::Path;
41+
use std::sync::atomic::{AtomicBool, Ordering};
4142
use std::{io, iter, mem};
4243

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

@@ -1612,7 +1613,7 @@ impl CrateMetadata {
16121613
dependencies,
16131614
dep_kind: Lock::new(dep_kind),
16141615
source: Lrc::new(source),
1615-
private_dep: Lock::new(private_dep),
1616+
private_dep: AtomicBool::new(private_dep),
16161617
host_hash,
16171618
extern_crate: Lock::new(None),
16181619
hygiene_context: Default::default(),
@@ -1660,8 +1661,11 @@ impl CrateMetadata {
16601661
self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
16611662
}
16621663

1663-
pub(crate) fn update_private_dep(&self, f: impl FnOnce(bool) -> bool) {
1664-
self.private_dep.with_lock(|private_dep| *private_dep = f(*private_dep))
1664+
/// `f` must not perform any I/O or take any locks. It may be called more than once.
1665+
pub(crate) fn update_private_dep(&self, mut f: impl FnMut(bool) -> bool) {
1666+
self.private_dep
1667+
.fetch_update(Ordering::Release, Ordering::Acquire, |private_dep| Some(f(private_dep)))
1668+
.expect("fetch_update only returns Err if `f` returns None`, which it doesn't");
16651669
}
16661670

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

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,11 @@ provide! { tcx, def_id, other, cdata,
287287

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

0 commit comments

Comments
 (0)