Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename subst::Kind to subst::GenericArg #64515

Merged
merged 2 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
}
}

impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::Kind<'tcx> {
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArg<'tcx> {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::infer::InferCtxt;
use crate::mir::interpret::ConstValue;
use std::sync::atomic::Ordering;
use crate::ty::fold::{TypeFoldable, TypeFolder};
use crate::ty::subst::Kind;
use crate::ty::subst::GenericArg;
use crate::ty::{self, BoundVar, InferConst, List, Ty, TyCtxt, TypeFlags};
use crate::ty::flags::FlagComputation;

Expand Down Expand Up @@ -282,7 +282,7 @@ struct Canonicalizer<'cx, 'tcx> {
query_state: &'cx mut OriginalQueryValues<'tcx>,
// Note that indices is only used once `var_values` is big enough to be
// heap-allocated.
indices: FxHashMap<Kind<'tcx>, BoundVar>,
indices: FxHashMap<GenericArg<'tcx>, BoundVar>,
canonicalize_region_mode: &'cx dyn CanonicalizeRegionMode,
needs_canonical_flags: TypeFlags,

Expand Down Expand Up @@ -566,7 +566,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
/// or returns an existing variable if `kind` has already been
/// seen. `kind` is expected to be an unbound variable (or
/// potentially a free region).
fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundVar {
fn canonical_var(&mut self, info: CanonicalVarInfo, kind: GenericArg<'tcx>) -> BoundVar {
let Canonicalizer {
variables,
query_state,
Expand Down
28 changes: 14 additions & 14 deletions src/librustc/infer/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use smallvec::SmallVec;
use std::ops::Index;
use syntax::source_map::Span;
use crate::ty::fold::TypeFoldable;
use crate::ty::subst::Kind;
use crate::ty::subst::GenericArg;
use crate::ty::{self, BoundVar, InferConst, Lift, List, Region, TyCtxt};

mod canonicalizer;
Expand Down Expand Up @@ -66,7 +66,7 @@ impl<'tcx> UseSpecializedDecodable for CanonicalVarInfos<'tcx> {}
/// canonicalized query response.
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable, HashStable)]
pub struct CanonicalVarValues<'tcx> {
pub var_values: IndexVec<BoundVar, Kind<'tcx>>,
pub var_values: IndexVec<BoundVar, GenericArg<'tcx>>,
}

/// When we canonicalize a value to form a query, we wind up replacing
Expand All @@ -83,7 +83,7 @@ pub struct OriginalQueryValues<'tcx> {

/// This is equivalent to `CanonicalVarValues`, but using a
/// `SmallVec` yields a significant performance win.
pub var_values: SmallVec<[Kind<'tcx>; 8]>,
pub var_values: SmallVec<[GenericArg<'tcx>; 8]>,
}

impl Default for OriginalQueryValues<'tcx> {
Expand Down Expand Up @@ -308,7 +308,7 @@ impl<'tcx, V> Canonical<'tcx, V> {
}

pub type QueryOutlivesConstraint<'tcx> =
ty::Binder<ty::OutlivesPredicate<Kind<'tcx>, Region<'tcx>>>;
ty::Binder<ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>;

impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
/// Creates a substitution S for the canonical value with fresh
Expand Down Expand Up @@ -359,7 +359,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
variables: &List<CanonicalVarInfo>,
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
) -> CanonicalVarValues<'tcx> {
let var_values: IndexVec<BoundVar, Kind<'tcx>> = variables
let var_values: IndexVec<BoundVar, GenericArg<'tcx>> = variables
.iter()
.map(|info| self.instantiate_canonical_var(span, *info, &universe_map))
.collect();
Expand All @@ -376,7 +376,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
span: Span,
cv_info: CanonicalVarInfo,
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
) -> Kind<'tcx> {
) -> GenericArg<'tcx> {
match cv_info.kind {
CanonicalVarKind::Ty(ty_kind) => {
let ty = match ty_kind {
Expand Down Expand Up @@ -495,19 +495,19 @@ impl<'tcx> CanonicalVarValues<'tcx> {
/// we'll return a substitution `subst` with:
/// `subst.var_values == [Type(^0), Lifetime(^1), Type(^2)]`.
pub fn make_identity(&self, tcx: TyCtxt<'tcx>) -> Self {
use crate::ty::subst::UnpackedKind;
use crate::ty::subst::GenericArgKind;

CanonicalVarValues {
var_values: self.var_values.iter()
.zip(0..)
.map(|(kind, i)| match kind.unpack() {
UnpackedKind::Type(..) => tcx.mk_ty(
GenericArgKind::Type(..) => tcx.mk_ty(
ty::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i).into())
).into(),
UnpackedKind::Lifetime(..) => tcx.mk_region(
GenericArgKind::Lifetime(..) => tcx.mk_region(
ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(i))
).into(),
UnpackedKind::Const(ct) => {
GenericArgKind::Const(ct) => {
tcx.mk_const(ty::Const {
ty: ct.ty,
val: ConstValue::Infer(
Expand All @@ -522,8 +522,8 @@ impl<'tcx> CanonicalVarValues<'tcx> {
}

impl<'a, 'tcx> IntoIterator for &'a CanonicalVarValues<'tcx> {
type Item = Kind<'tcx>;
type IntoIter = ::std::iter::Cloned<::std::slice::Iter<'a, Kind<'tcx>>>;
type Item = GenericArg<'tcx>;
type IntoIter = ::std::iter::Cloned<::std::slice::Iter<'a, GenericArg<'tcx>>>;

fn into_iter(self) -> Self::IntoIter {
self.var_values.iter().cloned()
Expand Down Expand Up @@ -570,9 +570,9 @@ BraceStructLiftImpl! {
}

impl<'tcx> Index<BoundVar> for CanonicalVarValues<'tcx> {
type Output = Kind<'tcx>;
type Output = GenericArg<'tcx>;

fn index(&self, value: BoundVar) -> &Kind<'tcx> {
fn index(&self, value: BoundVar) -> &GenericArg<'tcx> {
&self.var_values[value]
}
}
43 changes: 23 additions & 20 deletions src/librustc/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::traits::query::{Fallible, NoSolution};
use crate::traits::TraitEngine;
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
use crate::ty::fold::TypeFoldable;
use crate::ty::subst::{Kind, UnpackedKind};
use crate::ty::subst::{GenericArg, GenericArgKind};
use crate::ty::{self, BoundVar, InferConst, Ty, TyCtxt};
use crate::util::captures::Captures;

Expand Down Expand Up @@ -298,11 +298,14 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
&v.var_values[BoundVar::new(index)]
});
match (original_value.unpack(), result_value.unpack()) {
(UnpackedKind::Lifetime(ty::ReErased), UnpackedKind::Lifetime(ty::ReErased)) => {
// no action needed
(
GenericArgKind::Lifetime(ty::ReErased),
GenericArgKind::Lifetime(ty::ReErased),
) => {
// No action needed.
}

(UnpackedKind::Lifetime(v_o), UnpackedKind::Lifetime(v_r)) => {
(GenericArgKind::Lifetime(v_o), GenericArgKind::Lifetime(v_r)) => {
// To make `v_o = v_r`, we emit `v_o: v_r` and `v_r: v_o`.
if v_o != v_r {
output_query_region_constraints
Expand All @@ -314,12 +317,12 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
}
}

(UnpackedKind::Type(v1), UnpackedKind::Type(v2)) => {
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
let ok = self.at(cause, param_env).eq(v1, v2)?;
obligations.extend(ok.into_obligations());
}

(UnpackedKind::Const(v1), UnpackedKind::Const(v2)) => {
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
let ok = self.at(cause, param_env).eq(v1, v2)?;
obligations.extend(ok.into_obligations());
}
Expand Down Expand Up @@ -462,14 +465,14 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
// is directly equal to one of the canonical variables in the
// result, then we can type the corresponding value from the
// input. See the example above.
let mut opt_values: IndexVec<BoundVar, Option<Kind<'tcx>>> =
let mut opt_values: IndexVec<BoundVar, Option<GenericArg<'tcx>>> =
IndexVec::from_elem_n(None, query_response.variables.len());

// In terms of our example above, we are iterating over pairs like:
// [(?A, Vec<?0>), ('static, '?1), (?B, ?0)]
for (original_value, result_value) in original_values.var_values.iter().zip(result_values) {
match result_value.unpack() {
UnpackedKind::Type(result_value) => {
GenericArgKind::Type(result_value) => {
// e.g., here `result_value` might be `?0` in the example above...
if let ty::Bound(debruijn, b) = result_value.kind {
// ...in which case we would set `canonical_vars[0]` to `Some(?U)`.
Expand All @@ -479,7 +482,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
opt_values[b.var] = Some(*original_value);
}
}
UnpackedKind::Lifetime(result_value) => {
GenericArgKind::Lifetime(result_value) => {
// e.g., here `result_value` might be `'?1` in the example above...
if let &ty::RegionKind::ReLateBound(debruijn, br) = result_value {
// ... in which case we would set `canonical_vars[0]` to `Some('static)`.
Expand All @@ -489,7 +492,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
opt_values[br.assert_bound_var()] = Some(*original_value);
}
}
UnpackedKind::Const(result_value) => {
GenericArgKind::Const(result_value) => {
if let ty::Const {
val: ConstValue::Infer(InferConst::Canonical(debrujin, b)),
..
Expand Down Expand Up @@ -553,7 +556,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
// canonical variable; this is taken from
// `query_response.var_values` after applying the substitution
// `result_subst`.
let substituted_query_response = |index: BoundVar| -> Kind<'tcx> {
let substituted_query_response = |index: BoundVar| -> GenericArg<'tcx> {
query_response.substitute_projected(self.tcx, &result_subst, |v| &v.var_values[index])
};

Expand Down Expand Up @@ -586,17 +589,17 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
cause.clone(),
param_env,
match k1.unpack() {
UnpackedKind::Lifetime(r1) => ty::Predicate::RegionOutlives(
GenericArgKind::Lifetime(r1) => ty::Predicate::RegionOutlives(
ty::Binder::bind(
ty::OutlivesPredicate(r1, r2)
)
),
UnpackedKind::Type(t1) => ty::Predicate::TypeOutlives(
GenericArgKind::Type(t1) => ty::Predicate::TypeOutlives(
ty::Binder::bind(
ty::OutlivesPredicate(t1, r2)
)
),
UnpackedKind::Const(..) => {
GenericArgKind::Const(..) => {
// Consts cannot outlive one another, so we don't expect to
// ecounter this branch.
span_bug!(cause.span, "unexpected const outlives {:?}", constraint);
Expand All @@ -613,29 +616,29 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
cause: &ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
variables1: &OriginalQueryValues<'tcx>,
variables2: impl Fn(BoundVar) -> Kind<'tcx>,
variables2: impl Fn(BoundVar) -> GenericArg<'tcx>,
) -> InferResult<'tcx, ()> {
self.commit_if_ok(|_| {
let mut obligations = vec![];
for (index, value1) in variables1.var_values.iter().enumerate() {
let value2 = variables2(BoundVar::new(index));

match (value1.unpack(), value2.unpack()) {
(UnpackedKind::Type(v1), UnpackedKind::Type(v2)) => {
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
obligations
.extend(self.at(cause, param_env).eq(v1, v2)?.into_obligations());
}
(
UnpackedKind::Lifetime(ty::ReErased),
UnpackedKind::Lifetime(ty::ReErased),
GenericArgKind::Lifetime(ty::ReErased),
GenericArgKind::Lifetime(ty::ReErased),
) => {
// no action needed
}
(UnpackedKind::Lifetime(v1), UnpackedKind::Lifetime(v2)) => {
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
obligations
.extend(self.at(cause, param_env).eq(v1, v2)?.into_obligations());
}
(UnpackedKind::Const(v1), UnpackedKind::Const(v2)) => {
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
let ok = self.at(cause, param_env).eq(v1, v2)?;
obligations.extend(ok.into_obligations());
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/infer/canonical/substitute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use crate::infer::canonical::{Canonical, CanonicalVarValues};
use crate::ty::fold::TypeFoldable;
use crate::ty::subst::UnpackedKind;
use crate::ty::subst::GenericArgKind;
use crate::ty::{self, TyCtxt};

impl<'tcx, V> Canonical<'tcx, V> {
Expand Down Expand Up @@ -58,21 +58,21 @@ where
} else {
let fld_r = |br: ty::BoundRegion| {
match var_values.var_values[br.assert_bound_var()].unpack() {
UnpackedKind::Lifetime(l) => l,
GenericArgKind::Lifetime(l) => l,
r => bug!("{:?} is a region but value is {:?}", br, r),
}
};

let fld_t = |bound_ty: ty::BoundTy| {
match var_values.var_values[bound_ty.var].unpack() {
UnpackedKind::Type(ty) => ty,
GenericArgKind::Type(ty) => ty,
r => bug!("{:?} is a type but value is {:?}", bound_ty, r),
}
};

let fld_c = |bound_ct: ty::BoundVar, _| {
match var_values.var_values[bound_ct].unpack() {
UnpackedKind::Const(ct) => ct,
GenericArgKind::Const(ct) => ct,
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
use hir::def_id::CrateNum;
use hir::map::DisambiguatedDefPathData;
use ty::print::Printer;
use ty::subst::Kind;
use ty::subst::GenericArg;

struct AbsolutePathPrinter<'tcx> {
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -548,7 +548,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
fn path_generic_args(
self,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
_args: &[Kind<'tcx>],
_args: &[GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
print_prefix(self)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
use crate::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
use crate::ty::fold::{TypeFolder, TypeFoldable};
use crate::ty::relate::RelateResult;
use crate::ty::subst::{Kind, InternalSubsts, SubstsRef};
use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt, InferConst};
use crate::ty::{FloatVid, IntVid, TyVid, ConstVid};
use crate::util::nodemap::FxHashMap;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.next_region_var_in_universe(RegionVariableOrigin::NLL(origin), universe)
}

pub fn var_for_def(&self, span: Span, param: &ty::GenericParamDef) -> Kind<'tcx> {
pub fn var_for_def(&self, span: Span, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
match param.kind {
GenericParamDefKind::Lifetime => {
// Create a region inference variable for the given
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::traits::DomainGoal;
use crate::ty::error::TypeError;
use crate::ty::fold::{TypeFoldable, TypeVisitor};
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
use crate::ty::subst::Kind;
use crate::ty::subst::GenericArg;
use crate::ty::{self, Ty, TyCtxt, InferConst};
use crate::mir::interpret::ConstValue;
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -124,7 +124,7 @@ pub trait TypeRelatingDelegate<'tcx> {
#[derive(Clone, Debug)]
struct ScopesAndKind<'tcx> {
scopes: Vec<BoundRegionScope<'tcx>>,
kind: Kind<'tcx>,
kind: GenericArg<'tcx>,
}

#[derive(Clone, Debug, Default)]
Expand Down
Loading