Remove TyS

This commit is contained in:
Oli Scherer 2022-12-06 15:19:49 +00:00 committed by Oli Scherer
parent 983e101473
commit 3ea1f2de88
2 changed files with 14 additions and 16 deletions

View File

@ -16,18 +16,19 @@ types for equality: for each interned type `X`, we implemented [`PartialEq for
X`][peqimpl], so we can just compare pointers. The [`CtxtInterners`] type X`][peqimpl], so we can just compare pointers. The [`CtxtInterners`] type
contains a bunch of maps of interned types and the arena itself. contains a bunch of maps of interned types and the arena itself.
[peqimpl]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html#implementations [peqimpl]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#implementations
[`CtxtInterners`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.CtxtInterners.html#structfield.arena [`CtxtInterners`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.CtxtInterners.html#structfield.arena
### Example: `ty::TyS` ### Example: `ty::TyKind`
Taking the example of [`ty::TyS`] which represents a type in the compiler (you Taking the example of [`ty::TyKind`] which represents a type in the compiler (you
can read more [here](./ty.md)). Each time we want to construct a type, the can read more [here](./ty.md)). Each time we want to construct a type, the
compiler doesnt naively allocate from the buffer. Instead, we check if that compiler doesnt naively allocate from the buffer. Instead, we check if that
type was already constructed. If it was, we just get the same pointer we had type was already constructed. If it was, we just get the same pointer we had
before, otherwise we make a fresh pointer. With this schema if we want to know before, otherwise we make a fresh pointer. With this schema if we want to know
if two types are the same, all we need to do is compare the pointers which is if two types are the same, all we need to do is compare the pointers which is
efficient. `TyS` is carefully setup so you never construct them on the stack. efficient. `TyKind` should never be constructed on the stack, and it would be unusable
if done so.
You always allocate them from this arena and you always intern them so they are You always allocate them from this arena and you always intern them so they are
unique. unique.
@ -52,7 +53,7 @@ allocate, and which are found in this module. Here are a few examples:
[`TraitRef`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TraitRef.html [`TraitRef`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TraitRef.html
[`Predicate`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Predicate.html [`Predicate`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Predicate.html
[`ty::TyS`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html [`ty::TyKind`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/sty/type.TyKind.html
## The tcx and how it uses lifetimes ## The tcx and how it uses lifetimes

View File

@ -119,23 +119,20 @@ or `fn(i32) -> i32` (with type aliases fully expanded).
## `ty::Ty` implementation ## `ty::Ty` implementation
[`rustc_middle::ty::Ty`][ty_ty] is actually a type alias to [`&TyS`][tys]. [`rustc_middle::ty::Ty`][ty_ty] is actually a wrapper around
This type, which is short for "Type Structure", is where the main functionality is located. [`Interned<WithCachedTypeInfo<TyKind>>`][tykind].
You can ignore `TyS` struct in general; you will basically never access it explicitly. You can ignore `Interned` in general; you will basically never access it explicitly.
We always pass it by reference using the `Ty` alias. We always hide them within `Ty` and skip over it via `Deref` impls or methods.
The only exception is to define inherent methods on types. In particular, `TyS` has a [`kind`][kind] `TyKind` is a big enum
field of type [`TyKind`][tykind], which represents the key type information. `TyKind` is a big enum
with variants to represent many different Rust types with variants to represent many different Rust types
(e.g. primitives, references, abstract data types, generics, lifetimes, etc). (e.g. primitives, references, abstract data types, generics, lifetimes, etc).
`TyS` also has 2 more fields, `flags` and `outer_exclusive_binder`. They `WithCachedTypeInfo` has a few cached values like `flags` and `outer_exclusive_binder`. They
are convenient hacks for efficiency and summarize information about the type that we may want to are convenient hacks for efficiency and summarize information about the type that we may want to
know, but they dont come into the picture as much here. Finally, `ty::TyS`s know, but they dont come into the picture as much here. Finally, [`Interned`](./memory.md) allows
are [interned](./memory.md), so that the `ty::Ty` can be a thin pointer-like the `ty::Ty` to be a thin pointer-like
type. This allows us to do cheap comparisons for equality, along with the other type. This allows us to do cheap comparisons for equality, along with the other
benefits of interning. benefits of interning.
[tys]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html
[kind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html#structfield.kind
[tykind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html [tykind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html
## Allocating and working with types ## Allocating and working with types