]> git.lizzy.rs Git - rust.git/commitdiff
Remove HIR inlining
authorWesley Wiser <wwiser@gmail.com>
Sun, 15 Apr 2018 23:41:33 +0000 (19:41 -0400)
committerWesley Wiser <wwiser@gmail.com>
Fri, 20 Apr 2018 00:33:18 +0000 (20:33 -0400)
Fixes #49690

15 files changed:
src/librustc/dep_graph/dep_node.rs
src/librustc/hir/map/mod.rs
src/librustc/ich/impls_cstore.rs
src/librustc/middle/cstore.rs
src/librustc/ty/maps/config.rs
src/librustc/ty/maps/mod.rs
src/librustc/ty/maps/plumbing.rs
src/librustc_metadata/astencode.rs [deleted file]
src/librustc_metadata/cstore_impl.rs
src/librustc_metadata/decoder.rs
src/librustc_metadata/encoder.rs
src/librustc_metadata/isolated_encoder.rs
src/librustc_metadata/lib.rs
src/librustc_metadata/schema.rs
src/librustdoc/clean/inline.rs

index 1b90707323850dccd75e9411dd6124a304b84771..b4f39439d5b4d4d93c4b36bee707a1775650bd6a 100644 (file)
@@ -556,7 +556,6 @@ pub fn fingerprint_needed_for_crate_hash(self) -> bool {
     [input] DefSpan(DefId),
     [] LookupStability(DefId),
     [] LookupDeprecationEntry(DefId),
-    [] ItemBodyNestedBodies(DefId),
     [] ConstIsRvaluePromotableToStatic(DefId),
     [] RvaluePromotableMap(DefId),
     [] ImplParent(DefId),
@@ -567,6 +566,7 @@ pub fn fingerprint_needed_for_crate_hash(self) -> bool {
     [] ItemAttrs(DefId),
     [] TransFnAttrs(DefId),
     [] FnArgNames(DefId),
+    [] RenderedConst(DefId),
     [] DylibDepFormats(CrateNum),
     [] IsPanicRuntime(CrateNum),
     [] IsCompilerBuiltins(CrateNum),
@@ -615,7 +615,6 @@ pub fn fingerprint_needed_for_crate_hash(self) -> bool {
     [input] GetLangItems,
     [] DefinedLangItems(CrateNum),
     [] MissingLangItems(CrateNum),
-    [] ExternConstBody(DefId),
     [] VisibleParentMap,
     [input] MissingExternCrateItem(CrateNum),
     [input] UsedCrateSource(CrateNum),
index b88185c3154a9fea222d470159aa1afd4ee2dc17..9520ed32af9e1a4b7d9c96c88d5e0306db44157e 100644 (file)
 use hir::*;
 use hir::print::Nested;
 use hir::svh::Svh;
-use util::nodemap::{DefIdMap, FxHashMap};
+use util::nodemap::FxHashMap;
 
-use arena::SyncTypedArena;
 use std::io;
 use ty::TyCtxt;
 
-use rustc_data_structures::sync::Lock;
-
 pub mod blocks;
 mod collector;
 mod def_collector;
@@ -219,7 +216,6 @@ fn is_body_owner(self, node_id: NodeId) -> bool {
 pub struct Forest {
     krate: Crate,
     pub dep_graph: DepGraph,
-    inlined_bodies: SyncTypedArena<Body>
 }
 
 impl Forest {
@@ -227,7 +223,6 @@ pub fn new(krate: Crate, dep_graph: &DepGraph) -> Forest {
         Forest {
             krate,
             dep_graph: dep_graph.clone(),
-            inlined_bodies: SyncTypedArena::new()
         }
     }
 
@@ -264,9 +259,6 @@ pub struct Map<'hir> {
 
     definitions: &'hir Definitions,
 
-    /// Bodies inlined from other crates are cached here.
-    inlined_bodies: Lock<DefIdMap<&'hir Body>>,
-
     /// The reverse mapping of `node_to_hir_id`.
     hir_to_node_id: FxHashMap<HirId, NodeId>,
 }
@@ -923,21 +915,6 @@ pub fn expect_expr(&self, id: NodeId) -> &'hir Expr {
         }
     }
 
-    pub fn get_inlined_body_untracked(&self, def_id: DefId) -> Option<&'hir Body> {
-        self.inlined_bodies.borrow().get(&def_id).cloned()
-    }
-
-    pub fn intern_inlined_body(&self, def_id: DefId, body: Body) -> &'hir Body {
-        let mut inlined_bodies = self.inlined_bodies.borrow_mut();
-        if let Some(&b) = inlined_bodies.get(&def_id) {
-            debug_assert_eq!(&body, b);
-            return b;
-        }
-        let body = self.forest.inlined_bodies.alloc(body);
-        inlined_bodies.insert(def_id, body);
-        body
-    }
-
     /// Returns the name associated with the given NodeId's AST.
     pub fn name(&self, id: NodeId) -> Name {
         match self.get(id) {
@@ -1195,7 +1172,6 @@ pub fn map_crate<'hir>(sess: &::session::Session,
         map,
         hir_to_node_id,
         definitions,
-        inlined_bodies: Lock::new(DefIdMap()),
     };
 
     hir_id_validator::check_crate(&map);
index d885bd43bc89dbce656a42db81c6e5aa475bf3cb..96d7cb6b041a83508866c568a7a48572a37ecf64 100644 (file)
@@ -11,8 +11,6 @@
 //! This module contains `HashStable` implementations for various data types
 //! from rustc::middle::cstore in no particular order.
 
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
-
 use middle;
 
 impl_stable_hash_for!(enum middle::cstore::DepKind {
     rlib,
     rmeta
 });
-
-impl<HCX> HashStable<HCX> for middle::cstore::ExternBodyNestedBodies {
-    fn hash_stable<W: StableHasherResult>(&self,
-                                          hcx: &mut HCX,
-                                          hasher: &mut StableHasher<W>) {
-        let middle::cstore::ExternBodyNestedBodies {
-            nested_bodies: _,
-            fingerprint,
-        } = *self;
-
-        fingerprint.hash_stable(hcx, hasher);
-    }
-}
-
-impl<'a, HCX> HashStable<HCX> for middle::cstore::ExternConstBody<'a> {
-    fn hash_stable<W: StableHasherResult>(&self,
-                                          hcx: &mut HCX,
-                                          hasher: &mut StableHasher<W>) {
-        let middle::cstore::ExternConstBody {
-            body: _,
-            fingerprint,
-        } = *self;
-
-        fingerprint.hash_stable(hcx, hasher);
-    }
-}
index 292ec184dfae5d9ada4e8fa913462ffe6fb8f5be..60e197e614aa6f7e3e98459bb47bbab59d99867f 100644 (file)
 //! are *mostly* used as a part of that interface, but these should
 //! probably get a better home if someone can find one.
 
-use hir;
 use hir::def;
 use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
 use hir::map as hir_map;
 use hir::map::definitions::{Definitions, DefKey, DefPathTable};
 use hir::svh::Svh;
-use ich;
 use ty::{self, TyCtxt};
 use session::{Session, CrateDisambiguator};
 use session::search_paths::PathKind;
 
 use std::any::Any;
-use std::collections::BTreeMap;
 use std::path::{Path, PathBuf};
 use syntax::ast;
 use syntax::ext::base::SyntaxExtension;
@@ -209,26 +206,6 @@ fn get_dylib_metadata(&self,
                           -> Result<MetadataRef, String>;
 }
 
-#[derive(Clone)]
-pub struct ExternConstBody<'tcx> {
-    pub body: &'tcx hir::Body,
-
-    // It would require a lot of infrastructure to enable stable-hashing Bodies
-    // from other crates, so we hash on export and just store the fingerprint
-    // with them.
-    pub fingerprint: ich::Fingerprint,
-}
-
-#[derive(Clone)]
-pub struct ExternBodyNestedBodies {
-    pub nested_bodies: Lrc<BTreeMap<hir::BodyId, hir::Body>>,
-
-    // It would require a lot of infrastructure to enable stable-hashing Bodies
-    // from other crates, so we hash on export and just store the fingerprint
-    // with them.
-    pub fingerprint: ich::Fingerprint,
-}
-
 /// A store of Rust crates, through with their metadata
 /// can be accessed.
 ///
index 664c84f5986608ac2e48b2952da6e788ce9ee4bc..fea7de955e0bfdc72fa713bd0c94a321010ac785 100644 (file)
@@ -283,12 +283,6 @@ fn describe(_: TyCtxt, _: DefId) -> String {
     }
 }
 
-impl<'tcx> QueryDescription<'tcx> 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))
-    }
-}
-
 impl<'tcx> QueryDescription<'tcx> for queries::const_is_rvalue_promotable_to_static<'tcx> {
     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
         format!("const checking if rvalue is promotable to static `{}`",
index 2325b1893d996f85a6df0ff90e6662c23f898a14..0ab9f16dab481064f7b8b6330a2b5be32fb24eb1 100644 (file)
@@ -17,9 +17,8 @@
 use infer::canonical::{self, Canonical};
 use lint;
 use middle::borrowck::BorrowCheckResult;
-use middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary,
-                     ExternBodyNestedBodies, ForeignModule};
-use middle::cstore::{NativeLibraryKind, DepKind, CrateSource, ExternConstBody};
+use middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary, ForeignModule};
+use middle::cstore::{NativeLibraryKind, DepKind, CrateSource};
 use middle::privacy::AccessLevels;
 use middle::reachable::ReachableSet;
 use middle::region;
     [] fn item_attrs: ItemAttrs(DefId) -> Lrc<[ast::Attribute]>,
     [] fn trans_fn_attrs: trans_fn_attrs(DefId) -> TransFnAttrs,
     [] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
