1
Fork 0

rustc: Migrate CrateStore::item_body to a query

This commit migrates the `item_body` method on `CrateStore` to a query instead
to enable better tracking of dependencies and whatnot.
This commit is contained in:
Alex Crichton 2017-08-31 11:12:05 -07:00
parent 953490ddfa
commit 84ae4b75be
7 changed files with 14 additions and 30 deletions

View file

@ -563,6 +563,7 @@ define_dep_nodes!( <'tcx>
[] GetLangItems, [] GetLangItems,
[] DefinedLangItems(CrateNum), [] DefinedLangItems(CrateNum),
[] MissingLangItems(CrateNum), [] MissingLangItems(CrateNum),
[] ItemBody(DefId),
); );
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug { trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

View file

@ -42,7 +42,6 @@ use syntax::ext::base::SyntaxExtension;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax_pos::Span; use syntax_pos::Span;
use rustc_back::target::Target; use rustc_back::target::Target;
use hir;
pub use self::NativeLibraryKind::*; pub use self::NativeLibraryKind::*;
@ -258,10 +257,6 @@ pub trait CrateStore {
fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro; fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro;
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>; fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
// misc. metadata
fn item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-> &'tcx hir::Body;
// This is basically a 1-based range of ints, which is a little // This is basically a 1-based range of ints, which is a little
// silly - I may fix that. // silly - I may fix that.
fn crates(&self) -> Vec<CrateNum>; fn crates(&self) -> Vec<CrateNum>;
@ -350,12 +345,6 @@ impl CrateStore for DummyCrateStore {
} }
fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") } fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") }
// misc. metadata
fn item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-> &'tcx hir::Body {
bug!("item_body")
}
// This is basically a 1-based range of ints, which is a little // This is basically a 1-based range of ints, which is a little
// silly - I may fix that. // silly - I may fix that.
fn crates(&self) -> Vec<CrateNum> { vec![] } fn crates(&self) -> Vec<CrateNum> { vec![] }

View file

@ -1315,6 +1315,7 @@ define_maps! { <'tcx>
[] get_lang_items: get_lang_items_node(CrateNum) -> Rc<LanguageItems>, [] get_lang_items: get_lang_items_node(CrateNum) -> Rc<LanguageItems>,
[] defined_lang_items: DefinedLangItems(CrateNum) -> Rc<Vec<(DefIndex, usize)>>, [] defined_lang_items: DefinedLangItems(CrateNum) -> Rc<Vec<(DefIndex, usize)>>,
[] missing_lang_items: MissingLangItems(CrateNum) -> Rc<Vec<LangItem>>, [] missing_lang_items: MissingLangItems(CrateNum) -> Rc<Vec<LangItem>>,
[] item_body: ItemBody(DefId) -> &'tcx hir::Body,
} }
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> { fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {

View file

@ -354,7 +354,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
} }
} else { } else {
if tcx.is_const_fn(def_id) { if tcx.is_const_fn(def_id) {
tcx.sess.cstore.item_body(tcx, def_id) tcx.item_body(def_id)
} else { } else {
signal!(e, TypeckError) signal!(e, TypeckError)
} }
@ -774,7 +774,7 @@ fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
tcx.mir_const_qualif(def_id); tcx.mir_const_qualif(def_id);
tcx.hir.body(tcx.hir.body_owned_by(id)) tcx.hir.body(tcx.hir.body_owned_by(id))
} else { } else {
tcx.sess.cstore.item_body(tcx, def_id) tcx.item_body(def_id)
}; };
ConstContext::new(tcx, key.param_env.and(substs), tables).eval(&body.value) ConstContext::new(tcx, key.param_env.and(substs), tables).eval(&body.value)
} }

View file

@ -609,7 +609,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
let body = if let Some(id) = self.tcx.hir.as_local_node_id(def_id) { let body = if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
self.tcx.hir.body(self.tcx.hir.body_owned_by(id)) self.tcx.hir.body(self.tcx.hir.body_owned_by(id))
} else { } else {
self.tcx.sess.cstore.item_body(self.tcx, def_id) self.tcx.item_body(def_id)
}; };
let pat = self.lower_const_expr(&body.value, pat_id, span); let pat = self.lower_const_expr(&body.value, pat_id, span);
self.tables = old_tables; self.tables = old_tables;

View file

@ -214,6 +214,14 @@ provide! { <'tcx> tcx, def_id, other, cdata,
} }
defined_lang_items => { Rc::new(cdata.get_lang_items(&tcx.dep_graph)) } defined_lang_items => { Rc::new(cdata.get_lang_items(&tcx.dep_graph)) }
missing_lang_items => { Rc::new(cdata.get_missing_lang_items(&tcx.dep_graph)) } missing_lang_items => { Rc::new(cdata.get_missing_lang_items(&tcx.dep_graph)) }
item_body => {
if let Some(cached) = tcx.hir.get_inlined_body_untracked(def_id) {
return cached;
}
debug!("item_body({:?}): inlining item", def_id);
cdata.item_body(tcx, def_id.index)
}
} }
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) { pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@ -397,21 +405,6 @@ impl CrateStore for cstore::CStore {
}) })
} }
fn item_body<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
-> &'tcx hir::Body {
self.read_dep_node(def_id);
if let Some(cached) = tcx.hir.get_inlined_body_untracked(def_id) {
return cached;
}
debug!("item_body({:?}): inlining item", def_id);
self.get_crate_data(def_id.krate).item_body(tcx, def_id.index)
}
fn crates(&self) -> Vec<CrateNum> fn crates(&self) -> Vec<CrateNum>
{ {
let mut result = vec![]; let mut result = vec![];

View file

@ -474,7 +474,7 @@ impl hir::print::PpAnn for InlinedConst {
} }
fn print_inlined_const(cx: &DocContext, did: DefId) -> String { fn print_inlined_const(cx: &DocContext, did: DefId) -> String {
let body = cx.tcx.sess.cstore.item_body(cx.tcx, did); let body = cx.tcx.item_body(did);
let inlined = InlinedConst { let inlined = InlinedConst {
nested_bodies: cx.tcx.item_body_nested_bodies(did) nested_bodies: cx.tcx.item_body_nested_bodies(did)
}; };