]> git.lizzy.rs Git - rust.git/commitdiff
rustc: use tcx.at(span) to set the location of a query.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Mon, 24 Apr 2017 15:06:39 +0000 (18:06 +0300)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Mon, 24 Apr 2017 15:06:39 +0000 (18:06 +0300)
13 files changed:
src/librustc/middle/const_val.rs
src/librustc/ty/maps.rs
src/librustc/ty/mod.rs
src/librustc/ty/util.rs
src/librustc_const_eval/eval.rs
src/librustc_metadata/encoder.rs
src/librustc_mir/hair/cx/expr.rs
src/librustc_mir/transform/qualify_consts.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/method/probe.rs
src/librustc_typeck/coherence/builtin.rs
src/librustc_typeck/coherence/inherent_impls.rs
src/librustc_typeck/collect.rs

index ec7b3c4dd8dffd4514205789364611c8a89a4a26..74026abe64db2fd1c27a0b4a000bfbc490e04c5b 100644 (file)
@@ -14,7 +14,7 @@
 use hir;
 use hir::def::Def;
 use hir::def_id::DefId;
-use ty::{self, TyCtxt};
+use ty::TyCtxt;
 use ty::subst::Substs;
 use util::common::ErrorReported;
 use rustc_const_math::*;
@@ -228,7 +228,7 @@ pub fn eval_length(tcx: TyCtxt,
     let count_expr = &tcx.hir.body(count).value;
     let count_def_id = tcx.hir.body_owner_def_id(count);
     let substs = Substs::empty();
-    match ty::queries::const_eval::get(tcx, count_expr.span, (count_def_id, substs)) {
+    match tcx.at(count_expr.span).const_eval((count_def_id, substs)) {
         Ok(Integral(Usize(count))) => {
             let val = count.as_u64(tcx.sess.target.uint_type);
             assert_eq!(val as usize as u64, val);
index 3023e006d1b170ec0a51f1b7d229f8703cbb630c..1407e57dc2a6a7e48f56b027aaa34ca24462dd8d 100644 (file)
@@ -21,6 +21,7 @@
 
 use rustc_data_structures::indexed_vec::IndexVec;
 use std::cell::{RefCell, RefMut};
+use std::ops::Deref;
 use std::rc::Rc;
 use syntax_pos::{Span, DUMMY_SP};
 
@@ -329,14 +330,6 @@ pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K)
                 Self::try_get_with(tcx, span, key, Clone::clone)
             }
 
-            $(#[$attr])*
-            pub fn get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) -> $V {
-                Self::try_get(tcx, span, key).unwrap_or_else(|e| {
-                    tcx.report_cycle(e);
-                    Value::from_cycle_error(tcx.global_tcx())
-                })
-            }
-
             pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) {
                 // FIXME(eddyb) Move away from using `DepTrackingMap`
                 // so we don't have to explicitly ignore a false edge:
@@ -351,10 +344,42 @@ pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) {
             }
         })*
 
+        #[derive(Copy, Clone)]
+        pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
+            pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
+            pub span: Span,
+        }
+
+        impl<'a, 'gcx, 'tcx> Deref for TyCtxtAt<'a, 'gcx, 'tcx> {
+            type Target = TyCtxt<'a, 'gcx, 'tcx>;
+            fn deref(&self) -> &Self::Target {
+                &self.tcx
+            }
+        }
+
         impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
+            /// Return a transparent wrapper for `TyCtxt` which uses
+            /// `span` as the location of queries performed through it.
+            pub fn at(self, span: Span) -> TyCtxtAt<'a, $tcx, 'lcx> {
+                TyCtxtAt {
+                    tcx: self,
+                    span
+                }
+            }
+
+            $($(#[$attr])*
+            pub fn $name(self, key: $K) -> $V {
+                self.at(DUMMY_SP).$name(key)
+            })*
+        }
+
+        impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> {
             $($(#[$attr])*
             pub fn $name(self, key: $K) -> $V {
-                queries::$name::get(self, DUMMY_SP, key)
+                queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|e| {
+                    self.report_cycle(e);
+                    Value::from_cycle_error(self.global_tcx())
+                })
             })*
         }
 
