Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metadata: improve some confusing type and module names #37301

Merged
merged 4 commits into from
Oct 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 { .. } => {
Expand Down
92 changes: 39 additions & 53 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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>>,
Expand Down Expand Up @@ -129,7 +129,7 @@ struct ExtensionCrate {

enum PMDSource {
Registered(Rc<cstore::CrateMetadata>),
Owned(loader::Library),
Owned(Library),
}

impl Deref for PMDSource {
Expand All @@ -145,7 +145,7 @@ impl Deref for PMDSource {

enum LoadResult {
Previous(CrateNum),
Loaded(loader::Library),
Loaded(Library),
}

pub struct Macros {
Expand All @@ -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(),
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -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(),
}
}
};
Expand All @@ -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,
};
Expand All @@ -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);
}
Expand Down Expand Up @@ -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[..],
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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));
}
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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,
);

Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use cstore;
use encoder;
use loader;
use locator;
use schema;

use rustc::middle::cstore::{InlinedItem, CrateStore, CrateSource, ExternCrate};
Expand Down Expand Up @@ -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>)>
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Loading