Skip to content

Commit

Permalink
Remove HIR inlining
Browse files Browse the repository at this point in the history
Fixes #49690
  • Loading branch information
wesleywiser committed Apr 16, 2018
1 parent 8de5353 commit 26b3203
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 211 deletions.
3 changes: 1 addition & 2 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ define_dep_nodes!( <'tcx>
[input] DefSpan(DefId),
[] LookupStability(DefId),
[] LookupDeprecationEntry(DefId),
[] ItemBodyNestedBodies(DefId),
[] ConstIsRvaluePromotableToStatic(DefId),
[] RvaluePromotableMap(DefId),
[] ImplParent(DefId),
Expand All @@ -567,6 +566,7 @@ define_dep_nodes!( <'tcx>
[] ItemAttrs(DefId),
[] TransFnAttrs(DefId),
[] FnArgNames(DefId),
[] RenderedConst(DefId),
[] DylibDepFormats(CrateNum),
[] IsPanicRuntime(CrateNum),
[] IsCompilerBuiltins(CrateNum),
Expand Down Expand Up @@ -615,7 +615,6 @@ define_dep_nodes!( <'tcx>
[input] GetLangItems,
[] DefinedLangItems(CrateNum),
[] MissingLangItems(CrateNum),
[] ExternConstBody(DefId),
[] VisibleParentMap,
[input] MissingExternCrateItem(CrateNum),
[input] UsedCrateSource(CrateNum),
Expand Down
26 changes: 1 addition & 25 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::TypedArena;
use std::io;
use ty::TyCtxt;

use rustc_data_structures::sync::Lock;

pub mod blocks;
mod collector;
mod def_collector;
Expand Down Expand Up @@ -219,15 +216,13 @@ impl<'hir> MapEntry<'hir> {
pub struct Forest {
krate: Crate,
pub dep_graph: DepGraph,
inlined_bodies: TypedArena<Body>
}

impl Forest {
pub fn new(krate: Crate, dep_graph: &DepGraph) -> Forest {
Forest {
krate,
dep_graph: dep_graph.clone(),
inlined_bodies: TypedArena::new()
}
}

Expand Down Expand Up @@ -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>,
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 0 additions & 13 deletions src/librustc/ich/impls_cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,3 @@ impl<HCX> HashStable<HCX> for middle::cstore::ExternBodyNestedBodies {
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);
}
}
10 changes: 0 additions & 10 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,6 @@ pub trait MetadataLoader {
-> 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>>,
Expand Down
6 changes: 0 additions & 6 deletions src/librustc/ty/maps/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `{}`",
Expand Down
8 changes: 3 additions & 5 deletions src/librustc/ty/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -254,9 +253,9 @@ 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<ast::Name>,
[] 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,
Expand Down Expand Up @@ -376,7 +375,6 @@ define_maps! { <'tcx>
[] 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,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ty/maps/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,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!());
}
Expand All @@ -1055,6 +1054,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!()); }
Expand Down Expand Up @@ -1111,7 +1111,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!());
Expand Down
58 changes: 2 additions & 56 deletions src/librustc_metadata/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,89 +8,35 @@
// 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};
use rustc::ty;

#[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
rvalue_promotable_to_static
});

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);
}
}
7 changes: 1 addition & 6 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,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)
}
Expand Down Expand Up @@ -243,11 +243,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,
Expand Down
Loading

0 comments on commit 26b3203

Please sign in to comment.