Skip to content

Commit 593b535

Browse files
authored
Rollup merge of rust-lang#40540 - cramertj:check-bodies-as-query, r=nikomatsakis
On-demandify the typechecking of item bodies r? @nikomatsakis
2 parents 299a8f3 + 8c92044 commit 593b535

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};
@@ -542,18 +542,26 @@ pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult
542542

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

548550
fn check_item_bodies_task<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (): ()) {
549-
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
550-
tcx.item_tables(body_owner_def_id);
551-
});
551+
ty::queries::typeck_item_bodies::get(tcx, DUMMY_SP, LOCAL_CRATE)
552552
}
553553
}
554554

555+
fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) {
556+
debug_assert!(crate_num == LOCAL_CRATE);
557+
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
558+
tcx.item_tables(body_owner_def_id);
559+
});
560+
}
561+
555562
pub fn provide(providers: &mut Providers) {
556563
*providers = Providers {
564+
typeck_item_bodies,
557565
typeck_tables,
558566
closure_type,
559567
closure_kind,

0 commit comments

Comments
 (0)