Clean up CrateSource
.
This commit is contained in:
parent
624a9b7311
commit
c102d7fb68
@ -61,7 +61,6 @@ pub struct LinkMeta {
|
||||
pub struct CrateSource {
|
||||
pub dylib: Option<(PathBuf, PathKind)>,
|
||||
pub rlib: Option<(PathBuf, PathKind)>,
|
||||
pub cnum: CrateNum,
|
||||
}
|
||||
|
||||
#[derive(Copy, Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)]
|
||||
|
@ -37,7 +37,7 @@ use syntax::parse;
|
||||
use syntax::attr;
|
||||
use syntax::ext::base::SyntaxExtension;
|
||||
use syntax::parse::token::{InternedString, intern};
|
||||
use syntax_pos::{self, Span, mk_sp};
|
||||
use syntax_pos::{Span, DUMMY_SP, mk_sp};
|
||||
use log;
|
||||
|
||||
pub struct Library {
|
||||
@ -56,16 +56,14 @@ pub struct CrateLoader<'a> {
|
||||
|
||||
fn dump_crates(cstore: &CStore) {
|
||||
info!("resolved crates:");
|
||||
cstore.iter_crate_data_origins(|_, data, opt_source| {
|
||||
cstore.iter_crate_data(|_, data| {
|
||||
info!(" name: {}", data.name());
|
||||
info!(" cnum: {}", data.cnum);
|
||||
info!(" hash: {}", data.hash());
|
||||
info!(" reqd: {}", data.explicitly_linked.get());
|
||||
opt_source.map(|cs| {
|
||||
let CrateSource { dylib, rlib, cnum: _ } = cs;
|
||||
dylib.map(|dl| info!(" dylib: {}", dl.0.display()));
|
||||
rlib.map(|rl| info!(" rlib: {}", rl.0.display()));
|
||||
});
|
||||
let CrateSource { dylib, rlib } = data.source.clone();
|
||||
dylib.map(|dl| info!(" dylib: {}", dl.0.display()));
|
||||
rlib.map(|rl| info!(" rlib: {}", rl.0.display()));
|
||||
})
|
||||
}
|
||||
|
||||
@ -261,8 +259,7 @@ impl<'a> CrateLoader<'a> {
|
||||
span: Span,
|
||||
lib: Library,
|
||||
explicitly_linked: bool)
|
||||
-> (CrateNum, Rc<cstore::CrateMetadata>,
|
||||
cstore::CrateSource) {
|
||||
-> (CrateNum, Rc<cstore::CrateMetadata>) {
|
||||
info!("register crate `extern crate {} as {}`", name, ident);
|
||||
let crate_root = lib.metadata.get_root();
|
||||
self.verify_no_symbol_conflicts(span, &crate_root);
|
||||
@ -303,17 +300,14 @@ impl<'a> CrateLoader<'a> {
|
||||
cnum: cnum,
|
||||
codemap_import_info: RefCell::new(vec![]),
|
||||
explicitly_linked: Cell::new(explicitly_linked),
|
||||
source: cstore::CrateSource {
|
||||
dylib: dylib,
|
||||
rlib: rlib,
|
||||
},
|
||||
});
|
||||
|
||||
let source = cstore::CrateSource {
|
||||
dylib: dylib,
|
||||
rlib: rlib,
|
||||
cnum: cnum,
|
||||
};
|
||||
|
||||
self.cstore.set_crate_data(cnum, cmeta.clone());
|
||||
self.cstore.add_used_crate_source(source.clone());
|
||||
(cnum, cmeta, source)
|
||||
(cnum, cmeta)
|
||||
}
|
||||
|
||||
fn resolve_crate(&mut self,
|
||||
@ -324,7 +318,7 @@ impl<'a> CrateLoader<'a> {
|
||||
span: Span,
|
||||
kind: PathKind,
|
||||
explicitly_linked: bool)
|
||||
-> (CrateNum, Rc<cstore::CrateMetadata>, cstore::CrateSource) {
|
||||
-> (CrateNum, Rc<cstore::CrateMetadata>) {
|
||||
info!("resolving crate `extern crate {} as {}`", name, ident);
|
||||
let result = match self.existing_match(name, hash, kind) {
|
||||
Some(cnum) => LoadResult::Previous(cnum),
|
||||
@ -356,10 +350,8 @@ impl<'a> CrateLoader<'a> {
|
||||
match result {
|
||||
LoadResult::Previous(cnum) => {
|
||||
let data = self.cstore.get_crate_data(cnum);
|
||||
if explicitly_linked && !data.explicitly_linked.get() {
|
||||
data.explicitly_linked.set(explicitly_linked);
|
||||
}
|
||||
(cnum, data, self.cstore.used_crate_source(cnum))
|
||||
data.explicitly_linked.set(explicitly_linked || data.explicitly_linked.get());
|
||||
(cnum, data)
|
||||
}
|
||||
LoadResult::Loaded(library) => {
|
||||
self.register_crate(root, ident, name, span, library,
|
||||
@ -508,9 +500,8 @@ impl<'a> CrateLoader<'a> {
|
||||
|
||||
let (dylib, metadata) = match library {
|
||||
LoadResult::Previous(cnum) => {
|
||||
let dylib = self.cstore.opt_used_crate_source(cnum).unwrap().dylib;
|
||||
let data = self.cstore.get_crate_data(cnum);
|
||||
(dylib, PMDSource::Registered(data))
|
||||
(data.source.dylib.clone(), PMDSource::Registered(data))
|
||||
}
|
||||
LoadResult::Loaded(library) => {
|
||||
let dylib = library.dylib.clone();
|
||||
@ -754,9 +745,8 @@ impl<'a> CrateLoader<'a> {
|
||||
};
|
||||
info!("panic runtime not found -- loading {}", name);
|
||||
|
||||
let (cnum, data, _) = self.resolve_crate(&None, name, name, None,
|
||||
syntax_pos::DUMMY_SP,
|
||||
PathKind::Crate, false);
|
||||
let (cnum, data) =
|
||||
self.resolve_crate(&None, name, name, None, DUMMY_SP, PathKind::Crate, false);
|
||||
|
||||
// Sanity check the loaded crate to ensure it is indeed a panic runtime
|
||||
// and the panic strategy is indeed what we thought it was.
|
||||
@ -836,9 +826,8 @@ impl<'a> CrateLoader<'a> {
|
||||
} else {
|
||||
&self.sess.target.target.options.exe_allocation_crate
|
||||
};
|
||||
let (cnum, data, _) = self.resolve_crate(&None, name, name, None,
|
||||
syntax_pos::DUMMY_SP,
|
||||
PathKind::Crate, false);
|
||||
let (cnum, data) =
|
||||
self.resolve_crate(&None, name, name, None, DUMMY_SP, PathKind::Crate, false);
|
||||
|
||||
// Sanity check the crate we loaded to ensure that it is indeed an
|
||||
// allocator.
|
||||
|
@ -83,6 +83,8 @@ pub struct CrateMetadata {
|
||||
/// where this is false is when an allocator crate is injected into the
|
||||
/// dependency list, and therefore isn't actually needed to link an rlib.
|
||||
pub explicitly_linked: Cell<bool>,
|
||||
|
||||
pub source: CrateSource,
|
||||
}
|
||||
|
||||
pub struct CachedInlinedItem {
|
||||
@ -97,7 +99,6 @@ pub struct CStore {
|
||||
metas: RefCell<FxHashMap<CrateNum, Rc<CrateMetadata>>>,
|
||||
/// Map from NodeId's of local extern crate statements to crate numbers
|
||||
extern_mod_crate_map: RefCell<NodeMap<CrateNum>>,
|
||||
used_crate_sources: RefCell<Vec<CrateSource>>,
|
||||
used_libraries: RefCell<Vec<(String, NativeLibraryKind)>>,
|
||||
used_link_args: RefCell<Vec<String>>,
|
||||
statically_included_foreign_items: RefCell<NodeSet>,
|
||||
@ -112,7 +113,6 @@ impl CStore {
|
||||
dep_graph: dep_graph.clone(),
|
||||
metas: RefCell::new(FxHashMap()),
|
||||
extern_mod_crate_map: RefCell::new(FxHashMap()),
|
||||
used_crate_sources: RefCell::new(Vec::new()),
|
||||
used_libraries: RefCell::new(Vec::new()),
|
||||
used_link_args: RefCell::new(Vec::new()),
|
||||
statically_included_foreign_items: RefCell::new(NodeSet()),
|
||||
@ -146,38 +146,9 @@ impl CStore {
|
||||
}
|
||||
}
|
||||
|
||||
/// Like `iter_crate_data`, but passes source paths (if available) as well.
|
||||
pub fn iter_crate_data_origins<I>(&self, mut i: I)
|
||||
where I: FnMut(CrateNum, &CrateMetadata, Option<CrateSource>)
|
||||
{
|
||||
for (&k, v) in self.metas.borrow().iter() {
|
||||
let origin = self.opt_used_crate_source(k);
|
||||
origin.as_ref().map(|cs| {
|
||||
assert!(k == cs.cnum);
|
||||
});
|
||||
i(k, &v, origin);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_used_crate_source(&self, src: CrateSource) {
|
||||
let mut used_crate_sources = self.used_crate_sources.borrow_mut();
|
||||
if !used_crate_sources.contains(&src) {
|
||||
used_crate_sources.push(src);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opt_used_crate_source(&self, cnum: CrateNum) -> Option<CrateSource> {
|
||||
self.used_crate_sources
|
||||
.borrow_mut()
|
||||
.iter()
|
||||
.find(|source| source.cnum == cnum)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
self.metas.borrow_mut().clear();
|
||||
self.extern_mod_crate_map.borrow_mut().clear();
|
||||
self.used_crate_sources.borrow_mut().clear();
|
||||
self.used_libraries.borrow_mut().clear();
|
||||
self.used_link_args.borrow_mut().clear();
|
||||
self.statically_included_foreign_items.borrow_mut().clear();
|
||||
@ -223,14 +194,14 @@ impl CStore {
|
||||
}
|
||||
info!("topological ordering: {:?}", ordering);
|
||||
ordering.reverse();
|
||||
let mut libs = self.used_crate_sources
|
||||
let mut libs = self.metas
|
||||
.borrow()
|
||||
.iter()
|
||||
.map(|src| {
|
||||
(src.cnum,
|
||||
.map(|(&cnum, data)| {
|
||||
(cnum,
|
||||
match prefer {
|
||||
LinkagePreference::RequireDynamic => src.dylib.clone().map(|p| p.0),
|
||||
LinkagePreference::RequireStatic => src.rlib.clone().map(|p| p.0),
|
||||
LinkagePreference::RequireDynamic => data.source.dylib.clone().map(|p| p.0),
|
||||
LinkagePreference::RequireStatic => data.source.rlib.clone().map(|p| p.0),
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
@ -507,7 +507,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
||||
|
||||
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource
|
||||
{
|
||||
self.opt_used_crate_source(cnum).unwrap()
|
||||
self.get_crate_data(cnum).source.clone()
|
||||
}
|
||||
|
||||
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>
|
||||
|
Loading…
Reference in New Issue
Block a user