Auto merge of #37301 - jseyfried:improve_metadata_modules, r=eddyb
metadata: improve some confusing type and module names r? @eddyb
This commit is contained in:
commit
4845adde36
9 changed files with 59 additions and 78 deletions
|
|
@ -645,7 +645,8 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
|
|||
// its contents but the results of name resolution on those contents. Hopefully we'll push
|
||||
// this back at some point.
|
||||
let _ignore = sess.dep_graph.in_ignore();
|
||||
let mut crate_loader = CrateLoader::new(sess, &cstore, &krate, crate_name);
|
||||
let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name, krate.config.clone());
|
||||
crate_loader.preprocess(&krate);
|
||||
let resolver_arenas = Resolver::arenas();
|
||||
let mut resolver =
|
||||
Resolver::new(sess, &krate, make_glob_map, &mut crate_loader, &resolver_arenas);
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ use rustc::session::config::nightly_options;
|
|||
use rustc::session::early_error;
|
||||
use rustc::lint::Lint;
|
||||
use rustc::lint;
|
||||
use rustc_metadata::loader;
|
||||
use rustc_metadata::locator;
|
||||
use rustc_metadata::cstore::CStore;
|
||||
use rustc::util::common::time;
|
||||
|
||||
|
|
@ -578,8 +578,7 @@ impl RustcDefaultCalls {
|
|||
&Input::File(ref ifile) => {
|
||||
let path = &(*ifile);
|
||||
let mut v = Vec::new();
|
||||
loader::list_file_metadata(&sess.target.target, path, &mut v)
|
||||
.unwrap();
|
||||
locator::list_file_metadata(&sess.target.target, path, &mut v).unwrap();
|
||||
println!("{}", String::from_utf8(v).unwrap());
|
||||
}
|
||||
&Input::Str { .. } => {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
//! Validates all used crates and extern libraries and loads their metadata
|
||||
|
||||
use cstore::{self, CStore, CrateSource, MetadataBlob};
|
||||
use loader::{self, CratePaths};
|
||||
use locator::{self, CratePaths};
|
||||
use macro_import;
|
||||
use schema::CrateRoot;
|
||||
|
||||
|
|
@ -40,14 +40,14 @@ use syntax::parse::token::InternedString;
|
|||
use syntax_pos::{self, Span, mk_sp};
|
||||
use log;
|
||||
|
||||
pub struct CrateLoader<'a> {
|
||||
pub sess: &'a Session,
|
||||
pub creader: CrateReader<'a>,
|
||||
cstore: &'a CStore,
|
||||
pub struct Library {
|
||||
pub dylib: Option<(PathBuf, PathKind)>,
|
||||
pub rlib: Option<(PathBuf, PathKind)>,
|
||||
pub metadata: MetadataBlob,
|
||||
}
|
||||
|
||||
pub struct CrateReader<'a> {
|
||||
sess: &'a Session,
|
||||
pub struct CrateLoader<'a> {
|
||||
pub sess: &'a Session,
|
||||
cstore: &'a CStore,
|
||||
next_crate_num: CrateNum,
|
||||
foreign_item_map: FnvHashMap<String, Vec<ast::NodeId>>,
|
||||
|
|
@ -129,7 +129,7 @@ struct ExtensionCrate {
|
|||
|
||||
enum PMDSource {
|
||||
Registered(Rc<cstore::CrateMetadata>),
|
||||
Owned(loader::Library),
|
||||
Owned(Library),
|
||||
}
|
||||
|
||||
impl Deref for PMDSource {
|
||||
|
|
@ -145,7 +145,7 @@ impl Deref for PMDSource {
|
|||
|
||||
enum LoadResult {
|
||||
Previous(CrateNum),
|
||||
Loaded(loader::Library),
|
||||
Loaded(Library),
|
||||
}
|
||||
|
||||
pub struct Macros {
|
||||
|
|
@ -159,13 +159,13 @@ pub struct Macros {
|
|||
pub dylib: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl<'a> CrateReader<'a> {
|
||||
impl<'a> CrateLoader<'a> {
|
||||
pub fn new(sess: &'a Session,
|
||||
cstore: &'a CStore,
|
||||
local_crate_name: &str,
|
||||
local_crate_config: ast::CrateConfig)
|
||||
-> CrateReader<'a> {
|
||||
CrateReader {
|
||||
-> Self {
|
||||
CrateLoader {
|
||||
sess: sess,
|
||||
cstore: cstore,
|
||||
next_crate_num: cstore.next_crate_num(),
|
||||
|
|
@ -281,7 +281,7 @@ impl<'a> CrateReader<'a> {
|
|||
ident: &str,
|
||||
name: &str,
|
||||
span: Span,
|
||||
lib: loader::Library,
|
||||
lib: Library,
|
||||
explicitly_linked: bool)
|
||||
-> (CrateNum, Rc<cstore::CrateMetadata>,
|
||||
cstore::CrateSource) {
|
||||
|
|
@ -306,7 +306,7 @@ impl<'a> CrateReader<'a> {
|
|||
// Maintain a reference to the top most crate.
|
||||
let root = if root.is_some() { root } else { &crate_paths };
|
||||
|
||||
let loader::Library { dylib, rlib, metadata } = lib;
|
||||
let Library { dylib, rlib, metadata } = lib;
|
||||
|
||||
let cnum_map = self.resolve_crate_deps(root, &crate_root, &metadata, cnum, span);
|
||||
|
||||
|
|
@ -352,7 +352,7 @@ impl<'a> CrateReader<'a> {
|
|||
Some(cnum) => LoadResult::Previous(cnum),
|
||||
None => {
|
||||
info!("falling back to a load");
|
||||
let mut load_ctxt = loader::Context {
|
||||
let mut locate_ctxt = locator::Context {
|
||||
sess: self.sess,
|
||||
span: span,
|
||||
ident: ident,
|
||||
|
|
@ -368,9 +368,9 @@ impl<'a> CrateReader<'a> {
|
|||
rejected_via_version: vec!(),
|
||||
should_match_name: true,
|
||||
};
|
||||
match self.load(&mut load_ctxt) {
|
||||
match self.load(&mut locate_ctxt) {
|
||||
Some(result) => result,
|
||||
None => load_ctxt.report_load_errs(),
|
||||
None => locate_ctxt.report_errs(),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -390,8 +390,8 @@ impl<'a> CrateReader<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn load(&mut self, loader: &mut loader::Context) -> Option<LoadResult> {
|
||||
let library = match loader.maybe_load_library_crate() {
|
||||
fn load(&mut self, locate_ctxt: &mut locator::Context) -> Option<LoadResult> {
|
||||
let library = match locate_ctxt.maybe_load_library_crate() {
|
||||
Some(lib) => lib,
|
||||
None => return None,
|
||||
};
|
||||
|
|
@ -405,11 +405,11 @@ impl<'a> CrateReader<'a> {
|
|||
// don't want to match a host crate against an equivalent target one
|
||||
// already loaded.
|
||||
let root = library.metadata.get_root();
|
||||
if loader.triple == self.sess.opts.target_triple {
|
||||
if locate_ctxt.triple == self.sess.opts.target_triple {
|
||||
let mut result = LoadResult::Loaded(library);
|
||||
self.cstore.iter_crate_data(|cnum, data| {
|
||||
if data.name() == root.name && root.hash == data.hash() {
|
||||
assert!(loader.hash.is_none());
|
||||
assert!(locate_ctxt.hash.is_none());
|
||||
info!("load success, going to previous cnum: {}", cnum);
|
||||
result = LoadResult::Previous(cnum);
|
||||
}
|
||||
|
|
@ -494,7 +494,7 @@ impl<'a> CrateReader<'a> {
|
|||
let mut target_only = false;
|
||||
let ident = info.ident.clone();
|
||||
let name = info.name.clone();
|
||||
let mut load_ctxt = loader::Context {
|
||||
let mut locate_ctxt = locator::Context {
|
||||
sess: self.sess,
|
||||
span: span,
|
||||
ident: &ident[..],
|
||||
|
|
@ -510,7 +510,7 @@ impl<'a> CrateReader<'a> {
|
|||
rejected_via_version: vec!(),
|
||||
should_match_name: true,
|
||||
};
|
||||
let library = self.load(&mut load_ctxt).or_else(|| {
|
||||
let library = self.load(&mut locate_ctxt).or_else(|| {
|
||||
if !is_cross {
|
||||
return None
|
||||
}
|
||||
|
|
@ -519,15 +519,15 @@ impl<'a> CrateReader<'a> {
|
|||
target_only = true;
|
||||
should_link = info.should_link;
|
||||
|
||||
load_ctxt.target = &self.sess.target.target;
|
||||
load_ctxt.triple = target_triple;
|
||||
load_ctxt.filesearch = self.sess.target_filesearch(PathKind::Crate);
|
||||
locate_ctxt.target = &self.sess.target.target;
|
||||
locate_ctxt.triple = target_triple;
|
||||
locate_ctxt.filesearch = self.sess.target_filesearch(PathKind::Crate);
|
||||
|
||||
self.load(&mut load_ctxt)
|
||||
self.load(&mut locate_ctxt)
|
||||
});
|
||||
let library = match library {
|
||||
Some(l) => l,
|
||||
None => load_ctxt.report_load_errs(),
|
||||
None => locate_ctxt.report_errs(),
|
||||
};
|
||||
|
||||
let (dylib, metadata) = match library {
|
||||
|
|
@ -890,7 +890,7 @@ impl<'a> CrateReader<'a> {
|
|||
}
|
||||
|
||||
impl ExtensionCrate {
|
||||
fn register(self, creader: &mut CrateReader) {
|
||||
fn register(self, loader: &mut CrateLoader) {
|
||||
if !self.should_link {
|
||||
return
|
||||
}
|
||||
|
|
@ -901,31 +901,17 @@ impl ExtensionCrate {
|
|||
};
|
||||
|
||||
// Register crate now to avoid double-reading metadata
|
||||
creader.register_crate(&None,
|
||||
&self.ident,
|
||||
&self.name,
|
||||
self.span,
|
||||
library,
|
||||
true);
|
||||
loader.register_crate(&None, &self.ident, &self.name, self.span, library, true);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> CrateLoader<'a> {
|
||||
pub fn new(sess: &'a Session, cstore: &'a CStore, krate: &ast::Crate, crate_name: &str)
|
||||
-> Self {
|
||||
let loader = CrateLoader {
|
||||
sess: sess,
|
||||
cstore: cstore,
|
||||
creader: CrateReader::new(sess, cstore, crate_name, krate.config.clone()),
|
||||
};
|
||||
|
||||
pub fn preprocess(&mut self, krate: &ast::Crate) {
|
||||
for attr in krate.attrs.iter().filter(|m| m.name() == "link_args") {
|
||||
if let Some(ref linkarg) = attr.value_str() {
|
||||
loader.cstore.add_used_link_args(&linkarg);
|
||||
self.cstore.add_used_link_args(&linkarg);
|
||||
}
|
||||
}
|
||||
|
||||
loader
|
||||
}
|
||||
|
||||
fn process_foreign_mod(&mut self, i: &ast::Item, fm: &ast::ForeignMod) {
|
||||
|
|
@ -982,7 +968,7 @@ impl<'a> CrateLoader<'a> {
|
|||
Some(name) => name,
|
||||
None => continue,
|
||||
};
|
||||
let list = self.creader.foreign_item_map.entry(lib_name.to_string())
|
||||
let list = self.foreign_item_map.entry(lib_name.to_string())
|
||||
.or_insert(Vec::new());
|
||||
list.extend(fm.items.iter().map(|it| it.id));
|
||||
}
|
||||
|
|
@ -991,8 +977,8 @@ impl<'a> CrateLoader<'a> {
|
|||
|
||||
impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
|
||||
fn postprocess(&mut self, krate: &ast::Crate) {
|
||||
self.creader.inject_allocator_crate();
|
||||
self.creader.inject_panic_runtime(krate);
|
||||
self.inject_allocator_crate();
|
||||
self.inject_panic_runtime(krate);
|
||||
|
||||
if log_enabled!(log::INFO) {
|
||||
dump_crates(&self.cstore);
|
||||
|
|
@ -1001,7 +987,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
|
|||
for &(ref name, kind) in &self.sess.opts.libs {
|
||||
register_native_lib(self.sess, self.cstore, None, name.clone(), kind);
|
||||
}
|
||||
self.creader.register_statically_included_foreign_items();
|
||||
self.register_statically_included_foreign_items();
|
||||
}
|
||||
|
||||
fn process_item(&mut self, item: &ast::Item, definitions: &hir_map::Definitions) {
|
||||
|
|
@ -1024,12 +1010,12 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(info) = self.creader.extract_crate_info(item) {
|
||||
if let Some(info) = self.extract_crate_info(item) {
|
||||
if !info.should_link {
|
||||
return;
|
||||
}
|
||||
|
||||
let (cnum, ..) = self.creader.resolve_crate(
|
||||
let (cnum, ..) = self.resolve_crate(
|
||||
&None, &info.ident, &info.name, None, item.span, PathKind::Crate, true,
|
||||
);
|
||||
|
||||
|
|
@ -1038,7 +1024,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
|
|||
|
||||
let extern_crate =
|
||||
ExternCrate { def_id: def_id, span: item.span, direct: true, path_len: len };
|
||||
self.creader.update_extern_crate(cnum, extern_crate, &mut FnvHashSet());
|
||||
self.update_extern_crate(cnum, extern_crate, &mut FnvHashSet());
|
||||
|
||||
self.cstore.add_extern_mod_stmt_cnum(info.id, cnum);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// The crate store - a central repo for information collected about external
|
||||
// crates and libraries
|
||||
|
||||
use loader;
|
||||
use locator;
|
||||
use schema;
|
||||
|
||||
use rustc::dep_graph::DepGraph;
|
||||
|
|
@ -43,7 +43,7 @@ pub type CrateNumMap = IndexVec<CrateNum, CrateNum>;
|
|||
|
||||
pub enum MetadataBlob {
|
||||
Inflated(Bytes),
|
||||
Archive(loader::ArchiveMetadata),
|
||||
Archive(locator::ArchiveMetadata),
|
||||
}
|
||||
|
||||
/// Holds information about a syntax_pos::FileMap imported from another crate.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use cstore;
|
||||
use encoder;
|
||||
use loader;
|
||||
use locator;
|
||||
use schema;
|
||||
|
||||
use rustc::middle::cstore::{InlinedItem, CrateStore, CrateSource, ExternCrate};
|
||||
|
|
@ -497,12 +497,12 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
|
||||
fn metadata_filename(&self) -> &str
|
||||
{
|
||||
loader::METADATA_FILENAME
|
||||
locator::METADATA_FILENAME
|
||||
}
|
||||
|
||||
fn metadata_section_name(&self, target: &Target) -> &str
|
||||
{
|
||||
loader::meta_section_name(target)
|
||||
locator::meta_section_name(target)
|
||||
}
|
||||
|
||||
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, Option<PathBuf>)>
|
||||
|
|
@ -53,12 +53,12 @@ mod index_builder;
|
|||
mod index;
|
||||
mod encoder;
|
||||
mod decoder;
|
||||
mod csearch;
|
||||
mod cstore_impl;
|
||||
mod schema;
|
||||
|
||||
pub mod creader;
|
||||
pub mod cstore;
|
||||
pub mod loader;
|
||||
pub mod locator;
|
||||
pub mod macro_import;
|
||||
|
||||
__build_diagnostic_array! { librustc_metadata, DIAGNOSTICS }
|
||||
|
|
|
|||
|
|
@ -210,9 +210,10 @@
|
|||
//!
|
||||
//! That's the general overview of loading crates in the compiler, but it's by
|
||||
//! no means all of the necessary details. Take a look at the rest of
|
||||
//! metadata::loader or metadata::creader for all the juicy details!
|
||||
//! metadata::locator or metadata::creader for all the juicy details!
|
||||
|
||||
use cstore::MetadataBlob;
|
||||
use creader::Library;
|
||||
use schema::{METADATA_HEADER, rustc_version};
|
||||
|
||||
use rustc::hir::svh::Svh;
|
||||
|
|
@ -263,12 +264,6 @@ pub struct Context<'a> {
|
|||
pub should_match_name: bool,
|
||||
}
|
||||
|
||||
pub struct Library {
|
||||
pub dylib: Option<(PathBuf, PathKind)>,
|
||||
pub rlib: Option<(PathBuf, PathKind)>,
|
||||
pub metadata: MetadataBlob,
|
||||
}
|
||||
|
||||
pub struct ArchiveMetadata {
|
||||
_archive: ArchiveRO,
|
||||
// points into self._archive
|
||||
|
|
@ -315,10 +310,10 @@ impl<'a> Context<'a> {
|
|||
}
|
||||
|
||||
pub fn load_library_crate(&mut self) -> Library {
|
||||
self.find_library_crate().unwrap_or_else(|| self.report_load_errs())
|
||||
self.find_library_crate().unwrap_or_else(|| self.report_errs())
|
||||
}
|
||||
|
||||
pub fn report_load_errs(&mut self) -> ! {
|
||||
pub fn report_errs(&mut self) -> ! {
|
||||
let add = match self.root {
|
||||
&None => String::new(),
|
||||
&Some(ref r) => format!(" which `{}` depends on",
|
||||
|
|
@ -110,7 +110,7 @@ impl<'a> CrateLoader<'a> {
|
|||
if sel.is_empty() && reexport.is_empty() {
|
||||
// Make sure we can read macros from `#[no_link]` crates.
|
||||
if no_link {
|
||||
self.creader.read_macros(vi);
|
||||
self.read_macros(vi);
|
||||
}
|
||||
return Vec::new();
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ impl<'a> CrateLoader<'a> {
|
|||
return Vec::new();
|
||||
}
|
||||
|
||||
let mut macros = self.creader.read_macros(vi);
|
||||
let mut macros = self.read_macros(vi);
|
||||
let mut ret = Vec::new();
|
||||
let mut seen = HashSet::new();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
//! Used by `rustc` when loading a plugin.
|
||||
|
||||
use rustc::session::Session;
|
||||
use rustc_metadata::creader::CrateReader;
|
||||
use rustc_metadata::creader::CrateLoader;
|
||||
use rustc_metadata::cstore::CStore;
|
||||
use registry::Registry;
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ pub struct PluginRegistrar {
|
|||
|
||||
struct PluginLoader<'a> {
|
||||
sess: &'a Session,
|
||||
reader: CrateReader<'a>,
|
||||
reader: CrateLoader<'a>,
|
||||
plugins: Vec<PluginRegistrar>,
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ impl<'a> PluginLoader<'a> {
|
|||
-> PluginLoader<'a> {
|
||||
PluginLoader {
|
||||
sess: sess,
|
||||
reader: CrateReader::new(sess, cstore, crate_name, crate_config),
|
||||
reader: CrateLoader::new(sess, cstore, crate_name, crate_config),
|
||||
plugins: vec![],
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue