1
Fork 0

Get rid of 'tcx on ConstVid, EffectVid

This commit is contained in:
Michael Goulet 2023-10-24 20:13:36 +00:00
parent 98b4a64a16
commit a986ab4d4d
17 changed files with 150 additions and 130 deletions

View file

@ -141,18 +141,30 @@ pub struct ConstVarValue<'tcx> {
pub val: ConstVariableValue<'tcx>,
}
impl<'tcx> UnifyKey for ty::ConstVid<'tcx> {
#[derive(PartialEq, Copy, Clone, Debug)]
pub struct ConstVidKey<'tcx> {
pub vid: ty::ConstVid,
pub phantom: PhantomData<ty::Const<'tcx>>,
}
impl<'tcx> From<ty::ConstVid> for ConstVidKey<'tcx> {
fn from(vid: ty::ConstVid) -> Self {
ConstVidKey { vid, phantom: PhantomData }
}
}
impl<'tcx> UnifyKey for ConstVidKey<'tcx> {
type Value = ConstVarValue<'tcx>;
#[inline]
fn index(&self) -> u32 {
self.index
self.vid.as_u32()
}
#[inline]
fn from_index(i: u32) -> Self {
ty::ConstVid { index: i, phantom: PhantomData }
ConstVidKey::from(ty::ConstVid::from_u32(i))
}
fn tag() -> &'static str {
"ConstVid"
"ConstVidKey"
}
}
@ -224,17 +236,29 @@ impl<'tcx> UnifyValue for EffectVarValue<'tcx> {
}
}
impl<'tcx> UnifyKey for ty::EffectVid<'tcx> {
#[derive(PartialEq, Copy, Clone, Debug)]
pub struct EffectVidKey<'tcx> {
pub vid: ty::EffectVid,
pub phantom: PhantomData<EffectVarValue<'tcx>>,
}
impl<'tcx> From<ty::EffectVid> for EffectVidKey<'tcx> {
fn from(vid: ty::EffectVid) -> Self {
EffectVidKey { vid, phantom: PhantomData }
}
}
impl<'tcx> UnifyKey for EffectVidKey<'tcx> {
type Value = Option<EffectVarValue<'tcx>>;
#[inline]
fn index(&self) -> u32 {
self.index
self.vid.as_u32()
}
#[inline]
fn from_index(i: u32) -> Self {
ty::EffectVid { index: i, phantom: PhantomData }
EffectVidKey::from(ty::EffectVid::from_u32(i))
}
fn tag() -> &'static str {
"EffectVid"
"EffectVidKey"
}
}

View file

@ -57,7 +57,7 @@ impl<'tcx> Const<'tcx> {
}
#[inline]
pub fn new_var(tcx: TyCtxt<'tcx>, infer: ty::ConstVid<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
pub fn new_var(tcx: TyCtxt<'tcx>, infer: ty::ConstVid, ty: Ty<'tcx>) -> Const<'tcx> {
Const::new(tcx, ty::ConstKind::Infer(ty::InferConst::Var(infer)), ty)
}
@ -67,7 +67,7 @@ impl<'tcx> Const<'tcx> {
}
#[inline]
pub fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferConst<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
pub fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferConst, ty: Ty<'tcx>) -> Const<'tcx> {
Const::new(tcx, ty::ConstKind::Infer(infer), ty)
}

View file

