diff options
Diffstat (limited to 'compiler/rustc_type_ir')
-rw-r--r-- | compiler/rustc_type_ir/src/lib.rs | 49 | ||||
-rw-r--r-- | compiler/rustc_type_ir/src/structural_impls.rs | 162 | ||||
-rw-r--r-- | compiler/rustc_type_ir/src/sty.rs | 168 |
3 files changed, 272 insertions, 107 deletions
diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 878a6b784..b0f8ea7a0 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -6,6 +6,7 @@ #![feature(unwrap_infallible)] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] +#![cfg_attr(not(bootstrap), allow(internal_features))] #[macro_use] extern crate bitflags; @@ -31,6 +32,7 @@ mod macros; mod structural_impls; pub use codec::*; +pub use structural_impls::{DebugWithInfcx, InferCtxtLike, OptWithInfcx}; pub use sty::*; pub use ty_info::*; @@ -39,41 +41,41 @@ pub trait HashStableContext {} pub trait Interner: Sized { type AdtDef: Clone + Debug + Hash + Ord; - type SubstsRef: Clone + Debug + Hash + Ord; + type GenericArgsRef: Clone + DebugWithInfcx<Self> + Hash + Ord; type DefId: Clone + Debug + Hash + Ord; type Binder<T>; - type Ty: Clone + Debug + Hash + Ord; - type Const: Clone + Debug + Hash + Ord; - type Region: Clone + Debug + Hash + Ord; + type Ty: Clone + DebugWithInfcx<Self> + Hash + Ord; + type Const: Clone + DebugWithInfcx<Self> + Hash + Ord; + type Region: Clone + DebugWithInfcx<Self> + Hash + Ord; type Predicate; type TypeAndMut: Clone + Debug + Hash + Ord; type Mutability: Clone + Debug + Hash + Ord; type Movability: Clone + Debug + Hash + Ord; - type PolyFnSig: Clone + Debug + Hash + Ord; - type ListBinderExistentialPredicate: Clone + Debug + Hash + Ord; - type BinderListTy: Clone + Debug + Hash + Ord; + type PolyFnSig: Clone + DebugWithInfcx<Self> + Hash + Ord; + type ListBinderExistentialPredicate: Clone + DebugWithInfcx<Self> + Hash + Ord; + type BinderListTy: Clone + DebugWithInfcx<Self> + Hash + Ord; type ListTy: Clone + Debug + Hash + Ord + IntoIterator<Item = Self::Ty>; - type AliasTy: Clone + Debug + Hash + Ord; + type AliasTy: Clone + DebugWithInfcx<Self> + Hash + Ord; type ParamTy: Clone + Debug + Hash + Ord; type BoundTy: Clone + Debug + Hash + Ord; type PlaceholderType: Clone + Debug + Hash + Ord; + type InferTy: Clone + DebugWithInfcx<Self> + Hash + Ord; type ErrorGuaranteed: Clone + Debug + Hash + Ord; type PredicateKind: Clone + Debug + Hash + PartialEq + Eq; type AllocId: Clone + Debug + Hash + Ord; - type InferConst: Clone + Debug + Hash + Ord; - type AliasConst: Clone + Debug + Hash + Ord; + type InferConst: Clone + DebugWithInfcx<Self> + Hash + Ord; + type AliasConst: Clone + DebugWithInfcx<Self> + Hash + Ord; type PlaceholderConst: Clone + Debug + Hash + Ord; type ParamConst: Clone + Debug + Hash + Ord; type BoundConst: Clone + Debug + Hash + Ord; - type InferTy: Clone + Debug + Hash + Ord; type ValueConst: Clone + Debug + Hash + Ord; - type ExprConst: Clone + Debug + Hash + Ord; + type ExprConst: Clone + DebugWithInfcx<Self> + Hash + Ord; type EarlyBoundRegion: Clone + Debug + Hash + Ord; type BoundRegion: Clone + Debug + Hash + Ord; type FreeRegion: Clone + Debug + Hash + Ord; - type RegionVid: Clone + Debug + Hash + Ord; + type RegionVid: Clone + DebugWithInfcx<Self> + Hash + Ord; type PlaceholderRegion: Clone + Debug + Hash + Ord; fn ty_and_mut_to_parts(ty_and_mut: Self::TypeAndMut) -> (Self::Ty, Self::Mutability); @@ -214,6 +216,11 @@ bitflags! { /// Does this have `ConstKind::Placeholder`? const HAS_CT_PLACEHOLDER = 1 << 8; + /// Does this have placeholders? + const HAS_PLACEHOLDER = TypeFlags::HAS_TY_PLACEHOLDER.bits + | TypeFlags::HAS_RE_PLACEHOLDER.bits + | TypeFlags::HAS_CT_PLACEHOLDER.bits; + /// `true` if there are "names" of regions and so forth /// that are local to a particular fn/inferctxt const HAS_FREE_LOCAL_REGIONS = 1 << 9; @@ -407,7 +414,7 @@ pub fn debug_bound_var<T: std::fmt::Write>( var: impl std::fmt::Debug, ) -> Result<(), std::fmt::Error> { if debruijn == INNERMOST { - write!(fmt, "^{:?}", var) + write!(fmt, "^{var:?}") } else { write!(fmt, "^{}_{:?}", debruijn.index(), var) } @@ -775,20 +782,6 @@ impl fmt::Debug for FloatVid { } } -impl fmt::Debug for InferTy { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use InferTy::*; - match *self { - TyVar(ref v) => v.fmt(f), - IntVar(ref v) => v.fmt(f), - FloatVar(ref v) => v.fmt(f), - FreshTy(v) => write!(f, "FreshTy({v:?})"), - FreshIntTy(v) => write!(f, "FreshIntTy({v:?})"), - FreshFloatTy(v) => write!(f, "FreshFloatTy({v:?})"), - } - } -} - impl fmt::Debug for Variance { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(match *self { diff --git a/compiler/rustc_type_ir/src/structural_impls.rs b/compiler/rustc_type_ir/src/structural_impls.rs index 1e42175f6..f36f4ec86 100644 --- a/compiler/rustc_type_ir/src/structural_impls.rs +++ b/compiler/rustc_type_ir/src/structural_impls.rs @@ -4,12 +4,13 @@ use crate::fold::{FallibleTypeFolder, TypeFoldable}; use crate::visit::{TypeVisitable, TypeVisitor}; -use crate::{ConstKind, FloatTy, IntTy, Interner, UintTy}; +use crate::{ConstKind, FloatTy, InferTy, IntTy, Interner, UintTy, UniverseIndex}; use rustc_data_structures::functor::IdFunctor; use rustc_data_structures::sync::Lrc; use rustc_index::{Idx, IndexVec}; use core::fmt; +use std::marker::PhantomData; use std::ops::ControlFlow; /////////////////////////////////////////////////////////////////////////// @@ -22,7 +23,6 @@ TrivialTypeTraversalImpls! { (), bool, usize, - u8, u16, u32, u64, @@ -165,6 +165,116 @@ impl<I: Interner, T: TypeVisitable<I>, Ix: Idx> TypeVisitable<I> for IndexVec<Ix } } +/////////////////////////////////////////////////// +// Debug impls + +pub trait InferCtxtLike<I: Interner> { + fn universe_of_ty(&self, ty: I::InferTy) -> Option<UniverseIndex>; + fn universe_of_lt(&self, lt: I::RegionVid) -> Option<UniverseIndex>; + fn universe_of_ct(&self, ct: I::InferConst) -> Option<UniverseIndex>; +} + +impl<I: Interner> InferCtxtLike<I> for core::convert::Infallible { + fn universe_of_ty(&self, _ty: <I as Interner>::InferTy) -> Option<UniverseIndex> { + match *self {} + } + fn universe_of_ct(&self, _ct: <I as Interner>::InferConst) -> Option<UniverseIndex> { + match *self {} + } + fn universe_of_lt(&self, _lt: <I as Interner>::RegionVid) -> Option<UniverseIndex> { + match *self {} + } +} + +pub trait DebugWithInfcx<I: Interner>: fmt::Debug { + fn fmt<InfCtx: InferCtxtLike<I>>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result; +} + +impl<I: Interner, T: DebugWithInfcx<I> + ?Sized> DebugWithInfcx<I> for &'_ T { + fn fmt<InfCtx: InferCtxtLike<I>>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + <T as DebugWithInfcx<I>>::fmt(this.map(|&data| data), f) + } +} +impl<I: Interner, T: DebugWithInfcx<I>> DebugWithInfcx<I> for [T] { + fn fmt<InfCtx: InferCtxtLike<I>>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + match f.alternate() { + true => { + write!(f, "[\n")?; + for element in this.data.iter() { + write!(f, "{:?},\n", &this.wrap(element))?; + } + write!(f, "]") + } + false => { + write!(f, "[")?; + if this.data.len() > 0 { + for element in &this.data[..(this.data.len() - 1)] { + write!(f, "{:?}, ", &this.wrap(element))?; + } + if let Some(element) = this.data.last() { + write!(f, "{:?}", &this.wrap(element))?; + } + } + write!(f, "]") + } + } + } +} + +pub struct OptWithInfcx<'a, I: Interner, InfCtx: InferCtxtLike<I>, T> { + pub data: T, + pub infcx: Option<&'a InfCtx>, + _interner: PhantomData<I>, +} + +impl<I: Interner, InfCtx: InferCtxtLike<I>, T: Copy> Copy for OptWithInfcx<'_, I, InfCtx, T> {} +impl<I: Interner, InfCtx: InferCtxtLike<I>, T: Clone> Clone for OptWithInfcx<'_, I, InfCtx, T> { + fn clone(&self) -> Self { + Self { data: self.data.clone(), infcx: self.infcx, _interner: self._interner } + } +} + +impl<'a, I: Interner, T> OptWithInfcx<'a, I, core::convert::Infallible, T> { + pub fn new_no_ctx(data: T) -> Self { + Self { data, infcx: None, _interner: PhantomData } + } +} + +impl<'a, I: Interner, InfCtx: InferCtxtLike<I>, T> OptWithInfcx<'a, I, InfCtx, T> { + pub fn new(data: T, infcx: &'a InfCtx) -> Self { + Self { data, infcx: Some(infcx), _interner: PhantomData } + } + + pub fn wrap<U>(self, u: U) -> OptWithInfcx<'a, I, InfCtx, U> { + OptWithInfcx { data: u, infcx: self.infcx, _interner: PhantomData } + } + + pub fn map<U>(self, f: impl FnOnce(T) -> U) -> OptWithInfcx<'a, I, InfCtx, U> { + OptWithInfcx { data: f(self.data), infcx: self.infcx, _interner: PhantomData } + } + + pub fn as_ref(&self) -> OptWithInfcx<'a, I, InfCtx, &T> { + OptWithInfcx { data: &self.data, infcx: self.infcx, _interner: PhantomData } + } +} + +impl<I: Interner, InfCtx: InferCtxtLike<I>, T: DebugWithInfcx<I>> fmt::Debug + for OptWithInfcx<'_, I, InfCtx, T> +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + DebugWithInfcx::fmt(self.as_ref(), f) + } +} + impl fmt::Debug for IntTy { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name_str()) @@ -183,20 +293,60 @@ impl fmt::Debug for FloatTy { } } +impl fmt::Debug for InferTy { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use InferTy::*; + match *self { + TyVar(ref v) => v.fmt(f), + IntVar(ref v) => v.fmt(f), + FloatVar(ref v) => v.fmt(f), + FreshTy(v) => write!(f, "FreshTy({v:?})"), + FreshIntTy(v) => write!(f, "FreshIntTy({v:?})"), + FreshFloatTy(v) => write!(f, "FreshFloatTy({v:?})"), + } + } +} +impl<I: Interner<InferTy = InferTy>> DebugWithInfcx<I> for InferTy { + fn fmt<InfCtx: InferCtxtLike<I>>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + use InferTy::*; + match this.infcx.and_then(|infcx| infcx.universe_of_ty(*this.data)) { + None => write!(f, "{:?}", this.data), + Some(universe) => match *this.data { + TyVar(ty_vid) => write!(f, "?{}_{}t", ty_vid.index(), universe.index()), + IntVar(_) | FloatVar(_) | FreshTy(_) | FreshIntTy(_) | FreshFloatTy(_) => { + unreachable!() + } + }, + } + } +} + impl<I: Interner> fmt::Debug for ConstKind<I> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + OptWithInfcx::new_no_ctx(self).fmt(f) + } +} +impl<I: Interner> DebugWithInfcx<I> for ConstKind<I> { + fn fmt<InfCtx: InferCtxtLike<I>>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut core::fmt::Formatter<'_>, + ) -> core::fmt::Result { use ConstKind::*; - match self { + + match this.data { Param(param) => write!(f, "{param:?}"), - Infer(var) => write!(f, "{var:?}"), + Infer(var) => write!(f, "{:?}", &this.wrap(var)), Bound(debruijn, var) => crate::debug_bound_var(f, *debruijn, var.clone()), Placeholder(placeholder) => write!(f, "{placeholder:?}"), Unevaluated(uv) => { - write!(f, "{uv:?}") + write!(f, "{:?}", &this.wrap(uv)) } Value(valtree) => write!(f, "{valtree:?}"), Error(_) => write!(f, "{{const error}}"), - Expr(expr) => write!(f, "{expr:?}"), + Expr(expr) => write!(f, "{:?}", &this.wrap(expr)), } } } diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index b696f9b9b..72bd50ace 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -3,7 +3,6 @@ use std::cmp::Ordering; use std::{fmt, hash}; -use crate::DebruijnIndex; use crate::FloatTy; use crate::HashStableContext; use crate::IntTy; @@ -11,6 +10,7 @@ use crate::Interner; use crate::TyDecoder; use crate::TyEncoder; use crate::UintTy; +use crate::{DebruijnIndex, DebugWithInfcx, InferCtxtLike, OptWithInfcx}; use self::RegionKind::*; use self::TyKind::*; @@ -39,6 +39,7 @@ pub enum AliasKind { /// A projection `<Type as Trait>::AssocType`. /// Can get normalized away if monomorphic enough. Projection, + /// An associated type in an inherent `impl` Inherent, /// An opaque type (usually from `impl Trait` in type aliases or function return types) /// Can only be normalized away in RevealAll mode @@ -74,11 +75,11 @@ pub enum TyKind<I: Interner> { /// Algebraic data types (ADT). For example: structures, enumerations and unions. /// /// For example, the type `List<i32>` would be represented using the `AdtDef` - /// for `struct List<T>` and the substs `[i32]`. + /// for `struct List<T>` and the args `[i32]`. /// /// Note that generic parameters in fields only get lazily substituted - /// by using something like `adt_def.all_fields().map(|field| field.ty(tcx, substs))`. - Adt(I::AdtDef, I::SubstsRef), + /// by using something like `adt_def.all_fields().map(|field| field.ty(tcx, args))`. + Adt(I::AdtDef, I::GenericArgsRef), /// An unsized FFI type that is opaque to Rust. Written as `extern type T`. Foreign(I::DefId), @@ -110,7 +111,7 @@ pub enum TyKind<I: Interner> { /// fn foo() -> i32 { 1 } /// let bar = foo; // bar: fn() -> i32 {foo} /// ``` - FnDef(I::DefId, I::SubstsRef), + FnDef(I::DefId, I::GenericArgsRef), /// A pointer to a function. Written as `fn() -> i32`. /// @@ -130,20 +131,20 @@ pub enum TyKind<I: Interner> { /// The anonymous type of a closure. Used to represent the type of `|a| a`. /// - /// Closure substs contain both the - potentially substituted - generic parameters + /// Closure args contain both the - potentially substituted - generic parameters /// of its parent and some synthetic parameters. See the documentation for - /// `ClosureSubsts` for more details. - Closure(I::DefId, I::SubstsRef), + /// `ClosureArgs` for more details. + Closure(I::DefId, I::GenericArgsRef), /// The anonymous type of a generator. Used to represent the type of /// `|a| yield a`. /// - /// For more info about generator substs, visit the documentation for - /// `GeneratorSubsts`. - Generator(I::DefId, I::SubstsRef, I::Movability), + /// For more info about generator args, visit the documentation for + /// `GeneratorArgs`. + Generator(I::DefId, I::GenericArgsRef, I::Movability), /// A type representing the types stored inside a generator. - /// This should only appear as part of the `GeneratorSubsts`. + /// This should only appear as part of the `GeneratorArgs`. /// /// Note that the captured variables for generators are stored separately /// using a tuple in the same way as for closures. @@ -168,7 +169,7 @@ pub enum TyKind<I: Interner> { GeneratorWitness(I::BinderListTy), /// A type representing the types stored inside a generator. - /// This should only appear as part of the `GeneratorSubsts`. + /// This should only appear as part of the `GeneratorArgs`. /// /// Unlike upvars, the witness can reference lifetimes from /// inside of the generator itself. To deal with them in @@ -176,7 +177,7 @@ pub enum TyKind<I: Interner> { /// lifetimes bound by the witness itself. /// /// This variant is only using when `drop_tracking_mir` is set. - /// This contains the `DefId` and the `SubstsRef` of the generator. + /// This contains the `DefId` and the `GenericArgsRef` of the generator. /// The actual witness types are computed on MIR by the `mir_generator_witnesses` query. /// /// Looking at the following example, the witness for this generator @@ -191,7 +192,7 @@ pub enum TyKind<I: Interner> { /// } /// # ; /// ``` - GeneratorWitnessMIR(I::DefId, I::SubstsRef), + GeneratorWitnessMIR(I::DefId, I::GenericArgsRef), /// The never type `!`. Never, @@ -199,7 +200,9 @@ pub enum TyKind<I: Interner> { /// A tuple type. For example, `(i32, bool)`. Tuple(I::ListTy), - /// A projection or opaque type. Both of these types + /// A projection, opaque type, weak type alias, or inherent associated type. + /// All of these types are represented as pairs of def-id and args, and can + /// be normalized, so they are grouped conceptually. Alias(AliasKind, I::AliasTy), /// A type parameter; for example, `T` in `fn f<T>(x: T) {}`. @@ -503,42 +506,48 @@ impl<I: Interner> hash::Hash for TyKind<I> { } } -// This is manually implemented because a derive would require `I: Debug` -impl<I: Interner> fmt::Debug for TyKind<I> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { +impl<I: Interner> DebugWithInfcx<I> for TyKind<I> { + fn fmt<InfCtx: InferCtxtLike<I>>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut core::fmt::Formatter<'_>, + ) -> fmt::Result { + match this.data { Bool => write!(f, "bool"), Char => write!(f, "char"), Int(i) => write!(f, "{i:?}"), Uint(u) => write!(f, "{u:?}"), Float(float) => write!(f, "{float:?}"), - Adt(d, s) => f.debug_tuple_field2_finish("Adt", d, s), + Adt(d, s) => f.debug_tuple_field2_finish("Adt", d, &this.wrap(s)), Foreign(d) => f.debug_tuple_field1_finish("Foreign", d), Str => write!(f, "str"), - Array(t, c) => write!(f, "[{t:?}; {c:?}]"), - Slice(t) => write!(f, "[{t:?}]"), + Array(t, c) => write!(f, "[{:?}; {:?}]", &this.wrap(t), &this.wrap(c)), + Slice(t) => write!(f, "[{:?}]", &this.wrap(t)), RawPtr(p) => { let (ty, mutbl) = I::ty_and_mut_to_parts(p.clone()); match I::mutability_is_mut(mutbl) { true => write!(f, "*mut "), false => write!(f, "*const "), }?; - write!(f, "{ty:?}") + write!(f, "{:?}", &this.wrap(ty)) } Ref(r, t, m) => match I::mutability_is_mut(m.clone()) { - true => write!(f, "&{r:?} mut {t:?}"), - false => write!(f, "&{r:?} {t:?}"), + true => write!(f, "&{:?} mut {:?}", &this.wrap(r), &this.wrap(t)), + false => write!(f, "&{:?} {:?}", &this.wrap(r), &this.wrap(t)), }, - FnDef(d, s) => f.debug_tuple_field2_finish("FnDef", d, s), - FnPtr(s) => write!(f, "{s:?}"), + FnDef(d, s) => f.debug_tuple_field2_finish("FnDef", d, &this.wrap(s)), + FnPtr(s) => write!(f, "{:?}", &this.wrap(s)), Dynamic(p, r, repr) => match repr { - DynKind::Dyn => write!(f, "dyn {p:?} + {r:?}"), - DynKind::DynStar => write!(f, "dyn* {p:?} + {r:?}"), + DynKind::Dyn => write!(f, "dyn {:?} + {:?}", &this.wrap(p), &this.wrap(r)), + DynKind::DynStar => { + write!(f, "dyn* {:?} + {:?}", &this.wrap(p), &this.wrap(r)) + } }, - Closure(d, s) => f.debug_tuple_field2_finish("Closure", d, s), - Generator(d, s, m) => f.debug_tuple_field3_finish("Generator", d, s, m), - GeneratorWitness(g) => f.debug_tuple_field1_finish("GeneratorWitness", g), - GeneratorWitnessMIR(d, s) => f.debug_tuple_field2_finish("GeneratorWitnessMIR", d, s), + Closure(d, s) => f.debug_tuple_field2_finish("Closure", d, &this.wrap(s)), + Generator(d, s, m) => f.debug_tuple_field3_finish("Generator", d, &this.wrap(s), m), + GeneratorWitness(g) => f.debug_tuple_field1_finish("GeneratorWitness", &this.wrap(g)), + GeneratorWitnessMIR(d, s) => { + f.debug_tuple_field2_finish("GeneratorWitnessMIR", d, &this.wrap(s)) + } Never => write!(f, "!"), Tuple(t) => { let mut iter = t.clone().into_iter(); @@ -547,35 +556,41 @@ impl<I: Interner> fmt::Debug for TyKind<I> { match iter.next() { None => return write!(f, ")"), - Some(ty) => write!(f, "{ty:?}")?, + Some(ty) => write!(f, "{:?}", &this.wrap(ty))?, }; match iter.next() { None => return write!(f, ",)"), - Some(ty) => write!(f, "{ty:?})")?, + Some(ty) => write!(f, "{:?})", &this.wrap(ty))?, } for ty in iter { - write!(f, ", {ty:?}")?; + write!(f, ", {:?}", &this.wrap(ty))?; } write!(f, ")") } - Alias(i, a) => f.debug_tuple_field2_finish("Alias", i, a), + Alias(i, a) => f.debug_tuple_field2_finish("Alias", i, &this.wrap(a)), Param(p) => write!(f, "{p:?}"), Bound(d, b) => crate::debug_bound_var(f, *d, b), Placeholder(p) => write!(f, "{p:?}"), - Infer(t) => write!(f, "{t:?}"), + Infer(t) => write!(f, "{:?}", this.wrap(t)), TyKind::Error(_) => write!(f, "{{type error}}"), } } } +// This is manually implemented because a derive would require `I: Debug` +impl<I: Interner> fmt::Debug for TyKind<I> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + OptWithInfcx::new_no_ctx(self).fmt(f) + } +} // This is manually implemented because a derive would require `I: Encodable` impl<I: Interner, E: TyEncoder> Encodable<E> for TyKind<I> where I::ErrorGuaranteed: Encodable<E>, I::AdtDef: Encodable<E>, - I::SubstsRef: Encodable<E>, + I::GenericArgsRef: Encodable<E>, I::DefId: Encodable<E>, I::Ty: Encodable<E>, I::Const: Encodable<E>, @@ -609,9 +624,9 @@ where Float(f) => e.emit_enum_variant(disc, |e| { f.encode(e); }), - Adt(adt, substs) => e.emit_enum_variant(disc, |e| { + Adt(adt, args) => e.emit_enum_variant(disc, |e| { adt.encode(e); - substs.encode(e); + args.encode(e); }), Foreign(def_id) => e.emit_enum_variant(disc, |e| { def_id.encode(e); @@ -632,9 +647,9 @@ where t.encode(e); m.encode(e); }), - FnDef(def_id, substs) => e.emit_enum_variant(disc, |e| { + FnDef(def_id, args) => e.emit_enum_variant(disc, |e| { def_id.encode(e); - substs.encode(e); + args.encode(e); }), FnPtr(polyfnsig) => e.emit_enum_variant(disc, |e| { polyfnsig.encode(e); @@ -644,25 +659,25 @@ where r.encode(e); repr.encode(e); }), - Closure(def_id, substs) => e.emit_enum_variant(disc, |e| { + Closure(def_id, args) => e.emit_enum_variant(disc, |e| { def_id.encode(e); - substs.encode(e); + args.encode(e); }), - Generator(def_id, substs, m) => e.emit_enum_variant(disc, |e| { + Generator(def_id, args, m) => e.emit_enum_variant(disc, |e| { def_id.encode(e); - substs.encode(e); + args.encode(e); m.encode(e); }), GeneratorWitness(b) => e.emit_enum_variant(disc, |e| { b.encode(e); }), - GeneratorWitnessMIR(def_id, substs) => e.emit_enum_variant(disc, |e| { + GeneratorWitnessMIR(def_id, args) => e.emit_enum_variant(disc, |e| { def_id.encode(e); - substs.encode(e); + args.encode(e); }), Never => e.emit_enum_variant(disc, |_| {}), - Tuple(substs) => e.emit_enum_variant(disc, |e| { - substs.encode(e); + Tuple(args) => e.emit_enum_variant(disc, |e| { + args.encode(e); }), Alias(k, p) => e.emit_enum_variant(disc, |e| { k.encode(e); @@ -693,7 +708,7 @@ impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for TyKind<I> where I::ErrorGuaranteed: Decodable<D>, I::AdtDef: Decodable<D>, - I::SubstsRef: Decodable<D>, + I::GenericArgsRef: Decodable<D>, I::DefId: Decodable<D>, I::Ty: Decodable<D>, I::Const: Decodable<D>, @@ -760,7 +775,7 @@ impl<CTX: HashStableContext, I: Interner> HashStable<CTX> for TyKind<I> where I::AdtDef: HashStable<CTX>, I::DefId: HashStable<CTX>, - I::SubstsRef: HashStable<CTX>, + I::GenericArgsRef: HashStable<CTX>, I::Ty: HashStable<CTX>, I::Const: HashStable<CTX>, I::TypeAndMut: HashStable<CTX>, @@ -797,9 +812,9 @@ where Float(f) => { f.hash_stable(__hcx, __hasher); } - Adt(adt, substs) => { + Adt(adt, args) => { adt.hash_stable(__hcx, __hasher); - substs.hash_stable(__hcx, __hasher); + args.hash_stable(__hcx, __hasher); } Foreign(def_id) => { def_id.hash_stable(__hcx, __hasher); @@ -820,9 +835,9 @@ where t.hash_stable(__hcx, __hasher); m.hash_stable(__hcx, __hasher); } - FnDef(def_id, substs) => { + FnDef(def_id, args) => { def_id.hash_stable(__hcx, __hasher); - substs.hash_stable(__hcx, __hasher); + args.hash_stable(__hcx, __hasher); } FnPtr(polyfnsig) => { polyfnsig.hash_stable(__hcx, __hasher); @@ -832,25 +847,25 @@ where r.hash_stable(__hcx, __hasher); repr.hash_stable(__hcx, __hasher); } - Closure(def_id, substs) => { + Closure(def_id, args) => { def_id.hash_stable(__hcx, __hasher); - substs.hash_stable(__hcx, __hasher); + args.hash_stable(__hcx, __hasher); } - Generator(def_id, substs, m) => { + Generator(def_id, args, m) => { def_id.hash_stable(__hcx, __hasher); - substs.hash_stable(__hcx, __hasher); + args.hash_stable(__hcx, __hasher); m.hash_stable(__hcx, __hasher); } GeneratorWitness(b) => { b.hash_stable(__hcx, __hasher); } - GeneratorWitnessMIR(def_id, substs) => { + GeneratorWitnessMIR(def_id, args) => { def_id.hash_stable(__hcx, __hasher); - substs.hash_stable(__hcx, __hasher); + args.hash_stable(__hcx, __hasher); } Never => {} - Tuple(substs) => { - substs.hash_stable(__hcx, __hasher); + Tuple(args) => { + args.hash_stable(__hcx, __hasher); } Alias(k, p) => { k.hash_stable(__hcx, __hasher); @@ -1155,7 +1170,7 @@ impl<I: Interner> Clone for ConstKind<I> { /// These are regions that are stored behind a binder and must be substituted /// with some concrete region before being used. There are two kind of /// bound regions: early-bound, which are bound in an item's `Generics`, -/// and are substituted by an `InternalSubsts`, and late-bound, which are part of +/// and are substituted by an `GenericArgs`, and late-bound, which are part of /// higher-ranked types (e.g., `for<'a> fn(&'a ())`), and are substituted by /// the likes of `liberate_late_bound_regions`. The distinction exists /// because higher-ranked lifetimes aren't supported in all places. See [1][2]. @@ -1356,21 +1371,23 @@ impl<I: Interner> hash::Hash for RegionKind<I> { } } -// This is manually implemented because a derive would require `I: Debug` -impl<I: Interner> fmt::Debug for RegionKind<I> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { +impl<I: Interner> DebugWithInfcx<I> for RegionKind<I> { + fn fmt<InfCtx: InferCtxtLike<I>>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut core::fmt::Formatter<'_>, + ) -> core::fmt::Result { + match this.data { ReEarlyBound(data) => write!(f, "ReEarlyBound({data:?})"), ReLateBound(binder_id, bound_region) => { write!(f, "ReLateBound({binder_id:?}, {bound_region:?})") } - ReFree(fr) => fr.fmt(f), + ReFree(fr) => write!(f, "{fr:?}"), ReStatic => f.write_str("ReStatic"), - ReVar(vid) => vid.fmt(f), + ReVar(vid) => write!(f, "{:?}", &this.wrap(vid)), RePlaceholder(placeholder) => write!(f, "RePlaceholder({placeholder:?})"), @@ -1380,6 +1397,11 @@ impl<I: Interner> fmt::Debug for RegionKind<I> { } } } +impl<I: Interner> fmt::Debug for RegionKind<I> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + OptWithInfcx::new_no_ctx(self).fmt(f) + } +} // This is manually implemented because a derive would require `I: Encodable` impl<I: Interner, E: TyEncoder> Encodable<E> for RegionKind<I> |