Skip to content

Commit 0c2bf6f

Browse files
committed
Add an ensure() method to TyCtxt used to ensure queries are run
1 parent 7425663 commit 0c2bf6f

File tree

12 files changed

+38
-34
lines changed

12 files changed

+38
-34
lines changed

src/librustc/hir/check_attr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use ty::TyCtxt;
99
use ty::query::Providers;
10-
use ty::query::queries;
1110

1211
use hir;
1312
use hir::def_id::DefId;
@@ -355,7 +354,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckAttrVisitor<'a, 'tcx> {
355354

356355
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
357356
for &module in tcx.hir().krate().modules.keys() {
358-
queries::check_mod_attrs::ensure(tcx, tcx.hir().local_def_id(module));
357+
tcx.ensure().check_mod_attrs(tcx.hir().local_def_id(module));
359358
}
360359
}
361360

src/librustc/middle/intrinsicck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use hir::def::Def;
22
use hir::def_id::DefId;
33
use ty::{self, Ty, TyCtxt};
44
use ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx};
5-
use ty::query::{Providers, queries};
5+
use ty::query::Providers;
66

77
use rustc_target::spec::abi::Abi::RustIntrinsic;
88
use rustc_data_structures::indexed_vec::Idx;
@@ -12,7 +12,7 @@ use hir;
1212

1313
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
1414
for &module in tcx.hir().krate().modules.keys() {
15-
queries::check_mod_intrinsics::ensure(tcx, tcx.hir().local_def_id(module));
15+
tcx.ensure().check_mod_intrinsics(tcx.hir().local_def_id(module));
1616
}
1717
}
1818

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ use self::VarKind::*;
100100
use hir::def::*;
101101
use hir::Node;
102102
use ty::{self, TyCtxt};
103-
use ty::query::{Providers, queries};
103+
use ty::query::Providers;
104104
use lint;
105105
use errors::Applicability;
106106
use util::nodemap::{NodeMap, HirIdMap, HirIdSet};
@@ -187,7 +187,7 @@ fn check_mod_liveness<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) {
187187

188188
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
189189
for &module in tcx.hir().krate().modules.keys() {
190-
queries::check_mod_liveness::ensure(tcx, tcx.hir().local_def_id(module));
190+
tcx.ensure().check_mod_liveness(tcx.hir().local_def_id(module));
191191
}
192192
tcx.sess.abort_if_errors();
193193
}

src/librustc/middle/stability.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use hir::def::Def;
99
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
1010
use hir::intravisit::{self, Visitor, NestedVisitorMap};
1111
use ty::query::Providers;
12-
use ty::query::queries;
1312
use middle::privacy::AccessLevels;
1413
use session::{DiagnosticMessageId, Session};
1514
use syntax::symbol::Symbol;
@@ -458,7 +457,7 @@ impl<'a, 'tcx> Index<'tcx> {
458457

459458
pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
460459
for &module in tcx.hir().krate().modules.keys() {
461-
queries::check_mod_unstable_api_usage::ensure(tcx, tcx.hir().local_def_id(module));
460+
tcx.ensure().check_mod_unstable_api_usage(tcx.hir().local_def_id(module));
462461
}
463462
}
464463

src/librustc/ty/query/plumbing.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -969,20 +969,20 @@ macro_rules! define_queries_inner {
969969
fn handle_cycle_error(tcx: TyCtxt<'_, 'tcx, '_>) -> Self::Value {
970970
handle_cycle_error!([$($modifiers)*][tcx])
971971
}
972+
})*
973+
974+
#[derive(Copy, Clone)]
975+
pub struct TyCtxtEnsure<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
976+
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
972977
}
973978

974-
impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
975-
/// Ensure that either this query has all green inputs or been executed.
976-
/// Executing query::ensure(D) is considered a read of the dep-node D.
977-
///
978-
/// This function is particularly useful when executing passes for their
979-
/// side-effects -- e.g., in order to report errors for erroneous programs.
980-
///
981-
/// Note: The optimization is only available during incr. comp.
982-
pub fn ensure(tcx: TyCtxt<'a, $tcx, 'lcx>, key: $K) -> () {
983-
tcx.ensure_query::<queries::$name<'_>>(key);
984-
}
985-
})*
979+
impl<'a, $tcx, 'lcx> TyCtxtEnsure<'a, $tcx, 'lcx> {
980+
$($(#[$attr])*
981+
#[inline(always)]
982+
pub fn $name(self, key: $K) {
983+
self.tcx.ensure_query::<queries::$name<'_>>(key)
984+
})*
985+
}
986986

987987
#[derive(Copy, Clone)]
988988
pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
@@ -999,6 +999,15 @@ macro_rules! define_queries_inner {
999999
}
10001000

10011001
impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
1002+
/// Return a transparent wrapper for `TyCtxt` which ensures queries
1003+
/// are executed instead of returing their result
1004+
#[inline(always)]
1005+
pub fn ensure(self) -> TyCtxtEnsure<'a, $tcx, 'lcx> {
1006+
TyCtxtEnsure {
1007+
tcx: self,
1008+
}
1009+
}
1010+
10021011
/// Return a transparent wrapper for `TyCtxt` which uses
10031012
/// `span` as the location of queries performed through it.
10041013
#[inline(always)]

src/librustc/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
402402
return None;
403403
};
404404

