From a4b7ed7a42c716ab9f05e351f003d589124fd55d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:58 +0200 Subject: Adding upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_type_ir/src/lib.rs | 48 +++++++------- compiler/rustc_type_ir/src/sty.rs | 127 +++++++++++++++----------------------- 2 files changed, 76 insertions(+), 99 deletions(-) (limited to 'compiler/rustc_type_ir/src') diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index e3f7a1bd0..44004cb0b 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -42,7 +42,7 @@ pub trait Interner { type ListBinderExistentialPredicate: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type BinderListTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type ListTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; - type ProjectionTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; + type AliasTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type ParamTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type BoundTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type PlaceholderType: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; @@ -241,22 +241,30 @@ bitflags! { /// Basically anything but `ReLateBound` and `ReErased`. const HAS_FREE_REGIONS = 1 << 14; - /// Does this have any `ReLateBound` regions? Used to check - /// if a global bound is safe to evaluate. + /// Does this have any `ReLateBound` regions? const HAS_RE_LATE_BOUND = 1 << 15; + /// Does this have any `Bound` types? + const HAS_TY_LATE_BOUND = 1 << 16; + /// Does this have any `ConstKind::Bound` consts? + const HAS_CT_LATE_BOUND = 1 << 17; + /// Does this have any bound variables? + /// Used to check if a global bound is safe to evaluate. + const HAS_LATE_BOUND = TypeFlags::HAS_RE_LATE_BOUND.bits + | TypeFlags::HAS_TY_LATE_BOUND.bits + | TypeFlags::HAS_CT_LATE_BOUND.bits; /// Does this have any `ReErased` regions? - const HAS_RE_ERASED = 1 << 16; + const HAS_RE_ERASED = 1 << 18; /// Does this value have parameters/placeholders/inference variables which could be /// replaced later, in a way that would change the results of `impl` specialization? - const STILL_FURTHER_SPECIALIZABLE = 1 << 17; + const STILL_FURTHER_SPECIALIZABLE = 1 << 19; /// Does this value have `InferTy::FreshTy/FreshIntTy/FreshFloatTy`? - const HAS_TY_FRESH = 1 << 18; + const HAS_TY_FRESH = 1 << 20; /// Does this value have `InferConst::Fresh`? - const HAS_CT_FRESH = 1 << 19; + const HAS_CT_FRESH = 1 << 21; } } @@ -301,9 +309,9 @@ rustc_index::newtype_index! { /// /// [dbi]: https://en.wikipedia.org/wiki/De_Bruijn_index #[derive(HashStable_Generic)] + #[debug_format = "DebruijnIndex({})"] pub struct DebruijnIndex { - DEBUG_FORMAT = "DebruijnIndex({})", - const INNERMOST = 0, + const INNERMOST = 0; } } @@ -499,9 +507,8 @@ pub struct FloatVarValue(pub FloatTy); rustc_index::newtype_index! { /// A **ty**pe **v**ariable **ID**. - pub struct TyVid { - DEBUG_FORMAT = "_#{}t" - } + #[debug_format = "_#{}t"] + pub struct TyVid {} } /// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**. @@ -719,9 +726,9 @@ impl fmt::Debug for InferTy { 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), + FreshTy(v) => write!(f, "FreshTy({v:?})"), + FreshIntTy(v) => write!(f, "FreshIntTy({v:?})"), + FreshFloatTy(v) => write!(f, "FreshFloatTy({v:?})"), } } } @@ -744,9 +751,9 @@ impl fmt::Display for InferTy { TyVar(_) => write!(f, "_"), IntVar(_) => write!(f, "{}", "{integer}"), FloatVar(_) => write!(f, "{}", "{float}"), - FreshTy(v) => write!(f, "FreshTy({})", v), - FreshIntTy(v) => write!(f, "FreshIntTy({})", v), - FreshFloatTy(v) => write!(f, "FreshFloatTy({})", v), + FreshTy(v) => write!(f, "FreshTy({v})"), + FreshIntTy(v) => write!(f, "FreshIntTy({v})"), + FreshFloatTy(v) => write!(f, "FreshFloatTy({v})"), } } } @@ -788,9 +795,8 @@ rustc_index::newtype_index! { /// type -- an idealized representative of "types in general" that we /// use for checking generic functions. #[derive(HashStable_Generic)] - pub struct UniverseIndex { - DEBUG_FORMAT = "U{}", - } + #[debug_format = "U{}"] + pub struct UniverseIndex {} } impl UniverseIndex { diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index 3ed616d70..5f29588ae 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -1,6 +1,6 @@ #![allow(rustc::usage_of_ty_tykind)] -use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd}; +use std::cmp::Ordering; use std::{fmt, hash}; use crate::DebruijnIndex; @@ -19,19 +19,8 @@ use rustc_data_structures::stable_hasher::HashStable; use rustc_serialize::{Decodable, Decoder, Encodable}; /// Specifies how a trait object is represented. -#[derive( - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - Debug, - Encodable, - Decodable, - HashStable_Generic -)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Encodable, Decodable, HashStable_Generic)] pub enum DynKind { /// An unsized `dyn Trait` object Dyn, @@ -46,6 +35,13 @@ pub enum DynKind { DynStar, } +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Encodable, Decodable, HashStable_Generic)] +pub enum AliasKind { + Projection, + Opaque, +} + /// Defines the kinds of types used by the type system. /// /// Types written by the user start out as `hir::TyKind` and get @@ -170,21 +166,8 @@ pub enum TyKind { /// A tuple type. For example, `(i32, bool)`. Tuple(I::ListTy), - /// The projection of an associated type. For example, - /// `>::N`. - Projection(I::ProjectionTy), - - /// Opaque (`impl Trait`) type found in a return type. - /// - /// The `DefId` comes either from - /// * the `impl Trait` ast::Ty node, - /// * or the `type Foo = impl Trait` declaration - /// - /// For RPIT the substitutions are for the generics of the function, - /// while for TAIT it is used for the generic parameters of the alias. - /// - /// During codegen, `tcx.type_of(def_id)` can be used to get the underlying type. - Opaque(I::DefId, I::SubstsRef), + /// A projection or opaque type. Both of these types + Alias(AliasKind, I::AliasTy), /// A type parameter; for example, `T` in `fn f(x: T) {}`. Param(I::ParamTy), @@ -252,13 +235,12 @@ const fn tykind_discriminant(value: &TyKind) -> usize { GeneratorWitness(_) => 17, Never => 18, Tuple(_) => 19, - Projection(_) => 20, - Opaque(_, _) => 21, - Param(_) => 22, - Bound(_, _) => 23, - Placeholder(_) => 24, - Infer(_) => 25, - Error(_) => 26, + Alias(_, _) => 20, + Param(_) => 21, + Bound(_, _) => 22, + Placeholder(_) => 23, + Infer(_) => 24, + Error(_) => 25, } } @@ -268,9 +250,9 @@ impl Clone for TyKind { match self { Bool => Bool, Char => Char, - Int(i) => Int(i.clone()), - Uint(u) => Uint(u.clone()), - Float(f) => Float(f.clone()), + Int(i) => Int(*i), + Uint(u) => Uint(*u), + Float(f) => Float(*f), Adt(d, s) => Adt(d.clone(), s.clone()), Foreign(d) => Foreign(d.clone()), Str => Str, @@ -280,16 +262,15 @@ impl Clone for TyKind { Ref(r, t, m) => Ref(r.clone(), t.clone(), m.clone()), FnDef(d, s) => FnDef(d.clone(), s.clone()), FnPtr(s) => FnPtr(s.clone()), - Dynamic(p, r, repr) => Dynamic(p.clone(), r.clone(), repr.clone()), + Dynamic(p, r, repr) => Dynamic(p.clone(), r.clone(), *repr), Closure(d, s) => Closure(d.clone(), s.clone()), Generator(d, s, m) => Generator(d.clone(), s.clone(), m.clone()), GeneratorWitness(g) => GeneratorWitness(g.clone()), Never => Never, Tuple(t) => Tuple(t.clone()), - Projection(p) => Projection(p.clone()), - Opaque(d, s) => Opaque(d.clone(), s.clone()), + Alias(k, p) => Alias(*k, p.clone()), Param(p) => Param(p.clone()), - Bound(d, b) => Bound(d.clone(), b.clone()), + Bound(d, b) => Bound(*d, b.clone()), Placeholder(p) => Placeholder(p.clone()), Infer(t) => Infer(t.clone()), Error(e) => Error(e.clone()), @@ -323,8 +304,7 @@ impl PartialEq for TyKind { } (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g, (Tuple(a_t), Tuple(b_t)) => a_t == b_t, - (Projection(a_p), Projection(b_p)) => a_p == b_p, - (Opaque(a_d, a_s), Opaque(b_d, b_s)) => a_d == b_d && a_s == b_s, + (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p, (Param(a_p), Param(b_p)) => a_p == b_p, (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d == b_d && a_b == b_b, (Placeholder(a_p), Placeholder(b_p)) => a_p == b_p, @@ -381,8 +361,7 @@ impl Ord for TyKind { } (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g.cmp(b_g), (Tuple(a_t), Tuple(b_t)) => a_t.cmp(b_t), - (Projection(a_p), Projection(b_p)) => a_p.cmp(b_p), - (Opaque(a_d, a_s), Opaque(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), + (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i.cmp(b_i).then_with(|| a_p.cmp(b_p)), (Param(a_p), Param(b_p)) => a_p.cmp(b_p), (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d.cmp(b_d).then_with(|| a_b.cmp(b_b)), (Placeholder(a_p), Placeholder(b_p)) => a_p.cmp(b_p), @@ -443,10 +422,9 @@ impl hash::Hash for TyKind { } GeneratorWitness(g) => g.hash(state), Tuple(t) => t.hash(state), - Projection(p) => p.hash(state), - Opaque(d, s) => { - d.hash(state); - s.hash(state) + Alias(i, p) => { + i.hash(state); + p.hash(state); } Param(p) => p.hash(state), Bound(d, b) => { @@ -485,8 +463,7 @@ impl fmt::Debug for TyKind { GeneratorWitness(g) => f.debug_tuple_field1_finish("GeneratorWitness", g), Never => f.write_str("Never"), Tuple(t) => f.debug_tuple_field1_finish("Tuple", t), - Projection(p) => f.debug_tuple_field1_finish("Projection", p), - Opaque(d, s) => f.debug_tuple_field2_finish("Opaque", d, s), + Alias(i, a) => f.debug_tuple_field2_finish("Alias", i, a), Param(p) => f.debug_tuple_field1_finish("Param", p), Bound(d, b) => f.debug_tuple_field2_finish("Bound", d, b), Placeholder(p) => f.debug_tuple_field1_finish("Placeholder", p), @@ -513,7 +490,7 @@ where I::ListBinderExistentialPredicate: Encodable, I::BinderListTy: Encodable, I::ListTy: Encodable, - I::ProjectionTy: Encodable, + I::AliasTy: Encodable, I::ParamTy: Encodable, I::BoundTy: Encodable, I::PlaceholderType: Encodable, @@ -586,13 +563,10 @@ where Tuple(substs) => e.emit_enum_variant(disc, |e| { substs.encode(e); }), - Projection(p) => e.emit_enum_variant(disc, |e| { + Alias(k, p) => e.emit_enum_variant(disc, |e| { + k.encode(e); p.encode(e); }), - Opaque(def_id, substs) => e.emit_enum_variant(disc, |e| { - def_id.encode(e); - substs.encode(e); - }), Param(p) => e.emit_enum_variant(disc, |e| { p.encode(e); }), @@ -630,8 +604,9 @@ where I::ListBinderExistentialPredicate: Decodable, I::BinderListTy: Decodable, I::ListTy: Decodable, - I::ProjectionTy: Decodable, + I::AliasTy: Decodable, I::ParamTy: Decodable, + I::AliasTy: Decodable, I::BoundTy: Decodable, I::PlaceholderType: Decodable, I::InferTy: Decodable, @@ -660,13 +635,12 @@ where 17 => GeneratorWitness(Decodable::decode(d)), 18 => Never, 19 => Tuple(Decodable::decode(d)), - 20 => Projection(Decodable::decode(d)), - 21 => Opaque(Decodable::decode(d), Decodable::decode(d)), - 22 => Param(Decodable::decode(d)), - 23 => Bound(Decodable::decode(d), Decodable::decode(d)), - 24 => Placeholder(Decodable::decode(d)), - 25 => Infer(Decodable::decode(d)), - 26 => Error(Decodable::decode(d)), + 20 => Alias(Decodable::decode(d), Decodable::decode(d)), + 21 => Param(Decodable::decode(d)), + 22 => Bound(Decodable::decode(d), Decodable::decode(d)), + 23 => Placeholder(Decodable::decode(d)), + 24 => Infer(Decodable::decode(d)), + 25 => Error(Decodable::decode(d)), _ => panic!( "{}", format!( @@ -695,7 +669,7 @@ where I::Mutability: HashStable, I::BinderListTy: HashStable, I::ListTy: HashStable, - I::ProjectionTy: HashStable, + I::AliasTy: HashStable, I::BoundTy: HashStable, I::ParamTy: HashStable, I::PlaceholderType: HashStable, @@ -772,13 +746,10 @@ where Tuple(substs) => { substs.hash_stable(__hcx, __hasher); } - Projection(p) => { + Alias(k, p) => { + k.hash_stable(__hcx, __hasher); p.hash_stable(__hcx, __hasher); } - Opaque(def_id, substs) => { - def_id.hash_stable(__hcx, __hasher); - substs.hash_stable(__hcx, __hasher); - } Param(p) => { p.hash_stable(__hcx, __hasher); } @@ -836,7 +807,7 @@ where /// /// Note that inference variables and bound regions are not included /// in this diagram. In the case of inference variables, they should -/// be inferred to some other region from the diagram. In the case of +/// be inferred to some other region from the diagram. In the case of /// bound regions, they are excluded because they don't make sense to /// include -- the diagram indicates the relationship between free /// regions. @@ -965,7 +936,7 @@ impl Clone for RegionKind { fn clone(&self) -> Self { match self { ReEarlyBound(r) => ReEarlyBound(r.clone()), - ReLateBound(d, r) => ReLateBound(d.clone(), r.clone()), + ReLateBound(d, r) => ReLateBound(*d, r.clone()), ReFree(r) => ReFree(r.clone()), ReStatic => ReStatic, ReVar(r) => ReVar(r.clone()), @@ -1057,10 +1028,10 @@ impl hash::Hash for RegionKind { impl fmt::Debug for RegionKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - ReEarlyBound(data) => write!(f, "ReEarlyBound({:?})", data), + ReEarlyBound(data) => write!(f, "ReEarlyBound({data:?})"), ReLateBound(binder_id, bound_region) => { - write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region) + write!(f, "ReLateBound({binder_id:?}, {bound_region:?})") } ReFree(fr) => fr.fmt(f), @@ -1069,7 +1040,7 @@ impl fmt::Debug for RegionKind { ReVar(vid) => vid.fmt(f), - RePlaceholder(placeholder) => write!(f, "RePlaceholder({:?})", placeholder), + RePlaceholder(placeholder) => write!(f, "RePlaceholder({placeholder:?})"), ReErased => f.write_str("ReErased"), } -- cgit v1.2.3