Attempt to pass CrateMetadata flags on creation
This commit is contained in:
parent
466fc6815d
commit
ece778e2a3
3 changed files with 39 additions and 60 deletions
|
@ -11,6 +11,7 @@
|
||||||
//! Validates all used crates and extern libraries and loads their metadata
|
//! Validates all used crates and extern libraries and loads their metadata
|
||||||
|
|
||||||
use cstore::{self, CStore, CrateSource, MetadataBlob};
|
use cstore::{self, CStore, CrateSource, MetadataBlob};
|
||||||
|
use decoder::Metadata;
|
||||||
use locator::{self, CratePaths};
|
use locator::{self, CratePaths};
|
||||||
use schema::CrateRoot;
|
use schema::CrateRoot;
|
||||||
use rustc_data_structures::sync::{Lrc, RwLock, Lock};
|
use rustc_data_structures::sync::{Lrc, RwLock, Lock};
|
||||||
|
@ -222,13 +223,24 @@ impl<'a> CrateLoader<'a> {
|
||||||
crate_root.def_path_table.decode((&metadata, self.sess))
|
crate_root.def_path_table.decode((&metadata, self.sess))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let crate_entry = crate_root
|
||||||
|
.index
|
||||||
|
.lookup(metadata.raw_bytes(), CRATE_DEF_INDEX)
|
||||||
|
.unwrap()
|
||||||
|
.decode(&metadata);
|
||||||
|
|
||||||
|
let crate_attrs: Vec<ast::Attribute> = crate_entry
|
||||||
|
.attributes
|
||||||
|
.decode((&metadata, self.sess))
|
||||||
|
.collect();
|
||||||
|
|
||||||
let trait_impls = crate_root
|
let trait_impls = crate_root
|
||||||
.impls
|
.impls
|
||||||
.decode((&metadata, self.sess))
|
.decode((&metadata, self.sess))
|
||||||
.map(|trait_impls| (trait_impls.trait_id, trait_impls.impls))
|
.map(|trait_impls| (trait_impls.trait_id, trait_impls.impls))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut cmeta = cstore::CrateMetadata {
|
let cmeta = cstore::CrateMetadata {
|
||||||
name,
|
name,
|
||||||
extern_crate: Lock::new(None),
|
extern_crate: Lock::new(None),
|
||||||
def_path_table: Lrc::new(def_path_table),
|
def_path_table: Lrc::new(def_path_table),
|
||||||
|
@ -248,17 +260,15 @@ impl<'a> CrateLoader<'a> {
|
||||||
rlib,
|
rlib,
|
||||||
rmeta,
|
rmeta,
|
||||||
},
|
},
|
||||||
compiler_builtins: None,
|
compiler_builtins: attr::contains_name(&crate_attrs, "compiler_builtins"),
|
||||||
needs_allocator: None,
|
needs_allocator: attr::contains_name(&crate_attrs, "needs_allocator"),
|
||||||
needs_panic_runtime: None,
|
needs_panic_runtime: attr::contains_name(&crate_attrs, "needs_panic_runtime"),
|
||||||
no_builtins: None,
|
no_builtins: attr::contains_name(&crate_attrs, "no_builtins"),
|
||||||
panic_runtime: None,
|
panic_runtime: attr::contains_name(&crate_attrs, "panic_runtime"),
|
||||||
profiler_runtime: None,
|
profiler_runtime: attr::contains_name(&crate_attrs, "profiler_runtime"),
|
||||||
sanitizer_runtime: None,
|
sanitizer_runtime: attr::contains_name(&crate_attrs, "sanitizer_runtime"),
|
||||||
};
|
};
|
||||||
|
|
||||||
cmeta.derive_attributes(self.sess);
|
|
||||||
|
|
||||||
let cmeta = Lrc::new(cmeta);
|
let cmeta = Lrc::new(cmeta);
|
||||||
self.cstore.set_crate_data(cnum, cmeta.clone());
|
self.cstore.set_crate_data(cnum, cmeta.clone());
|
||||||
(cnum, cmeta)
|
(cnum, cmeta)
|
||||||
|
@ -651,12 +661,12 @@ impl<'a> CrateLoader<'a> {
|
||||||
|
|
||||||
self.cstore.iter_crate_data(|cnum, data| {
|
self.cstore.iter_crate_data(|cnum, data| {
|
||||||
needs_panic_runtime = needs_panic_runtime ||
|
needs_panic_runtime = needs_panic_runtime ||
|
||||||
data.needs_panic_runtime();
|
data.needs_panic_runtime;
|
||||||
if data.is_panic_runtime() {
|
if data.panic_runtime {
|
||||||
// Inject a dependency from all #![needs_panic_runtime] to this
|
// Inject a dependency from all #![needs_panic_runtime] to this
|
||||||
// #![panic_runtime] crate.
|
// #![panic_runtime] crate.
|
||||||
self.inject_dependency_if(cnum, "a panic runtime",
|
self.inject_dependency_if(cnum, "a panic runtime",
|
||||||
&|data| data.needs_panic_runtime());
|
&|data| data.needs_panic_runtime);
|
||||||
runtime_found = runtime_found || *data.dep_kind.lock() == DepKind::Explicit;
|
runtime_found = runtime_found || *data.dep_kind.lock() == DepKind::Explicit;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -693,7 +703,7 @@ impl<'a> CrateLoader<'a> {
|
||||||
|
|
||||||
// Sanity check the loaded crate to ensure it is indeed a panic runtime
|
// Sanity check the loaded crate to ensure it is indeed a panic runtime
|
||||||
// and the panic strategy is indeed what we thought it was.
|
// and the panic strategy is indeed what we thought it was.
|
||||||
if !data.is_panic_runtime() {
|
if !data.panic_runtime {
|
||||||
self.sess.err(&format!("the crate `{}` is not a panic runtime",
|
self.sess.err(&format!("the crate `{}` is not a panic runtime",
|
||||||
name));
|
name));
|
||||||
}
|
}
|
||||||
|
@ -705,7 +715,7 @@ impl<'a> CrateLoader<'a> {
|
||||||
|
|
||||||
self.sess.injected_panic_runtime.set(Some(cnum));
|
self.sess.injected_panic_runtime.set(Some(cnum));
|
||||||
self.inject_dependency_if(cnum, "a panic runtime",
|
self.inject_dependency_if(cnum, "a panic runtime",
|
||||||
&|data| data.needs_panic_runtime());
|
&|data| data.needs_panic_runtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inject_sanitizer_runtime(&mut self) {
|
fn inject_sanitizer_runtime(&mut self) {
|
||||||
|
@ -800,7 +810,7 @@ impl<'a> CrateLoader<'a> {
|
||||||
PathKind::Crate, dep_kind);
|
PathKind::Crate, dep_kind);
|
||||||
|
|
||||||
// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
|
// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
|
||||||
if !data.is_sanitizer_runtime() {
|
if !data.sanitizer_runtime {
|
||||||
self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
|
self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
|
||||||
name));
|
name));
|
||||||
}
|
}
|
||||||
|
@ -823,7 +833,7 @@ impl<'a> CrateLoader<'a> {
|
||||||
PathKind::Crate, dep_kind);
|
PathKind::Crate, dep_kind);
|
||||||
|
|
||||||
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
|
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
|
||||||
if !data.is_profiler_runtime() {
|
if !data.profiler_runtime {
|
||||||
self.sess.err(&format!("the crate `profiler_builtins` is not \
|
self.sess.err(&format!("the crate `profiler_builtins` is not \
|
||||||
a profiler runtime"));
|
a profiler runtime"));
|
||||||
}
|
}
|
||||||
|
@ -840,7 +850,7 @@ impl<'a> CrateLoader<'a> {
|
||||||
let mut needs_allocator = attr::contains_name(&krate.attrs,
|
let mut needs_allocator = attr::contains_name(&krate.attrs,
|
||||||
"needs_allocator");
|
"needs_allocator");
|
||||||
self.cstore.iter_crate_data(|_, data| {
|
self.cstore.iter_crate_data(|_, data| {
|
||||||
needs_allocator = needs_allocator || data.needs_allocator();
|
needs_allocator = needs_allocator || data.needs_allocator;
|
||||||
});
|
});
|
||||||
if !needs_allocator {
|
if !needs_allocator {
|
||||||
self.sess.injected_allocator.set(None);
|
self.sess.injected_allocator.set(None);
|
||||||
|
|
|
@ -13,11 +13,11 @@
|
||||||
|
|
||||||
use schema;
|
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::map::definitions::DefPathTable;
|
||||||
use rustc::hir::svh::Svh;
|
use rustc::hir::svh::Svh;
|
||||||
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
|
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
|
||||||
use rustc::session::{CrateDisambiguator, Session};
|
use rustc::session::CrateDisambiguator;
|
||||||
use rustc_target::spec::PanicStrategy;
|
use rustc_target::spec::PanicStrategy;
|
||||||
use rustc_data_structures::indexed_vec::IndexVec;
|
use rustc_data_structures::indexed_vec::IndexVec;
|
||||||
use rustc::util::nodemap::{FxHashMap, NodeMap};
|
use rustc::util::nodemap::{FxHashMap, NodeMap};
|
||||||
|
@ -87,13 +87,13 @@ pub struct CrateMetadata {
|
||||||
pub proc_macros: Option<Vec<(ast::Name, Lrc<SyntaxExtension>)>>,
|
pub proc_macros: Option<Vec<(ast::Name, Lrc<SyntaxExtension>)>>,
|
||||||
|
|
||||||
// Booleans derived from attributes
|
// Booleans derived from attributes
|
||||||
pub compiler_builtins: Option<bool>,
|
pub compiler_builtins: bool,
|
||||||
pub needs_allocator: Option<bool>,
|
pub needs_allocator: bool,
|
||||||
pub needs_panic_runtime: Option<bool>,
|
pub needs_panic_runtime: bool,
|
||||||
pub no_builtins: Option<bool>,
|
pub no_builtins: bool,
|
||||||
pub panic_runtime: Option<bool>,
|
pub panic_runtime: bool,
|
||||||
pub profiler_runtime: Option<bool>,
|
pub profiler_runtime: bool,
|
||||||
pub sanitizer_runtime: Option<bool>,
|
pub sanitizer_runtime: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CStore {
|
pub struct CStore {
|
||||||
|
@ -190,17 +190,15 @@ impl CrateMetadata {
|
||||||
pub fn name(&self) -> Symbol {
|
pub fn name(&self) -> Symbol {
|
||||||
self.root.name
|
self.root.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash(&self) -> Svh {
|
pub fn hash(&self) -> Svh {
|
||||||
self.root.hash
|
self.root.hash
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disambiguator(&self) -> CrateDisambiguator {
|
pub fn disambiguator(&self) -> CrateDisambiguator {
|
||||||
self.root.disambiguator
|
self.root.disambiguator
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn needs_allocator(&self) -> bool {
|
|
||||||
self.needs_allocator.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_global_allocator(&self) -> bool {
|
pub fn has_global_allocator(&self) -> bool {
|
||||||
self.root.has_global_allocator
|
self.root.has_global_allocator
|
||||||
}
|
}
|
||||||
|
@ -209,30 +207,6 @@ impl CrateMetadata {
|
||||||
self.root.has_default_lib_allocator
|
self.root.has_default_lib_allocator
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_panic_runtime(&self) -> bool {
|
|
||||||
self.panic_runtime.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn needs_panic_runtime(&self) -> bool {
|
|
||||||
self.needs_panic_runtime.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_compiler_builtins(&self) -> bool {
|
|
||||||
self.compiler_builtins.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_sanitizer_runtime(&self) -> bool {
|
|
||||||
self.sanitizer_runtime.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_profiler_runtime(&self) -> bool {
|
|
||||||
self.profiler_runtime.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_no_builtins(&self) -> bool {
|
|
||||||
self.no_builtins.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn panic_strategy(&self) -> PanicStrategy {
|
pub fn panic_strategy(&self) -> PanicStrategy {
|
||||||
self.root.panic_strategy.clone()
|
self.root.panic_strategy.clone()
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,17 +170,12 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||||
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
|
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
|
||||||
|
|
||||||
dylib_dependency_formats => { Lrc::new(cdata.get_dylib_dependency_formats()) }
|
dylib_dependency_formats => { Lrc::new(cdata.get_dylib_dependency_formats()) }
|
||||||
is_panic_runtime => { cdata.is_panic_runtime() }
|
|
||||||
is_compiler_builtins => { cdata.is_compiler_builtins() }
|
|
||||||
has_global_allocator => { cdata.has_global_allocator() }
|
has_global_allocator => { cdata.has_global_allocator() }
|
||||||
is_sanitizer_runtime => { cdata.is_sanitizer_runtime() }
|
|
||||||
is_profiler_runtime => { cdata.is_profiler_runtime() }
|
|
||||||
panic_strategy => { cdata.panic_strategy() }
|
panic_strategy => { cdata.panic_strategy() }
|
||||||
extern_crate => {
|
extern_crate => {
|
||||||
let r = Lrc::new(*cdata.extern_crate.lock());
|
let r = Lrc::new(*cdata.extern_crate.lock());
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
is_no_builtins => { cdata.is_no_builtins() }
|
|
||||||
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
|
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
|
||||||
reachable_non_generics => {
|
reachable_non_generics => {
|
||||||
let reachable_non_generics = tcx
|
let reachable_non_generics = tcx
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue