about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorIsaac Whitfield <iw@whitfin.io>2018-05-10 08:38:21 -0700
committerIsaac Whitfield <iw@whitfin.io>2018-05-18 09:37:29 -0700
commitece778e2a30bcfbc1b571874c5e2f2a4ca045bf6 (patch)
treeec4debec5b60d707afcc2409b6b9588a65733f71 /src
parent466fc6815d23dc201e26aa3210f3476443805e80 (diff)
downloadrust-ece778e2a30bcfbc1b571874c5e2f2a4ca045bf6.tar.gz
rust-ece778e2a30bcfbc1b571874c5e2f2a4ca045bf6.zip
Attempt to pass CrateMetadata flags on creation
Diffstat (limited to 'src')
-rw-r--r--src/librustc_metadata/creader.rs46
-rw-r--r--src/librustc_metadata/cstore.rs48
-rw-r--r--src/librustc_metadata/cstore_impl.rs5
3 files changed, 39 insertions, 60 deletions
diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs
index 796048b58d1..cc2c0e2502a 100644
--- a/src/librustc_metadata/creader.rs
+++ b/src/librustc_metadata/creader.rs
@@ -11,6 +11,7 @@
 //! Validates all used crates and extern libraries and loads their metadata
 
 use cstore::{self, CStore, CrateSource, MetadataBlob};
+use decoder::Metadata;
 use locator::{self, CratePaths};
 use schema::CrateRoot;
 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))
         });
 
+        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
             .impls
             .decode((&metadata, self.sess))
             .map(|trait_impls| (trait_impls.trait_id, trait_impls.impls))
             .collect();
 
-        let mut cmeta = cstore::CrateMetadata {
+        let cmeta = cstore::CrateMetadata {
             name,
             extern_crate: Lock::new(None),
             def_path_table: Lrc::new(def_path_table),
@@ -248,17 +260,15 @@ impl<'a> CrateLoader<'a> {
                 rlib,
                 rmeta,
             },
-            compiler_builtins: None,
-            needs_allocator: None,
-            needs_panic_runtime: None,
-            no_builtins: None,
-            panic_runtime: None,
-            profiler_runtime: None,
-            sanitizer_runtime: None,
+            compiler_builtins: attr::contains_name(&crate_attrs, "compiler_builtins"),
+            needs_allocator: attr::contains_name(&crate_attrs, "needs_allocator"),
+            needs_panic_runtime: attr::contains_name(&crate_attrs, "needs_panic_runtime"),
+            no_builtins: attr::contains_name(&crate_attrs, "no_builtins"),
+            panic_runtime: attr::contains_name(&crate_attrs, "panic_runtime"),
+            profiler_runtime: attr::contains_name(&crate_attrs, "profiler_runtime"),
+            sanitizer_runtime: attr::contains_name(&crate_attrs, "sanitizer_runtime"),
         };
 
-        cmeta.derive_attributes(self.sess);
-
         let cmeta = Lrc::new(cmeta);
         self.cstore.set_crate_data(cnum, cmeta.clone());
         (cnum, cmeta)
@@ -651,12 +661,12 @@ impl<'a> CrateLoader<'a> {
 
         self.cstore.iter_crate_data(|cnum, data| {
             needs_panic_runtime = needs_panic_runtime ||
-                                  data.needs_panic_runtime();
-            if data.is_panic_runtime() {
+                                  data.needs_panic_runtime;
+            if data.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());
+                                          &|data| data.needs_panic_runtime);
                 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
         // 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",
                                    name));
         }
@@ -705,7 +715,7 @@ impl<'a> CrateLoader<'a> {
 
         self.sess.injected_panic_runtime.set(Some(cnum));
         self.inject_dependency_if(cnum, "a panic runtime",
-                                  &|data| data.needs_panic_runtime());
+                                  &|data| data.needs_panic_runtime);
     }
 
     fn inject_sanitizer_runtime(&mut self) {
@@ -800,7 +810,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() {
+                if !data.sanitizer_runtime {
                     self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
                                            name));
                 }
@@ -823,7 +833,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() {
+            if !data.profiler_runtime {
                 self.sess.err(&format!("the crate `profiler_builtins` is not \
                                         a profiler runtime"));
             }
@@ -840,7 +850,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();
+            needs_allocator = needs_allocator || data.needs_allocator;
         });
         if !needs_allocator {
             self.sess.injected_allocator.set(None);
diff --git a/src/librustc_metadata/cstore.rs b/src/librustc_metadata/cstore.rs
index 4650c64543f..132e1e23fc4 100644
--- a/src/librustc_metadata/cstore.rs
+++ b/src/librustc_metadata/cstore.rs
@@ -13,11 +13,11 @@
 
 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::{CrateDisambiguator, Session};
+use rustc::session::CrateDisambiguator;
 use rustc_target::spec::PanicStrategy;
 use rustc_data_structures::indexed_vec::IndexVec;
 use rustc::util::nodemap::{FxHashMap, NodeMap};
@@ -87,13 +87,13 @@ pub struct CrateMetadata {
     pub proc_macros: Option<Vec<(ast::Name, Lrc<SyntaxExtension>)>>,
 
     // Booleans derived from attributes
-    pub compiler_builtins: Option<bool>,
-    pub needs_allocator: Option<bool>,
-    pub needs_panic_runtime: Option<bool>,
-    pub no_builtins: Option<bool>,
-    pub panic_runtime: Option<bool>,
-    pub profiler_runtime: Option<bool>,
-    pub sanitizer_runtime: Option<bool>,
+    pub compiler_builtins: bool,
+    pub needs_allocator: bool,
+    pub needs_panic_runtime: bool,
+    pub no_builtins: bool,
+    pub panic_runtime: bool,
+    pub profiler_runtime: bool,
+    pub sanitizer_runtime: bool,
 }
 
 pub struct CStore {
@@ -190,17 +190,15 @@ 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) -> bool {
-        self.needs_allocator.unwrap_or(false)
-    }
-
     pub fn has_global_allocator(&self) -> bool {
         self.root.has_global_allocator
     }
@@ -209,30 +207,6 @@ impl CrateMetadata {
         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 {
         self.root.panic_strategy.clone()
     }
diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs
index 6bb6b1a1747..ac61840661b 100644
--- a/src/librustc_metadata/cstore_impl.rs
+++ b/src/librustc_metadata/cstore_impl.rs
@@ -170,17 +170,12 @@ 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() }
-    is_compiler_builtins => { cdata.is_compiler_builtins() }
     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() }
     extern_crate => {
         let r = Lrc::new(*cdata.extern_crate.lock());
         r
     }
-    is_no_builtins => { cdata.is_no_builtins() }
     impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
     reachable_non_generics => {
         let reachable_non_generics = tcx