Skip to content

Commit decf759

Browse files
committed
rustc: use tcx.at(span) to set the location of a query.
1 parent 9bde6b6 commit decf759

File tree

13 files changed

+56
-34
lines changed

13 files changed

+56
-34
lines changed

src/librustc/middle/const_val.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use rustc_const_math::ConstInt;
1414
use hir;
1515
use hir::def::Def;
1616
use hir::def_id::DefId;
17-
use ty::{self, TyCtxt};
17+
use ty::TyCtxt;
1818
use ty::subst::Substs;
1919
use util::common::ErrorReported;
2020
use rustc_const_math::*;
@@ -228,7 +228,7 @@ pub fn eval_length(tcx: TyCtxt,
228228
let count_expr = &tcx.hir.body(count).value;
229229
let count_def_id = tcx.hir.body_owner_def_id(count);
230230
let substs = Substs::empty();
231-
match ty::queries::const_eval::get(tcx, count_expr.span, (count_def_id, substs)) {
231+
match tcx.at(count_expr.span).const_eval((count_def_id, substs)) {
232232
Ok(Integral(Usize(count))) => {
233233
let val = count.as_u64(tcx.sess.target.uint_type);
234234
assert_eq!(val as usize as u64, val);

src/librustc/ty/maps.rs

+34-9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use util::nodemap::NodeSet;
2121

2222
use rustc_data_structures::indexed_vec::IndexVec;
2323
use std::cell::{RefCell, RefMut};
24+
use std::ops::Deref;
2425
use std::rc::Rc;
2526
use syntax_pos::{Span, DUMMY_SP};
2627

@@ -329,14 +330,6 @@ macro_rules! define_maps {
329330
Self::try_get_with(tcx, span, key, Clone::clone)
330331
}
331332

332-
$(#[$attr])*
333-
pub fn get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) -> $V {
334-
Self::try_get(tcx, span, key).unwrap_or_else(|e| {
335-
tcx.report_cycle(e);
336-
Value::from_cycle_error(tcx.global_tcx())
337-
})
338-
}
339-
340333
pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) {
341334
// FIXME(eddyb) Move away from using `DepTrackingMap`
342335
// so we don't have to explicitly ignore a false edge:
@@ -351,10 +344,42 @@ macro_rules! define_maps {
351344
}
352345
})*
353346

347+
#[derive(Copy, Clone)]
348+
pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
349+
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
350+
pub span: Span,
351+
}
352+
353+
impl<'a, 'gcx, 'tcx> Deref for TyCtxtAt<'a, 'gcx, 'tcx> {
354+
type Target = TyCtxt<'a, 'gcx, 'tcx>;
355+
fn deref(&self) -> &Self::Target {
356+
&self.tcx
357+
}
358+
}
359+
354360
impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
361+
/// Return a transparent wrapper for `TyCtxt` which uses
362+
/// `span` as the location of queries performed through it.
363+
pub fn at(self, span: Span) -> TyCtxtAt<'a, $tcx, 'lcx> {
364+
TyCtxtAt {
365+
tcx: self,
366+
span
367+
}
368+
}
369+
370+
$($(#[$attr])*
371+
pub fn $name(self, key: $K) -> $V {
372+
self.at(DUMMY_SP).$name(key)
373+
})*
374+
}
375+
376+
impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> {
355377
$($(#[$attr])*
356378
pub fn $name(self, key: $K) -> $V {
357-
queries::$name::get(self, DUMMY_SP, key)
379+
queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|e| {
380+
self.report_cycle(e);
381+
Value::from_cycle_error(self.global_tcx())
382+
})
358383
})*
359384
}
360385

src/librustc/ty/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2699,9 +2699,8 @@ pub fn provide_extern(providers: &mut ty::maps::Providers) {
26992699
/// A map for the local crate mapping each type to a vector of its
27002700
/// inherent impls. This is not meant to be used outside of coherence;
27012701
/// rather, you should request the vector for a specific type via
2702-
/// `ty::queries::inherent_impls::get(def_id)` so as to minimize your
2703-
/// dependencies (constructing this map requires touching the entire
2704-
/// crate).
2702+
/// `tcx.inherent_impls(def_id)` so as to minimize your dependencies
2703+
/// (constructing this map requires touching the entire crate).
27052704
#[derive(Clone, Debug)]
27062705
pub struct CrateInherentImpls {
27072706
pub inherent_impls: DefIdMap<Rc<Vec<DefId>>>,

src/librustc/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
522522
ty::TyAdt(def, substs) => {
523523
let ty::DtorckConstraint {
524524
dtorck_types, outlives
525-
} = ty::queries::adt_dtorck_constraint::get(self, span, def.did);
525+
} = self.at(span).adt_dtorck_constraint(def.did);
526526
Ok(ty::DtorckConstraint {
527527
// FIXME: we can try to recursively `dtorck_constraint_on_ty`
528528
// there, but that needs some way to handle cycles.

src/librustc_const_eval/eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
299299
match cx.tables.qpath_def(qpath, e.id) {
300300
Def::Const(def_id) |
301301
Def::AssociatedConst(def_id) => {
302-
match ty::queries::const_eval::get(tcx, e.span, (def_id, substs)) {
302+
match tcx.at(e.span).const_eval((def_id, substs)) {
303303
Ok(val) => val,
304304
Err(ConstEvalErr { kind: TypeckError, .. }) => {
305305
signal!(e, TypeckError);

src/librustc_metadata/encoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> {
547547
let kind = match impl_item.kind {
548548
ty::AssociatedKind::Const => {
549549
EntryKind::AssociatedConst(container,
550-
ty::queries::mir_const_qualif::get(self.tcx, ast_item.span, def_id))
550+
self.tcx.at(ast_item.span).mir_const_qualif(def_id))
551551
}
552552
ty::AssociatedKind::Method => {
553553
let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
@@ -656,7 +656,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> {
656656
hir::ItemStatic(_, hir::MutMutable, _) => EntryKind::MutStatic,
657657
hir::ItemStatic(_, hir::MutImmutable, _) => EntryKind::ImmStatic,
658658
hir::ItemConst(..) => {
659-
EntryKind::Const(ty::queries::mir_const_qualif::get(tcx, item.span, def_id))
659+
EntryKind::Const(tcx.at(item.span).mir_const_qualif(def_id))
660660
}
661661
hir::ItemFn(_, _, constness, .., body) => {
662662
let data = FnData {
@@ -732,7 +732,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> {
732732
let coerce_unsized_info =
733733
trait_ref.and_then(|t| {
734734
if Some(t.def_id) == tcx.lang_items.coerce_unsized_trait() {
735-
Some(ty::queries::coerce_unsized_info::get(tcx, item.span, def_id))
735+
Some(tcx.at(item.span).coerce_unsized_info(def_id))
736736
} else {
737737
None
738738
}

src/librustc_mir/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
594594
let c = &cx.tcx.hir.body(count).value;
595595
let def_id = cx.tcx.hir.body_owner_def_id(count);
596596
let substs = Substs::empty();
597-
let count = match ty::queries::const_eval::get(cx.tcx, c.span, (def_id, substs)) {
597+
let count = match cx.tcx.at(c.span).const_eval((def_id, substs)) {
598598
Ok(ConstVal::Integral(ConstInt::Usize(u))) => u,
599599
Ok(other) => bug!("constant evaluation of repeat count yielded {:?}", other),
600600
Err(s) => cx.fatal_const_eval_err(&s, c.span, "expression")

src/librustc_mir/transform/qualify_consts.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
573573
if substs.types().next().is_some() {
574574
self.add_type(constant.ty);
575575
} else {
576-
let bits = ty::queries::mir_const_qualif::get(self.tcx,
577-
constant.span,
578-
def_id);
576+
let bits = self.tcx.at(constant.span).mir_const_qualif(def_id);
579577

580578
let qualif = Qualif::from_bits(bits).expect("invalid mir_const_qualif");
581579
self.add(qualif);

src/librustc_typeck/astconv.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
238238
let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF);
239239
let default_needs_object_self = |p: &ty::TypeParameterDef| {
240240
if is_object && p.has_default {
241-
if ty::queries::type_of::get(tcx, span, p.def_id).has_self_ty() {
241+
if tcx.at(span).type_of(p.def_id).has_self_ty() {
242242
// There is no suitable inference default for a type parameter
243243
// that references self, in an object type.
244244
return true;
@@ -307,7 +307,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
307307
// This is a default type parameter.
308308
self.normalize_ty(
309309
span,
310-
ty::queries::type_of::get(tcx, span, def.def_id)
310+
tcx.at(span).type_of(def.def_id)
311311
.subst_spanned(tcx, substs, Some(span))
312312
)
313313
}
@@ -600,7 +600,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
600600
let substs = self.ast_path_substs_for_ty(span, did, item_segment);
601601
self.normalize_ty(
602602
span,
603-
ty::queries::type_of::get(self.tcx(), span, did).subst(self.tcx(), substs)
603+
self.tcx().at(span).type_of(did).subst(self.tcx(), substs)
604604
)
605605
}
606606

@@ -1018,7 +1018,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
10181018
assert_eq!(opt_self_ty, None);
10191019
self.prohibit_type_params(&path.segments);
10201020

1021-
let ty = ty::queries::type_of::get(tcx, span, def_id);
1021+
let ty = tcx.at(span).type_of(def_id);
10221022
if let Some(free_substs) = self.get_free_substs() {
10231023
ty.subst(tcx, free_substs)
10241024
} else {

src/librustc_typeck/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
479479
}
480480

481481
fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId) {
482-
let impl_def_ids = ty::queries::inherent_impls::get(self.tcx, self.span, def_id);
482+
let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id);
483483
for &impl_def_id in impl_def_ids.iter() {
484484
self.assemble_inherent_impl_probe(impl_def_id);
485485
}

src/librustc_typeck/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn visit_implementation_of_coerce_unsized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
170170
// course.
171171
if impl_did.is_local() {
172172
let span = tcx.def_span(impl_did);
173-
ty::queries::coerce_unsized_info::get(tcx, span, impl_did);
173+
tcx.at(span).coerce_unsized_info(impl_did);
174174
}
175175
}
176176

src/librustc_typeck/coherence/inherent_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! for any change, but it is very cheap to compute. In practice, most
1515
//! code in the compiler never *directly* requests this map. Instead,
1616
//! it requests the inherent impls specific to some type (via
17-
//! `ty::queries::inherent_impls::get(def_id)`). That value, however,
17+
//! `tcx.inherent_impls(def_id)`). That value, however,
1818
//! is computed by selecting an idea from this table.
1919
2020
use rustc::dep_graph::DepNode;

src/librustc_typeck/collect.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
207207
def_id: DefId)
208208
-> ty::GenericPredicates<'tcx>
209209
{
210-
ty::queries::type_param_predicates::get(self.tcx, span, (self.item_def_id, def_id))
210+
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id))
211211
}
212212

213213
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) {
475475
hir::ItemTrait(..) => {
476476
tcx.generics_of(def_id);
477477
tcx.trait_def(def_id);
478-
ty::queries::super_predicates_of::get(tcx, it.span, def_id);
478+
tcx.at(it.span).super_predicates_of(def_id);
479479
tcx.predicates_of(def_id);
480480
},
481481
hir::ItemStruct(ref struct_def, _) |
@@ -556,7 +556,7 @@ fn convert_enum_variant_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
556556
prev_discr = Some(if let Some(e) = variant.node.disr_expr {
557557
let expr_did = tcx.hir.local_def_id(e.node_id);
558558
let substs = Substs::empty();
559-
let result = ty::queries::const_eval::get(tcx, variant.span, (expr_did, substs));
559+
let result = tcx.at(variant.span).const_eval((expr_did, substs));
560560

561561
// enum variant evaluation happens before the global constant check
562562
// so we need to report the real error
@@ -725,7 +725,7 @@ fn super_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
725725
// Now require that immediate supertraits are converted,
726726
// which will, in turn, reach indirect supertraits.
727727
for bound in superbounds.iter().filter_map(|p| p.to_opt_poly_trait_ref()) {
728-
ty::queries::super_predicates_of::get(tcx, item.span, bound.def_id());
728+
tcx.at(item.span).super_predicates_of(bound.def_id());
729729
}
730730

731731
ty::GenericPredicates {

0 commit comments

Comments
 (0)