1
Fork 0

Remove unnecessary impl methods for CrateMetadata

This commit is contained in:
Isaac Whitfield 2018-05-12 16:36:53 -07:00
parent 680f3b24ba
commit 55a00a95cf
3 changed files with 36 additions and 97 deletions

View file

@ -58,9 +58,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(|_, data| { cstore.iter_crate_data(|_, data| {
info!(" name: {}", data.name()); info!(" name: {}", data.root.name);
info!(" cnum: {}", data.cnum); info!(" cnum: {}", data.cnum);
info!(" hash: {}", data.hash()); info!(" hash: {}", data.root.hash);
info!(" reqd: {:?}", *data.dep_kind.lock()); info!(" reqd: {:?}", *data.dep_kind.lock());
let CrateSource { dylib, rlib, rmeta } = data.source.clone(); let CrateSource { dylib, rlib, rmeta } = data.source.clone();
dylib.map(|dl| info!(" dylib: {}", dl.0.display())); dylib.map(|dl| info!(" dylib: {}", dl.0.display()));
@ -113,7 +113,7 @@ impl<'a> CrateLoader<'a> {
if data.name != name { return } if data.name != name { return }
match hash { match hash {
Some(hash) if *hash == data.hash() => { ret = Some(cnum); return } Some(hash) if *hash == data.root.hash => { ret = Some(cnum); return }
Some(..) => return, Some(..) => return,
None => {} None => {}
} }
@ -172,9 +172,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.name() == root.name && // same crate-name if other.root.name == root.name && // same crate-name
other.disambiguator() == root.disambiguator && // same crate-disambiguator other.root.disambiguator == root.disambiguator && // same crate-disambiguator
other.hash() != root.hash { // but different SVH other.root.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 \
@ -343,7 +343,7 @@ impl<'a> CrateLoader<'a> {
if locate_ctxt.triple == &self.sess.opts.target_triple { if locate_ctxt.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.name() == root.name && root.hash == data.hash() { if data.root.name == root.name && root.hash == data.root.hash {
assert!(locate_ctxt.hash.is_none()); assert!(locate_ctxt.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);
@ -642,12 +642,12 @@ impl<'a> CrateLoader<'a> {
self.cstore.iter_crate_data(|cnum, data| { self.cstore.iter_crate_data(|cnum, data| {
needs_panic_runtime = needs_panic_runtime || needs_panic_runtime = needs_panic_runtime ||
data.needs_panic_runtime(); data.root.needs_panic_runtime;
if data.is_panic_runtime() { if data.root.panic_runtime {
// Inject a dependency from all #![needs_panic_runtime] to this // Inject a dependency from all #![needs_panic_runtime] to this
// #![panic_runtime] crate. // #![panic_runtime] crate.
self.inject_dependency_if(cnum, "a panic runtime", self.inject_dependency_if(cnum, "a panic runtime",
&|data| data.needs_panic_runtime()); &|data| data.root.needs_panic_runtime);
runtime_found = runtime_found || *data.dep_kind.lock() == DepKind::Explicit; runtime_found = runtime_found || *data.dep_kind.lock() == DepKind::Explicit;
} }
}); });
@ -684,11 +684,11 @@ impl<'a> CrateLoader<'a> {
// Sanity check the loaded crate to ensure it is indeed a panic runtime // Sanity check the loaded crate to ensure it is indeed a panic runtime
// and the panic strategy is indeed what we thought it was. // and the panic strategy is indeed what we thought it was.
if !data.is_panic_runtime() { if !data.root.panic_runtime {
self.sess.err(&format!("the crate `{}` is not a panic runtime", self.sess.err(&format!("the crate `{}` is not a panic runtime",
name)); name));
} }
if data.panic_strategy() != desired_strategy { if data.root.panic_strategy != desired_strategy {
self.sess.err(&format!("the crate `{}` does not have the panic \ self.sess.err(&format!("the crate `{}` does not have the panic \
strategy `{}`", strategy `{}`",
name, desired_strategy.desc())); name, desired_strategy.desc()));
@ -696,7 +696,7 @@ impl<'a> CrateLoader<'a> {
self.sess.injected_panic_runtime.set(Some(cnum)); self.sess.injected_panic_runtime.set(Some(cnum));
self.inject_dependency_if(cnum, "a panic runtime", self.inject_dependency_if(cnum, "a panic runtime",
&|data| data.needs_panic_runtime()); &|data| data.root.needs_panic_runtime);
} }
fn inject_sanitizer_runtime(&mut self) { fn inject_sanitizer_runtime(&mut self) {
@ -791,7 +791,7 @@ impl<'a> CrateLoader<'a> {
PathKind::Crate, dep_kind); PathKind::Crate, dep_kind);
// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime // Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
if !data.is_sanitizer_runtime() { if !data.root.sanitizer_runtime {
self.sess.err(&format!("the crate `{}` is not a sanitizer runtime", self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
name)); name));
} }
@ -814,7 +814,7 @@ impl<'a> CrateLoader<'a> {
PathKind::Crate, dep_kind); PathKind::Crate, dep_kind);
// Sanity check the loaded crate to ensure it is indeed a profiler runtime // Sanity check the loaded crate to ensure it is indeed a profiler runtime
if !data.is_profiler_runtime() { if !data.root.profiler_runtime {
self.sess.err(&format!("the crate `profiler_builtins` is not \ self.sess.err(&format!("the crate `profiler_builtins` is not \
a profiler runtime")); a profiler runtime"));
} }
@ -831,7 +831,7 @@ impl<'a> CrateLoader<'a> {
let mut needs_allocator = attr::contains_name(&krate.attrs, let mut needs_allocator = attr::contains_name(&krate.attrs,
"needs_allocator"); "needs_allocator");
self.cstore.iter_crate_data(|_, data| { self.cstore.iter_crate_data(|_, data| {
needs_allocator = needs_allocator || data.needs_allocator(); needs_allocator = needs_allocator || data.root.needs_allocator;
}); });
if !needs_allocator { if !needs_allocator {
self.sess.injected_allocator.set(None); self.sess.injected_allocator.set(None);
@ -873,7 +873,7 @@ impl<'a> CrateLoader<'a> {
None None
}; };
self.cstore.iter_crate_data(|_, data| { self.cstore.iter_crate_data(|_, data| {
if !data.has_global_allocator() { if !data.root.has_global_allocator {
return return
} }
match global_allocator { match global_allocator {
@ -882,14 +882,14 @@ impl<'a> CrateLoader<'a> {
conflicts with this global \ conflicts with this global \
allocator in: {}", allocator in: {}",
other_crate, other_crate,
data.name())); data.root.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.name())); allocator in: {}", data.root.name));
} }
None => global_allocator = Some(Some(data.name())), None => global_allocator = Some(Some(data.root.name)),
} }
}); });
if global_allocator.is_some() { if global_allocator.is_some() {
@ -951,7 +951,7 @@ impl<'a> CrateLoader<'a> {
// error. // error.
let mut allocator = None; let mut allocator = None;
self.cstore.iter_crate_data(|_, data| { self.cstore.iter_crate_data(|_, data| {
if allocator.is_none() && data.has_default_lib_allocator() { if allocator.is_none() && data.root.has_default_lib_allocator {
allocator = Some(data.clone()); allocator = Some(data.clone());
} }
}); });
@ -1027,9 +1027,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).name(), self.cstore.get_crate_data(krate).root.name,
what, what,
data.name())); data.root.name));
} }
} }

