1
Fork 0

rustc_metadata: inherit dependency privacy flag

This commit is contained in:
Michael Howell 2023-05-01 11:51:00 -07:00
parent 64025bb168
commit e36020cdb3
5 changed files with 21 additions and 8 deletions

View file

@ -365,6 +365,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
lib: Library, lib: Library,
dep_kind: CrateDepKind, dep_kind: CrateDepKind,
name: Symbol, name: Symbol,
private_dep: bool,
) -> Result<CrateNum, CrateError> { ) -> Result<CrateNum, CrateError> {
let _prof_timer = self.sess.prof.generic_activity("metadata_register_crate"); let _prof_timer = self.sess.prof.generic_activity("metadata_register_crate");
@ -518,15 +519,16 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
if !name.as_str().is_ascii() { if !name.as_str().is_ascii() {
return Err(CrateError::NonAsciiName(name)); 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, dep)) => (
Some(root), Some(root),
Some(dep.hash), Some(dep.hash),
dep.host_hash, dep.host_hash,
Some(&dep.extra_filename[..]), Some(&dep.extra_filename[..]),
PathKind::Dependency, 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) { let result = if let Some(cnum) = self.existing_match(name, hash, path_kind) {
(LoadResult::Previous(cnum), None) (LoadResult::Previous(cnum), None)
@ -562,10 +564,11 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
dep_kind = CrateDepKind::MacrosOnly; dep_kind = CrateDepKind::MacrosOnly;
} }
data.update_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));
data.update_private_dep(|private_dep| private_dep && private_dep);
Ok(cnum) Ok(cnum)
} }
(LoadResult::Loaded(library), host_library) => { (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!(), _ => panic!(),
} }

View file

@ -113,7 +113,7 @@ pub(crate) struct CrateMetadata {
source: Lrc<CrateSource>, source: Lrc<CrateSource>,
/// Whether or not this crate should be consider a private dependency /// Whether or not this crate should be consider a private dependency
/// for purposes of the 'exported_private_dependencies' lint /// 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`. /// The hash for the host proc macro. Used to support `-Z dual-proc-macro`.
host_hash: Option<Svh>, host_hash: Option<Svh>,
@ -690,12 +690,13 @@ impl MetadataBlob {
writeln!(out, "=External Dependencies=")?; writeln!(out, "=External Dependencies=")?;
for (i, dep) in root.crate_deps.decode(self).enumerate() { 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; let number = i + 1;
writeln!( writeln!(
out, 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")?; write!(out, "\n")?;
@ -1617,7 +1618,7 @@ impl CrateMetadata {
dependencies, dependencies,
dep_kind: Lock::new(dep_kind), dep_kind: Lock::new(dep_kind),
source: Lrc::new(source), source: Lrc::new(source),
private_dep, private_dep: Lock::new(private_dep),
host_hash, host_hash,
extern_crate: Lock::new(None), extern_crate: Lock::new(None),
hygiene_context: Default::default(), hygiene_context: Default::default(),
@ -1665,6 +1666,10 @@ impl CrateMetadata {
self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind)) 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> { pub(crate) fn required_panic_strategy(&self) -> Option<PanicStrategy> {
self.root.required_panic_strategy self.root.required_panic_strategy
} }

View file

@ -285,7 +285,10 @@ provide! { tcx, def_id, other, cdata,
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) } is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) } 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_panic_runtime => { cdata.root.panic_runtime }
is_compiler_builtins => { cdata.root.compiler_builtins } is_compiler_builtins => { cdata.root.compiler_builtins }
has_global_allocator => { cdata.root.has_global_allocator } has_global_allocator => { cdata.root.has_global_allocator }

View file

@ -1880,6 +1880,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
host_hash: self.tcx.crate_host_hash(cnum), host_hash: self.tcx.crate_host_hash(cnum),
kind: self.tcx.dep_kind(cnum), kind: self.tcx.dep_kind(cnum),
extra_filename: self.tcx.extra_filename(cnum).clone(), extra_filename: self.tcx.extra_filename(cnum).clone(),
is_private: self.tcx.is_private_dep(cnum),
}; };
(cnum, dep) (cnum, dep)
}) })

View file

@ -302,6 +302,7 @@ pub(crate) struct CrateDep {
pub host_hash: Option<Svh>, pub host_hash: Option<Svh>,
pub kind: CrateDepKind, pub kind: CrateDepKind,
pub extra_filename: String, pub extra_filename: String,
pub is_private: bool,
} }
#[derive(MetadataEncodable, MetadataDecodable)] #[derive(MetadataEncodable, MetadataDecodable)]