diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs
index 1b90707323850..b4f39439d5b4d 100644
--- a/src/librustc/dep_graph/dep_node.rs
+++ b/src/librustc/dep_graph/dep_node.rs
@@ -556,7 +556,6 @@ define_dep_nodes!( <'tcx>
[input] DefSpan(DefId),
[] LookupStability(DefId),
[] LookupDeprecationEntry(DefId),
- [] ItemBodyNestedBodies(DefId),
[] ConstIsRvaluePromotableToStatic(DefId),
[] RvaluePromotableMap(DefId),
[] ImplParent(DefId),
@@ -567,6 +566,7 @@ define_dep_nodes!( <'tcx>
[] ItemAttrs(DefId),
[] TransFnAttrs(DefId),
[] FnArgNames(DefId),
+ [] RenderedConst(DefId),
[] DylibDepFormats(CrateNum),
[] IsPanicRuntime(CrateNum),
[] IsCompilerBuiltins(CrateNum),
@@ -615,7 +615,6 @@ define_dep_nodes!( <'tcx>
[input] GetLangItems,
[] DefinedLangItems(CrateNum),
[] MissingLangItems(CrateNum),
- [] ExternConstBody(DefId),
[] VisibleParentMap,
[input] MissingExternCrateItem(CrateNum),
[input] UsedCrateSource(CrateNum),
diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs
index b88185c3154a9..9520ed32af9e1 100644
--- a/src/librustc/hir/map/mod.rs
+++ b/src/librustc/hir/map/mod.rs
@@ -30,14 +30,11 @@ use syntax_pos::Span;
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 @@ impl<'hir> MapEntry<'hir> {
pub struct Forest {
krate: Crate,
pub dep_graph: DepGraph,
- inlined_bodies: SyncTypedArena
}
impl Forest {
@@ -227,7 +223,6 @@ impl 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>,
-
/// The reverse mapping of `node_to_hir_id`.
hir_to_node_id: FxHashMap,
}
@@ -923,21 +915,6 @@ impl<'hir> Map<'hir> {
}
}
- 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);
diff --git a/src/librustc/ich/impls_cstore.rs b/src/librustc/ich/impls_cstore.rs
index d885bd43bc89d..96d7cb6b041a8 100644
--- a/src/librustc/ich/impls_cstore.rs
+++ b/src/librustc/ich/impls_cstore.rs
@@ -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 {
@@ -64,29 +62,3 @@ impl_stable_hash_for!(struct middle::cstore::CrateSource {
rlib,
rmeta
});
-
-impl HashStable for middle::cstore::ExternBodyNestedBodies {
- fn hash_stable(&self,
- hcx: &mut HCX,
- hasher: &mut StableHasher) {
- let middle::cstore::ExternBodyNestedBodies {
- nested_bodies: _,
- fingerprint,
- } = *self;
-
- fingerprint.hash_stable(hcx, hasher);
- }
-}
-
-impl<'a, HCX> HashStable for middle::cstore::ExternConstBody<'a> {
- fn hash_stable(&self,
- hcx: &mut HCX,
- hasher: &mut StableHasher) {
- let middle::cstore::ExternConstBody {
- body: _,
- fingerprint,
- } = *self;
-
- fingerprint.hash_stable(hcx, hasher);
- }
-}
diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs
index 292ec184dfae5..60e197e614aa6 100644
--- a/src/librustc/middle/cstore.rs
+++ b/src/librustc/middle/cstore.rs
@@ -22,19 +22,16 @@
//! 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 @@ pub trait MetadataLoader {
-> Result;
}
-#[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>,
-
- // 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.
///
diff --git a/src/librustc/ty/maps/config.rs b/src/librustc/ty/maps/config.rs
index 664c84f598660..fea7de955e0bf 100644
--- a/src/librustc/ty/maps/config.rs
+++ b/src/librustc/ty/maps/config.rs
@@ -283,12 +283,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::trait_of_item<'tcx> {
}
}
-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 `{}`",
diff --git a/src/librustc/ty/maps/mod.rs b/src/librustc/ty/maps/mod.rs
index 2325b1893d996..0ab9f16dab481 100644
--- a/src/librustc/ty/maps/mod.rs
+++ b/src/librustc/ty/maps/mod.rs
@@ -17,9 +17,8 @@ use hir::svh::Svh;
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;
@@ -254,9 +253,11 @@ define_maps! { <'tcx>
[] fn item_attrs: ItemAttrs(DefId) -> Lrc<[ast::Attribute]>,
[] fn trans_fn_attrs: trans_fn_attrs(DefId) -> TransFnAttrs,
[] fn fn_arg_names: FnArgNames(DefId) -> Vec,
+ /// 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,
[] fn trait_of_item: TraitOfItem(DefId) -> Option,
- [] 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,
[] fn is_mir_available: IsMirAvailable(DefId) -> bool,
@@ -376,7 +377,6 @@ define_maps! { <'tcx>
[] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc,
[] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc>,
[] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc>,
- [] fn extern_const_body: ExternConstBody(DefId) -> ExternConstBody<'tcx>,
[] fn visible_parent_map: visible_parent_map_node(CrateNum)
-> Lrc>,
[] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
diff --git a/src/librustc/ty/maps/plumbing.rs b/src/librustc/ty/maps/plumbing.rs
index 4f6925938c802..8d6c7474a9f94 100644
--- a/src/librustc/ty/maps/plumbing.rs
+++ b/src/librustc/ty/maps/plumbing.rs
@@ -1048,7 +1048,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
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 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
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 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
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
index 71b15643cbcef..0000000000000
--- a/src/librustc_metadata/astencode.rs
+++ /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 or the MIT license
-// , 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,
- pub tables: Lazy>,
- pub nested_bodies: LazySeq,
- 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> {
- 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);
- }
-}
diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs
index 2c995d2f5cde6..a11b95cb5b6c1 100644
--- a/src/librustc_metadata/cstore_impl.rs
+++ b/src/librustc_metadata/cstore_impl.rs
@@ -142,7 +142,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
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 @@ provide! { <'tcx> tcx, def_id, other, cdata,
// 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 @@ provide! { <'tcx> tcx, def_id, other, cdata,
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,
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index 936d680380c99..0147e8dc60759 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -17,8 +17,7 @@ use rustc_data_structures::sync::{Lrc, ReadGuard};
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::mir::Mir;
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 @@ impl<'a, 'tcx> MetadataBlob {
impl<'tcx> EntryKind<'tcx> {
fn to_def(&self, did: DefId) -> Option {
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 @@ impl<'a, 'tcx> CrateMetadata {
}
}
- 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 @@ impl<'a, 'tcx> CrateMetadata {
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 @@ impl<'a, 'tcx> CrateMetadata {
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 @@ impl<'a, 'tcx> CrateMetadata {
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 {
let sections = self.root
.wasm_custom_sections
diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs
index 67c180e94caff..212de375a3f91 100644
--- a/src/librustc_metadata/encoder.rs
+++ b/src/librustc_metadata/encoder.rs
@@ -622,7 +622,6 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
generics: None,
predicates: None,
- ast: None,
mir: None
}
}
@@ -701,7 +699,6 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
- ast: None,
mir: None,
}
}
@@ -759,7 +756,6 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, '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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, '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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
!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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, '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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, '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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, '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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
self.tcx.lookup_deprecation(def_id).map(|depr| self.lazy(&depr))
}
+ fn encode_rendered_const_for_body(&mut self, body_id: hir::BodyId) -> Lazy {
+ 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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
_ => 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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
variances: LazySeq::empty(),
generics: None,
predicates: None,
- ast: None,
mir: None,
}
}
@@ -1269,7 +1287,6 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
generics: None,
predicates: None,
- ast: None,
mir: None,
}
}
@@ -1292,7 +1309,6 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
- ast: None,
mir: None,
}
}
@@ -1337,7 +1353,6 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
generics: Some(self.encode_generics(def_id)),
predicates: None,
- ast: None,
mir: self.encode_optimized_mir(def_id),
}
}
@@ -1346,10 +1361,12 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, '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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, '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 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
- ast: None,
mir: None,
}
}
diff --git a/src/librustc_metadata/isolated_encoder.rs b/src/librustc_metadata/isolated_encoder.rs
index 689c190966ee8..88594afa32024 100644
--- a/src/librustc_metadata/isolated_encoder.rs
+++ b/src/librustc_metadata/isolated_encoder.rs
@@ -55,10 +55,4 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
{
self.ecx.lazy_seq_ref(slice.iter())
}
-
- pub fn lazy_seq_ref_from_slice(&mut self, slice: &[&T]) -> LazySeq
- where T: Encodable
- {
- self.ecx.lazy_seq_ref(slice.iter().map(|x| *x))
- }
}
diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs
index cbbc9d74228de..9ecb3fd6cddf6 100644
--- a/src/librustc_metadata/lib.rs
+++ b/src/librustc_metadata/lib.rs
@@ -44,7 +44,6 @@ extern crate rustc_data_structures;
mod diagnostics;
-mod astencode;
mod index_builder;
mod index;
mod encoder;
diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs
index 23ea5e4cc5504..5d6db1abe7b68 100644
--- a/src/librustc_metadata/schema.rs
+++ b/src/librustc_metadata/schema.rs
@@ -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>,
pub predicates: Option>>,
- pub ast: Option>>,
pub mir: Option>>,
}
@@ -283,13 +281,12 @@ impl_stable_hash_for!(struct Entry<'tcx> {
variances,
generics,
predicates,
- ast,
mir
});
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
pub enum EntryKind<'tcx> {
- Const(u8),
+ Const(ConstQualif, Lazy),
ImmStatic,
MutStatic,
ForeignImmStatic,
@@ -313,7 +310,7 @@ pub enum EntryKind<'tcx> {
Impl(Lazy>),
Method(Lazy>),
AssociatedType(AssociatedContainer),
- AssociatedConst(AssociatedContainer, u8),
+ AssociatedConst(AssociatedContainer, ConstQualif, Lazy),
}
impl<'a, 'gcx> HashStable> for EntryKind<'gcx> {
@@ -333,8 +330,9 @@ impl<'a, 'gcx> HashStable> for EntryKind<'gcx> {
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 @@ impl<'a, 'gcx> HashStable> for EntryKind<'gcx> {
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 @@ impl<'a, 'gcx> HashStable> for EntryKind<'gcx> {
}
}
+/// 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> for RenderedConst {
+ #[inline]
+ fn hash_stable(&self,
+ hcx: &mut StableHashingContext<'a>,
+ hasher: &mut StableHasher) {
+ self.0.hash_stable(hcx, hasher);
+ }
+}
+
#[derive(RustcEncodable, RustcDecodable)]
pub struct ModData {
pub reexports: LazySeq,
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs
index 090adc27ef010..32f23e923d91b 100644
--- a/src/librustdoc/clean/inline.rs
+++ b/src/librustdoc/clean/inline.rs
@@ -10,10 +10,7 @@
//! 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 build_module(cx: &DocContext, did: DefId) -> clean::Module {
}
}
-struct InlinedConst {
- nested_bodies: Lrc>
-}
-
-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 {