+    /// Gets the rendered value of the specified constant or associated constant.
+    /// Used by rustdoc.
+    [] fn rendered_const: RenderedConst(DefId) -> String,
     [] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
     [] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
-    [] fn item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> ExternBodyNestedBodies,
     [] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
     [] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
     [] fn is_mir_available: IsMirAvailable(DefId) -> bool,
     [] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc<LanguageItems>,
     [] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<Vec<(DefId, usize)>>,
     [] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<Vec<LangItem>>,
-    [] fn extern_const_body: ExternConstBody(DefId) -> ExternConstBody<'tcx>,
     [] fn visible_parent_map: visible_parent_map_node(CrateNum)
         -> Lrc<DefIdMap<DefId>>,
     [] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
index 4f6925938c8029ee9d43fc5912b4f497946c7286..8d6c7474a9f94f495569460e2938754f7651caba 100644 (file)
@@ -1048,7 +1048,6 @@ macro_rules! force {
         DepKind::LookupDeprecationEntry => {
             force!(lookup_deprecation_entry, def_id!());
         }
-        DepKind::ItemBodyNestedBodies => { force!(item_body_nested_bodies, def_id!()); }
         DepKind::ConstIsRvaluePromotableToStatic => {
             force!(const_is_rvalue_promotable_to_static, def_id!());
         }
@@ -1063,6 +1062,7 @@ macro_rules! force {
         DepKind::ItemAttrs => { force!(item_attrs, def_id!()); }
         DepKind::TransFnAttrs => { force!(trans_fn_attrs, def_id!()); }
         DepKind::FnArgNames => { force!(fn_arg_names, def_id!()); }
+        DepKind::RenderedConst => { force!(rendered_const, def_id!()); }
         DepKind::DylibDepFormats => { force!(dylib_dependency_formats, krate!()); }
         DepKind::IsPanicRuntime => { force!(is_panic_runtime, krate!()); }
         DepKind::IsCompilerBuiltins => { force!(is_compiler_builtins, krate!()); }
@@ -1119,7 +1119,6 @@ macro_rules! force {
         DepKind::GetLangItems => { force!(get_lang_items, LOCAL_CRATE); }
         DepKind::DefinedLangItems => { force!(defined_lang_items, krate!()); }
         DepKind::MissingLangItems => { force!(missing_lang_items, krate!()); }
-        DepKind::ExternConstBody => { force!(extern_const_body, def_id!()); }
         DepKind::VisibleParentMap => { force!(visible_parent_map, LOCAL_CRATE); }
         DepKind::MissingExternCrateItem => {
             force!(missing_extern_crate_item, krate!());
diff --git a/src/librustc_metadata/astencode.rs b/src/librustc_metadata/astencode.rs
deleted file mode 100644 (file)
index 71b1564..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use rustc::hir::intravisit::{Visitor, NestedVisitorMap};
-
-use isolated_encoder::IsolatedEncoder;
-use schema::*;
-
-use rustc::hir;
-use rustc::ty::{self, TyCtxt};
-
-use rustc::ich::Fingerprint;
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
-
-#[derive(RustcEncodable, RustcDecodable)]
-pub struct Ast<'tcx> {
-    pub body: Lazy<hir::Body>,
-    pub tables: Lazy<ty::TypeckTables<'tcx>>,
-    pub nested_bodies: LazySeq<hir::Body>,
-    pub rvalue_promotable_to_static: bool,
-    pub stable_bodies_hash: Fingerprint,
-}
-
-impl_stable_hash_for!(struct Ast<'tcx> {
-    body,
-    tables,
-    nested_bodies,
-    rvalue_promotable_to_static,
-    stable_bodies_hash
-});
-
-impl<'a, 'b, 'tcx> IsolatedEncoder<'a, 'b, 'tcx> {
-    pub fn encode_body(&mut self, body_id: hir::BodyId) -> Lazy<Ast<'tcx>> {
-        let body = self.tcx.hir.body(body_id);
-
-        // In order to avoid having to hash hir::Bodies from extern crates, we
-        // hash them here, during export, and store the hash with metadata.
-        let stable_bodies_hash = {
-            let mut hcx = self.tcx.create_stable_hashing_context();
-            let mut hasher = StableHasher::new();
-
-            hcx.while_hashing_hir_bodies(true, |hcx| {
-                body.hash_stable(hcx, &mut hasher);
-            });
-
-            hasher.finish()
-        };
-
-        let lazy_body = self.lazy(body);
-        let body_owner_def_id = self.tcx.hir.body_owner_def_id(body_id);
-        let tables = self.tcx.typeck_tables_of(body_owner_def_id);
-        let lazy_tables = self.lazy(tables);
-
-        let mut visitor = NestedBodyCollector {
-            tcx: self.tcx,
-            bodies_found: Vec::new(),
-        };
-        visitor.visit_body(body);
-        let lazy_nested_bodies = self.lazy_seq_ref_from_slice(&visitor.bodies_found);
-
-        let rvalue_promotable_to_static =
-            self.tcx.const_is_rvalue_promotable_to_static(body_owner_def_id);
-
-        self.lazy(&Ast {
-            body: lazy_body,
-            tables: lazy_tables,
-            nested_bodies: lazy_nested_bodies,
-            rvalue_promotable_to_static,
-            stable_bodies_hash,
-        })
-    }
-}
-
-struct NestedBodyCollector<'a, 'tcx: 'a> {
-    tcx: TyCtxt<'a, 'tcx, 'tcx>,
-    bodies_found: Vec<&'tcx hir::Body>,
-}
-
-impl<'a, 'tcx: 'a> Visitor<'tcx> for NestedBodyCollector<'a, 'tcx> {
-    fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::None
-    }
-
-    fn visit_nested_body(&mut self, body: hir::BodyId) {
-        let body = self.tcx.hir.body(body);
-        self.bodies_found.push(body);
-        self.visit_body(body);
-    }
-}
index 2c995d2f5cde637be697c85cc20935ab6fb3eb47..a11b95cb5b6c1a02bbb33881587176017807f714 100644 (file)
@@ -142,7 +142,6 @@ fn into_args(self) -> (DefId, DefId) { (self.0.as_def_id(), self.1) }
     mir_const_qualif => {
         (cdata.mir_const_qualif(def_id.index), Lrc::new(IdxSetBuf::new_empty(0)))
     }
