about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIsaac Whitfield <iw@whitfin.io>2018-05-12 10:20:53 -0700
committerIsaac Whitfield <iw@whitfin.io>2018-05-18 09:37:29 -0700
commit680f3b24ba9b9e6dbf9301fe4af09a12fe8bb9cb (patch)
tree105f3c791d2d02b6f73c73438bc11286b9655208
parentca60c404b622c4e65db2d0171ef45c42635316bf (diff)
downloadrust-680f3b24ba9b9e6dbf9301fe4af09a12fe8bb9cb.tar.gz
rust-680f3b24ba9b9e6dbf9301fe4af09a12fe8bb9cb.zip
Serialize attributes into the CrateRoot
-rw-r--r--src/librustc_incremental/persist/dirty_clean.rs22
-rw-r--r--src/librustc_incremental/persist/work_product.rs2
-rw-r--r--src/librustc_metadata/creader.rs37
-rw-r--r--src/librustc_metadata/cstore.rs37
-rw-r--r--src/librustc_metadata/cstore_impl.rs10
-rw-r--r--src/librustc_metadata/decoder.rs16
-rw-r--r--src/librustc_metadata/encoder.rs12
-rw-r--r--src/librustc_metadata/schema.rs8
8 files changed, 80 insertions, 64 deletions
diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs
index 8f406161831..1549ef5e928 100644
--- a/src/librustc_incremental/persist/dirty_clean.rs
+++ b/src/librustc_incremental/persist/dirty_clean.rs
@@ -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 {
diff --git a/src/librustc_incremental/persist/work_product.rs b/src/librustc_incremental/persist/work_product.rs
index d0c7766cbae..c0ccbd67a31 100644
--- a/src/librustc_incremental/persist/work_product.rs
+++ b/src/librustc_incremental/persist/work_product.rs
@@ -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()
@@ -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))
 }
 
diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs
index cc2c0e2502a..5675396f407 100644
--- a/src/librustc_metadata/creader.rs
+++ b/src/librustc_metadata/creader.rs
@@ -11,7 +11,6 @@
 //! 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};
@@ -223,17 +222,6 @@ 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))
@@ -259,14 +247,7 @@ impl<'a> CrateLoader<'a> {
                 dylib,
                 rlib,
                 rmeta,
-            },
-            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"),
+            }
         };
 
         let cmeta = Lrc::new(cmeta);