405-
ty::query::queries::coherent_trait::ensure(self, drop_trait);
405+
self.ensure().coherent_trait(drop_trait);
406406

407407
let mut dtor_did = None;
408408
let ty = self.type_of(adt_did);

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
121121
// Note that `mir_validated` is a "stealable" result; the
122122
// thief, `optimized_mir()`, forces borrowck, so we know that
123123
// is not yet stolen.
124-
ty::query::queries::mir_validated::ensure(tcx, owner_def_id);
124+
tcx.ensure().mir_validated(owner_def_id);
125125

126126
// option dance because you can't capture an uninitialized variable
127127
// by mut-ref.

src/librustc_passes/loops.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use self::Context::*;
33
use rustc::session::Session;
44

55
use rustc::ty::query::Providers;
6-
use rustc::ty::query::queries;
76
use rustc::ty::TyCtxt;
87
use rustc::hir::def_id::DefId;
98
use rustc::hir::map::Map;
@@ -48,7 +47,7 @@ struct CheckLoopVisitor<'a, 'hir: 'a> {
4847

4948
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
5049
for &module in tcx.hir().krate().modules.keys() {
51-
queries::check_mod_loops::ensure(tcx, tcx.hir().local_def_id(module));
50+
tcx.ensure().check_mod_loops(tcx.hir().local_def_id(module));
5251
}
5352
}
5453

src/librustc_privacy/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc::lint;
2222
use rustc::middle::privacy::{AccessLevel, AccessLevels};
2323
use rustc::ty::{self, TyCtxt, Ty, TraitRef, TypeFoldable, GenericParamDefKind};
2424
use rustc::ty::fold::TypeVisitor;
25-
use rustc::ty::query::{Providers, queries};
25+
use rustc::ty::query::Providers;
2626
use rustc::ty::subst::Substs;
2727
use rustc::util::nodemap::NodeSet;
2828
use rustc_data_structures::fx::FxHashSet;
@@ -1722,7 +1722,7 @@ fn privacy_access_levels<'tcx>(
17221722
let krate = tcx.hir().krate();
17231723

17241724
for &module in krate.modules.keys() {
1725-
queries::check_mod_privacy::ensure(tcx, tcx.hir().local_def_id(module));
1725+
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id(module));
17261726
}
17271727

17281728
// Build up a set of all exported items in the AST. This is a set of all

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ use rustc::ty::{
109109
use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
110110
use rustc::ty::fold::TypeFoldable;
111111
use rustc::ty::query::Providers;
112-
use rustc::ty::query::queries;
113112
use rustc::ty::subst::{UnpackedKind, Subst, Substs, UserSelfTy, UserSubsts};
114113
use rustc::ty::util::{Representability, IntTypeExt, Discr};
115114
use rustc::ty::layout::VariantIdx;
@@ -703,7 +702,7 @@ pub fn check_wf_new<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Result<(), ErrorRe
703702
pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Result<(), ErrorReported> {
704703
tcx.sess.track_errors(|| {
705704
for &module in tcx.hir().krate().modules.keys() {
706-
queries::check_mod_item_types::ensure(tcx, tcx.hir().local_def_id(module));
705+
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
707706
}
708707
})
709708
}
@@ -722,7 +721,7 @@ fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum
722721
debug_assert!(crate_num == LOCAL_CRATE);
723722
Ok(tcx.sess.track_errors(|| {
724723
tcx.par_body_owners(|body_owner_def_id| {
725-
ty::query::queries::typeck_tables_of::ensure(tcx, body_owner_def_id);
724+
tcx.ensure().typeck_tables_of(body_owner_def_id);
726725
});
727726
})?)
728727
}

src/librustc_typeck/coherence/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ fn coherent_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
137137

138138
pub fn check_coherence<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
139139
for &trait_def_id in tcx.hir().krate().trait_impls.keys() {
140-
ty::query::queries::coherent_trait::ensure(tcx, trait_def_id);
140+
tcx.ensure().coherent_trait(trait_def_id);
141141
}
142142

143143
unsafety::check(tcx);
144144
orphan::check(tcx);
145145

146146
// these queries are executed for side-effects (error reporting):
147-
ty::query::queries::crate_inherent_impls::ensure(tcx, LOCAL_CRATE);
148-
ty::query::queries::crate_inherent_impls_overlap_check::ensure(tcx, LOCAL_CRATE);
147+
tcx.ensure().crate_inherent_impls(LOCAL_CRATE);
148+
tcx.ensure().crate_inherent_impls_overlap_check(LOCAL_CRATE);
149149
}
150150

151151
/// Overlap: No two impls for the same trait are implemented for the

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use middle::resolve_lifetime as rl;
2323
use middle::weak_lang_items;
2424
use rustc::mir::mono::Linkage;
2525
use rustc::ty::query::Providers;
26-
use rustc::ty::query::queries;
2726
use rustc::ty::subst::Substs;
2827
use rustc::ty::util::Discr;
2928
use rustc::ty::util::IntTypeExt;
@@ -58,7 +57,7 @@ struct OnlySelfBounds(bool);
5857

5958
pub fn collect_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
6059
for &module in tcx.hir().krate().modules.keys() {
61-
queries::collect_mod_item_types::ensure(tcx, tcx.hir().local_def_id(module));
60+
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module));
6261
}
6362
}
6463

0 commit comments

Comments
 (0)