Skip to content

Commit 7b30550

Browse files
committed
Support listing all items in -Zls
1 parent ff00763 commit 7b30550

File tree

1 file changed

+80
-10
lines changed

1 file changed

+80
-10
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,13 @@ impl MetadataBlob {
732732
) -> io::Result<()> {
733733
let root = self.get_root();
734734

735-
let all_ls_kinds = vec!["root".to_owned(), "lang_items".to_owned(), "features".to_owned()];
736-
let ls_kinds = if ls_kinds.contains(&"all".to_owned()) {
737-
&all_ls_kinds
738-
} else {
739-
ls_kinds
740-
};
735+
let all_ls_kinds = vec![
736+
"root".to_owned(),
737+
"lang_items".to_owned(),
738+
"features".to_owned(),
739+
"items".to_owned(),
740+
];
741+
let ls_kinds = if ls_kinds.contains(&"all".to_owned()) { &all_ls_kinds } else { ls_kinds };
741742

742743
for kind in ls_kinds {
743744
match &**kind {
@@ -778,7 +779,7 @@ impl MetadataBlob {
778779
root.profiler_runtime
779780
)?;
780781

781-
writeln!(out, "\n=External Dependencies=")?;
782+
writeln!(out, "=External Dependencies=")?;
782783
let dylib_dependency_formats =
783784
root.dylib_dependency_formats.decode(self).collect::<Vec<_>>();
784785
for (i, dep) in root.crate_deps.decode(self).enumerate() {
@@ -801,7 +802,7 @@ impl MetadataBlob {
801802
}
802803

803804
"lang_items" => {
804-
writeln!(out, "\n=Lang items=")?;
805+
writeln!(out, "=Lang items=")?;
805806
for (id, lang_item) in root.lang_items.decode(self) {
806807
writeln!(
807808
out,
@@ -823,7 +824,7 @@ impl MetadataBlob {
823824
}
824825

825826
"features" => {
826-
writeln!(out, "\n=Lib features=")?;
827+
writeln!(out, "=Lib features=")?;
827828
for (feature, since) in root.lib_features.decode(self) {
828829
writeln!(
829830
out,
@@ -839,8 +840,77 @@ impl MetadataBlob {
839840
write!(out, "\n")?;
840841
}
841842

843+
"items" => {
844+
writeln!(out, "=Items=")?;
845+
846+
fn print_item(
847+
blob: &MetadataBlob,
848+
out: &mut dyn io::Write,
849+
item: DefIndex,
850+
indent: usize,
851+
) -> io::Result<()> {
852+
let root = blob.get_root();
853+
854+
let def_kind = root.tables.opt_def_kind.get(blob, item).unwrap();
855+
let def_key = root.tables.def_keys.get(blob, item).unwrap().decode(blob);
856+
let def_name = if item == CRATE_DEF_INDEX {
857+
rustc_span::symbol::kw::Crate
858+
} else {
859+
def_key
860+
.disambiguated_data
861+
.data
862+
.get_opt_name()
863+
.unwrap_or_else(|| Symbol::intern("???"))
864+
};
865+
let visibility =
866+
root.tables.visibility.get(blob, item).unwrap().decode(blob).map_id(
867+
|index| {
868+
format!(
869+
"crate{}",
870+
DefPath::make(LOCAL_CRATE, index, |parent| root
871+
.tables
872+
.def_keys
873+
.get(blob, parent)
874+
.unwrap()
875+
.decode(blob))
876+
.to_string_no_crate_verbose()
877+
)
878+
},
879+
);
880+
write!(
881+
out,
882+
"{nil: <indent$}{:?} {:?} {} {{",
883+
visibility,
884+
def_kind,
885+
def_name,
886+
nil = "",
887+
)?;
888+
889+
if let Some(children) =
890+
root.tables.module_children_non_reexports.get(blob, item)
891+
{
892+
write!(out, "\n")?;
893+
for child in children.decode(blob) {
894+
print_item(blob, out, child, indent + 4)?;
895+
}
896+
writeln!(out, "{nil: <indent$}}}", nil = "")?;
897+
} else {
898+
writeln!(out, "}}")?;
899+
}
900+
901+
Ok(())
902+
}
903+
904+
print_item(self, out, CRATE_DEF_INDEX, 0)?;
905+
906+
write!(out, "\n")?;
907+
}
908+
842909
_ => {
843-
writeln!(out, "unknown -Zls kind. allowed values are: no, all, root, lang_items, features")?;
910+
writeln!(
911+
out,
912+
"unknown -Zls kind. allowed values are: no, all, root, lang_items, features, items"
913+
)?;
844914
}
845915
}
846916
}

0 commit comments

Comments
 (0)