Skip to content

Commit 8c92044

Browse files
committed
On-demandify the typechecking of item bodies
1 parent 134c4a0 commit 8c92044

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/librustc/ty/maps.rs

+13
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ impl<'tcx> QueryDescription for queries::mir_shims<'tcx> {
189189
}
190190
}
191191

192+
impl<'tcx> QueryDescription for queries::typeck_item_bodies<'tcx> {
193+
fn describe(_: TyCtxt, _: CrateNum) -> String {
194+
format!("type-checking all item bodies")
195+
}
196+
}
197+
198+
192199
macro_rules! define_maps {
193200
(<$tcx:tt>
194201
$($(#[$attr:meta])*
@@ -396,6 +403,8 @@ define_maps! { <'tcx>
396403
pub custom_coerce_unsized_kind: ItemSignature(DefId)
397404
-> ty::adjustment::CustomCoerceUnsized,
398405

406+
pub typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> (),
407+
399408
pub typeck_tables: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
400409

401410
pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
@@ -420,3 +429,7 @@ fn coherent_inherent_impls_dep_node(_: CrateNum) -> DepNode<DefId> {
420429
fn mir_shim(instance: ty::InstanceDef) -> DepNode<DefId> {
421430
instance.dep_node()
422431
}
432+
433+
fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
434+
DepNode::TypeckBodiesKrate
435+
}

src/librustc_typeck/check/mod.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ use astconv::AstConv;
8484
use dep_graph::DepNode;
8585
use fmt_macros::{Parser, Piece, Position};
8686
use hir::def::{Def, CtorKind};
87-
use hir::def_id::{DefId, LOCAL_CRATE};
87+
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
8888
use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin, TypeTrace};
8989
use rustc::infer::type_variable::{self, TypeVariableOrigin};
9090
use rustc::ty::subst::{Kind, Subst, Substs};
@@ -540,18 +540,26 @@ pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult
540540

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

546548
fn check_item_bodies_task<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (): ()) {
547-
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
548-
tcx.item_tables(body_owner_def_id);
549-
});
549+
ty::queries::typeck_item_bodies::get(tcx, DUMMY_SP, LOCAL_CRATE)
550550
}
551551
}
552552

553+
fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) {
554+
debug_assert!(crate_num == LOCAL_CRATE);
555+
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
556+
tcx.item_tables(body_owner_def_id);
557+
});
558+
}
559+
553560
pub fn provide(providers: &mut Providers) {
554561
*providers = Providers {
562+
typeck_item_bodies,
555563
typeck_tables,
556564
closure_type,
557565
closure_kind,

0 commit comments

Comments
 (0)