Skip to content

Commit

Permalink
Rollup merge of rust-lang#40540 - cramertj:check-bodies-as-query, r=n…
Browse files Browse the repository at this point in the history
…ikomatsakis

On-demandify the typechecking of item bodies

r? @nikomatsakis
  • Loading branch information
alexcrichton committed Mar 25, 2017
2 parents 299a8f3 + 8c92044 commit 593b535
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/librustc/ty/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ impl<'tcx> QueryDescription for queries::mir_shims<'tcx> {
}
}

impl<'tcx> QueryDescription for queries::typeck_item_bodies<'tcx> {
fn describe(_: TyCtxt, _: CrateNum) -> String {
format!("type-checking all item bodies")
}
}


macro_rules! define_maps {
(<$tcx:tt>
$($(#[$attr:meta])*
Expand Down Expand Up @@ -396,6 +403,8 @@ define_maps! { <'tcx>
pub custom_coerce_unsized_kind: ItemSignature(DefId)
-> ty::adjustment::CustomCoerceUnsized,

pub typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> (),

pub typeck_tables: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,

pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
Expand All @@ -420,3 +429,7 @@ fn coherent_inherent_impls_dep_node(_: CrateNum) -> DepNode<DefId> {
fn mir_shim(instance: ty::InstanceDef) -> DepNode<DefId> {
instance.dep_node()
}

fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
DepNode::TypeckBodiesKrate
}
16 changes: 12 additions & 4 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ use astconv::AstConv;
use dep_graph::DepNode;
use fmt_macros::{Parser, Piece, Position};
use hir::def::{Def, CtorKind};
use hir::def_id::{DefId, LOCAL_CRATE};
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin, TypeTrace};
use rustc::infer::type_variable::{self, TypeVariableOrigin};
use rustc::ty::subst::{Kind, Subst, Substs};
Expand Down Expand Up @@ -542,18 +542,26 @@ pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult

pub fn check_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult {
return tcx.sess.track_errors(|| {
// FIXME(cramertj): This `with_task` should be removed once there is a task for
// typeck or for the compilation as a whole
tcx.dep_graph.with_task(DepNode::TypeckBodiesKrate, tcx, (), check_item_bodies_task);
});

fn check_item_bodies_task<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (): ()) {
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
tcx.item_tables(body_owner_def_id);
});
ty::queries::typeck_item_bodies::get(tcx, DUMMY_SP, LOCAL_CRATE)
}
}

fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) {
debug_assert!(crate_num == LOCAL_CRATE);
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
tcx.item_tables(body_owner_def_id);
});
}

pub fn provide(providers: &mut Providers) {
*providers = Providers {
typeck_item_bodies,
typeck_tables,
closure_type,
closure_kind,
Expand Down

0 comments on commit 593b535

Please sign in to comment.