rustc_metadata: Privatize CrateMetadata::dep_kind

This commit is contained in:
Vadim Petrochenkov 2019-11-23 23:34:17 +03:00
parent 32aa58c96b
commit 765133ac2e
2 changed files with 12 additions and 6 deletions

View File

@ -50,7 +50,7 @@ fn dump_crates(cstore: &CStore) {
info!(" name: {}", data.root.name);
info!(" cnum: {}", cnum);
info!(" hash: {}", data.root.hash);
info!(" reqd: {:?}", *data.dep_kind.lock());
info!(" reqd: {:?}", data.dep_kind());
let CrateSource { dylib, rlib, rmeta } = data.source();
dylib.as_ref().map(|dl| info!(" dylib: {}", dl.0.display()));
rlib.as_ref().map(|rl| info!(" rlib: {}", rl.0.display()));
@ -353,9 +353,7 @@ fn maybe_resolve_crate<'b>(
if data.root.is_proc_macro_crate() {
dep_kind = DepKind::UnexportedMacrosOnly;
}
data.dep_kind.with_lock(|data_dep_kind| {
*data_dep_kind = cmp::max(*data_dep_kind, dep_kind);
});
data.update_dep_kind(|data_dep_kind| cmp::max(data_dep_kind, dep_kind));
Ok(cnum)
}
(LoadResult::Loaded(library), host_library) => {
@ -503,7 +501,7 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
// #![panic_runtime] crate.
self.inject_dependency_if(cnum, "a panic runtime",
&|data| data.root.needs_panic_runtime);
runtime_found = runtime_found || *data.dep_kind.lock() == DepKind::Explicit;
runtime_found = runtime_found || data.dep_kind() == DepKind::Explicit;
}
});

View File

@ -99,7 +99,7 @@
/// Same ID set as `cnum_map` plus maybe some injected crates like panic runtime.
dependencies: Lock<Vec<CrateNum>>,
/// How to link (or not link) this crate to the currently compiled crate.
crate dep_kind: Lock<DepKind>,
dep_kind: Lock<DepKind>,
/// Filesystem location of this crate.
source: CrateSource,
/// Whether or not this crate should be consider a private dependency
@ -1538,6 +1538,14 @@ fn get_crate_dep_node_index(&self, tcx: TyCtxt<'tcx>) -> DepNodeIndex {
crate fn source(&self) -> &CrateSource {
&self.source
}
crate fn dep_kind(&self) -> DepKind {
*self.dep_kind.lock()
}
crate fn update_dep_kind(&self, f: impl FnOnce(DepKind) -> DepKind) {
self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
}
}
// Cannot be implemented on 'ProcMacro', as libproc_macro