1
Fork 0

On-demandify the typechecking of item bodies

This commit is contained in:
Taylor Cramer 2017-03-14 22:46:36 -07:00
parent 07a34293fa
commit 3b10b4e95f
2 changed files with 22 additions and 6 deletions

View file

@ -13,6 +13,7 @@ use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use middle::const_val::ConstVal; use middle::const_val::ConstVal;
use middle::privacy::AccessLevels; use middle::privacy::AccessLevels;
use mir; use mir;
use session::CompileResult;
use ty::{self, CrateInherentImpls, Ty, TyCtxt}; use ty::{self, CrateInherentImpls, Ty, TyCtxt};
use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::indexed_vec::IndexVec;
@ -202,6 +203,13 @@ impl<'tcx> QueryDescription for queries::privacy_access_levels<'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 { macro_rules! define_maps {
(<$tcx:tt> (<$tcx:tt>
$($(#[$attr:meta])* $($(#[$attr:meta])*
@ -409,6 +417,8 @@ define_maps! { <'tcx>
pub coerce_unsized_info: ItemSignature(DefId) pub coerce_unsized_info: ItemSignature(DefId)
-> ty::adjustment::CoerceUnsizedInfo, -> ty::adjustment::CoerceUnsizedInfo,
pub typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
pub typeck_tables: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>, pub typeck_tables: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (), pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
@ -444,3 +454,7 @@ fn crate_inherent_impls_dep_node(_: CrateNum) -> DepNode<DefId> {
fn mir_shim(instance: ty::InstanceDef) -> DepNode<DefId> { fn mir_shim(instance: ty::InstanceDef) -> DepNode<DefId> {
instance.dep_node() instance.dep_node()
} }
fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
DepNode::TypeckBodiesKrate
}

View file

@ -84,7 +84,7 @@ use astconv::AstConv;
use dep_graph::DepNode; use dep_graph::DepNode;
use fmt_macros::{Parser, Piece, Position}; use fmt_macros::{Parser, Piece, Position};
use hir::def::{Def, CtorKind}; 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::{self, InferCtxt, InferOk, RegionVariableOrigin, TypeTrace};
use rustc::infer::type_variable::{self, TypeVariableOrigin}; use rustc::infer::type_variable::{self, TypeVariableOrigin};
use rustc::ty::subst::{Kind, Subst, Substs}; use rustc::ty::subst::{Kind, Subst, Substs};
@ -541,19 +541,21 @@ 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 { pub fn check_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult {
return tcx.sess.track_errors(|| { ty::queries::typeck_item_bodies::get(tcx, DUMMY_SP, LOCAL_CRATE)
tcx.dep_graph.with_task(DepNode::TypeckBodiesKrate, tcx, (), check_item_bodies_task); }
});
fn check_item_bodies_task<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (): ()) { fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> CompileResult {
debug_assert!(crate_num == LOCAL_CRATE);
tcx.sess.track_errors(|| {
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| { tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
tcx.item_tables(body_owner_def_id); tcx.item_tables(body_owner_def_id);
}); });
} })
} }
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {
*providers = Providers { *providers = Providers {
typeck_item_bodies,
typeck_tables, typeck_tables,
closure_type, closure_type,
closure_kind, closure_kind,