View file

@ -15,10 +15,7 @@ use schema;
use rustc::hir::def_id::{CrateNum, DefIndex}; use rustc::hir::def_id::{CrateNum, DefIndex};
use rustc::hir::map::definitions::DefPathTable; use rustc::hir::map::definitions::DefPathTable;
use rustc::hir::svh::Svh;
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader}; use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
use rustc::session::CrateDisambiguator;
use rustc_target::spec::PanicStrategy;
use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::indexed_vec::IndexVec;
use rustc::util::nodemap::{FxHashMap, NodeMap}; use rustc::util::nodemap::{FxHashMap, NodeMap};
@ -176,61 +173,3 @@ impl CStore {
self.extern_mod_crate_map.borrow().get(&emod_id).cloned() self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
} }
} }
impl CrateMetadata {
pub fn name(&self) -> Symbol {
self.root.name
}
pub fn hash(&self) -> Svh {
self.root.hash
}
pub fn disambiguator(&self) -> CrateDisambiguator {
self.root.disambiguator
}
pub fn needs_allocator(&self) -> bool {
self.root.needs_allocator
}
pub fn has_global_allocator(&self) -> bool {
self.root.has_global_allocator
}
pub fn has_default_lib_allocator(&self) -> bool {
self.root.has_default_lib_allocator
}
pub fn is_panic_runtime(&self) -> bool {
self.root.panic_runtime
}
pub fn needs_panic_runtime(&self) -> bool {
self.root.needs_panic_runtime
}
pub fn is_compiler_builtins(&self) -> bool {
self.root.compiler_builtins
}
pub fn is_sanitizer_runtime(&self) -> bool {
self.root.sanitizer_runtime
}
pub fn is_profiler_runtime(&self) -> bool {
self.root.profiler_runtime
}
pub fn is_no_builtins(&self) -> bool {
self.root.no_builtins
}
pub fn panic_strategy(&self) -> PanicStrategy {
self.root.panic_strategy
}
pub fn edition(&self) -> Edition {
self.root.edition
}
}

