rustc_metadata: Merge cstore.rs
into creader.rs
This commit is contained in:
parent
3b1d60a6bc
commit
753ce4518e
@ -25,7 +25,6 @@
|
||||
use rustc_data_structures::sync::{Lrc, ParallelIterator, par_iter};
|
||||
use rustc_errors::PResult;
|
||||
use rustc_incremental;
|
||||
use rustc_metadata::cstore;
|
||||
use rustc_mir as mir;
|
||||
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str};
|
||||
use rustc_passes::{self, ast_validation, hir_stats, layout_test};
|
||||
@ -728,7 +727,7 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
|
||||
rustc_passes::provide(providers);
|
||||
rustc_traits::provide(providers);
|
||||
middle::region::provide(providers);
|
||||
cstore::provide(providers);
|
||||
rustc_metadata::provide(providers);
|
||||
lint::provide(providers);
|
||||
rustc_lint::provide(providers);
|
||||
rustc_codegen_utils::provide(providers);
|
||||
@ -736,7 +735,7 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
|
||||
}
|
||||
|
||||
pub fn default_provide_extern(providers: &mut ty::query::Providers<'_>) {
|
||||
cstore::provide_extern(providers);
|
||||
rustc_metadata::provide_extern(providers);
|
||||
rustc_codegen_ssa::provide_extern(providers);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
//! Validates all used crates and extern libraries and loads their metadata
|
||||
|
||||
use crate::cstore::CStore;
|
||||
use crate::locator::{CrateLocator, CratePaths};
|
||||
use crate::rmeta::{CrateMetadata, CrateNumMap, CrateRoot, CrateDep, MetadataBlob};
|
||||
|
||||
use rustc::hir::def_id::CrateNum;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc::middle::cstore::DepKind;
|
||||
use rustc::session::{Session, CrateDisambiguator};
|
||||
use rustc::session::config::{Sanitizer, self};
|
||||
@ -21,18 +22,22 @@
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::edition::Edition;
|
||||
use syntax::expand::allocator::{global_allocator_spans, AllocatorKind};
|
||||
use syntax::symbol::{Symbol, sym};
|
||||
use syntax::span_fatal;
|
||||
use syntax_expand::base::SyntaxExtension;
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
use log::{debug, info, log_enabled};
|
||||
use proc_macro::bridge::client::ProcMacro;
|
||||
|
||||
use rustc_error_codes::*;
|
||||
|
||||
crate struct Library {
|
||||
pub source: CrateSource,
|
||||
pub metadata: MetadataBlob,
|
||||
#[derive(Clone)]
|
||||
pub struct CStore {
|
||||
metas: IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>,
|
||||
crate injected_panic_runtime: Option<CrateNum>,
|
||||
crate allocator_kind: Option<AllocatorKind>,
|
||||
}
|
||||
|
||||
pub struct CrateLoader<'a> {
|
||||
@ -44,18 +49,14 @@ pub struct CrateLoader<'a> {
|
||||
cstore: CStore,
|
||||
}
|
||||
|
||||
fn dump_crates(cstore: &CStore) {
|
||||
info!("resolved crates:");
|
||||
cstore.iter_crate_data(|cnum, data| {
|
||||
info!(" name: {}", data.name());
|
||||
info!(" cnum: {}", cnum);
|
||||
info!(" hash: {}", data.hash());
|
||||
info!(" reqd: {:?}", data.dep_kind());
|
||||
let CrateSource { dylib, rlib, rmeta } = data.source();
|
||||
dylib.as_ref().map(|dl| info!(" dylib: {}", dl.0.display()));
|
||||
rlib.as_ref().map(|rl| info!(" rlib: {}", rl.0.display()));
|
||||
rmeta.as_ref().map(|rl| info!(" rmeta: {}", rl.0.display()));
|
||||
});
|
||||
pub enum LoadedMacro {
|
||||
MacroDef(ast::Item, Edition),
|
||||
ProcMacro(SyntaxExtension),
|
||||
}
|
||||
|
||||
crate struct Library {
|
||||
pub source: CrateSource,
|
||||
pub metadata: MetadataBlob,
|
||||
}
|
||||
|
||||
enum LoadResult {
|
||||
@ -75,6 +76,74 @@ fn report(self) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
fn dump_crates(cstore: &CStore) {
|
||||
info!("resolved crates:");
|
||||
cstore.iter_crate_data(|cnum, data| {
|
||||
info!(" name: {}", data.name());
|
||||
info!(" cnum: {}", cnum);
|
||||
info!(" hash: {}", data.hash());
|
||||
info!(" reqd: {:?}", data.dep_kind());
|
||||
let CrateSource { dylib, rlib, rmeta } = data.source();
|
||||
dylib.as_ref().map(|dl| info!(" dylib: {}", dl.0.display()));
|
||||
rlib.as_ref().map(|rl| info!(" rlib: {}", rl.0.display()));
|
||||
rmeta.as_ref().map(|rl| info!(" rmeta: {}", rl.0.display()));
|
||||
});
|
||||
}
|
||||
|
||||
impl CStore {
|
||||
crate fn alloc_new_crate_num(&mut self) -> CrateNum {
|
||||
self.metas.push(None);
|
||||
CrateNum::new(self.metas.len() - 1)
|
||||
}
|
||||
|
||||
crate fn get_crate_data(&self, cnum: CrateNum) -> &CrateMetadata {
|
||||
self.metas[cnum].as_ref()
|
||||
.unwrap_or_else(|| panic!("Failed to get crate data for {:?}", cnum))
|
||||
}
|
||||
|
||||
crate fn set_crate_data(&mut self, cnum: CrateNum, data: CrateMetadata) {
|
||||
assert!(self.metas[cnum].is_none(), "Overwriting crate metadata entry");
|
||||
self.metas[cnum] = Some(Lrc::new(data));
|
||||
}
|
||||
|
||||
crate fn iter_crate_data(&self, mut f: impl FnMut(CrateNum, &CrateMetadata)) {
|
||||
for (cnum, data) in self.metas.iter_enumerated() {
|
||||
if let Some(data) = data {
|
||||
f(cnum, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn push_dependencies_in_postorder(&self, deps: &mut Vec<CrateNum>, cnum: CrateNum) {
|
||||
if !deps.contains(&cnum) {
|
||||
let data = self.get_crate_data(cnum);
|
||||
for &dep in data.dependencies().iter() {
|
||||
if dep != cnum {
|
||||
self.push_dependencies_in_postorder(deps, dep);
|
||||
}
|
||||
}
|
||||
|
||||
deps.push(cnum);
|
||||
}
|
||||
}
|
||||
|
||||
crate fn crate_dependencies_in_postorder(&self, cnum: CrateNum) -> Vec<CrateNum> {
|
||||
let mut deps = Vec::new();
|
||||
if cnum == LOCAL_CRATE {
|
||||
self.iter_crate_data(|cnum, _| self.push_dependencies_in_postorder(&mut deps, cnum));
|
||||
} else {
|
||||
self.push_dependencies_in_postorder(&mut deps, cnum);
|
||||
}
|
||||
deps
|
||||
}
|
||||
|
||||
crate fn crate_dependencies_in_reverse_postorder(&self, cnum: CrateNum) -> Vec<CrateNum> {
|
||||
let mut deps = self.crate_dependencies_in_postorder(cnum);
|
||||
deps.reverse();
|
||||
deps
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> CrateLoader<'a> {
|
||||
pub fn new(
|
||||
sess: &'a Session,
|
||||
@ -85,7 +154,15 @@ pub fn new(
|
||||
sess,
|
||||
metadata_loader,
|
||||
local_crate_name: Symbol::intern(local_crate_name),
|
||||
cstore: Default::default(),
|
||||
cstore: CStore {
|
||||
// We add an empty entry for LOCAL_CRATE (which maps to zero) in
|
||||
// order to make array indices in `metas` match with the
|
||||
// corresponding `CrateNum`. This first entry will always remain
|
||||
// `None`.
|
||||
metas: IndexVec::from_elem_n(None, 1),
|
||||
injected_panic_runtime: None,
|
||||
allocator_kind: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,94 +0,0 @@
|
||||
// The crate store - a central repo for information collected about external
|
||||
// crates and libraries
|
||||
|
||||
use crate::rmeta::CrateMetadata;
|
||||
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc::hir::def_id::{LOCAL_CRATE, CrateNum};
|
||||
use syntax::ast;
|
||||
use syntax::edition::Edition;
|
||||
use syntax::expand::allocator::AllocatorKind;
|
||||
use syntax_expand::base::SyntaxExtension;
|
||||
|
||||
pub use crate::rmeta::{provide, provide_extern};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CStore {
|
||||
metas: IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>,
|
||||
crate injected_panic_runtime: Option<CrateNum>,
|
||||
crate allocator_kind: Option<AllocatorKind>,
|
||||
}
|
||||
|
||||
pub enum LoadedMacro {
|
||||
MacroDef(ast::Item, Edition),
|
||||
ProcMacro(SyntaxExtension),
|
||||
}
|
||||
|
||||
impl Default for CStore {
|
||||
fn default() -> Self {
|
||||
CStore {
|
||||
// We add an empty entry for LOCAL_CRATE (which maps to zero) in
|
||||
// order to make array indices in `metas` match with the
|
||||
// corresponding `CrateNum`. This first entry will always remain
|
||||
// `None`.
|
||||
metas: IndexVec::from_elem_n(None, 1),
|
||||
injected_panic_runtime: None,
|
||||
allocator_kind: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CStore {
|
||||
crate fn alloc_new_crate_num(&mut self) -> CrateNum {
|
||||
self.metas.push(None);
|
||||
CrateNum::new(self.metas.len() - 1)
|
||||
}
|
||||
|
||||
crate fn get_crate_data(&self, cnum: CrateNum) -> &CrateMetadata {
|
||||
self.metas[cnum].as_ref()
|
||||
.unwrap_or_else(|| panic!("Failed to get crate data for {:?}", cnum))
|
||||
}
|
||||
|
||||
crate fn set_crate_data(&mut self, cnum: CrateNum, data: CrateMetadata) {
|
||||
assert!(self.metas[cnum].is_none(), "Overwriting crate metadata entry");
|
||||
self.metas[cnum] = Some(Lrc::new(data));
|
||||
}
|
||||
|
||||
crate fn iter_crate_data(&self, mut f: impl FnMut(CrateNum, &CrateMetadata)) {
|
||||
for (cnum, data) in self.metas.iter_enumerated() {
|
||||
if let Some(data) = data {
|
||||
f(cnum, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn push_dependencies_in_postorder(&self, deps: &mut Vec<CrateNum>, cnum: CrateNum) {
|
||||
if !deps.contains(&cnum) {
|
||||
let data = self.get_crate_data(cnum);
|
||||
for &dep in data.dependencies().iter() {
|
||||
if dep != cnum {
|
||||
self.push_dependencies_in_postorder(deps, dep);
|
||||
}
|
||||
}
|
||||
|
||||
deps.push(cnum);
|
||||
}
|
||||
}
|
||||
|
||||
crate fn crate_dependencies_in_postorder(&self, cnum: CrateNum) -> Vec<CrateNum> {
|
||||
let mut deps = Vec::new();
|
||||
if cnum == LOCAL_CRATE {
|
||||
self.iter_crate_data(|cnum, _| self.push_dependencies_in_postorder(&mut deps, cnum));
|
||||
} else {
|
||||
self.push_dependencies_in_postorder(&mut deps, cnum);
|
||||
}
|
||||
deps
|
||||
}
|
||||
|
||||
crate fn crate_dependencies_in_reverse_postorder(&self, cnum: CrateNum) -> Vec<CrateNum> {
|
||||
let mut deps = self.crate_dependencies_in_postorder(cnum);
|
||||
deps.reverse();
|
||||
deps
|
||||
}
|
||||
}
|
@ -24,6 +24,8 @@
|
||||
#[macro_use]
|
||||
extern crate rustc_data_structures;
|
||||
|
||||
pub use rmeta::{provide, provide_extern};
|
||||
|
||||
mod dependency_format;
|
||||
mod foreign_modules;
|
||||
mod link_args;
|
||||
@ -31,7 +33,6 @@
|
||||
mod rmeta;
|
||||
|
||||
pub mod creader;
|
||||
pub mod cstore;
|
||||
pub mod dynamic_lib;
|
||||
pub mod locator;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::cstore::{self, LoadedMacro};
|
||||
use crate::creader::{CStore, LoadedMacro};
|
||||
use crate::link_args;
|
||||
use crate::native_libs;
|
||||
use crate::foreign_modules;
|
||||
@ -382,7 +382,7 @@ pub fn provide(providers: &mut Providers<'_>) {
|
||||
};
|
||||
}
|
||||
|
||||
impl cstore::CStore {
|
||||
impl CStore {
|
||||
pub fn export_macros_untracked(&self, cnum: CrateNum) {
|
||||
let data = self.get_crate_data(cnum);
|
||||
let mut dep_kind = data.dep_kind.lock();
|
||||
@ -458,7 +458,7 @@ pub fn crate_source_untracked(&self, cnum: CrateNum) -> CrateSource {
|
||||
}
|
||||
}
|
||||
|
||||
impl CrateStore for cstore::CStore {
|
||||
impl CrateStore for CStore {
|
||||
fn crate_data_as_any(&self, cnum: CrateNum) -> &dyn Any {
|
||||
self.get_crate_data(cnum)
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
|
||||
use rustc::ty;
|
||||
use rustc::middle::cstore::CrateStore;
|
||||
use rustc_metadata::cstore::LoadedMacro;
|
||||
use rustc_metadata::creader::LoadedMacro;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::ptr;
|
||||
|
@ -32,8 +32,7 @@
|
||||
use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap};
|
||||
use rustc::span_bug;
|
||||
|
||||
use rustc_metadata::creader::CrateLoader;
|
||||
use rustc_metadata::cstore::CStore;
|
||||
use rustc_metadata::creader::{CrateLoader, CStore};
|
||||
|
||||
use syntax::{struct_span_err, unwrap_or};
|
||||
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
|
||||
|
@ -10,7 +10,7 @@
|
||||
use rustc::hir;
|
||||
use rustc::hir::def::{Res, DefKind, CtorKind};
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc_metadata::cstore::LoadedMacro;
|
||||
use rustc_metadata::creader::LoadedMacro;
|
||||
use rustc::ty;
|
||||
use rustc::util::nodemap::FxHashSet;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user