-    typeck_tables_of => { cdata.item_body_tables(def_id.index, tcx) }
     fn_sig => { cdata.fn_sig(def_id.index, tcx) }
     inherent_impls => { Lrc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
     is_const_fn => { cdata.is_const_fn(def_id.index) }
@@ -161,9 +160,9 @@ fn into_args(self) -> (DefId, DefId) { (self.0.as_def_id(), self.1) }
     // This is only used by rustdoc anyway, which shouldn't have
     // incremental recompilation ever enabled.
     fn_arg_names => { cdata.get_fn_arg_names(def_id.index) }
+    rendered_const => { cdata.get_rendered_const(def_id.index) }
     impl_parent => { cdata.get_parent_impl(def_id.index) }
     trait_of_item => { cdata.get_trait_of_item(def_id.index) }
-    item_body_nested_bodies => { cdata.item_body_nested_bodies(tcx, def_id.index) }
     const_is_rvalue_promotable_to_static => {
         cdata.const_is_rvalue_promotable_to_static(def_id.index)
     }
@@ -243,11 +242,6 @@ fn into_args(self) -> (DefId, DefId) { (self.0.as_def_id(), self.1) }
     defined_lang_items => { Lrc::new(cdata.get_lang_items()) }
     missing_lang_items => { Lrc::new(cdata.get_missing_lang_items()) }
 
-    extern_const_body => {
-        debug!("item_body({:?}): inlining item", def_id);
-        cdata.extern_const_body(tcx, def_id.index)
-    }
-
     missing_extern_crate_item => {
         let r = match *cdata.extern_crate.borrow() {
             Some(extern_crate) if !extern_crate.direct => true,
index 936d680380c993a994cae26b43b69ea08cfc9398..0147e8dc6075948f38e20a8fd0ac72f6e7726dc8 100644 (file)
@@ -17,8 +17,7 @@
 use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash,
                       DisambiguatedDefPathData};
 use rustc::hir;
-use rustc::middle::cstore::{LinkagePreference, ExternConstBody,
-                            ExternBodyNestedBodies};
+use rustc::middle::cstore::LinkagePreference;
 use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
 use rustc::hir::def::{self, Def, CtorKind};
 use rustc::hir::def_id::{CrateNum, DefId, DefIndex,
@@ -33,7 +32,6 @@
 use rustc::util::captures::Captures;
 use rustc::util::nodemap::FxHashMap;
 
-use std::collections::BTreeMap;
 use std::io;
 use std::mem;
 use std::u32;
@@ -433,7 +431,7 @@ pub fn list_crate_metadata(&self,
 impl<'tcx> EntryKind<'tcx> {
     fn to_def(&self, did: DefId) -> Option<Def> {
         Some(match *self {
-            EntryKind::Const(_) => Def::Const(did),
+            EntryKind::Const(..) => Def::Const(did),
             EntryKind::AssociatedConst(..) => Def::AssociatedConst(did),
             EntryKind::ImmStatic |
             EntryKind::ForeignImmStatic => Def::Static(did, false),
@@ -794,54 +792,12 @@ pub fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F, sess: &Sessio
         }
     }
 
-    pub fn extern_const_body(&self,
-                             tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                             id: DefIndex)
-                             -> ExternConstBody<'tcx> {
-        assert!(!self.is_proc_macro(id));
-        let ast = self.entry(id).ast.unwrap();
-        let def_id = self.local_def_id(id);
-        let ast = ast.decode((self, tcx));
-        let body = ast.body.decode((self, tcx));
-        ExternConstBody {
-            body: tcx.hir.intern_inlined_body(def_id, body),
-            fingerprint: ast.stable_bodies_hash,
-        }
-    }
-
-    pub fn item_body_tables(&self,
-                            id: DefIndex,
-                            tcx: TyCtxt<'a, 'tcx, 'tcx>)
-                            -> &'tcx ty::TypeckTables<'tcx> {
-        let ast = self.entry(id).ast.unwrap().decode(self);
-        tcx.alloc_tables(ast.tables.decode((self, tcx)))
-    }
-
-    pub fn item_body_nested_bodies(&self,
-                                   tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                                   id: DefIndex)
-                                   -> ExternBodyNestedBodies {
-        if let Some(ref ast) = self.entry(id).ast {
-            let mut ast = ast.decode(self);
-            let nested_bodies: BTreeMap<_, _> = ast.nested_bodies
-                                                   .decode((self, tcx.sess))
-                                                   .map(|body| (body.id(), body))
-                                                   .collect();
-            ExternBodyNestedBodies {
-                nested_bodies: Lrc::new(nested_bodies),
-                fingerprint: ast.stable_bodies_hash,
-            }
-        } else {
-            ExternBodyNestedBodies {
-                nested_bodies: Lrc::new(BTreeMap::new()),
-                fingerprint: Fingerprint::ZERO,
-            }
-        }
-    }
-
     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
+        match self.entry(id).kind {
+            EntryKind::AssociatedConst(_, data, _) |
+            EntryKind::Const(data, _) => data.ast_promotable,
+            _ => bug!(),
+        }
     }
 
     pub fn is_item_mir_available(&self, id: DefIndex) -> bool {
@@ -861,10 +817,10 @@ pub fn maybe_get_optimized_mir(&self,
 
     pub fn mir_const_qualif(&self, id: DefIndex) -> u8 {
         match self.entry(id).kind {
-            EntryKind::Const(qualif) |
-            EntryKind::AssociatedConst(AssociatedContainer::ImplDefault, qualif) |
-            EntryKind::AssociatedConst(AssociatedContainer::ImplFinal, qualif) => {
-                qualif
+            EntryKind::Const(qualif, _) |
+            EntryKind::AssociatedConst(AssociatedContainer::ImplDefault, qualif, _) |
+            EntryKind::AssociatedConst(AssociatedContainer::ImplFinal, qualif, _) => {
+                qualif.mir
             }
             _ => bug!(),
         }
@@ -877,7 +833,7 @@ pub fn get_associated_item(&self, id: DefIndex) -> ty::AssociatedItem {
         let name = def_key.disambiguated_data.data.get_opt_name().unwrap();
 
         let (kind, container, has_self) = match item.kind {
-            EntryKind::AssociatedConst(container, _) => {
+            EntryKind::AssociatedConst(container, _, _) => {
                 (ty::AssociatedKind::Const, container, false)
             }
             EntryKind::Method(data) => {
@@ -1076,6 +1032,14 @@ pub fn exported_symbols(&self,
         lazy_seq.decode((self, tcx)).collect()
     }
 
+    pub fn get_rendered_const(&self, id: DefIndex) -> String {
+        match self.entry(id).kind {
+            EntryKind::Const(_, data) |
+            EntryKind::AssociatedConst(_, _, data) => data.decode(self).0,
+            _ => bug!(),
+        }
+    }
+
     pub fn wasm_custom_sections(&self) -> Vec<DefId> {
         let sections = self.root
             .wasm_custom_sections
index 67c180e94caff01129e6ba91540bb1724413dfd7..212de375a3f91655c09069f0346049f2d548f653 100644 (file)
@@ -622,7 +622,6 @@ fn encode_enum_variant_info(&mut self,
             generics: Some(self.encode_generics(def_id)),
             predicates: Some(self.encode_predicates(def_id)),
 
-            ast: None,
             mir: self.encode_optimized_mir(def_id),
         }
     }
@@ -660,7 +659,6 @@ fn encode_info_for_mod(&mut self,
             generics: None,
             predicates: None,
 
-            ast: None,
             mir: None
         }
     }
@@ -701,7 +699,6 @@ fn encode_field(&mut self,
             generics: Some(self.encode_generics(def_id)),
             predicates: Some(self.encode_predicates(def_id)),
 
-            ast: None,
             mir: None,
         }
     }
@@ -759,7 +756,6 @@ fn encode_struct_ctor(&mut self, (adt_def_id, def_id): (DefId, DefId)) -> Entry<
             generics: Some(self.encode_generics(def_id)),
             predicates: Some(self.encode_predicates(def_id)),
 
-            ast: None,
             mir: self.encode_optimized_mir(def_id),
         }
     }
@@ -795,7 +791,18 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> {
 
         let kind = match trait_item.kind {
             ty::AssociatedKind::Const => {
-                EntryKind::AssociatedConst(container, 0)
+                let const_qualif =
+                    if let hir::TraitItemKind::Const(_, Some(body)) = ast_item.node {
+                        self.const_qualif(0, body)
+                    } else {
+                        ConstQualif { mir: 0, ast_promotable: false }
+                    };
+
+                let rendered =
+                    hir::print::to_string(&self.tcx.hir, |s| s.print_trait_item(ast_item));
+                let rendered_const = self.lazy(&RenderedConst(rendered));
+
+                EntryKind::AssociatedConst(container, const_qualif, rendered_const)
             }
             ty::AssociatedKind::Method => {
                 let fn_data = if let hir::TraitItemKind::Method(_, ref m) = ast_item.node {
@@ -855,11 +862,6 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> {
             generics: Some(self.encode_generics(def_id)),
             predicates: Some(self.encode_predicates(def_id)),
 
-            ast: if let hir::TraitItemKind::Const(_, Some(body)) = ast_item.node {
-                Some(self.encode_body(body))
-            } else {
-                None
-            },
             mir: self.encode_optimized_mir(def_id),
         }
     }
@@ -869,6 +871,13 @@ fn metadata_output_only(&self) -> bool {
         !self.tcx.sess.opts.output_types.should_trans()
     }
 
+    fn const_qualif(&self, mir: u8, body_id: hir::BodyId) -> ConstQualif {
+        let body_owner_def_id = self.tcx.hir.body_owner_def_id(body_id);
+        let ast_promotable = self.tcx.const_is_rvalue_promotable_to_static(body_owner_def_id);
+
+        ConstQualif { mir, ast_promotable }
+    }
+
     fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
         debug!("IsolatedEncoder::encode_info_for_impl_item({:?})", def_id);
         let tcx = self.tcx;
@@ -886,8 +895,15 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
 
         let kind = match impl_item.kind {
             ty::AssociatedKind::Const => {
-                EntryKind::AssociatedConst(container,
-                    self.tcx.at(ast_item.span).mir_const_qualif(def_id).0)
+                if let hir::ImplItemKind::Const(_, body_id) = ast_item.node {
+                    let mir = self.tcx.at(ast_item.span).mir_const_qualif(def_id).0;
+
+                    EntryKind::AssociatedConst(container,
+                        self.const_qualif(mir, body_id),
+                        self.encode_rendered_const_for_body(body_id))
+                } else {
+                    bug!()
+                }
             }
             ty::AssociatedKind::Method => {
                 let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
@@ -908,20 +924,20 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
             ty::AssociatedKind::Type => EntryKind::AssociatedType(container)
         };
 
-        let (ast, mir) = if let hir::ImplItemKind::Const(_, body) = ast_item.node {
-            (Some(body), true)
-        } else if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
-            let generics = self.tcx.generics_of(def_id);
-            let types = generics.parent_types as usize + generics.types.len();
-            let needs_inline = (types > 0 || tcx.trans_fn_attrs(def_id).requests_inline()) &&
-                !self.metadata_output_only();
-            let is_const_fn = sig.constness == hir::Constness::Const;
-            let ast = if is_const_fn { Some(body) } else { None };
-            let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
-            (ast, needs_inline || is_const_fn || always_encode_mir)
-        } else {
-            (None, false)
-        };
+        let mir =
+            if let hir::ImplItemKind::Const(..) = ast_item.node {
+                true
+            } else if let hir::ImplItemKind::Method(ref sig, _) = ast_item.node {
+                let generics = self.tcx.generics_of(def_id);
+                let types = generics.parent_types as usize + generics.types.len();
+                let needs_inline = types > 0 || tcx.trans_fn_attrs(def_id).requests_inline() &&
+                    !self.metadata_output_only();
+                let is_const_fn = sig.constness == hir::Constness::Const;
+                let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
+                needs_inline || is_const_fn || always_encode_mir
+            } else {
+                false
+            };
 
         Entry {
             kind,
@@ -942,7 +958,6 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
             generics: Some(self.encode_generics(def_id)),
             predicates: Some(self.encode_predicates(def_id)),
 
-            ast: ast.map(|body| self.encode_body(body)),
             mir: if mir { self.encode_optimized_mir(def_id) } else { None },
         }
     }
@@ -999,6 +1014,13 @@ fn encode_deprecation(&mut self, def_id: DefId) -> Option<Lazy<attr::Deprecation
         self.tcx.lookup_deprecation(def_id).map(|depr| self.lazy(&depr))
     }
 
+    fn encode_rendered_const_for_body(&mut self, body_id: hir::BodyId) -> Lazy<RenderedConst> {
+        let body = self.tcx.hir.body(body_id);
+        let rendered = hir::print::to_string(&self.tcx.hir, |s| s.print_expr(&body.value));
+        let rendered_const = &RenderedConst(rendered);
+        self.lazy(rendered_const)
+    }
+
     fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) -> Entry<'tcx> {
         let tcx = self.tcx;
 
@@ -1007,8 +1029,12 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
         let kind = match item.node {
             hir::ItemStatic(_, hir::MutMutable, _) => EntryKind::MutStatic,
             hir::ItemStatic(_, hir::MutImmutable, _) => EntryKind::ImmStatic,
-            hir::ItemConst(..) => {
-                EntryKind::Const(tcx.at(item.span).mir_const_qualif(def_id).0)
+            hir::ItemConst(_, body_id) => {
+                let mir = tcx.at(item.span).mir_const_qualif(def_id).0;
+                EntryKind::Const(
+                    self.const_qualif(mir, body_id),
+                    self.encode_rendered_const_for_body(body_id)
+                )
             }
             hir::ItemFn(_, _, constness, .., body) => {
                 let data = FnData {
@@ -1191,13 +1217,6 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
                 _ => None,
             },
 
-            ast: match item.node {
-                hir::ItemConst(_, body) |
-                hir::ItemFn(_, _, hir::Constness::Const, _, _, body) => {
-                    Some(self.encode_body(body))
-                }
-                _ => None,
-            },
             mir: match item.node {
                 hir::ItemStatic(..) => {
                     self.encode_optimized_mir(def_id)
@@ -1240,7 +1259,6 @@ fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef) -> Entry<'tcx
             variances: LazySeq::empty(),
             generics: None,
             predicates: None,
-            ast: None,
             mir: None,
         }
     }
@@ -1269,7 +1287,6 @@ fn encode_info_for_ty_param(&mut self,
             generics: None,
             predicates: None,
 
-            ast: None,
             mir: None,
         }
     }
@@ -1292,7 +1309,6 @@ fn encode_info_for_anon_ty(&mut self, def_id: DefId) -> Entry<'tcx> {
             generics: Some(self.encode_generics(def_id)),
             predicates: Some(self.encode_predicates(def_id)),
 
-            ast: None,
             mir: None,
         }
     }
@@ -1337,7 +1353,6 @@ fn encode_info_for_closure(&mut self, def_id: DefId) -> Entry<'tcx> {
             generics: Some(self.encode_generics(def_id)),
             predicates: None,
 
-            ast: None,
             mir: self.encode_optimized_mir(def_id),
         }
     }
@@ -1346,10 +1361,12 @@ fn encode_info_for_embedded_const(&mut self, def_id: DefId) -> Entry<'tcx> {
         debug!("IsolatedEncoder::encode_info_for_embedded_const({:?})", def_id);
         let tcx = self.tcx;
         let id = tcx.hir.as_local_node_id(def_id).unwrap();
-        let body = tcx.hir.body_owned_by(id);
+        let body_id = tcx.hir.body_owned_by(id);
+        let const_data = self.encode_rendered_const_for_body(body_id);
+        let mir = tcx.mir_const_qualif(def_id).0;
 
         Entry {
-            kind: EntryKind::Const(tcx.mir_const_qualif(def_id).0),
+            kind: EntryKind::Const(self.const_qualif(mir, body_id), const_data),
             visibility: self.lazy(&ty::Visibility::Public),
             span: self.lazy(&tcx.def_span(def_id)),
             attributes: LazySeq::empty(),
@@ -1363,7 +1380,6 @@ fn encode_info_for_embedded_const(&mut self, def_id: DefId) -> Entry<'tcx> {
             generics: Some(self.encode_generics(def_id)),
             predicates: Some(self.encode_predicates(def_id)),
 
-            ast: Some(self.encode_body(body)),
             mir: self.encode_optimized_mir(def_id),
         }
     }
@@ -1565,7 +1581,6 @@ fn encode_info_for_foreign_item(&mut self,
             generics: Some(self.encode_generics(def_id)),
             predicates: Some(self.encode_predicates(def_id)),
 
-            ast: None,
             mir: None,
         }
     }
index 689c190966ee8214bc4fe827f04fa55e9eabb0d0..88594afa32024f5cb69c11897a61e47a1302abf2 100644 (file)
@@ -55,10 +55,4 @@ pub fn lazy_seq_from_slice<T>(&mut self, slice: &[T]) -> LazySeq<T>
     {
         self.ecx.lazy_seq_ref(slice.iter())
     }
-
-    pub fn lazy_seq_ref_from_slice<T>(&mut self, slice: &[&T]) -> LazySeq<T>
-        where T: Encodable
-    {
-        self.ecx.lazy_seq_ref(slice.iter().map(|x| *x))
-    }
 }
index cbbc9d74228de9e8bf9de8c7d262cec33aefd7ed..9ecb3fd6cddf6aae48e57ddabbc54fabda79bd85 100644 (file)
@@ -44,7 +44,6 @@
 
 mod diagnostics;
 
-mod astencode;
 mod index_builder;
 mod index;
 mod encoder;
index 23ea5e4cc55043b97ef075feb1c90302aaaa1c58..5d6db1abe7b68f0663ba66cdd4234e5d6c7e366e 100644 (file)
@@ -8,7 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use astencode;
 use index;
 
 use rustc::hir;
@@ -266,7 +265,6 @@ pub struct Entry<'tcx> {
     pub generics: Option<Lazy<ty::Generics>>,
     pub predicates: Option<Lazy<ty::GenericPredicates<'tcx>>>,
 
-    pub ast: Option<Lazy<astencode::Ast<'tcx>>>,
     pub mir: Option<Lazy<mir::Mir<'tcx>>>,
 }
 
@@ -283,13 +281,12 @@ pub struct Entry<'tcx> {
     variances,
     generics,
     predicates,
-    ast,
     mir
 });
 
 #[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
 pub enum EntryKind<'tcx> {
