Add an ensure() method to TyCtxt used to ensure queries are run
This commit is contained in:
parent
7425663011
commit
0c2bf6fe2a
12 changed files with 38 additions and 34 deletions
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
use ty::TyCtxt;
|
||||
use ty::query::Providers;
|
||||
use ty::query::queries;
|
||||
|
||||
use hir;
|
||||
use hir::def_id::DefId;
|
||||
|
|
@ -355,7 +354,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckAttrVisitor<'a, 'tcx> {
|
|||
|
||||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
queries::check_mod_attrs::ensure(tcx, tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_attrs(tcx.hir().local_def_id(module));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use hir::def::Def;
|
|||
use hir::def_id::DefId;
|
||||
use ty::{self, Ty, TyCtxt};
|
||||
use ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx};
|
||||
use ty::query::{Providers, queries};
|
||||
use ty::query::Providers;
|
||||
|
||||
use rustc_target::spec::abi::Abi::RustIntrinsic;
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
|
|
@ -12,7 +12,7 @@ use hir;
|
|||
|
||||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
queries::check_mod_intrinsics::ensure(tcx, tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_intrinsics(tcx.hir().local_def_id(module));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ use self::VarKind::*;
|
|||
use hir::def::*;
|
||||
use hir::Node;
|
||||
use ty::{self, TyCtxt};
|
||||
use ty::query::{Providers, queries};
|
||||
use ty::query::Providers;
|
||||
use lint;
|
||||
use errors::Applicability;
|
||||
use util::nodemap::{NodeMap, HirIdMap, HirIdSet};
|
||||
|
|
@ -187,7 +187,7 @@ fn check_mod_liveness<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) {
|
|||
|
||||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
queries::check_mod_liveness::ensure(tcx, tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_liveness(tcx.hir().local_def_id(module));
|
||||
}
|
||||
tcx.sess.abort_if_errors();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ use hir::def::Def;
|
|||
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
|
||||
use hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use ty::query::Providers;
|
||||
use ty::query::queries;
|
||||
use middle::privacy::AccessLevels;
|
||||
use session::{DiagnosticMessageId, Session};
|
||||
use syntax::symbol::Symbol;
|
||||
|
|
@ -458,7 +457,7 @@ impl<'a, 'tcx> Index<'tcx> {
|
|||
|
||||
pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
queries::check_mod_unstable_api_usage::ensure(tcx, tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_unstable_api_usage(tcx.hir().local_def_id(module));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -969,20 +969,20 @@ macro_rules! define_queries_inner {
|
|||
fn handle_cycle_error(tcx: TyCtxt<'_, 'tcx, '_>) -> Self::Value {
|
||||
handle_cycle_error!([$($modifiers)*][tcx])
|
||||
}
|
||||
})*
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct TyCtxtEnsure<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
|
||||
/// Ensure that either this query has all green inputs or been executed.
|
||||
/// Executing query::ensure(D) is considered a read of the dep-node D.
|
||||
///
|
||||
/// This function is particularly useful when executing passes for their
|
||||
/// side-effects -- e.g., in order to report errors for erroneous programs.
|
||||
///
|
||||
/// Note: The optimization is only available during incr. comp.
|
||||
pub fn ensure(tcx: TyCtxt<'a, $tcx, 'lcx>, key: $K) -> () {
|
||||
tcx.ensure_query::<queries::$name<'_>>(key);
|
||||
}
|
||||
})*
|
||||
impl<'a, $tcx, 'lcx> TyCtxtEnsure<'a, $tcx, 'lcx> {
|
||||
$($(#[$attr])*
|
||||
#[inline(always)]
|
||||
pub fn $name(self, key: $K) {
|
||||
self.tcx.ensure_query::<queries::$name<'_>>(key)
|
||||
})*
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
|
|
@ -999,6 +999,15 @@ macro_rules! define_queries_inner {
|
|||
}
|
||||
|
||||
impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
|
||||
/// Return a transparent wrapper for `TyCtxt` which ensures queries
|
||||
/// are executed instead of returing their result
|
||||
#[inline(always)]
|
||||
pub fn ensure(self) -> TyCtxtEnsure<'a, $tcx, 'lcx> {
|
||||
TyCtxtEnsure {
|
||||
tcx: self,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a transparent wrapper for `TyCtxt` which uses
|
||||
/// `span` as the location of queries performed through it.
|
||||
#[inline(always)]
|
||||
|
|
|
|||
|
|
@ -402,7 +402,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
return None;
|
||||
};
|
||||
|
||||
ty::query::queries::coherent_trait::ensure(self, drop_trait);
|
||||
self.ensure().coherent_trait(drop_trait);
|
||||
|
||||
let mut dtor_did = None;
|
||||
let ty = self.type_of(adt_did);
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
|
|||
// Note that `mir_validated` is a "stealable" result; the
|
||||
// thief, `optimized_mir()`, forces borrowck, so we know that
|
||||
// is not yet stolen.
|
||||
ty::query::queries::mir_validated::ensure(tcx, owner_def_id);
|
||||
tcx.ensure().mir_validated(owner_def_id);
|
||||
|
||||
// option dance because you can't capture an uninitialized variable
|
||||
// by mut-ref.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ use self::Context::*;
|
|||
use rustc::session::Session;
|
||||
|
||||
use rustc::ty::query::Providers;
|
||||
use rustc::ty::query::queries;
|
||||
use rustc::ty::TyCtxt;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::map::Map;
|
||||
|
|
@ -48,7 +47,7 @@ struct CheckLoopVisitor<'a, 'hir: 'a> {
|
|||
|
||||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
queries::check_mod_loops::ensure(tcx, tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_loops(tcx.hir().local_def_id(module));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use rustc::lint;
|
|||
use rustc::middle::privacy::{AccessLevel, AccessLevels};
|
||||
use rustc::ty::{self, TyCtxt, Ty, TraitRef, TypeFoldable, GenericParamDefKind};
|
||||
use rustc::ty::fold::TypeVisitor;
|
||||
use rustc::ty::query::{Providers, queries};
|
||||
use rustc::ty::query::Providers;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::util::nodemap::NodeSet;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
|
|
@ -1722,7 +1722,7 @@ fn privacy_access_levels<'tcx>(
|
|||
let krate = tcx.hir().krate();
|
||||
|
||||
for &module in krate.modules.keys() {
|
||||
queries::check_mod_privacy::ensure(tcx, tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id(module));
|
||||
}
|
||||
|
||||
// Build up a set of all exported items in the AST. This is a set of all
|
||||
|
|
|
|||
|
|
@ -109,7 +109,6 @@ use rustc::ty::{
|
|||
use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
|
||||
use rustc::ty::fold::TypeFoldable;
|
||||
use rustc::ty::query::Providers;
|
||||
use rustc::ty::query::queries;
|
||||
use rustc::ty::subst::{UnpackedKind, Subst, Substs, UserSelfTy, UserSubsts};
|
||||
use rustc::ty::util::{Representability, IntTypeExt, Discr};
|
||||
use rustc::ty::layout::VariantIdx;
|
||||
|
|
@ -703,7 +702,7 @@ pub fn check_wf_new<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Result<(), ErrorRe
|
|||
pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Result<(), ErrorReported> {
|
||||
tcx.sess.track_errors(|| {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
queries::check_mod_item_types::ensure(tcx, tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -722,7 +721,7 @@ fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum
|
|||
debug_assert!(crate_num == LOCAL_CRATE);
|
||||
Ok(tcx.sess.track_errors(|| {
|
||||
tcx.par_body_owners(|body_owner_def_id| {
|
||||
ty::query::queries::typeck_tables_of::ensure(tcx, body_owner_def_id);
|
||||
tcx.ensure().typeck_tables_of(body_owner_def_id);
|
||||
});
|
||||
})?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,15 +137,15 @@ fn coherent_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
|
|||
|
||||
pub fn check_coherence<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
for &trait_def_id in tcx.hir().krate().trait_impls.keys() {
|
||||
ty::query::queries::coherent_trait::ensure(tcx, trait_def_id);
|
||||
tcx.ensure().coherent_trait(trait_def_id);
|
||||
}
|
||||
|
||||
unsafety::check(tcx);
|
||||
orphan::check(tcx);
|
||||
|
||||
// these queries are executed for side-effects (error reporting):
|
||||
ty::query::queries::crate_inherent_impls::ensure(tcx, LOCAL_CRATE);
|
||||
ty::query::queries::crate_inherent_impls_overlap_check::ensure(tcx, LOCAL_CRATE);
|
||||
tcx.ensure().crate_inherent_impls(LOCAL_CRATE);
|
||||
tcx.ensure().crate_inherent_impls_overlap_check(LOCAL_CRATE);
|
||||
}
|
||||
|
||||
/// Overlap: No two impls for the same trait are implemented for the
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ use middle::resolve_lifetime as rl;
|
|||
use middle::weak_lang_items;
|
||||
use rustc::mir::mono::Linkage;
|
||||
use rustc::ty::query::Providers;
|
||||
use rustc::ty::query::queries;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::ty::util::Discr;
|
||||
use rustc::ty::util::IntTypeExt;
|
||||
|
|
@ -58,7 +57,7 @@ struct OnlySelfBounds(bool);
|
|||
|
||||
pub fn collect_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
queries::collect_mod_item_types::ensure(tcx, tcx.hir().local_def_id(module));
|
||||
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue