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

Remove attribute_cache from CrateMetadata #50528

Merged
merged 8 commits into from
May 23, 2018
Merged
22 changes: 13 additions & 9 deletions src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,20 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> {
out
}

fn dep_nodes(&self, labels: &Labels, def_id: DefId) -> Vec<DepNode> {
let mut out = Vec::with_capacity(labels.len());
fn dep_nodes<'l>(
&self,
labels: &'l Labels,
def_id: DefId
) -> impl Iterator<Item = DepNode> + 'l {
let def_path_hash = self.tcx.def_path_hash(def_id);
for label in labels.iter() {
match DepNode::from_label_string(label, def_path_hash) {
Ok(dep_node) => out.push(dep_node),
Err(()) => unreachable!(),
}
}
out
labels
.iter()
.map(move |label| {
match DepNode::from_label_string(label, def_path_hash) {
Ok(dep_node) => dep_node,
Err(()) => unreachable!(),
}
})
}

fn dep_node_str(&self, dep_node: &DepNode) -> String {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/work_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
if sess.opts.incremental.is_none() {
return None
}
let work_product_id = WorkProductId::from_cgu_name(cgu_name);

let saved_files: Option<Vec<_>> =
files.iter()
Expand Down Expand Up @@ -63,6 +62,7 @@ pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
saved_files,
};

let work_product_id = WorkProductId::from_cgu_name(cgu_name);
Some((work_product_id, work_product))
}

Expand Down
51 changes: 24 additions & 27 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ pub struct CrateLoader<'a> {
fn dump_crates(cstore: &CStore) {
info!("resolved crates:");
cstore.iter_crate_data(|_, data| {
info!(" name: {}", data.name());
info!(" name: {}", data.root.name);
info!(" cnum: {}", data.cnum);
info!(" hash: {}", data.hash());
info!(" hash: {}", data.root.hash);
info!(" reqd: {:?}", *data.dep_kind.lock());
let CrateSource { dylib, rlib, rmeta } = data.source.clone();
dylib.map(|dl| info!(" dylib: {}", dl.0.display()));
Expand Down Expand Up @@ -113,7 +113,7 @@ impl<'a> CrateLoader<'a> {
if data.name != name { return }

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,
None => {}
}
Expand Down Expand Up @@ -172,9 +172,9 @@ impl<'a> CrateLoader<'a> {

// Check for conflicts with any crate loaded so far
self.cstore.iter_crate_data(|_, other| {
if other.name() == root.name && // same crate-name
other.disambiguator() == root.disambiguator && // same crate-disambiguator
other.hash() != root.hash { // but different SVH
if other.root.name == root.name && // same crate-name
other.root.disambiguator == root.disambiguator && // same crate-disambiguator
other.root.hash != root.hash { // but different SVH
span_fatal!(self.sess, span, E0523,
"found two different crates with name `{}` that are \
not distinguished by differing `-C metadata`. This \
Expand Down Expand Up @@ -214,7 +214,6 @@ impl<'a> CrateLoader<'a> {
let root = if root.is_some() { root } else { &crate_paths };

let Library { dylib, rlib, rmeta, metadata } = lib;

let cnum_map = self.resolve_crate_deps(root, &crate_root, &metadata, cnum, span, dep_kind);

let dependencies: Vec<CrateNum> = cnum_map.iter().cloned().collect();
Expand Down Expand Up @@ -243,13 +242,12 @@ impl<'a> CrateLoader<'a> {
cnum,
dependencies: Lock::new(dependencies),
codemap_import_info: RwLock::new(vec![]),
attribute_cache: Lock::new([Vec::new(), Vec::new()]),
dep_kind: Lock::new(dep_kind),
source: cstore::CrateSource {
dylib,
rlib,
rmeta,
},
}
};

let cmeta = Lrc::new(cmeta);
Expand Down Expand Up @@ -345,7 +343,7 @@ impl<'a> CrateLoader<'a> {
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() {
if data.root.name == root.name && root.hash == data.root.hash {
assert!(locate_ctxt.hash.is_none());
info!("load success, going to previous cnum: {}", cnum);
result = LoadResult::Previous(cnum);
Expand Down Expand Up @@ -642,15 +640,14 @@ impl<'a> CrateLoader<'a> {
let mut needs_panic_runtime = attr::contains_name(&krate.attrs,
"needs_panic_runtime");

let sess = self.sess;
self.cstore.iter_crate_data(|cnum, data| {
needs_panic_runtime = needs_panic_runtime ||
data.needs_panic_runtime(sess);
if data.is_panic_runtime(sess) {
data.root.needs_panic_runtime;
if data.root.panic_runtime {
// Inject a dependency from all #![needs_panic_runtime] to this
// #![panic_runtime] crate.
self.inject_dependency_if(cnum, "a panic runtime",
&|data| data.needs_panic_runtime(sess));
&|data| data.root.needs_panic_runtime);
runtime_found = runtime_found || *data.dep_kind.lock() == DepKind::Explicit;
}
});
Expand Down Expand Up @@ -687,19 +684,19 @@ impl<'a> CrateLoader<'a> {

// Sanity check the loaded crate to ensure it is indeed a panic runtime
// and the panic strategy is indeed what we thought it was.
if !data.is_panic_runtime(self.sess) {
if !data.root.panic_runtime {
self.sess.err(&format!("the crate `{}` is not a panic runtime",
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 \
strategy `{}`",
name, desired_strategy.desc()));
}

self.sess.injected_panic_runtime.set(Some(cnum));
self.inject_dependency_if(cnum, "a panic runtime",
&|data| data.needs_panic_runtime(self.sess));
&|data| data.root.needs_panic_runtime);
}

fn inject_sanitizer_runtime(&mut self) {
Expand Down Expand Up @@ -794,7 +791,7 @@ impl<'a> CrateLoader<'a> {
PathKind::Crate, dep_kind);

// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
if !data.is_sanitizer_runtime(self.sess) {
if !data.root.sanitizer_runtime {
self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
name));
}
Expand All @@ -817,7 +814,7 @@ impl<'a> CrateLoader<'a> {
PathKind::Crate, dep_kind);

// Sanity check the loaded crate to ensure it is indeed a profiler runtime
if !data.is_profiler_runtime(self.sess) {
if !data.root.profiler_runtime {
self.sess.err(&format!("the crate `profiler_builtins` is not \
a profiler runtime"));
}
Expand All @@ -834,7 +831,7 @@ impl<'a> CrateLoader<'a> {
let mut needs_allocator = attr::contains_name(&krate.attrs,
"needs_allocator");
self.cstore.iter_crate_data(|_, data| {
needs_allocator = needs_allocator || data.needs_allocator(self.sess);
needs_allocator = needs_allocator || data.root.needs_allocator;
});
if !needs_allocator {
self.sess.injected_allocator.set(None);
Expand Down Expand Up @@ -876,7 +873,7 @@ impl<'a> CrateLoader<'a> {
None
};
self.cstore.iter_crate_data(|_, data| {
if !data.has_global_allocator() {
if !data.root.has_global_allocator {
return
}
match global_allocator {
Expand All @@ -885,14 +882,14 @@ impl<'a> CrateLoader<'a> {
conflicts with this global \
allocator in: {}",
other_crate,
data.name()));
data.root.name));
}
Some(None) => {
self.sess.err(&format!("the #[global_allocator] in this \
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() {
Expand Down Expand Up @@ -954,7 +951,7 @@ impl<'a> CrateLoader<'a> {
// error.
let mut allocator = None;
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());
}
});
Expand Down Expand Up @@ -1030,9 +1027,9 @@ impl<'a> CrateLoader<'a> {
self.sess.err(&format!("the crate `{}` cannot depend \
on a crate that needs {}, but \
it depends on `{}`",
self.cstore.get_crate_data(krate).name(),
self.cstore.get_crate_data(krate).root.name,
what,
data.name()));
data.root.name));
}
}

Expand Down
72 changes: 2 additions & 70 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@

use schema;

use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex};
use rustc::hir::def_id::{CrateNum, DefIndex};
use rustc::hir::map::definitions::DefPathTable;
use rustc::hir::svh::Svh;
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
use rustc::session::{Session, CrateDisambiguator};
use rustc_target::spec::PanicStrategy;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc::util::nodemap::{FxHashMap, NodeMap};

use rustc_data_structures::sync::{Lrc, RwLock, Lock};
use syntax::{ast, attr};
use syntax::edition::Edition;
use syntax::ast;
use syntax::ext::base::SyntaxExtension;
use syntax::symbol::Symbol;
use syntax_pos;
Expand Down Expand Up @@ -69,7 +65,6 @@ pub struct CrateMetadata {
pub cnum: CrateNum,
pub dependencies: Lock<Vec<CrateNum>>,
pub codemap_import_info: RwLock<Vec<ImportedFileMap>>,
pub attribute_cache: Lock<[Vec<Option<Lrc<[ast::Attribute]>>>; 2]>,

pub root: schema::CrateRoot,

Expand Down Expand Up @@ -177,66 +172,3 @@ impl CStore {
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, sess: &Session) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
attr::contains_name(&attrs, "needs_allocator")
}

pub fn has_global_allocator(&self) -> bool {
self.root.has_global_allocator.clone()
}

pub fn has_default_lib_allocator(&self) -> bool {
self.root.has_default_lib_allocator.clone()
}

pub fn is_panic_runtime(&self, sess: &Session) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
attr::contains_name(&attrs, "panic_runtime")
}

pub fn needs_panic_runtime(&self, sess: &Session) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
attr::contains_name(&attrs, "needs_panic_runtime")
}

pub fn is_compiler_builtins(&self, sess: &Session) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
attr::contains_name(&attrs, "compiler_builtins")
}

pub fn is_sanitizer_runtime(&self, sess: &Session) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
attr::contains_name(&attrs, "sanitizer_runtime")
}

pub fn is_profiler_runtime(&self, sess: &Session) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
attr::contains_name(&attrs, "profiler_runtime")
}

pub fn is_no_builtins(&self, sess: &Session) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
attr::contains_name(&attrs, "no_builtins")
}

pub fn panic_strategy(&self) -> PanicStrategy {
self.root.panic_strategy.clone()
}

pub fn edition(&self) -> Edition {
self.root.edition
}
}
28 changes: 14 additions & 14 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,17 @@ provide! { <'tcx> tcx, def_id, other, cdata,
is_mir_available => { cdata.is_item_mir_available(def_id.index) }

dylib_dependency_formats => { Lrc::new(cdata.get_dylib_dependency_formats()) }
is_panic_runtime => { cdata.is_panic_runtime(tcx.sess) }
is_compiler_builtins => { cdata.is_compiler_builtins(tcx.sess) }
has_global_allocator => { cdata.has_global_allocator() }
is_sanitizer_runtime => { cdata.is_sanitizer_runtime(tcx.sess) }
is_profiler_runtime => { cdata.is_profiler_runtime(tcx.sess) }
panic_strategy => { cdata.panic_strategy() }
is_panic_runtime => { cdata.root.panic_runtime }
is_compiler_builtins => { cdata.root.compiler_builtins }
has_global_allocator => { cdata.root.has_global_allocator }
is_sanitizer_runtime => { cdata.root.sanitizer_runtime }
is_profiler_runtime => { cdata.root.profiler_runtime }
panic_strategy => { cdata.root.panic_strategy }
extern_crate => {
let r = Lrc::new(*cdata.extern_crate.lock());
r
}
is_no_builtins => { cdata.is_no_builtins(tcx.sess) }
is_no_builtins => { cdata.root.no_builtins }
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
reachable_non_generics => {
let reachable_non_generics = tcx
Expand Down Expand Up @@ -209,9 +209,9 @@ provide! { <'tcx> tcx, def_id, other, cdata,
DefId { krate: def_id.krate, index }
})
}
crate_disambiguator => { cdata.disambiguator() }
crate_hash => { cdata.hash() }
original_crate_name => { cdata.name() }
crate_disambiguator => { cdata.root.disambiguator }
crate_hash => { cdata.root.hash }
original_crate_name => { cdata.root.name }

extra_filename => { cdata.root.extra_filename.clone() }

Expand Down Expand Up @@ -457,17 +457,17 @@ impl CrateStore for cstore::CStore {

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
{
self.get_crate_data(cnum).hash()
self.get_crate_data(cnum).root.hash
}

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
Expand Down Expand Up @@ -519,7 +519,7 @@ impl CrateStore for cstore::CStore {
} else if data.name == "proc_macro" &&
self.get_crate_data(id.krate).item_name(id.index) == "quote" {
let ext = SyntaxExtension::ProcMacro(Box::new(::proc_macro::__internal::Quoter),
data.edition());
data.root.edition);
return LoadedMacro::ProcMacro(Lrc::new(ext));
}

Expand Down
Loading