-    Const(u8),
+    Const(ConstQualif, Lazy<RenderedConst>),
     ImmStatic,
     MutStatic,
     ForeignImmStatic,
@@ -313,7 +310,7 @@ pub enum EntryKind<'tcx> {
     Impl(Lazy<ImplData<'tcx>>),
     Method(Lazy<MethodData<'tcx>>),
     AssociatedType(AssociatedContainer),
-    AssociatedConst(AssociatedContainer, u8),
+    AssociatedConst(AssociatedContainer, ConstQualif, Lazy<RenderedConst>),
 }
 
 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for EntryKind<'gcx> {
@@ -333,8 +330,9 @@ fn hash_stable<W: StableHasherResult>(&self,
             EntryKind::Type => {
                 // Nothing else to hash here.
             }
-            EntryKind::Const(qualif) => {
+            EntryKind::Const(qualif, ref const_data) => {
                 qualif.hash_stable(hcx, hasher);
+                const_data.hash_stable(hcx, hasher);
             }
             EntryKind::Enum(ref repr_options) => {
                 repr_options.hash_stable(hcx, hasher);
@@ -375,7 +373,7 @@ fn hash_stable<W: StableHasherResult>(&self,
             EntryKind::AssociatedType(associated_container) => {
                 associated_container.hash_stable(hcx, hasher);
             }
-            EntryKind::AssociatedConst(associated_container, qualif) => {
+            EntryKind::AssociatedConst(associated_container, qualif, _) => {
                 associated_container.hash_stable(hcx, hasher);
                 qualif.hash_stable(hcx, hasher);
             }
@@ -383,6 +381,29 @@ fn hash_stable<W: StableHasherResult>(&self,
     }
 }
 
+/// Additional data for EntryKind::Const and EntryKind::AssociatedConst
+#[derive(Clone, Copy, RustcEncodable, RustcDecodable)]
+pub struct ConstQualif {
+    pub mir: u8,
+    pub ast_promotable: bool,
+}
+
+impl_stable_hash_for!(struct ConstQualif { mir, ast_promotable });
+
+/// Contains a constant which has been rendered to a String.
+/// Used by rustdoc.
+#[derive(RustcEncodable, RustcDecodable)]
+pub struct RenderedConst(pub String);
+
+impl<'a> HashStable<StableHashingContext<'a>> for RenderedConst {
+    #[inline]
+    fn hash_stable<W: StableHasherResult>(&self,
+                                          hcx: &mut StableHashingContext<'a>,
+                                          hasher: &mut StableHasher<W>) {
+        self.0.hash_stable(hcx, hasher);
+    }
+}
+
 #[derive(RustcEncodable, RustcDecodable)]
 pub struct ModData {
     pub reexports: LazySeq<def::Export>,
index 090adc27ef01083d609abe5cd99954b7ea573c53..32f23e923d91ba8121caf583fa4d330c7ff747a2 100644 (file)
 
 //! Support for inlining external documentation into the current AST.
 
-use std::collections::BTreeMap;
-use std::io;
 use std::iter::once;
-use rustc_data_structures::sync::Lrc;
 
 use syntax::ast;
 use rustc::hir;
@@ -408,27 +405,8 @@ fn fill_in(cx: &DocContext, did: DefId, items: &mut Vec<clean::Item>) {
     }
 }
 
-struct InlinedConst {
-    nested_bodies: Lrc<BTreeMap<hir::BodyId, hir::Body>>
-}
-
-impl hir::print::PpAnn for InlinedConst {
-    fn nested(&self, state: &mut hir::print::State, nested: hir::print::Nested)
-              -> io::Result<()> {
-        if let hir::print::Nested::Body(body) = nested {
-            state.print_expr(&self.nested_bodies[&body].value)
-        } else {
-            Ok(())
-        }
-    }
-}
-
 pub fn print_inlined_const(cx: &DocContext, did: DefId) -> String {
-    let body = cx.tcx.extern_const_body(did).body;
-    let inlined = InlinedConst {
-        nested_bodies: cx.tcx.item_body_nested_bodies(did).nested_bodies
-    };
-    hir::print::to_string(&inlined, |s| s.print_expr(&body.value))
+    cx.tcx.rendered_const(did)
 }
 
 fn build_const(cx: &DocContext, did: DefId) -> clean::Constant {