summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_type_ir/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /compiler/rustc_type_ir/src
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_type_ir/src')
-rw-r--r--compiler/rustc_type_ir/src/fold.rs14
-rw-r--r--compiler/rustc_type_ir/src/lib.rs48
-rw-r--r--compiler/rustc_type_ir/src/sty.rs107
-rw-r--r--compiler/rustc_type_ir/src/visit.rs5
4 files changed, 72 insertions, 102 deletions
diff --git a/compiler/rustc_type_ir/src/fold.rs b/compiler/rustc_type_ir/src/fold.rs
index 371c61191..e7a6831f5 100644
--- a/compiler/rustc_type_ir/src/fold.rs
+++ b/compiler/rustc_type_ir/src/fold.rs
@@ -11,7 +11,7 @@
//! modification. These are the ones containing the most important type-related
//! information, such as `Ty`, `Predicate`, `Region`, and `Const`.
//!
-//! There are three groups of traits involved in each traversal.
+//! There are three traits involved in each traversal.
//! - `TypeFoldable`. This is implemented once for many types, including:
//! - Types of interest, for which the methods delegate to the folder.
//! - All other types, including generic containers like `Vec` and `Option`.
@@ -51,6 +51,12 @@ use crate::{visit::TypeVisitable, Interner};
///
/// To implement this conveniently, use the derive macro located in
/// `rustc_macros`.
+///
+/// This trait is a sub-trait of `TypeVisitable`. This is because many
+/// `TypeFolder` instances use the methods in `TypeVisitableExt` while folding,
+/// which means in practice almost every foldable type needs to also be
+/// visitable. (However, there are some types that are visitable without being
+/// foldable.)
pub trait TypeFoldable<I: Interner>: TypeVisitable<I> {
/// The entry point for folding. To fold a value `t` with a folder `f`
/// call: `t.try_fold_with(f)`.
@@ -58,7 +64,7 @@ pub trait TypeFoldable<I: Interner>: TypeVisitable<I> {
/// For most types, this just traverses the value, calling `try_fold_with`
/// on each field/element.
///
- /// For types of interest (such as `Ty`), the implementation of method
+ /// For types of interest (such as `Ty`), the implementation of this method
/// calls a folder method specifically for that type (such as
/// `F::try_fold_ty`). This is where control transfers from `TypeFoldable`
/// to `TypeFolder`.
@@ -121,7 +127,7 @@ pub trait TypeFolder<I: Interner>: FallibleTypeFolder<I, Error = !> {
}
// The default region folder is a no-op because `Region` is non-recursive
- // and has no `super_visit_with` method to call. That also explains the
+ // and has no `super_fold_with` method to call. That also explains the
// lack of `I::Region: TypeSuperFoldable<I>` bound on this method.
fn fold_region(&mut self, r: I::Region) -> I::Region {
r
@@ -170,7 +176,7 @@ pub trait FallibleTypeFolder<I: Interner>: Sized {
}
// The default region folder is a no-op because `Region` is non-recursive
- // and has no `super_visit_with` method to call. That also explains the
+ // and has no `super_fold_with` method to call. That also explains the
// lack of `I::Region: TypeSuperFoldable<I>` bound on this method.
fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, Self::Error> {
Ok(r)
diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs
index b0f8ea7a0..83401b65c 100644
--- a/compiler/rustc_type_ir/src/lib.rs
+++ b/compiler/rustc_type_ir/src/lib.rs
@@ -6,7 +6,7 @@
#![feature(unwrap_infallible)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
-#![cfg_attr(not(bootstrap), allow(internal_features))]
+#![allow(internal_features)]
#[macro_use]
extern crate bitflags;
@@ -41,7 +41,12 @@ pub trait HashStableContext {}
pub trait Interner: Sized {
type AdtDef: Clone + Debug + Hash + Ord;
- type GenericArgsRef: Clone + DebugWithInfcx<Self> + Hash + Ord;
+ type GenericArgsRef: Clone
+ + DebugWithInfcx<Self>
+ + Hash
+ + Ord
+ + IntoIterator<Item = Self::GenericArg>;
+ type GenericArg: Clone + DebugWithInfcx<Self> + Hash + Ord;
type DefId: Clone + Debug + Hash + Ord;
type Binder<T>;
type Ty: Clone + DebugWithInfcx<Self> + Hash + Ord;
@@ -294,6 +299,9 @@ bitflags! {
/// Does this have `Generator` or `GeneratorWitness`?
const HAS_TY_GENERATOR = 1 << 23;
+
+ /// Does this have any binders with bound vars (e.g. that need to be anonymized)?
+ const HAS_BINDER_VARS = 1 << 24;
}
}
@@ -574,16 +582,16 @@ rustc_index::newtype_index! {
pub struct TyVid {}
}
-/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
-pub struct IntVid {
- pub index: u32,
+rustc_index::newtype_index! {
+ /// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
+ #[debug_format = "?{}i"]
+ pub struct IntVid {}
}
-/// An **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
-pub struct FloatVid {
- pub index: u32,
+rustc_index::newtype_index! {
+ /// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
+ #[debug_format = "?{}f"]
+ pub struct FloatVid {}
}
/// A placeholder for a type that hasn't been inferred yet.
@@ -645,11 +653,11 @@ impl UnifyKey for IntVid {
type Value = Option<IntVarValue>;
#[inline] // make this function eligible for inlining - it is quite hot.
fn index(&self) -> u32 {
- self.index
+ self.as_u32()
}
#[inline]
fn from_index(i: u32) -> IntVid {
- IntVid { index: i }
+ IntVid::from_u32(i)
}
fn tag() -> &'static str {
"IntVid"
@@ -662,11 +670,11 @@ impl UnifyKey for FloatVid {
type Value = Option<FloatVarValue>;
#[inline]
fn index(&self) -> u32 {
- self.index
+ self.as_u32()
}
#[inline]
fn from_index(i: u32) -> FloatVid {
- FloatVid { index: i }
+ FloatVid::from_u32(i)
}
fn tag() -> &'static str {
"FloatVid"
@@ -770,18 +778,6 @@ impl fmt::Debug for FloatVarValue {
}
}
-impl fmt::Debug for IntVid {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "?{}i", self.index)
- }
-}
-
-impl fmt::Debug for FloatVid {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "?{}f", self.index)
- }
-}
-
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/sty.rs b/compiler/rustc_type_ir/src/sty.rs
index 72bd50ace..f19e9935f 100644
--- a/compiler/rustc_type_ir/src/sty.rs
+++ b/compiler/rustc_type_ir/src/sty.rs
@@ -146,37 +146,11 @@ pub enum TyKind<I: Interner> {
/// A type representing the types stored inside a generator.
/// 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.
- ///
- /// Unlike upvars, the witness can reference lifetimes from
- /// inside of the generator itself. To deal with them in
- /// the type of the generator, we convert them to higher ranked
- /// lifetimes bound by the witness itself.
- ///
- /// Looking at the following example, the witness for this generator
- /// may end up as something like `for<'a> [Vec<i32>, &'a Vec<i32>]`:
- ///
- /// ```ignore UNSOLVED (ask @compiler-errors, should this error? can we just swap the yields?)
- /// #![feature(generators)]
- /// |a| {
- /// let x = &vec![3];
- /// yield a;
- /// yield x[0];
- /// }
- /// # ;
- /// ```
- GeneratorWitness(I::BinderListTy),
-
- /// A type representing the types stored inside a generator.
- /// 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
/// the type of the generator, we convert them to higher ranked
/// lifetimes bound by the witness itself.
///
- /// This variant is only using when `drop_tracking_mir` is set.
/// This contains the `DefId` and the `GenericArgsRef` of the generator.
/// The actual witness types are computed on MIR by the `mir_generator_witnesses` query.
///
@@ -192,7 +166,7 @@ pub enum TyKind<I: Interner> {
/// }
/// # ;
/// ```
- GeneratorWitnessMIR(I::DefId, I::GenericArgsRef),
+ GeneratorWitness(I::DefId, I::GenericArgsRef),
/// The never type `!`.
Never,
@@ -278,7 +252,7 @@ const fn tykind_discriminant<I: Interner>(value: &TyKind<I>) -> usize {
Dynamic(..) => 14,
Closure(_, _) => 15,
Generator(_, _, _) => 16,
- GeneratorWitness(_) => 17,
+ GeneratorWitness(_, _) => 17,
Never => 18,
Tuple(_) => 19,
Alias(_, _) => 20,
@@ -287,7 +261,6 @@ const fn tykind_discriminant<I: Interner>(value: &TyKind<I>) -> usize {
Placeholder(_) => 23,
Infer(_) => 24,
Error(_) => 25,
- GeneratorWitnessMIR(_, _) => 26,
}
}
@@ -312,8 +285,7 @@ impl<I: Interner> Clone for TyKind<I> {
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()),
- GeneratorWitnessMIR(d, s) => GeneratorWitnessMIR(d.clone(), s.clone()),
+ GeneratorWitness(d, s) => GeneratorWitness(d.clone(), s.clone()),
Never => Never,
Tuple(t) => Tuple(t.clone()),
Alias(k, p) => Alias(*k, p.clone()),
@@ -355,10 +327,7 @@ impl<I: Interner> PartialEq for TyKind<I> {
(Generator(a_d, a_s, a_m), Generator(b_d, b_s, b_m)) => {
a_d == b_d && a_s == b_s && a_m == b_m
}
- (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g,
- (GeneratorWitnessMIR(a_d, a_s), GeneratorWitnessMIR(b_d, b_s)) => {
- a_d == b_d && a_s == b_s
- }
+ (GeneratorWitness(a_d, a_s), GeneratorWitness(b_d, b_s)) => a_d == b_d && a_s == b_s,
(Tuple(a_t), Tuple(b_t)) => a_t == b_t,
(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,
@@ -415,10 +384,9 @@ impl<I: Interner> Ord for TyKind<I> {
(Generator(a_d, a_s, a_m), Generator(b_d, b_s, b_m)) => {
a_d.cmp(b_d).then_with(|| a_s.cmp(b_s).then_with(|| a_m.cmp(b_m)))
}
- (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g.cmp(b_g),
(
- GeneratorWitnessMIR(a_d, a_s),
- GeneratorWitnessMIR(b_d, b_s),
+ GeneratorWitness(a_d, a_s),
+ GeneratorWitness(b_d, b_s),
) => match Ord::cmp(a_d, b_d) {
Ordering::Equal => Ord::cmp(a_s, b_s),
cmp => cmp,
@@ -483,8 +451,7 @@ impl<I: Interner> hash::Hash for TyKind<I> {
s.hash(state);
m.hash(state)
}
- GeneratorWitness(g) => g.hash(state),
- GeneratorWitnessMIR(d, s) => {
+ GeneratorWitness(d, s) => {
d.hash(state);
s.hash(state);
}
@@ -517,7 +484,21 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
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, &this.wrap(s)),
+ Adt(d, s) => {
+ write!(f, "{d:?}")?;
+ let mut s = s.clone().into_iter();
+ let first = s.next();
+ match first {
+ Some(first) => write!(f, "<{:?}", first)?,
+ None => return Ok(()),
+ };
+
+ for arg in s {
+ write!(f, ", {:?}", arg)?;
+ }
+
+ write!(f, ">")
+ }
Foreign(d) => f.debug_tuple_field1_finish("Foreign", d),
Str => write!(f, "str"),
Array(t, c) => write!(f, "[{:?}; {:?}]", &this.wrap(t), &this.wrap(c)),
@@ -544,28 +525,23 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
},
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))
+ GeneratorWitness(d, s) => {
+ f.debug_tuple_field2_finish("GeneratorWitness", d, &this.wrap(s))
}
Never => write!(f, "!"),
Tuple(t) => {
- let mut iter = t.clone().into_iter();
-
write!(f, "(")?;
-
- match iter.next() {
- None => return write!(f, ")"),
- Some(ty) => write!(f, "{:?}", &this.wrap(ty))?,
- };
-
- match iter.next() {
- None => return write!(f, ",)"),
- Some(ty) => write!(f, "{:?})", &this.wrap(ty))?,
+ let mut count = 0;
+ for ty in t.clone() {
+ if count > 0 {
+ write!(f, ", ")?;
+ }
+ write!(f, "{:?}", &this.wrap(ty))?;
+ count += 1;
}
-
- for ty in iter {
- write!(f, ", {:?}", &this.wrap(ty))?;
+ // unary tuples need a trailing comma
+ if count == 1 {
+ write!(f, ",")?;
}
write!(f, ")")
}
@@ -668,10 +644,7 @@ where
args.encode(e);
m.encode(e);
}),
- GeneratorWitness(b) => e.emit_enum_variant(disc, |e| {
- b.encode(e);
- }),
- GeneratorWitnessMIR(def_id, args) => e.emit_enum_variant(disc, |e| {
+ GeneratorWitness(def_id, args) => e.emit_enum_variant(disc, |e| {
def_id.encode(e);
args.encode(e);
}),
@@ -748,7 +721,7 @@ where
14 => Dynamic(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)),
15 => Closure(Decodable::decode(d), Decodable::decode(d)),
16 => Generator(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)),
- 17 => GeneratorWitness(Decodable::decode(d)),
+ 17 => GeneratorWitness(Decodable::decode(d), Decodable::decode(d)),
18 => Never,
19 => Tuple(Decodable::decode(d)),
20 => Alias(Decodable::decode(d), Decodable::decode(d)),
@@ -757,12 +730,11 @@ where
23 => Placeholder(Decodable::decode(d)),
24 => Infer(Decodable::decode(d)),
25 => Error(Decodable::decode(d)),
- 26 => GeneratorWitnessMIR(Decodable::decode(d), Decodable::decode(d)),
_ => panic!(
"{}",
format!(
"invalid enum variant tag while decoding `{}`, expected 0..{}",
- "TyKind", 27,
+ "TyKind", 26,
)
),
}
@@ -856,10 +828,7 @@ where
args.hash_stable(__hcx, __hasher);
m.hash_stable(__hcx, __hasher);
}
- GeneratorWitness(b) => {
- b.hash_stable(__hcx, __hasher);
- }
- GeneratorWitnessMIR(def_id, args) => {
+ GeneratorWitness(def_id, args) => {
def_id.hash_stable(__hcx, __hasher);
args.hash_stable(__hcx, __hasher);
}
diff --git a/compiler/rustc_type_ir/src/visit.rs b/compiler/rustc_type_ir/src/visit.rs
index 878c7aec6..891a4dda2 100644
--- a/compiler/rustc_type_ir/src/visit.rs
+++ b/compiler/rustc_type_ir/src/visit.rs
@@ -8,7 +8,7 @@
//! visitation. These are the ones containing the most important type-related
//! information, such as `Ty`, `Predicate`, `Region`, and `Const`.
//!
-//! There are three groups of traits involved in each traversal.
+//! There are three traits involved in each traversal.
//! - `TypeVisitable`. This is implemented once for many types, including:
//! - Types of interest, for which the methods delegate to the visitor.
//! - All other types, including generic containers like `Vec` and `Option`.
@@ -17,7 +17,6 @@
//! interest, and defines the visiting "skeleton" for these types. (This
//! excludes `Region` because it is non-recursive, i.e. it never contains
//! other types of interest.)
-//!
//! - `TypeVisitor`. This is implemented for each visitor. This defines how
//! types of interest are visited.
//!
@@ -60,7 +59,7 @@ pub trait TypeVisitable<I: Interner>: fmt::Debug + Clone {
///
/// For types of interest (such as `Ty`), the implementation of this method
/// that calls a visitor method specifically for that type (such as
- /// `V::visit_ty`). This is where control transfers from `TypeFoldable` to
+ /// `V::visit_ty`). This is where control transfers from `TypeVisitable` to
/// `TypeVisitor`.
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy>;
}