@@ -661,12 +642,12 @@ impl<'a> CrateLoader<'a> {
 
         self.cstore.iter_crate_data(|cnum, data| {
             needs_panic_runtime = needs_panic_runtime ||
-                                  data.needs_panic_runtime;
-            if data.panic_runtime {
+                                  data.needs_panic_runtime();
+            if data.is_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;
             }
         });
@@ -703,7 +684,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.panic_runtime {
+        if !data.is_panic_runtime() {
             self.sess.err(&format!("the crate `{}` is not a panic runtime",
                                    name));
         }
@@ -715,7 +696,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) {
@@ -810,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.sanitizer_runtime {
+                if !data.is_sanitizer_runtime() {
                     self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
                                            name));
                 }
@@ -833,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.profiler_runtime {
+            if !data.is_profiler_runtime() {
                 self.sess.err(&format!("the crate `profiler_builtins` is not \
                                         a profiler runtime"));
             }
@@ -850,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;
+            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 e8b95bc5440..c267ce9ed21 100644
--- a/src/librustc_metadata/cstore.rs
+++ b/src/librustc_metadata/cstore.rs
@@ -85,15 +85,6 @@ pub struct CrateMetadata {
     pub source: CrateSource,
 
     pub proc_macros: Option<Vec<(ast::Name, Lrc<SyntaxExtension>)>>,
-
-    // Booleans derived from attributes
-    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 {
@@ -199,6 +190,10 @@ impl CrateMetadata {
         self.root.disambiguator
     }
 
+    pub fn needs_allocator(&self) -> bool {
+        self.root.needs_allocator
+    }
+
     pub fn has_global_allocator(&self) -> bool {
         self.root.has_global_allocator
     }
@@ -207,6 +202,30 @@ impl CrateMetadata {
         self.root.has_default_lib_allocator
     }
 
+    pub fn is_panic_runtime(&self) -> bool {
+        self.root.panic_runtime
+    }
+
+    pub fn needs_panic_runtime(&self) -> bool {
+        self.root.needs_panic_runtime
+    }
+
+    pub fn is_compiler_builtins(&self) -> bool {
+        self.root.compiler_builtins
+    }
+
+    pub fn is_sanitizer_runtime(&self) -> bool {
+        self.root.sanitizer_runtime
+    }
+
+    pub fn is_profiler_runtime(&self) -> bool {
+        self.root.profiler_runtime
+    }
+
+    pub fn is_no_builtins(&self) -> bool {
+        self.root.no_builtins
+    }
+
     pub fn panic_strategy(&self) -> PanicStrategy {
         self.root.panic_strategy
     }
diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs
index fedcfe6eb25..6bb6b1a1747 100644
--- a/src/librustc_metadata/cstore_impl.rs
+++ b/src/librustc_metadata/cstore_impl.rs
@@ -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.panic_runtime }
-    is_compiler_builtins => { cdata.compiler_builtins }
+    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.sanitizer_runtime }
-    is_profiler_runtime => { cdata.profiler_runtime }
+    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.no_builtins }
+    is_no_builtins => { cdata.is_no_builtins() }
     impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
     reachable_non_generics => {
         let reachable_non_generics = tcx
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index 9a15b2dce04..8af4649ed5f 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -557,12 +557,14 @@ impl<'a, 'tcx> CrateMetadata {
                        -> &'tcx ty::AdtDef {
         let item = self.entry(item_id);
         let did = self.local_def_id(item_id);
-        let kind = match item.kind {
-            EntryKind::Enum(_) => ty::AdtKind::Enum,
-            EntryKind::Struct(_, _) => ty::AdtKind::Struct,
-            EntryKind::Union(_, _) => ty::AdtKind::Union,
+
+        let (kind, repr) = match item.kind {
+            EntryKind::Enum(repr) => (ty::AdtKind::Enum, repr),
+            EntryKind::Struct(_, repr) => (ty::AdtKind::Struct, repr),
+            EntryKind::Union(_, repr) => (ty::AdtKind::Union, repr),
             _ => bug!("get_adt_def called on a non-ADT {:?}", did),
         };
+
         let variants = if let ty::AdtKind::Enum = kind {
             item.children
                 .decode(self)
@@ -573,12 +575,6 @@ impl<'a, 'tcx> CrateMetadata {
         } else {
             vec![self.get_variant(&item, item_id)]
         };
-        let (kind, repr) = match item.kind {
-            EntryKind::Enum(repr) => (ty::AdtKind::Enum, repr),
-            EntryKind::Struct(_, repr) => (ty::AdtKind::Struct, repr),
-            EntryKind::Union(_, repr) => (ty::AdtKind::Union, repr),
-            _ => bug!("get_adt_def called on a non-ADT {:?}", did),
-        };
 
         tcx.alloc_adt_def(did, kind, variants, repr)
     }
diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs
index d00f4f32c10..a08b6cdfc1d 100644
--- a/src/librustc_metadata/encoder.rs
+++ b/src/librustc_metadata/encoder.rs
@@ -483,10 +483,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
         let index = items.write_index(&mut self.opaque.cursor);
         let index_bytes = self.position() - i;
 
+        let attrs = tcx.hir.krate_attrs();
         let link_meta = self.link_meta;
         let is_proc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeProcMacro);
-        let has_default_lib_allocator =
-            attr::contains_name(tcx.hir.krate_attrs(), "default_lib_allocator");
+        let has_default_lib_allocator = attr::contains_name(&attrs, "default_lib_allocator");
         let has_global_allocator = *tcx.sess.has_global_allocator.get();
 
         let root = self.lazy(&CrateRoot {
@@ -510,6 +510,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
                 None
             },
 
+            compiler_builtins: attr::contains_name(&attrs, "compiler_builtins"),
+            needs_allocator: attr::contains_name(&attrs, "needs_allocator"),
+            needs_panic_runtime: attr::contains_name(&attrs, "needs_panic_runtime"),
+            no_builtins: attr::contains_name(&attrs, "no_builtins"),
+            panic_runtime: attr::contains_name(&attrs, "panic_runtime"),
+            profiler_runtime: attr::contains_name(&attrs, "profiler_runtime"),
+            sanitizer_runtime: attr::contains_name(&attrs, "sanitizer_runtime"),
+
             crate_deps,
             dylib_dependency_formats,
             lang_items,
diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs
index 8e17b7f8d69..2e89ea6d2c1 100644
--- a/src/librustc_metadata/schema.rs
+++ b/src/librustc_metadata/schema.rs
@@ -210,6 +210,14 @@ pub struct CrateRoot {
     pub interpret_alloc_index: LazySeq<u32>,
 
     pub index: LazySeq<index::Index>,
+
+    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,
 }
 
 #[derive(RustcEncodable, RustcDecodable)]