@ -80,19 +80,19 @@ static_assert_size!(super::ConstKind<'_>, 32);
/// An inference variable for a const, for use in const generics.
#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Hash)]
pub enum InferConst<'tcx> {
pub enum InferConst {
/// Infer the value of the const.
Var(ty::ConstVid<'tcx>),
Var(ty::ConstVid),
/// Infer the value of the effect.
///
/// For why this is separate from the `Var` variant above, see the
/// documentation on `EffectVid`.
EffectVar(ty::EffectVid<'tcx>),
EffectVar(ty::EffectVid),
/// A fresh const variable. See `infer::freshen` for more details.
Fresh(u32),
}
impl<CTX> HashStable<CTX> for InferConst<'_> {
impl<CTX> HashStable<CTX> for InferConst {
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
match self {
InferConst::Var(_) | InferConst::EffectVar(_) => {

View file

@ -100,7 +100,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type PolyFnSig = PolyFnSig<'tcx>;
type AllocId = crate::mir::interpret::AllocId;
type Const = ty::Const<'tcx>;
type InferConst = ty::InferConst<'tcx>;
type InferConst = ty::InferConst;
type AliasConst = ty::UnevaluatedConst<'tcx>;
type PlaceholderConst = ty::PlaceholderConst<'tcx>;
type ParamConst = ty::ParamConst;

View file

@ -1084,19 +1084,19 @@ impl ParamTerm {
}
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum TermVid<'tcx> {
pub enum TermVid {
Ty(ty::TyVid),
Const(ty::ConstVid<'tcx>),
Const(ty::ConstVid),
}
impl From<ty::TyVid> for TermVid<'_> {
impl From<ty::TyVid> for TermVid {
fn from(value: ty::TyVid) -> Self {
TermVid::Ty(value)
}
}
impl<'tcx> From<ty::ConstVid<'tcx>> for TermVid<'tcx> {
fn from(value: ty::ConstVid<'tcx>) -> Self {
impl From<ty::ConstVid> for TermVid {
fn from(value: ty::ConstVid) -> Self {
TermVid::Const(value)
}
}

View file

@ -1194,7 +1194,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
None
}
fn const_infer_name(&self, _: ty::ConstVid<'tcx>) -> Option<Symbol> {
fn const_infer_name(&self, _: ty::ConstVid) -> Option<Symbol> {
None
}
@ -1742,7 +1742,7 @@ pub struct FmtPrinterData<'a, 'tcx> {
pub region_highlight_mode: RegionHighlightMode<'tcx>,
pub ty_infer_name_resolver: Option<Box<dyn Fn(ty::TyVid) -> Option<Symbol> + 'a>>,
pub const_infer_name_resolver: Option<Box<dyn Fn(ty::ConstVid<'tcx>) -> Option<Symbol> + 'a>>,
pub const_infer_name_resolver: Option<Box<dyn Fn(ty::ConstVid) -> Option<Symbol> + 'a>>,
}
impl<'a, 'tcx> Deref for FmtPrinter<'a, 'tcx> {
@ -2082,7 +2082,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
self.printed_type_count = 0;
}
fn const_infer_name(&self, id: ty::ConstVid<'tcx>) -> Option<Symbol> {
fn const_infer_name(&self, id: ty::ConstVid) -> Option<Symbol> {
self.0.const_infer_name_resolver.as_ref().and_then(|func| func(id))
}

View file

@ -128,18 +128,6 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::FnSig<'tcx> {
}
}
impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "?{}c", self.index)
}
}
impl fmt::Debug for ty::EffectVid<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "?{}e", self.index)
}
}
impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
with_no_trimmed_paths!(fmt::Display::fmt(self, f))
@ -251,7 +239,7 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for AliasTy<'tcx> {
}
}
impl<'tcx> fmt::Debug for ty::InferConst<'tcx> {
impl fmt::Debug for ty::InferConst {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
InferConst::Var(var) => write!(f, "{var:?}"),
@ -260,7 +248,7 @@ impl<'tcx> fmt::Debug for ty::InferConst<'tcx> {
}
}
}
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::InferConst<'tcx> {
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::InferConst {
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
this: WithInfcx<'_, Infcx, &Self>,
f: &mut core::fmt::Formatter<'_>,
@ -269,8 +257,8 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::InferConst<'tcx> {
match this.infcx.universe_of_ct(*this.data) {
None => write!(f, "{:?}", this.data),
Some(universe) => match *this.data {
Var(vid) => write!(f, "?{}_{}c", vid.index, universe.index()),
EffectVar(vid) => write!(f, "?{}_{}e", vid.index, universe.index()),
Var(vid) => write!(f, "?{}_{}c", vid.index(), universe.index()),
EffectVar(vid) => write!(f, "?{}_{}e", vid.index(), universe.index()),
Fresh(_) => {
unreachable!()
}
@ -862,7 +850,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
}
}
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InferConst<'tcx> {
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InferConst {
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
self,
_folder: &mut F,
@ -871,7 +859,7 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InferConst<'tcx> {
}
}
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for InferConst<'tcx> {
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for InferConst {
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(
&self,
_visitor: &mut V,

View file

@ -29,7 +29,6 @@ use std::assert_matches::debug_assert_matches;
use std::borrow::Cow;
use std::cmp::Ordering;
use std::fmt;
use std::marker::PhantomData;
use std::ops::{ControlFlow, Deref, Range};
use ty::util::IntTypeExt;
@ -1583,26 +1582,22 @@ impl fmt::Debug for EarlyBoundRegion {
}
}
/// A **`const`** **v**ariable **ID**.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(HashStable, TyEncodable, TyDecodable)]
pub struct ConstVid<'tcx> {
pub index: u32,
pub phantom: PhantomData<&'tcx ()>,
rustc_index::newtype_index! {
/// A **`const`** **v**ariable **ID**.
#[debug_format = "?{}c"]
pub struct ConstVid {}
}
/// An **effect** **v**ariable **ID**.
///
/// Handling effect infer variables happens separately from const infer variables
/// because we do not want to reuse any of the const infer machinery. If we try to
/// relate an effect variable with a normal one, we would ICE, which can catch bugs
/// where we are not correctly using the effect var for an effect param. Fallback
/// is also implemented on top of having separate effect and normal const variables.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(TyEncodable, TyDecodable)]
pub struct EffectVid<'tcx> {
pub index: u32,
pub phantom: PhantomData<&'tcx ()>,
rustc_index::newtype_index! {
/// An **effect** **v**ariable **ID**.
///
/// Handling effect infer variables happens separately from const infer variables
/// because we do not want to reuse any of the const infer machinery. If we try to
/// relate an effect variable with a normal one, we would ICE, which can catch bugs
/// where we are not correctly using the effect var for an effect param. Fallback
/// is also implemented on top of having separate effect and normal const variables.
#[debug_format = "?{}e"]
pub struct EffectVid {}
}
rustc_index::newtype_index! {