Skip to content

Commit 84ae4b7

Browse files
committed
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.
1 parent 953490d commit 84ae4b7

File tree

7 files changed

+14
-30
lines changed

7 files changed

+14
-30
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ define_dep_nodes!( <'tcx>
563563
[] GetLangItems,
564564
[] DefinedLangItems(CrateNum),
565565
[] MissingLangItems(CrateNum),
566+
[] ItemBody(DefId),
566567
);
567568

568569
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

src/librustc/middle/cstore.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use syntax::ext::base::SyntaxExtension;
4242
use syntax::symbol::Symbol;
4343
use syntax_pos::Span;
4444
use rustc_back::target::Target;
45-
use hir;
4645

4746
pub use self::NativeLibraryKind::*;
4847

@@ -258,10 +257,6 @@ pub trait CrateStore {
258257
fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro;
259258
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
260259

261-
// misc. metadata
262-
fn item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
263-
-> &'tcx hir::Body;
264-
265260
// This is basically a 1-based range of ints, which is a little
266261
// silly - I may fix that.
267262
fn crates(&self) -> Vec<CrateNum>;
@@ -350,12 +345,6 @@ impl CrateStore for DummyCrateStore {
350345
}
351346
fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") }
352347

353-
// misc. metadata
354-
fn item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
355-
-> &'tcx hir::Body {
356-
bug!("item_body")
357-
}
358-
359348
// This is basically a 1-based range of ints, which is a little
360349
// silly - I may fix that.
361350
fn crates(&self) -> Vec<CrateNum> { vec![] }

src/librustc/ty/maps.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,7 @@ define_maps! { <'tcx>
13151315
[] get_lang_items: get_lang_items_node(CrateNum) -> Rc<LanguageItems>,
13161316
[] defined_lang_items: DefinedLangItems(CrateNum) -> Rc<Vec<(DefIndex, usize)>>,
13171317
[] missing_lang_items: MissingLangItems(CrateNum) -> Rc<Vec<LangItem>>,
1318+
[] item_body: ItemBody(DefId) -> &'tcx hir::Body,
13181319
}
13191320

13201321
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {

src/librustc_const_eval/eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
354354
}
355355
} else {
356356
if tcx.is_const_fn(def_id) {
357-
tcx.sess.cstore.item_body(tcx, def_id)
357+
tcx.item_body(def_id)
358358
} else {
359359
signal!(e, TypeckError)
360360
}
@@ -774,7 +774,7 @@ fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
774774
tcx.mir_const_qualif(def_id);
775775
tcx.hir.body(tcx.hir.body_owned_by(id))
776776
} else {
777-
tcx.sess.cstore.item_body(tcx, def_id)
777+
tcx.item_body(def_id)
778778
};
779779
ConstContext::new(tcx, key.param_env.and(substs), tables).eval(&body.value)
780780
}

src/librustc_const_eval/pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
609609
let body = if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
610610
self.tcx.hir.body(self.tcx.hir.body_owned_by(id))
611611
} else {
612-
self.tcx.sess.cstore.item_body(self.tcx, def_id)
612+
self.tcx.item_body(def_id)
613613
};
614614
let pat = self.lower_const_expr(&body.value, pat_id, span);
615615
self.tables = old_tables;

src/librustc_metadata/cstore_impl.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ provide! { <'tcx> tcx, def_id, other, cdata,
214214
}
215215
defined_lang_items => { Rc::new(cdata.get_lang_items(&tcx.dep_graph)) }
216216
missing_lang_items => { Rc::new(cdata.get_missing_lang_items(&tcx.dep_graph)) }
217+
218+
item_body => {
219+
if let Some(cached) = tcx.hir.get_inlined_body_untracked(def_id) {
220+
return cached;
221+
}
222+
debug!("item_body({:?}): inlining item", def_id);
223+
cdata.item_body(tcx, def_id.index)
224+
}
217225
}
218226

219227
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@@ -397,21 +405,6 @@ impl CrateStore for cstore::CStore {
397405
})
398406
}
399407

400-
fn item_body<'a, 'tcx>(&self,
401-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
402-
def_id: DefId)
403-
-> &'tcx hir::Body {
404-
self.read_dep_node(def_id);
405-
406-
if let Some(cached) = tcx.hir.get_inlined_body_untracked(def_id) {
407-
return cached;
408-
}
409-
410-
debug!("item_body({:?}): inlining item", def_id);
411-
412-
self.get_crate_data(def_id.krate).item_body(tcx, def_id.index)
413-
}
414-
415408
fn crates(&self) -> Vec<CrateNum>
416409
{
417410
let mut result = vec![];

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl hir::print::PpAnn for InlinedConst {
474474
}
475475

476476
fn print_inlined_const(cx: &DocContext, did: DefId) -> String {
477-
let body = cx.tcx.sess.cstore.item_body(cx.tcx, did);
477+
let body = cx.tcx.item_body(did);
478478
let inlined = InlinedConst {
479479
nested_bodies: cx.tcx.item_body_nested_bodies(did)
480480
};

0 commit comments

Comments
 (0)