View file

@ -170,17 +170,17 @@ provide! { <'tcx> tcx, def_id, other, cdata,
is_mir_available => { cdata.is_item_mir_available(def_id.index) } is_mir_available => { cdata.is_item_mir_available(def_id.index) }
dylib_dependency_formats => { Lrc::new(cdata.get_dylib_dependency_formats()) } dylib_dependency_formats => { Lrc::new(cdata.get_dylib_dependency_formats()) }
is_panic_runtime => { cdata.is_panic_runtime() } is_panic_runtime => { cdata.root.panic_runtime }
is_compiler_builtins => { cdata.is_compiler_builtins() } is_compiler_builtins => { cdata.root.compiler_builtins }
has_global_allocator => { cdata.has_global_allocator() } has_global_allocator => { cdata.root.has_global_allocator }
is_sanitizer_runtime => { cdata.is_sanitizer_runtime() } is_sanitizer_runtime => { cdata.root.sanitizer_runtime }
is_profiler_runtime => { cdata.is_profiler_runtime() } is_profiler_runtime => { cdata.root.profiler_runtime }
panic_strategy => { cdata.panic_strategy() } panic_strategy => { cdata.root.panic_strategy }
extern_crate => { extern_crate => {
let r = Lrc::new(*cdata.extern_crate.lock()); let r = Lrc::new(*cdata.extern_crate.lock());
r r
} }
is_no_builtins => { cdata.is_no_builtins() } is_no_builtins => { cdata.root.no_builtins }
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) } impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
reachable_non_generics => { reachable_non_generics => {
let reachable_non_generics = tcx let reachable_non_generics = tcx
@ -209,9 +209,9 @@ provide! { <'tcx> tcx, def_id, other, cdata,
DefId { krate: def_id.krate, index } DefId { krate: def_id.krate, index }
}) })
} }
crate_disambiguator => { cdata.disambiguator() } crate_disambiguator => { cdata.root.disambiguator }
crate_hash => { cdata.hash() } crate_hash => { cdata.root.hash }
original_crate_name => { cdata.name() } original_crate_name => { cdata.root.name }
extra_filename => { cdata.root.extra_filename.clone() } extra_filename => { cdata.root.extra_filename.clone() }
@ -457,17 +457,17 @@ impl CrateStore for cstore::CStore {
fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator
{ {
self.get_crate_data(cnum).disambiguator() self.get_crate_data(cnum).root.disambiguator
} }
fn crate_hash_untracked(&self, cnum: CrateNum) -> hir::svh::Svh fn crate_hash_untracked(&self, cnum: CrateNum) -> hir::svh::Svh
{ {
self.get_crate_data(cnum).hash() self.get_crate_data(cnum).root.hash
} }
fn crate_edition_untracked(&self, cnum: CrateNum) -> Edition fn crate_edition_untracked(&self, cnum: CrateNum) -> Edition
{ {
self.get_crate_data(cnum).edition() self.get_crate_data(cnum).root.edition
} }
/// Returns the `DefKey` for a given `DefId`. This indicates the /// Returns the `DefKey` for a given `DefId`. This indicates the