1
Fork 0

rustc_metadata: Privatize CrateMetadata::root

This commit is contained in:
Vadim Petrochenkov 2019-11-24 00:46:33 +03:00
parent a9cef4945f
commit 3b1d60a6bc
2 changed files with 32 additions and 16 deletions

View file

@ -47,9 +47,9 @@ pub struct CrateLoader<'a> {
fn dump_crates(cstore: &CStore) { fn dump_crates(cstore: &CStore) {
info!("resolved crates:"); info!("resolved crates:");
cstore.iter_crate_data(|cnum, data| { cstore.iter_crate_data(|cnum, data| {
info!(" name: {}", data.root.name()); info!(" name: {}", data.name());
info!(" cnum: {}", cnum); info!(" cnum: {}", cnum);
info!(" hash: {}", data.root.hash()); info!(" hash: {}", data.hash());
info!(" reqd: {:?}", data.dep_kind()); info!(" reqd: {:?}", data.dep_kind());
let CrateSource { dylib, rlib, rmeta } = data.source(); let CrateSource { dylib, rlib, rmeta } = data.source();
dylib.as_ref().map(|dl| info!(" dylib: {}", dl.0.display())); dylib.as_ref().map(|dl| info!(" dylib: {}", dl.0.display()));
@ -101,10 +101,10 @@ impl<'a> CrateLoader<'a> {
-> Option<CrateNum> { -> Option<CrateNum> {
let mut ret = None; let mut ret = None;
self.cstore.iter_crate_data(|cnum, data| { self.cstore.iter_crate_data(|cnum, data| {
if data.root.name() != name { return } if data.name() != name { return }
match hash { match hash {
Some(hash) if *hash == data.root.hash() => { ret = Some(cnum); return } Some(hash) if *hash == data.hash() => { ret = Some(cnum); return }
Some(..) => return, Some(..) => return,
None => {} None => {}
} }
@ -164,9 +164,9 @@ impl<'a> CrateLoader<'a> {
// Check for conflicts with any crate loaded so far // Check for conflicts with any crate loaded so far
self.cstore.iter_crate_data(|_, other| { self.cstore.iter_crate_data(|_, other| {
if other.root.name() == root.name() && // same crate-name if other.name() == root.name() && // same crate-name
other.root.disambiguator() == root.disambiguator() && // same crate-disambiguator other.disambiguator() == root.disambiguator() && // same crate-disambiguator
other.root.hash() != root.hash() { // but different SVH other.hash() != root.hash() { // but different SVH
span_fatal!(self.sess, span, E0523, span_fatal!(self.sess, span, E0523,
"found two different crates with name `{}` that are \ "found two different crates with name `{}` that are \
not distinguished by differing `-C metadata`. This \ not distinguished by differing `-C metadata`. This \
@ -350,7 +350,7 @@ impl<'a> CrateLoader<'a> {
match result { match result {
(LoadResult::Previous(cnum), None) => { (LoadResult::Previous(cnum), None) => {
let data = self.cstore.get_crate_data(cnum); let data = self.cstore.get_crate_data(cnum);
if data.root.is_proc_macro_crate() { if data.is_proc_macro_crate() {
dep_kind = DepKind::UnexportedMacrosOnly; dep_kind = DepKind::UnexportedMacrosOnly;
} }
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));
@ -378,7 +378,7 @@ impl<'a> CrateLoader<'a> {
if locator.triple == self.sess.opts.target_triple { if locator.triple == self.sess.opts.target_triple {
let mut result = LoadResult::Loaded(library); let mut result = LoadResult::Loaded(library);
self.cstore.iter_crate_data(|cnum, data| { self.cstore.iter_crate_data(|cnum, data| {
if data.root.name() == root.name() && root.hash() == data.root.hash() { if data.name() == root.name() && root.hash() == data.hash() {
assert!(locator.hash.is_none()); assert!(locator.hash.is_none());
info!("load success, going to previous cnum: {}", cnum); info!("load success, going to previous cnum: {}", cnum);
result = LoadResult::Previous(cnum); result = LoadResult::Previous(cnum);
@ -621,7 +621,7 @@ impl<'a> CrateLoader<'a> {
let mut uses_std = false; let mut uses_std = false;
self.cstore.iter_crate_data(|_, data| { self.cstore.iter_crate_data(|_, data| {
if data.root.name() == sym::std { if data.name() == sym::std {
uses_std = true; uses_std = true;
} }
}); });
@ -731,14 +731,14 @@ impl<'a> CrateLoader<'a> {
conflicts with this global \ conflicts with this global \
allocator in: {}", allocator in: {}",
other_crate, other_crate,
data.root.name())); data.name()));
} }
Some(None) => { Some(None) => {
self.sess.err(&format!("the `#[global_allocator]` in this \ self.sess.err(&format!("the `#[global_allocator]` in this \
crate conflicts with global \ crate conflicts with global \
allocator in: {}", data.root.name())); allocator in: {}", data.name()));
} }
None => global_allocator = Some(Some(data.root.name())), None => global_allocator = Some(Some(data.name())),
} }
}); });
if global_allocator.is_some() { if global_allocator.is_some() {
@ -786,9 +786,9 @@ impl<'a> CrateLoader<'a> {
self.sess.err(&format!("the crate `{}` cannot depend \ self.sess.err(&format!("the crate `{}` cannot depend \
on a crate that needs {}, but \ on a crate that needs {}, but \
it depends on `{}`", it depends on `{}`",
self.cstore.get_crate_data(krate).root.name(), self.cstore.get_crate_data(krate).name(),
what, what,
data.root.name())); data.name()));
} }
} }

View file

@ -66,7 +66,7 @@ crate struct CrateMetadata {
/// lifetime is only used behind `Lazy`, and therefore acts like an /// lifetime is only used behind `Lazy`, and therefore acts like an
/// universal (`for<'tcx>`), that is paired up with whichever `TyCtxt` /// universal (`for<'tcx>`), that is paired up with whichever `TyCtxt`
/// is being used to decode those values. /// is being used to decode those values.
crate root: CrateRoot<'static>, root: CrateRoot<'static>,
/// For each definition in this crate, we encode a key. When the /// For each definition in this crate, we encode a key. When the
/// crate is loaded, we read all the keys and put them in this /// crate is loaded, we read all the keys and put them in this
/// hashmap, which gives the reverse mapping. This allows us to /// hashmap, which gives the reverse mapping. This allows us to
@ -1594,6 +1594,22 @@ impl<'a, 'tcx> CrateMetadata {
crate fn has_default_lib_allocator(&self) -> bool { crate fn has_default_lib_allocator(&self) -> bool {
self.root.has_default_lib_allocator self.root.has_default_lib_allocator
} }
crate fn is_proc_macro_crate(&self) -> bool {
self.root.is_proc_macro_crate()
}
crate fn name(&self) -> Symbol {
self.root.name
}
crate fn disambiguator(&self) -> CrateDisambiguator {
self.root.disambiguator
}
crate fn hash(&self) -> Svh {
self.root.hash
}
} }
// Cannot be implemented on 'ProcMacro', as libproc_macro // Cannot be implemented on 'ProcMacro', as libproc_macro