Skip to content

Commit d147c52

Browse files
committed
Remove TyS
1 parent d3564ba commit d147c52

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/memory.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ types for equality: for each interned type `X`, we implemented [`PartialEq for
1616
X`][peqimpl], so we can just compare pointers. The [`CtxtInterners`] type
1717
contains a bunch of maps of interned types and the arena itself.
1818

19-
[peqimpl]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html#implementations
19+
[peqimpl]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#implementations
2020
[`CtxtInterners`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.CtxtInterners.html#structfield.arena
2121

22-
### Example: `ty::TyS`
22+
### Example: `ty::TyKind`
2323

24-
Taking the example of [`ty::TyS`] which represents a type in the compiler (you
24+
Taking the example of [`ty::TyKind`] which represents a type in the compiler (you
2525
can read more [here](./ty.md)). Each time we want to construct a type, the
2626
compiler doesn’t naively allocate from the buffer. Instead, we check if that
2727
type was already constructed. If it was, we just get the same pointer we had
2828
before, otherwise we make a fresh pointer. With this schema if we want to know
2929
if two types are the same, all we need to do is compare the pointers which is
30-
efficient. `TyS` is carefully setup so you never construct them on the stack.
30+
efficient. `TyKind` should never be constructed on the stack, and it would be unusable
31+
if done so.
3132
You always allocate them from this arena and you always intern them so they are
3233
unique.
3334

@@ -52,7 +53,7 @@ allocate, and which are found in this module. Here are a few examples:
5253
[`TraitRef`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TraitRef.html
5354
[`Predicate`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Predicate.html
5455

55-
[`ty::TyS`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html
56+
[`ty::TyKind`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/sty/type.TyKind.html
5657

5758
## The tcx and how it uses lifetimes
5859

src/ty.md

+8-11
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,20 @@ or `fn(i32) -> i32` (with type aliases fully expanded).
119119

120120
## `ty::Ty` implementation
121121

122-
[`rustc_middle::ty::Ty`][ty_ty] is actually a type alias to [`&TyS`][tys].
123-
This type, which is short for "Type Structure", is where the main functionality is located.
124-
You can ignore `TyS` struct in general; you will basically never access it explicitly.
125-
We always pass it by reference using the `Ty` alias.
126-
The only exception is to define inherent methods on types. In particular, `TyS` has a [`kind`][kind]
127-
field of type [`TyKind`][tykind], which represents the key type information. `TyKind` is a big enum
122+
[`rustc_middle::ty::Ty`][ty_ty] is actually a wrapper around
123+
[`Interned<WithCachedTypeInfo<TyKind>>`][tykind].
124+
You can ignore `Interned` in general; you will basically never access it explicitly.
125+
We always hide them within `Ty` and skip over it via `Deref` impls or methods.
126+
`TyKind` is a big enum
128127
with variants to represent many different Rust types
129128
(e.g. primitives, references, abstract data types, generics, lifetimes, etc).
130-
`TyS` also has 2 more fields, `flags` and `outer_exclusive_binder`. They
129+
`WithCachedTypeInfo` has a few cached values like `flags` and `outer_exclusive_binder`. They
131130
are convenient hacks for efficiency and summarize information about the type that we may want to
132-
know, but they don’t come into the picture as much here. Finally, `ty::TyS`s
133-
are [interned](./memory.md), so that the `ty::Ty` can be a thin pointer-like
131+
know, but they don’t come into the picture as much here. Finally, [`Interned`](./memory.md) allows
132+
the `ty::Ty` to be a thin pointer-like
134133
type. This allows us to do cheap comparisons for equality, along with the other
135134
benefits of interning.
136135

137-
[tys]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html
138-
[kind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html#structfield.kind
139136
[tykind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html
140137

141138
## Allocating and working with types

0 commit comments

Comments
 (0)