Skip to content

Commit

Permalink
debug creader
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 28, 2025
1 parent 3c5534f commit ee49697
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
20 changes: 12 additions & 8 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl<'a> std::fmt::Debug for CrateDump<'a> {
writeln!(fmt, " cnum: {cnum}")?;
writeln!(fmt, " hash: {}", data.hash())?;
writeln!(fmt, " reqd: {:?}", data.dep_kind())?;
writeln!(fmt, " priv: {:?}", data.private_dep())?;
let CrateSource { dylib, rlib, rmeta } = data.source();
if let Some(dylib) = dylib {
writeln!(fmt, " dylib: {}", dylib.0.display())?;
Expand Down Expand Up @@ -402,6 +403,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
/// command parameter is set to `public-dependency`
fn is_private_dep(&self, name: Symbol, private_dep: Option<bool>) -> bool {
let extern_private = self.sess.opts.externs.get(name.as_str()).map(|e| e.is_private_dep);
debug!("name: {name}, private: {private_dep:?}, extern private: {extern_private:?}");
match (extern_private, private_dep) {
// Explicit non-private via `--extern`, explicit non-private from metadata, or
// unspecified with default to public.
Expand Down Expand Up @@ -433,10 +435,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
let cnum = feed.key();

info!(
"register crate `{}` (cnum = {}. private_dep = {})",
"register crate `{}` (cnum = {cnum}. private_dep = {private_dep})",
crate_root.name(),
cnum,
private_dep
);

// Maintain a reference to the top most crate.
Expand Down Expand Up @@ -573,11 +573,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
mut dep_kind: CrateDepKind,
dep_of: Option<(&'b CratePaths, &'b CrateDep)>,
) -> Result<CrateNum, CrateError> {
info!("resolving crate `{}`", name);
if !name.as_str().is_ascii() {
return Err(CrateError::NonAsciiName(name));
}

let dep_root = dep_of.map(|d| d.0);
let dep = dep_of.map(|d| d.1);
let hash = dep.map(|d| d.hash);
Expand All @@ -586,6 +581,15 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
let path_kind = if dep.is_some() { PathKind::Dependency } else { PathKind::Crate };
let private_dep = dep.map(|d| d.is_private);

info!(
"resolving crate `{}`, dep of {:?} private {private_dep:?}",
name,
dep_root.map(|d| d.name)
);
if !name.as_str().is_ascii() {
return Err(CrateError::NonAsciiName(name));
}

let result = if let Some(cnum) = self.existing_match(name, hash, path_kind) {
(LoadResult::Previous(cnum), None)
} else {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,10 @@ impl CrateMetadata {
self.root.header.hash
}

pub(crate) fn private_dep(&self) -> bool {
self.private_dep
}

fn num_def_ids(&self) -> usize {
self.root.tables.def_keys.size()
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
}

ItemKind::ExternCrate(orig_name) => {
tracing::info!(
"extern crate {:?}",
(&orig_name, &item, &local_def_id, &vis, &parent)
);
self.build_reduced_graph_for_extern_crate(
orig_name,
item,
Expand Down

0 comments on commit ee49697

Please sign in to comment.