Skip to content

Commit 3b10b4e

Browse files
committed
On-demandify the typechecking of item bodies
1 parent 07a3429 commit 3b10b4e

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/librustc/ty/maps.rs

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
1313
use middle::const_val::ConstVal;
1414
use middle::privacy::AccessLevels;
1515
use mir;
16+
use session::CompileResult;
1617
use ty::{self, CrateInherentImpls, Ty, TyCtxt};
1718

1819
use rustc_data_structures::indexed_vec::IndexVec;
@@ -202,6 +203,13 @@ impl<'tcx> QueryDescription for queries::privacy_access_levels<'tcx> {
202203
}
203204
}
204205

206+
impl<'tcx> QueryDescription for queries::typeck_item_bodies<'tcx> {
207+
fn describe(_: TyCtxt, _: CrateNum) -> String {
208+
format!("type-checking all item bodies")
209+
}
210+
}
211+
212+
205213
macro_rules! define_maps {
206214
(<$tcx:tt>
207215
$($(#[$attr:meta])*
@@ -409,6 +417,8 @@ define_maps! { <'tcx>
409417
pub coerce_unsized_info: ItemSignature(DefId)
410418
-> ty::adjustment::CoerceUnsizedInfo,
411419

420+
pub typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
421+
412422
pub typeck_tables: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
413423

414424
pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
@@ -444,3 +454,7 @@ fn crate_inherent_impls_dep_node(_: CrateNum) -> DepNode<DefId> {
444454
fn mir_shim(instance: ty::InstanceDef) -> DepNode<DefId> {
445455
instance.dep_node()
446456
}
457+
458+
fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
459+
DepNode::TypeckBodiesKrate
460+
}

src/librustc_typeck/check/mod.rs

+8-6
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};
@@ -541,19 +541,21 @@ pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult
541541
}
542542

543543
pub fn check_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult {
544-
return tcx.sess.track_errors(|| {
545-
tcx.dep_graph.with_task(DepNode::TypeckBodiesKrate, tcx, (), check_item_bodies_task);
546-
});
544+
ty::queries::typeck_item_bodies::get(tcx, DUMMY_SP, LOCAL_CRATE)
545+
}
547546

548-
fn check_item_bodies_task<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (): ()) {
547+
fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> CompileResult {
548+
debug_assert!(crate_num == LOCAL_CRATE);
549+
tcx.sess.track_errors(|| {
549550
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
550551
tcx.item_tables(body_owner_def_id);
551552
});
552-
}
553+
})
553554
}
554555

555556
pub fn provide(providers: &mut Providers) {
556557
*providers = Providers {
558+
typeck_item_bodies,
557559
typeck_tables,
558560
closure_type,
559561
closure_kind,

0 commit comments

Comments
 (0)