summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_type_ir/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_type_ir/src/lib.rs')
-rw-r--r--compiler/rustc_type_ir/src/lib.rs142
1 files changed, 75 insertions, 67 deletions
diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs
index 44004cb0b..5a991e03d 100644
--- a/compiler/rustc_type_ir/src/lib.rs
+++ b/compiler/rustc_type_ir/src/lib.rs
@@ -1,6 +1,9 @@
+#![feature(associated_type_defaults)]
#![feature(fmt_helpers_for_derive)]
#![feature(min_specialization)]
+#![feature(never_type)]
#![feature(rustc_attrs)]
+#![feature(unwrap_infallible)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
@@ -18,8 +21,14 @@ use std::hash::Hash;
use std::mem::discriminant;
pub mod codec;
+pub mod fold;
pub mod sty;
pub mod ty_info;
+pub mod visit;
+
+#[macro_use]
+mod macros;
+mod structural_impls;
pub use codec::*;
pub use sty::*;
@@ -28,68 +37,69 @@ pub use ty_info::*;
/// Needed so we can use #[derive(HashStable_Generic)]
pub trait HashStableContext {}
-pub trait Interner {
- type AdtDef: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type SubstsRef: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type DefId: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type Ty: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type Const: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type Region: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type TypeAndMut: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type Mutability: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type Movability: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type PolyFnSig: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- 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 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;
- type InferTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type ErrorGuaranteed: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
+pub trait Interner: Sized {
+ type AdtDef: Clone + Debug + Hash + Ord;
+ type SubstsRef: Clone + Debug + 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 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 ListTy: Clone + Debug + Hash + Ord;
+ type AliasTy: Clone + Debug + Hash + Ord;
+ type ParamTy: Clone + Debug + Hash + Ord;
+ type BoundTy: Clone + Debug + Hash + Ord;
+ type PlaceholderType: Clone + Debug + Hash + Ord;
+ type InferTy: Clone + Debug + Hash + Ord;
+ type ErrorGuaranteed: Clone + Debug + Hash + Ord;
type PredicateKind: Clone + Debug + Hash + PartialEq + Eq;
- type AllocId: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
+ type AllocId: Clone + Debug + Hash + Ord;
- type EarlyBoundRegion: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type BoundRegion: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type FreeRegion: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type RegionVid: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
- type PlaceholderRegion: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + 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 PlaceholderRegion: Clone + Debug + Hash + Ord;
}
-pub trait InternAs<T: ?Sized, R> {
+/// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter`
+/// that produces `T` items. You could combine them with
+/// `f(&iter.collect::<Vec<_>>())`, but this requires allocating memory for the
+/// `Vec`.
+///
+/// This trait allows for faster implementations, intended for cases where the
+/// number of items produced by the iterator is small. There is a blanket impl
+/// for `T` items, but there is also a fallible impl for `Result<T, E>` items.
+pub trait CollectAndApply<T, R>: Sized {
type Output;
- fn intern_with<F>(self, f: F) -> Self::Output
+
+ /// Produce a result of type `Self::Output` from `iter`. The result will
+ /// typically be produced by applying `f` on the elements produced by
+ /// `iter`, though this may not happen in some impls, e.g. if an error
+ /// occured during iteration.
+ fn collect_and_apply<I, F>(iter: I, f: F) -> Self::Output
where
+ I: Iterator<Item = Self>,
F: FnOnce(&[T]) -> R;
}
-impl<I, T, R, E> InternAs<T, R> for I
-where
- E: InternIteratorElement<T, R>,
- I: Iterator<Item = E>,
-{
- type Output = E::Output;
- fn intern_with<F>(self, f: F) -> Self::Output
+/// The blanket impl that always collects all elements and applies `f`.
+impl<T, R> CollectAndApply<T, R> for T {
+ type Output = R;
+
+ /// Equivalent to `f(&iter.collect::<Vec<_>>())`.
+ fn collect_and_apply<I, F>(mut iter: I, f: F) -> R
where
+ I: Iterator<Item = T>,
F: FnOnce(&[T]) -> R,
{
- E::intern_with(self, f)
- }
-}
-
-pub trait InternIteratorElement<T, R>: Sized {
- type Output;
- fn intern_with<I: Iterator<Item = Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output;
-}
-
-impl<T, R> InternIteratorElement<T, R> for T {
- type Output = R;
- fn intern_with<I: Iterator<Item = Self>, F: FnOnce(&[T]) -> R>(
- mut iter: I,
- f: F,
- ) -> Self::Output {
// This code is hot enough that it's worth specializing for the most
// common length lists, to avoid the overhead of `SmallVec` creation.
// Lengths 0, 1, and 2 typically account for ~95% of cases. If
@@ -116,23 +126,17 @@ impl<T, R> InternIteratorElement<T, R> for T {
}
}
-impl<'a, T, R> InternIteratorElement<T, R> for &'a T
-where
- T: Clone + 'a,
-{
- type Output = R;
- fn intern_with<I: Iterator<Item = Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output {
- // This code isn't hot.
- f(&iter.cloned().collect::<SmallVec<[_; 8]>>())
- }
-}
-
-impl<T, R, E> InternIteratorElement<T, R> for Result<T, E> {
+/// A fallible impl that will fail, without calling `f`, if there are any
+/// errors during collection.
+impl<T, R, E> CollectAndApply<T, R> for Result<T, E> {
type Output = Result<R, E>;
- fn intern_with<I: Iterator<Item = Self>, F: FnOnce(&[T]) -> R>(
- mut iter: I,
- f: F,
- ) -> Self::Output {
+
+ /// Equivalent to `Ok(f(&iter.collect::<Result<Vec<_>>>()?))`.
+ fn collect_and_apply<I, F>(mut iter: I, f: F) -> Result<R, E>
+ where
+ I: Iterator<Item = Result<T, E>>,
+ F: FnOnce(&[T]) -> R,
+ {
// This code is hot enough that it's worth specializing for the most
// common length lists, to avoid the overhead of `SmallVec` creation.
// Lengths 0, 1, and 2 typically account for ~95% of cases. If
@@ -220,7 +224,8 @@ bitflags! {
// which is different from how types/const are freshened.
| TypeFlags::HAS_TY_FRESH.bits
| TypeFlags::HAS_CT_FRESH.bits
- | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits;
+ | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits
+ | TypeFlags::HAS_RE_ERASED.bits;
/// Does this have `Projection`?
const HAS_TY_PROJECTION = 1 << 10;
@@ -265,6 +270,9 @@ bitflags! {
/// Does this value have `InferConst::Fresh`?
const HAS_CT_FRESH = 1 << 21;
+
+ /// Does this have `Generator` or `GeneratorWitness`?
+ const HAS_TY_GENERATOR = 1 << 22;
}
}