index 9af8e2a3fc220b1c47b09642cb57d02b79961207..a923ae154027b882d6130d53c194deddd2f65866 100644 (file)
@@ -2699,9 +2699,8 @@ pub fn provide_extern(providers: &mut ty::maps::Providers) {
 /// A map for the local crate mapping each type to a vector of its
 /// inherent impls. This is not meant to be used outside of coherence;
 /// rather, you should request the vector for a specific type via
-/// `ty::queries::inherent_impls::get(def_id)` so as to minimize your
-/// dependencies (constructing this map requires touching the entire
-/// crate).
+/// `tcx.inherent_impls(def_id)` so as to minimize your dependencies
+/// (constructing this map requires touching the entire crate).
 #[derive(Clone, Debug)]
 pub struct CrateInherentImpls {
     pub inherent_impls: DefIdMap<Rc<Vec<DefId>>>,
index 54e00efc08e7736cc1d54403680c09dd1dcacec9..87921c80502e09a48f6d21d0cea212392d30b5ff 100644 (file)
@@ -522,7 +522,7 @@ pub fn dtorck_constraint_for_ty(self,
             ty::TyAdt(def, substs) => {
                 let ty::DtorckConstraint {
                     dtorck_types, outlives
-                } = ty::queries::adt_dtorck_constraint::get(self, span, def.did);
+                } = self.at(span).adt_dtorck_constraint(def.did);
                 Ok(ty::DtorckConstraint {
                     // FIXME: we can try to recursively `dtorck_constraint_on_ty`
                     // there, but that needs some way to handle cycles.
index e7ccf3cbdb8f2762f5411c48565cf7619f8055f8..9470316c7e7e018799cc5677c4fed84f05842828 100644 (file)
@@ -299,7 +299,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
           match cx.tables.qpath_def(qpath, e.id) {
               Def::Const(def_id) |
               Def::AssociatedConst(def_id) => {
-                    match ty::queries::const_eval::get(tcx, e.span, (def_id, substs)) {
+                    match tcx.at(e.span).const_eval((def_id, substs)) {
                         Ok(val) => val,
                         Err(ConstEvalErr { kind: TypeckError, .. }) => {
                             signal!(e, TypeckError);
index 4fd8d478717aff66f7950b50043b813367d196d5..783e7604cdaf1b424e0effa9d38b4f0a94ece427 100644 (file)
@@ -547,7 +547,7 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
         let kind = match impl_item.kind {
             ty::AssociatedKind::Const => {
                 EntryKind::AssociatedConst(container,
-                    ty::queries::mir_const_qualif::get(self.tcx, ast_item.span, def_id))
+                    self.tcx.at(ast_item.span).mir_const_qualif(def_id))
             }
             ty::AssociatedKind::Method => {
                 let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
@@ -656,7 +656,7 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
             hir::ItemStatic(_, hir::MutMutable, _) => EntryKind::MutStatic,
             hir::ItemStatic(_, hir::MutImmutable, _) => EntryKind::ImmStatic,
             hir::ItemConst(..) => {
-                EntryKind::Const(ty::queries::mir_const_qualif::get(tcx, item.span, def_id))
+                EntryKind::Const(tcx.at(item.span).mir_const_qualif(def_id))
             }
             hir::ItemFn(_, _, constness, .., body) => {
                 let data = FnData {
@@ -732,7 +732,7 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
                 let coerce_unsized_info =
                     trait_ref.and_then(|t| {
                         if Some(t.def_id) == tcx.lang_items.coerce_unsized_trait() {
-                            Some(ty::queries::coerce_unsized_info::get(tcx, item.span, def_id))
+                            Some(tcx.at(item.span).coerce_unsized_info(def_id))
                         } else {
                             None
                         }
index 736c076ea15446cb4b510cafb72e434290df6fef..7b267fa276b1873598cdd609c8496b6d9da5ea14 100644 (file)
@@ -594,7 +594,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
             let c = &cx.tcx.hir.body(count).value;
             let def_id = cx.tcx.hir.body_owner_def_id(count);
             let substs = Substs::empty();
-            let count = match ty::queries::const_eval::get(cx.tcx, c.span, (def_id, substs)) {
+            let count = match cx.tcx.at(c.span).const_eval((def_id, substs)) {
                 Ok(ConstVal::Integral(ConstInt::Usize(u))) => u,
                 Ok(other) => bug!("constant evaluation of repeat count yielded {:?}", other),
                 Err(s) => cx.fatal_const_eval_err(&s, c.span, "expression")
index 48f70c2685129f76dfb43e80111a0cea0d03c5ff..afb775aa01e70a73c35726397186446ba8bc7a71 100644 (file)
@@ -573,9 +573,7 @@ fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
                     if substs.types().next().is_some() {
                         self.add_type(constant.ty);
                     } else {
-                        let bits = ty::queries::mir_const_qualif::get(self.tcx,
-                                                                      constant.span,
-                                                                      def_id);
+                        let bits = self.tcx.at(constant.span).mir_const_qualif(def_id);
 
                         let qualif = Qualif::from_bits(bits).expect("invalid mir_const_qualif");
                         self.add(qualif);
index c1865899894435967d6e4e6a1142802b2541bce0..c06e0bd5cede969552f7411de70e65cb63202069 100644 (file)
@@ -238,7 +238,7 @@ fn create_substs_for_ast_path(&self,
         let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF);
         let default_needs_object_self = |p: &ty::TypeParameterDef| {
             if is_object && p.has_default {
-                if ty::queries::type_of::get(tcx, span, p.def_id).has_self_ty() {
+                if tcx.at(span).type_of(p.def_id).has_self_ty() {
                     // There is no suitable inference default for a type parameter
                     // that references self, in an object type.
                     return true;
@@ -307,7 +307,7 @@ fn create_substs_for_ast_path(&self,
                     // This is a default type parameter.
                     self.normalize_ty(
                         span,
-                        ty::queries::type_of::get(tcx, span, def.def_id)
+                        tcx.at(span).type_of(def.def_id)
                             .subst_spanned(tcx, substs, Some(span))
                     )
                 }
@@ -600,7 +600,7 @@ fn ast_path_to_ty(&self,
         let substs = self.ast_path_substs_for_ty(span, did, item_segment);
         self.normalize_ty(
             span,
-            ty::queries::type_of::get(self.tcx(), span, did).subst(self.tcx(), substs)
+            self.tcx().at(span).type_of(did).subst(self.tcx(), substs)
         )
     }
 
@@ -1018,7 +1018,7 @@ pub fn def_to_ty(&self,
                 assert_eq!(opt_self_ty, None);
                 self.prohibit_type_params(&path.segments);
 
-                let ty = ty::queries::type_of::get(tcx, span, def_id);
+                let ty = tcx.at(span).type_of(def_id);
                 if let Some(free_substs) = self.get_free_substs() {
                     ty.subst(tcx, free_substs)
                 } else {
index 6dd4fb7301bc3df3b2378bdd00b3251628750b60..70d7336820659c788a13e319d3b64084cac147f4 100644 (file)
@@ -479,7 +479,7 @@ fn assemble_inherent_impl_for_primitive(&mut self, lang_def_id: Option<DefId>) {
     }
 
     fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId) {
-        let impl_def_ids = ty::queries::inherent_impls::get(self.tcx, self.span, def_id);
+        let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id);
         for &impl_def_id in impl_def_ids.iter() {
             self.assemble_inherent_impl_probe(impl_def_id);
         }
index 937769537683707f1cd6ae57b9478d8aee277cb8..57193b3584dfa97b80f93be60cbb21ecf5910761 100644 (file)
@@ -170,7 +170,7 @@ fn visit_implementation_of_coerce_unsized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     // course.
     if impl_did.is_local() {
         let span = tcx.def_span(impl_did);
-        ty::queries::coerce_unsized_info::get(tcx, span, impl_did);
+        tcx.at(span).coerce_unsized_info(impl_did);
     }
 }
 
index 45881bb3b783a66ab27106582a0b859e99da2a8f..400aaf82fe428f5c7aa11e9b7238b936679d17a4 100644 (file)
@@ -14,7 +14,7 @@
 //! for any change, but it is very cheap to compute. In practice, most
 //! code in the compiler never *directly* requests this map. Instead,
 //! it requests the inherent impls specific to some type (via
-//! `ty::queries::inherent_impls::get(def_id)`). That value, however,
+//! `tcx.inherent_impls(def_id)`). That value, however,
 //! is computed by selecting an idea from this table.
 
 use rustc::dep_graph::DepNode;
index 83727e9da032598a86307b2438f9de788550f160..099586e6bcc2a5b9482ab198b8f7ff254a626b0b 100644 (file)
@@ -207,7 +207,7 @@ fn get_type_parameter_bounds(&self,
                                  def_id: DefId)
                                  -> ty::GenericPredicates<'tcx>
     {
-        ty::queries::type_param_predicates::get(self.tcx, span, (self.item_def_id, def_id))
+        self.tcx.at(span).type_param_predicates((self.item_def_id, def_id))
     }
 
     fn get_free_substs(&self) -> Option<&Substs<'tcx>> {
@@ -475,7 +475,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) {
         hir::ItemTrait(..) => {
             tcx.generics_of(def_id);
             tcx.trait_def(def_id);
-            ty::queries::super_predicates_of::get(tcx, it.span, def_id);
+            tcx.at(it.span).super_predicates_of(def_id);
             tcx.predicates_of(def_id);
         },
         hir::ItemStruct(ref struct_def, _) |
@@ -556,7 +556,7 @@ fn convert_enum_variant_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         prev_discr = Some(if let Some(e) = variant.node.disr_expr {
             let expr_did = tcx.hir.local_def_id(e.node_id);
             let substs = Substs::empty();
-            let result = ty::queries::const_eval::get(tcx, variant.span, (expr_did, substs));
+            let result = tcx.at(variant.span).const_eval((expr_did, substs));
 
             // enum variant evaluation happens before the global constant check
             // so we need to report the real error
@@ -725,7 +725,7 @@ fn super_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     // Now require that immediate supertraits are converted,
     // which will, in turn, reach indirect supertraits.
     for bound in superbounds.iter().filter_map(|p| p.to_opt_poly_trait_ref()) {
-        ty::queries::super_predicates_of::get(tcx, item.span, bound.def_id());
+        tcx.at(item.span).super_predicates_of(bound.def_id());
     }
 
     ty::GenericPredicates {