提交 3dd303aa 编写于 作者: S scalexm

Rename `BoundTyIndex` to `BoundVar`

上级 d0447550
...@@ -147,7 +147,7 @@ fn hash_stable<W: StableHasherResult>(&self, ...@@ -147,7 +147,7 @@ fn hash_stable<W: StableHasherResult>(&self,
} }
} }
impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::BoundTyIndex { impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::BoundVar {
#[inline] #[inline]
fn hash_stable<W: StableHasherResult>(&self, fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'gcx>, hcx: &mut StableHashingContext<'gcx>,
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use ty::fold::{TypeFoldable, TypeFolder}; use ty::fold::{TypeFoldable, TypeFolder};
use ty::subst::Kind; use ty::subst::Kind;
use ty::{self, BoundTy, BoundTyIndex, Lift, List, Ty, TyCtxt, TypeFlags}; use ty::{self, BoundTy, BoundVar, Lift, List, Ty, TyCtxt, TypeFlags};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;
...@@ -277,7 +277,7 @@ struct Canonicalizer<'cx, 'gcx: 'tcx, 'tcx: 'cx> { ...@@ -277,7 +277,7 @@ struct Canonicalizer<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
query_state: &'cx mut OriginalQueryValues<'tcx>, query_state: &'cx mut OriginalQueryValues<'tcx>,
// Note that indices is only used once `var_values` is big enough to be // Note that indices is only used once `var_values` is big enough to be
// heap-allocated. // heap-allocated.
indices: FxHashMap<Kind<'tcx>, BoundTyIndex>, indices: FxHashMap<Kind<'tcx>, BoundVar>,
canonicalize_region_mode: &'cx dyn CanonicalizeRegionMode, canonicalize_region_mode: &'cx dyn CanonicalizeRegionMode,
needs_canonical_flags: TypeFlags, needs_canonical_flags: TypeFlags,
} }
...@@ -455,7 +455,7 @@ fn canonicalize<V>( ...@@ -455,7 +455,7 @@ fn canonicalize<V>(
/// or returns an existing variable if `kind` has already been /// or returns an existing variable if `kind` has already been
/// seen. `kind` is expected to be an unbound variable (or /// seen. `kind` is expected to be an unbound variable (or
/// potentially a free region). /// potentially a free region).
fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTyIndex { fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundVar {
let Canonicalizer { let Canonicalizer {
variables, variables,
query_state, query_state,
...@@ -475,7 +475,7 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTy ...@@ -475,7 +475,7 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTy
// direct linear search of `var_values`. // direct linear search of `var_values`.
if let Some(idx) = var_values.iter().position(|&k| k == kind) { if let Some(idx) = var_values.iter().position(|&k| k == kind) {
// `kind` is already present in `var_values`. // `kind` is already present in `var_values`.
BoundTyIndex::new(idx) BoundVar::new(idx)
} else { } else {
// `kind` isn't present in `var_values`. Append it. Likewise // `kind` isn't present in `var_values`. Append it. Likewise
// for `info` and `variables`. // for `info` and `variables`.
...@@ -490,11 +490,11 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTy ...@@ -490,11 +490,11 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTy
*indices = var_values *indices = var_values
.iter() .iter()
.enumerate() .enumerate()
.map(|(i, &kind)| (kind, BoundTyIndex::new(i))) .map(|(i, &kind)| (kind, BoundVar::new(i)))
.collect(); .collect();
} }
// The cv is the index of the appended element. // The cv is the index of the appended element.
BoundTyIndex::new(var_values.len() - 1) BoundVar::new(var_values.len() - 1)
} }
} else { } else {
// `var_values` is large. Do a hashmap search via `indices`. // `var_values` is large. Do a hashmap search via `indices`.
...@@ -502,7 +502,7 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTy ...@@ -502,7 +502,7 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTy
variables.push(info); variables.push(info);
var_values.push(kind); var_values.push(kind);
assert_eq!(variables.len(), var_values.len()); assert_eq!(variables.len(), var_values.len());
BoundTyIndex::new(variables.len() - 1) BoundVar::new(variables.len() - 1)
}) })
}; };
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
use syntax::source_map::Span; use syntax::source_map::Span;
use ty::fold::TypeFoldable; use ty::fold::TypeFoldable;
use ty::subst::Kind; use ty::subst::Kind;
use ty::{self, BoundTyIndex, Lift, List, Region, TyCtxt}; use ty::{self, BoundVar, Lift, List, Region, TyCtxt};
mod canonicalizer; mod canonicalizer;
...@@ -73,7 +73,7 @@ impl<'gcx> UseSpecializedDecodable for CanonicalVarInfos<'gcx> {} ...@@ -73,7 +73,7 @@ impl<'gcx> UseSpecializedDecodable for CanonicalVarInfos<'gcx> {}
/// canonicalized query response. /// canonicalized query response.
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)] #[derive(Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)]
pub struct CanonicalVarValues<'tcx> { pub struct CanonicalVarValues<'tcx> {
pub var_values: IndexVec<BoundTyIndex, Kind<'tcx>>, pub var_values: IndexVec<BoundVar, Kind<'tcx>>,
} }
/// When we canonicalize a value to form a query, we wind up replacing /// When we canonicalize a value to form a query, we wind up replacing
...@@ -337,7 +337,7 @@ fn instantiate_canonical_vars( ...@@ -337,7 +337,7 @@ fn instantiate_canonical_vars(
variables: &List<CanonicalVarInfo>, variables: &List<CanonicalVarInfo>,
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex, universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
) -> CanonicalVarValues<'tcx> { ) -> CanonicalVarValues<'tcx> {
let var_values: IndexVec<BoundTyIndex, Kind<'tcx>> = variables let var_values: IndexVec<BoundVar, Kind<'tcx>> = variables
.iter() .iter()
.map(|info| self.instantiate_canonical_var(span, *info, &universe_map)) .map(|info| self.instantiate_canonical_var(span, *info, &universe_map))
.collect(); .collect();
...@@ -456,10 +456,10 @@ impl<'a, 'tcx, R> Lift<'tcx> for QueryResponse<'a, R> { ...@@ -456,10 +456,10 @@ impl<'a, 'tcx, R> Lift<'tcx> for QueryResponse<'a, R> {
} where R: Lift<'tcx> } where R: Lift<'tcx>
} }
impl<'tcx> Index<BoundTyIndex> for CanonicalVarValues<'tcx> { impl<'tcx> Index<BoundVar> for CanonicalVarValues<'tcx> {
type Output = Kind<'tcx>; type Output = Kind<'tcx>;
fn index(&self, value: BoundTyIndex) -> &Kind<'tcx> { fn index(&self, value: BoundVar) -> &Kind<'tcx> {
&self.var_values[value] &self.var_values[value]
} }
} }
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
use traits::{Obligation, ObligationCause, PredicateObligation}; use traits::{Obligation, ObligationCause, PredicateObligation};
use ty::fold::TypeFoldable; use ty::fold::TypeFoldable;
use ty::subst::{Kind, UnpackedKind}; use ty::subst::{Kind, UnpackedKind};
use ty::{self, BoundTyIndex, Lift, Ty, TyCtxt}; use ty::{self, BoundVar, Lift, Ty, TyCtxt};
impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> { impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> {
/// The "main method" for a canonicalized trait query. Given the /// The "main method" for a canonicalized trait query. Given the
...@@ -273,7 +273,7 @@ pub fn instantiate_nll_query_response_and_region_obligations<R>( ...@@ -273,7 +273,7 @@ pub fn instantiate_nll_query_response_and_region_obligations<R>(
for (index, original_value) in original_values.var_values.iter().enumerate() { for (index, original_value) in original_values.var_values.iter().enumerate() {
// ...with the value `v_r` of that variable from the query. // ...with the value `v_r` of that variable from the query.
let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| { let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| {
&v.var_values[BoundTyIndex::new(index)] &v.var_values[BoundVar::new(index)]
}); });
match (original_value.unpack(), result_value.unpack()) { match (original_value.unpack(), result_value.unpack()) {
(UnpackedKind::Lifetime(ty::ReErased), UnpackedKind::Lifetime(ty::ReErased)) => { (UnpackedKind::Lifetime(ty::ReErased), UnpackedKind::Lifetime(ty::ReErased)) => {
...@@ -423,7 +423,7 @@ fn query_response_substitution_guess<R>( ...@@ -423,7 +423,7 @@ fn query_response_substitution_guess<R>(
// is directly equal to one of the canonical variables in the // is directly equal to one of the canonical variables in the
// result, then we can type the corresponding value from the // result, then we can type the corresponding value from the
// input. See the example above. // input. See the example above.
let mut opt_values: IndexVec<BoundTyIndex, Option<Kind<'tcx>>> = let mut opt_values: IndexVec<BoundVar, Option<Kind<'tcx>>> =
IndexVec::from_elem_n(None, query_response.variables.len()); IndexVec::from_elem_n(None, query_response.variables.len());
// In terms of our example above, we are iterating over pairs like: // In terms of our example above, we are iterating over pairs like:
...@@ -457,7 +457,7 @@ fn query_response_substitution_guess<R>( ...@@ -457,7 +457,7 @@ fn query_response_substitution_guess<R>(
.enumerate() .enumerate()
.map(|(index, info)| { .map(|(index, info)| {
if info.is_existential() { if info.is_existential() {
match opt_values[BoundTyIndex::new(index)] { match opt_values[BoundVar::new(index)] {
Some(k) => k, Some(k) => k,
None => self.instantiate_canonical_var(cause.span, *info, |u| { None => self.instantiate_canonical_var(cause.span, *info, |u| {
universe_map[u.as_usize()] universe_map[u.as_usize()]
...@@ -496,7 +496,7 @@ fn unify_query_response_substitution_guess<R>( ...@@ -496,7 +496,7 @@ fn unify_query_response_substitution_guess<R>(
// canonical variable; this is taken from // canonical variable; this is taken from
// `query_response.var_values` after applying the substitution // `query_response.var_values` after applying the substitution
// `result_subst`. // `result_subst`.
let substituted_query_response = |index: BoundTyIndex| -> Kind<'tcx> { let substituted_query_response = |index: BoundVar| -> Kind<'tcx> {
query_response.substitute_projected(self.tcx, &result_subst, |v| &v.var_values[index]) query_response.substitute_projected(self.tcx, &result_subst, |v| &v.var_values[index])
}; };
...@@ -552,12 +552,12 @@ fn unify_canonical_vars( ...@@ -552,12 +552,12 @@ fn unify_canonical_vars(
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
variables1: &OriginalQueryValues<'tcx>, variables1: &OriginalQueryValues<'tcx>,
variables2: impl Fn(BoundTyIndex) -> Kind<'tcx>, variables2: impl Fn(BoundVar) -> Kind<'tcx>,
) -> InferResult<'tcx, ()> { ) -> InferResult<'tcx, ()> {
self.commit_if_ok(|_| { self.commit_if_ok(|_| {
let mut obligations = vec![]; let mut obligations = vec![];
for (index, value1) in variables1.var_values.iter().enumerate() { for (index, value1) in variables1.var_values.iter().enumerate() {
let value2 = variables2(BoundTyIndex::new(index)); let value2 = variables2(BoundVar::new(index));
match (value1.unpack(), value2.unpack()) { match (value1.unpack(), value2.unpack()) {
(UnpackedKind::Type(v1), UnpackedKind::Type(v2)) => { (UnpackedKind::Type(v1), UnpackedKind::Type(v2)) => {
......
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
use hir; use hir;
pub use self::sty::{Binder, BoundTy, BoundTyKind, BoundTyIndex, DebruijnIndex, INNERMOST}; pub use self::sty::{Binder, BoundTy, BoundTyKind, BoundVar, DebruijnIndex, INNERMOST};
pub use self::sty::{FnSig, GenSig, CanonicalPolyFnSig, PolyFnSig, PolyGenSig}; pub use self::sty::{FnSig, GenSig, CanonicalPolyFnSig, PolyFnSig, PolyGenSig};
pub use self::sty::{InferTy, ParamTy, ProjectionTy, ExistentialPredicate}; pub use self::sty::{InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
pub use self::sty::{ClosureSubsts, GeneratorSubsts, UpvarSubsts, TypeAndMut}; pub use self::sty::{ClosureSubsts, GeneratorSubsts, UpvarSubsts, TypeAndMut};
......
...@@ -1171,7 +1171,7 @@ pub enum RegionKind { ...@@ -1171,7 +1171,7 @@ pub enum RegionKind {
ReClosureBound(RegionVid), ReClosureBound(RegionVid),
/// Canonicalized region, used only when preparing a trait query. /// Canonicalized region, used only when preparing a trait query.
ReCanonical(BoundTyIndex), ReCanonical(BoundVar),
} }
impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {} impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {}
...@@ -1225,13 +1225,13 @@ pub enum InferTy { ...@@ -1225,13 +1225,13 @@ pub enum InferTy {
} }
newtype_index! { newtype_index! {
pub struct BoundTyIndex { .. } pub struct BoundVar { .. }
} }
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
pub struct BoundTy { pub struct BoundTy {
pub level: DebruijnIndex, pub level: DebruijnIndex,
pub var: BoundTyIndex, pub var: BoundVar,
pub kind: BoundTyKind, pub kind: BoundTyKind,
} }
...@@ -1245,7 +1245,7 @@ pub enum BoundTyKind { ...@@ -1245,7 +1245,7 @@ pub enum BoundTyKind {
impl_stable_hash_for!(enum self::BoundTyKind { Anon, Param(a) }); impl_stable_hash_for!(enum self::BoundTyKind { Anon, Param(a) });
impl BoundTy { impl BoundTy {
pub fn new(level: DebruijnIndex, var: BoundTyIndex) -> Self { pub fn new(level: DebruijnIndex, var: BoundVar) -> Self {
BoundTy { BoundTy {
level, level,
var, var,
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
use hir::def_id::DefId; use hir::def_id::DefId;
use infer::canonical::Canonical; use infer::canonical::Canonical;
use ty::{self, BoundTyIndex, Lift, List, Ty, TyCtxt}; use ty::{self, BoundVar, Lift, List, Ty, TyCtxt};
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use serialize::{self, Encodable, Encoder, Decodable, Decoder}; use serialize::{self, Encodable, Encoder, Decodable, Decoder};
...@@ -553,7 +553,7 @@ pub fn is_identity(&self) -> bool { ...@@ -553,7 +553,7 @@ pub fn is_identity(&self) -> bool {
return false; return false;
} }
self.value.substs.iter().zip(BoundTyIndex::new(0)..).all(|(kind, cvar)| { self.value.substs.iter().zip(BoundVar::new(0)..).all(|(kind, cvar)| {
match kind.unpack() { match kind.unpack() {
UnpackedKind::Type(ty) => match ty.sty { UnpackedKind::Type(ty) => match ty.sty {
ty::Bound(ref b) => cvar == b.var, ty::Bound(ref b) => cvar == b.var,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册