rustc: use tcx.at(span) to set the location of a query.
This commit is contained in:
parent
9bde6b6d96
commit
decf7598ef
|
@ -14,7 +14,7 @@ pub use rustc_const_math::ConstInt;
|
|||
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);
|
||||
|
|
|
@ -21,6 +21,7 @@ use util::nodemap::NodeSet;
|
|||
|
||||
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 @@ macro_rules! define_maps {
|
|||
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 @@ macro_rules! define_maps {
|
|||
}
|
||||
})*
|
||||
|
||||
#[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 {
|
||||
queries::$name::get(self, DUMMY_SP, key)
|
||||
self.at(DUMMY_SP).$name(key)
|
||||
})*
|
||||
}
|
||||
|
||||
impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> {
|
||||
$($(#[$attr])*
|
||||
pub fn $name(self, key: $K) -> $V {
|
||||
queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|e| {
|
||||
self.report_cycle(e);
|
||||
Value::from_cycle_error(self.global_tcx())
|
||||
})
|
||||
})*
|
||||
}
|
||||
|
||||
|
|
|
@ -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>>>,
|
||||
|
|
|
@ -522,7 +522,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -547,7 +547,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, '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 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> {
|
|||
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 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -573,9 +573,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
|
|||
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);
|
||||
|
|
|
@ -238,7 +238,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
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 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
// 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 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
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 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
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 {
|
||||
|
|
|
@ -479,7 +479,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -207,7 +207,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
|
|||
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 {
|
||||
|
|
Loading…
Reference in New Issue