Skip to content

Commit

Permalink
rustc_metadata: inherit dependency privacy flag
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed May 25, 2023
1 parent 64025bb commit e36020c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
9 changes: 6 additions & 3 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
lib: Library,
dep_kind: CrateDepKind,
name: Symbol,
private_dep: bool,
) -> Result<CrateNum, CrateError> {
let _prof_timer = self.sess.prof.generic_activity("metadata_register_crate");

Expand Down Expand Up @@ -518,15 +519,16 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
if !name.as_str().is_ascii() {
return Err(CrateError::NonAsciiName(name));
}
let (root, hash, host_hash, extra_filename, path_kind) = match dep {
let (root, hash, host_hash, extra_filename, path_kind, private_dep) = match dep {
Some((root, dep)) => (
Some(root),
Some(dep.hash),
dep.host_hash,
Some(&dep.extra_filename[..]),
PathKind::Dependency,
dep.is_private,
),
None => (None, None, None, None, PathKind::Crate),
None => (None, None, None, None, PathKind::Crate, false),
};
let result = if let Some(cnum) = self.existing_match(name, hash, path_kind) {
(LoadResult::Previous(cnum), None)
Expand Down Expand Up @@ -562,10 +564,11 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
dep_kind = CrateDepKind::MacrosOnly;
}
data.update_dep_kind(|data_dep_kind| cmp::max(data_dep_kind, dep_kind));
data.update_private_dep(|private_dep| private_dep && private_dep);
Ok(cnum)
}
(LoadResult::Loaded(library), host_library) => {
self.register_crate(host_library, root, library, dep_kind, name)
self.register_crate(host_library, root, library, dep_kind, name, private_dep)
}
_ => panic!(),
}
Expand Down
13 changes: 9 additions & 4 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub(crate) struct CrateMetadata {
source: Lrc<CrateSource>,
/// Whether or not this crate should be consider a private dependency
/// for purposes of the 'exported_private_dependencies' lint
private_dep: bool,
private_dep: Lock<bool>,
/// The hash for the host proc macro. Used to support `-Z dual-proc-macro`.
host_hash: Option<Svh>,

Expand Down Expand Up @@ -690,12 +690,13 @@ impl MetadataBlob {
writeln!(out, "=External Dependencies=")?;

for (i, dep) in root.crate_deps.decode(self).enumerate() {
let CrateDep { name, extra_filename, hash, host_hash, kind } = dep;
let CrateDep { name, extra_filename, hash, host_hash, kind, is_private } = dep;
let number = i + 1;

writeln!(
out,
"{number} {name}{extra_filename} hash {hash} host_hash {host_hash:?} kind {kind:?}"
"{number} {name}{extra_filename} hash {hash} host_hash {host_hash:?} kind {kind:?} {privacy}",
privacy = if is_private { "private" } else { "public" }
)?;
}
write!(out, "\n")?;
Expand Down Expand Up @@ -1617,7 +1618,7 @@ impl CrateMetadata {
dependencies,
dep_kind: Lock::new(dep_kind),
source: Lrc::new(source),
private_dep,
private_dep: Lock::new(private_dep),
host_hash,
extern_crate: Lock::new(None),
hygiene_context: Default::default(),
Expand Down Expand Up @@ -1665,6 +1666,10 @@ impl CrateMetadata {
self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
}

pub(crate) fn update_private_dep(&self, f: impl FnOnce(bool) -> bool) {
self.private_dep.with_lock(|private_dep| *private_dep = f(*private_dep))
}

pub(crate) fn required_panic_strategy(&self) -> Option<PanicStrategy> {
self.root.required_panic_strategy
}
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ provide! { tcx, def_id, other, cdata,
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }

dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
is_private_dep => { cdata.private_dep }
is_private_dep => {
let r = *cdata.private_dep.lock();
r
}
is_panic_runtime => { cdata.root.panic_runtime }
is_compiler_builtins => { cdata.root.compiler_builtins }
has_global_allocator => { cdata.root.has_global_allocator }
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
host_hash: self.tcx.crate_host_hash(cnum),
kind: self.tcx.dep_kind(cnum),
extra_filename: self.tcx.extra_filename(cnum).clone(),
is_private: self.tcx.is_private_dep(cnum),
};
(cnum, dep)
})
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ pub(crate) struct CrateDep {
pub host_hash: Option<Svh>,
pub kind: CrateDepKind,
pub extra_filename: String,
pub is_private: bool,
}

#[derive(MetadataEncodable, MetadataDecodable)]
Expand Down

0 comments on commit e36020c

Please sign in to comment.