about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTaylor Cramer <cramertaylorj@gmail.com>2017-04-28 00:50:27 -0700
committerTaylor Cramer <cramertj@google.com>2017-05-01 10:24:04 -0700
commit05b2081e2344cf396427451572f8c3b6e2331f6b (patch)
tree3765577fea5bd617b62ca8c0bc56eaa769dfcf28 /src
parent526d39948af4004bb60c04dc82d60b7b395966bb (diff)
downloadrust-05b2081e2344cf396427451572f8c3b6e2331f6b.tar.gz
rust-05b2081e2344cf396427451572f8c3b6e2331f6b.zip
Queryify item_body_nested_bodies
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/cstore.rs5
-rw-r--r--src/librustc/ty/maps.rs19
-rw-r--r--src/librustc_metadata/cstore_impl.rs12
-rw-r--r--src/librustc_metadata/decoder.rs9
-rw-r--r--src/librustdoc/clean/inline.rs5
5 files changed, 27 insertions, 23 deletions
diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs
index 0b43e65ddbf..d327b3ed9d3 100644
--- a/src/librustc/middle/cstore.rs
+++ b/src/librustc/middle/cstore.rs
@@ -35,7 +35,6 @@ use session::search_paths::PathKind;
 use util::nodemap::{NodeSet, DefIdMap};
 
 use std::any::Any;
-use std::collections::BTreeMap;
 use std::path::PathBuf;
 use std::rc::Rc;
 use syntax::ast;
@@ -250,7 +249,6 @@ pub trait CrateStore {
     // misc. metadata
     fn item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
                            -> &'tcx hir::Body;
-    fn item_body_nested_bodies(&self, def: DefId) -> BTreeMap<hir::BodyId, hir::Body>;
     fn const_is_rvalue_promotable_to_static(&self, def: DefId) -> bool;
 
     fn is_item_mir_available(&self, def: DefId) -> bool;
@@ -401,9 +399,6 @@ impl CrateStore for DummyCrateStore {
                            -> &'tcx hir::Body {
         bug!("item_body")
     }
-    fn item_body_nested_bodies(&self, def: DefId) -> BTreeMap<hir::BodyId, hir::Body> {
-        bug!("item_body_nested_bodies")
-    }
     fn const_is_rvalue_promotable_to_static(&self, def: DefId) -> bool {
         bug!("const_is_rvalue_promotable_to_static")
     }
diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs
index 76398294aca..a7f1c556f03 100644
--- a/src/librustc/ty/maps.rs
+++ b/src/librustc/ty/maps.rs
@@ -24,6 +24,7 @@ use util::nodemap::NodeSet;
 use rustc_data_structures::indexed_vec::IndexVec;
 use std::cell::{RefCell, RefMut};
 use std::mem;
+use std::collections::BTreeMap;
 use std::ops::Deref;
 use std::rc::Rc;
 use syntax_pos::{Span, DUMMY_SP};
@@ -291,10 +292,16 @@ impl<'tcx> QueryDescription for queries::def_span<'tcx> {
     }
 }
 
