about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2019-01-26 11:47:56 +0100
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2019-01-29 21:10:33 +0100
commit0c2bf6fe2a0257712ea52a17e396b00cfd92b25c (patch)
tree2b2d3b2aea0ef02709394750f68825c98c48765d /src
parent74256630117fedf479edbd1145cac47c88036aec (diff)
downloadrust-0c2bf6fe2a0257712ea52a17e396b00cfd92b25c.tar.gz
rust-0c2bf6fe2a0257712ea52a17e396b00cfd92b25c.zip
Add an ensure() method to TyCtxt used to ensure queries are run
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/check_attr.rs3
-rw-r--r--src/librustc/middle/intrinsicck.rs4
-rw-r--r--src/librustc/middle/liveness.rs4
-rw-r--r--src/librustc/middle/stability.rs3
-rw-r--r--src/librustc/ty/query/plumbing.rs33
-rw-r--r--src/librustc/ty/util.rs2
-rw-r--r--src/librustc_borrowck/borrowck/mod.rs2
-rw-r--r--src/librustc_passes/loops.rs3
-rw-r--r--src/librustc_privacy/lib.rs4
-rw-r--r--src/librustc_typeck/check/mod.rs5
-rw-r--r--src/librustc_typeck/coherence/mod.rs6
-rw-r--r--src/librustc_typeck/collect.rs3
12 files changed, 38 insertions, 34 deletions
diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs
index df111b2be31..a2947fa0d8c 100644
--- a/src/librustc/hir/check_attr.rs
+++ b/src/librustc/hir/check_attr.rs
@@ -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));
     }
 }
 
diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs
index a0f7954eb0c..29d3713900a 100644
--- a/src/librustc/middle/intrinsicck.rs
+++ b/src/librustc/middle/intrinsicck.rs
@@ -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));
     }
 }
 
diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs
index 4ef8e1a0cf9..0724d3a262d 100644
--- a/src/librustc/middle/liveness.rs
+++ b/src/librustc/middle/liveness.rs
@@ -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();
 }
diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs
index 918e286c435..8b8318db205 100644
--- a/src/librustc/middle/stability.rs
+++ b/src/librustc/middle/stability.rs
@@ -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));
     }
 }
 
diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs
index e777c883c37..783a4646540 100644
--- a/src/librustc/ty/query/plumbing.rs
+++ b/src/librustc/ty/query/plumbing.rs
@@ -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)]
diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs
index 75fc0f716a2..2fe47b2f032 100644
--- a/src/librustc/ty/util.rs
+++ b/src/librustc/ty/util.rs
@@ -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);
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs
index 5c11d622d0a..f177f3661ac 100644
--- a/src/librustc_borrowck/borrowck/mod.rs
+++ b/src/librustc_borrowck/borrowck/mod.rs
@@ -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.
diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs
index 0dcfc72d10b..f05a7be7d75 100644
--- a/src/librustc_passes/loops.rs
+++ b/src/librustc_passes/loops.rs
@@ -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));
     }
 }
 
diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs
index dcbb9ff4a75..7f2b82f7e01 100644
--- a/src/librustc_privacy/lib.rs
+++ b/src/librustc_privacy/lib.rs
@@ -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
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index c94713980d8..85bed301d1b 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -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);
         });
     })?)
 }
diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs
index 8053ed130e9..13d24026ba3 100644
--- a/src/librustc_typeck/coherence/mod.rs
+++ b/src/librustc_typeck/coherence/mod.rs
@@ -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
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index ade84faae8d..6cfb1ceaa12 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -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));
     }
 }