+impl<'tcx> QueryDescription for queries::item_body_nested_bodies<'tcx> {
+    fn describe(tcx: TyCtxt, def_id: DefId) -> String {
+        format!("nested item bodies of `{}`", tcx.item_path_str(def_id))
+    }
+}
+
 macro_rules! define_maps {
     (<$tcx:tt>
      $($(#[$attr:meta])*
-       [$($pub:tt)*] $name:ident: $node:ident($K:ty) -> $V:ty),*) => {
+       [$($pub:tt)*] $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {
         pub struct Maps<$tcx> {
             providers: IndexVec<CrateNum, Providers<$tcx>>,
             query_stack: RefCell<Vec<(Span, Query<$tcx>)>>,
@@ -577,7 +584,9 @@ define_maps! { <'tcx>
     [] symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
 
     [] describe_def: DescribeDef(DefId) -> Option<Def>,
-    [] def_span: DefSpan(DefId) -> Span
+    [] def_span: DefSpan(DefId) -> Span,
+
+    [] item_body_nested_bodies: metadata_dep_node(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
 }
 
 fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {
@@ -592,6 +601,10 @@ fn reachability_dep_node(_: CrateNum) -> DepNode<DefId> {
     DepNode::Reachability
 }
 
+fn metadata_dep_node(def_id: DefId) -> DepNode<DefId> {
+    DepNode::MetaData(def_id)
+}
+
 fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepNode<DefId> {
     instance.dep_node()
 }
@@ -608,4 +621,4 @@ fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
 
 fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepNode<DefId> {
     DepNode::ConstEval(def_id)
-}
\ No newline at end of file
+}
diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs
index 36b993aad69..067fe246d94 100644
--- a/src/librustc_metadata/cstore_impl.rs
+++ b/src/librustc_metadata/cstore_impl.rs
@@ -115,6 +115,13 @@ provide! { <'tcx> tcx, def_id, cdata
     is_foreign_item => { cdata.is_foreign_item(def_id.index) }
     describe_def => { cdata.get_def(def_id.index) }
     def_span => { cdata.get_span(def_id.index, &tcx.sess) }
+    item_body_nested_bodies => {
+        let map: BTreeMap<_, _> = cdata.entry(def_id.index).ast.into_iter().flat_map(|ast| {
+            ast.decode(cdata).nested_bodies.decode(cdata).map(|body| (body.id(), body))
+        }).collect();
+
+        Rc::new(map)
+    }
 }
 
 impl CrateStore for cstore::CStore {
@@ -432,11 +439,6 @@ impl CrateStore for cstore::CStore {
         self.get_crate_data(def_id.krate).item_body(tcx, def_id.index)
     }
 
-    fn item_body_nested_bodies(&self, def: DefId) -> BTreeMap<hir::BodyId, hir::Body> {
-        self.dep_graph.read(DepNode::MetaData(def));
-        self.get_crate_data(def.krate).item_body_nested_bodies(def.index)
-    }
-
     fn const_is_rvalue_promotable_to_static(&self, def: DefId) -> bool {
         self.dep_graph.read(DepNode::MetaData(def));
         self.get_crate_data(def.krate).const_is_rvalue_promotable_to_static(def.index)
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index 28fea2eec60..9da9829b61d 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -28,7 +28,6 @@ use rustc::mir::Mir;
 
 use std::borrow::Cow;
 use std::cell::Ref;
-use std::collections::BTreeMap;
 use std::io;
 use std::mem;
 use std::rc::Rc;
@@ -451,7 +450,7 @@ impl<'a, 'tcx> CrateMetadata {
         self.root.index.lookup(self.blob.raw_bytes(), item_id)
     }
 
-    fn entry(&self, item_id: DefIndex) -> Entry<'tcx> {
+    pub fn entry(&self, item_id: DefIndex) -> Entry<'tcx> {
         match self.maybe_entry(item_id) {
             None => {
                 bug!("entry: id not found: {:?} in crate {:?} with number {}",
@@ -773,12 +772,6 @@ impl<'a, 'tcx> CrateMetadata {
         tcx.alloc_tables(ast.tables.decode((self, tcx)))
     }
 
-    pub fn item_body_nested_bodies(&self, id: DefIndex) -> BTreeMap<hir::BodyId, hir::Body> {
-        self.entry(id).ast.into_iter().flat_map(|ast| {
-            ast.decode(self).nested_bodies.decode(self).map(|body| (body.id(), body))
-        }).collect()
-    }
-
     pub fn const_is_rvalue_promotable_to_static(&self, id: DefIndex) -> bool {
         self.entry(id).ast.expect("const item missing `ast`")
             .decode(self).rvalue_promotable_to_static
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs
index 71bb53e9b81..9dea0e3d830 100644
--- a/src/librustdoc/clean/inline.rs
+++ b/src/librustdoc/clean/inline.rs
@@ -13,6 +13,7 @@
 use std::collections::BTreeMap;
 use std::io;
 use std::iter::once;
+use std::rc::Rc;
 
 use syntax::ast;
 use rustc::hir;
@@ -471,7 +472,7 @@ fn build_module(cx: &DocContext, did: DefId) -> clean::Module {
 }
 
 struct InlinedConst {
-    nested_bodies: BTreeMap<hir::BodyId, hir::Body>
+    nested_bodies: Rc<BTreeMap<hir::BodyId, hir::Body>>
 }
 
 impl hir::print::PpAnn for InlinedConst {
@@ -488,7 +489,7 @@ impl hir::print::PpAnn for InlinedConst {
 fn print_inlined_const(cx: &DocContext, did: DefId) -> String {
     let body = cx.tcx.sess.cstore.item_body(cx.tcx, did);
     let inlined = InlinedConst {
-        nested_bodies: cx.tcx.sess.cstore.item_body_nested_bodies(did)
+        nested_bodies: cx.tcx.item_body_nested_bodies(did)
     };
     hir::print::to_string(&inlined, |s| s.print_expr(&body.value))
 }