Skip to content

Commit f7a2862

Browse files
committed
Auto merge of #634 - Areredify:book_typename_fix, r=jackh726
rewrite parts concerning typename, fix links fixes #631
2 parents fc7cb87 + bfb3f83 commit f7a2862

File tree

3 files changed

+66
-85
lines changed

3 files changed

+66
-85
lines changed

book/src/types/rust_types.md

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ describes why each variant exists.
3939

4040
### Application types
4141

42-
The `Apply` variant contains an `ApplicationTy`. These are kind of the
43-
"normal Rust types", like `Vec<u32>` or `f32`. They consist of a "type
44-
name" (in our examples, `Vec` and `f32` respecively) and zero or more
45-
generic arguments (respectively, `[u32]` and `[]`).
42+
Most of "normal rust types" like `Vec<u32>` or `(f32, Vec<isize>)` are represented with
43+
`TyKind` variants containing some type-specific info ("type name") and a substitution
44+
that is "applied" to that type. In this case, type names are `Vec` and "tuple of arity 2",
45+
and substitutions are `[u32]` and `[f32, Vec<isize>]`.
4646

4747
They are equal to other types (modulo aliases, see below) iff they
4848
have the same "type name" and the generic arguments are
@@ -61,17 +61,13 @@ placeholder. Similarly, in that same function, the associated type
6161
Like application types, placeholder *types* are only known to be
6262
equal.
6363

64-
However, we choose not to represent placeholder types as type names
65-
because they need to be created during type unification and other
66-
operations, and hence that would require treating `TypeName` less opaquely.
67-
68-
Moreover, when proving negative goals, e.g., `not { Implemented(T:
64+
When proving negative goals, e.g., `not { Implemented(T:
6965
Trait) }`, placeholders are treated quite differently from application
7066
types, since they do not (in fact) represent a known type. When
71-
solving negative goals, placeholderes are replaced with inference
67+
solving negative goals, placeholders are replaced with inference
7268
variables -- the idea is that this goal is only true if there is *no
7369
type* `T` that implements `Trait`. Therefore, if we can find no
74-
answeres for `exists<T> { Implemented(T: Trait) }`, then we know that
70+
answers for `exists<T> { Implemented(T: Trait) }`, then we know that
7571
the negation is true. (Note that this means that e.g. `forall<X> { X =
7672
i32 }` is false but so is `forall<X> { not { X = i32 } }`.)
7773

@@ -110,16 +106,16 @@ that is outside the scope of the chalk-ir crate.
110106

111107
### Function pointer types
112108

113-
The `Fn` variant wraps a `FnTy` struct and represents a `fn()` type
109+
The `Function` variant wraps a `FnPointer` struct and represents a `fn()` type
114110
(in other words, a function pointer). In some ways, fn types are like
115111
application types, but with one crucial difference: they also contain
116112
a `forall` binder that for lifetimes whose value is determined when
117113
the function is called. Consider e.g. a type like `fn(&u32)` or --
118114
more explicitly -- `for<'a> fn(&'a u32)`.
119115

120-
Two `Fn` types `A, B` are equal `A = B` if `A <: B` and `B <: A`
116+
Two `Function` types `A, B` are equal `A = B` if `A <: B` and `B <: A`
121117

122-
Two `Fn` types `A, B` are subtypes `A <: B` if
118+
Two `Function` types `A, B` are subtypes `A <: B` if
123119

124120
* After instantiating the lifetime parameters on `B` universally...
125121
* You can instantiate the lifetime parameters on `A` existentially...
@@ -143,7 +139,7 @@ them in the [aliases chapter](./rust_types/alias.md).
143139

144140
### Bound variables
145141

146-
The `BoundVariable` variant represents some variable that is bound in
142+
The `BoundVar` variant represents some variable that is bound in
147143
an outer term. For example, given a term like `forall<X> {
148144
Implemented(X: Trait) }`, the `X` is bound. Bound variables in chalk
149145
(like rustc) use de bruijin indices (See below).
@@ -166,44 +162,41 @@ other type without any effect, and so forth.
166162

167163
## Mapping to rustc types
168164

169-
The rustc [`TyKind`] enum has a lot more variants than chalk. This
165+
The rustc [`TyKind`] enum is almost equivalent to chalk's. This
170166
section describes how the rustc types can be mapped to chalk
171167
types. The intention is that, at least when transitioning, rustc would
172168
implement the `Interner` trait and would map from the [`TyKind`]
173169
enum to chalk's `TyKind` on the fly, when `data()` is invoked.
174170

175171
[`TyKind`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html
176172

177-
This section describes how each of rustc's variants can be mapped to
178-
Chalk variants.
179-
180173
| rustc type | chalk variant (and some notes) |
181174
| ------------- | ------------------ |
182-
| `Bool` | `Apply` |
183-
| `Char` | `Apply` |
184-
| `Int(_)` | `Apply` |
185-
| `Uint(_)` | `Apply` |
186-
| `Float(_)` | `Apply` |
187-
| `Adt(_, _)` | `Apply` |
188-
| `Foreign(_)` | `Apply` |
189-
| `Str` | `Apply` |
190-
| `Array(_, _)` | `Apply` |
191-
| `Slice(_)` | `Apply` |
192-
| `RawPtr(_)` | `Apply` |
193-
| `Ref(_, _, _)` | `Apply` |
194-
| `FnDef(_, _)` | `Apply` |
195-
| `FnPtr(_, _)` | `Fn` |
196-
| `Dynamic(_, _)` | `Dyn` |
197-
| `Closure(_, _)` | `Apply` |
198-
| `Generator(_, _)` | `Apply` |
199-
| `GeneratorWitness(_)` | `GeneratorWitness` |
200-
| `Never` | `Apply` |
201-
| `Tuple(_)` | `Apply` |
202-
| `Projection(_)` | `Alias` |
203-
| `UnnormalizedProjection(_)` | (see below) |
204-
| `Opaque(_, _)` | `Alias` |
205-
| `Param(_)` | XXX Placeholder? |
206-
| `Bound(_, _)` | `BoundVariable` |
207-
| `Placeholder(_)` | `Placeholder` |
208-
| `Infer(_)` | `InferenceVar` |
175+
| `Bool` | `Scalar` |
176+
| `Char` | `Scalar` |
177+
| `Int` | `Scalar` |
178+
| `Uint` | `Scalar` |
179+
| `Float` | `Scalar` |
180+
| `Adt` | `Adt` |
181+
| `Foreign` | `Foreign` |
182+
| `Str` | `Str` |
183+
| `Array` | `Array` |
184+
| `Slice` | `Slice` |
185+
| `RawPtr` | `Raw` |
186+
| `Ref` | `Ref` |
187+
| `FnDef` | `FnDef` |
188+
| `FnPtr` | `Function` |
189+
| `Dynamic` | `Dyn` |
190+
| `Closure` | `Closure` |
191+
| `Generator` | `Generator` |
192+
| `GeneratorWitness` | `GeneratorWitness` |
193+
| `Never` | `Never` |
194+
| `Tuple` | `Tuple` |
195+
| `Projection` | `Alias` |
196+
| `UnnormalizedProjection` | (see below) |
197+
| `Opaque` | `Alias` |
198+
| `Param` | XXX Placeholder? |
199+
| `Bound` | `BoundVar` |
200+
| `Placeholder` | `Placeholder` |
201+
| `Infer` | `InferenceVar` |
209202
| `Error` | `Error` |

book/src/types/rust_types/alias.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ definition, and depend a bit on the kind of alias. We describe that lowering in
5757
## Alias placeholders
5858

5959
For each kind of alias (except for explicit type aliases), there is also a
60-
corresponding *placeholder* variant in the [`TypeName`] enum. In those cases
60+
corresponding *placeholder* variant in the [`TyKind`] enum. In those cases
6161
where we cannot normalize the alias to something specific, it can be equated to
6262
the placeholder type (see e.g. [`AssociatedType`], which is the placeholder
6363
variant for associated type projections). Note that placeholders are
6464
*application types* -- unlike an alias, a placeholder is only known to be equal
6565
with itself, just like an application type.
6666

67-
[`TypeName`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TypeName.html
68-
[`AssociatedType`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TypeName.html#variant.AssociatedType
67+
[`TyKind`]: https://rust-lang.github.io/chalk/chalk_ir/enum.TyKind.html
68+
[`AssociatedType`]: https://rust-lang.github.io/chalk/chalk_ir/enum.TyKind.html#variant.AssociatedType
6969

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
# Application types
22

3-
An [`ApplicationTy`] is kind of a "normal Rust type", like
4-
`Vec<u32>` or `f32`. Such types are only "equal" to themselves (modulo
5-
aliases, see below), and they may take type arguments. Note that we
6-
group together *both* user-defined structs/enums/unions (like `Vec`)
3+
[`TyKind`] variants that consist of some type-specific info ("type name")
4+
and a substitution are usually referred to as application types.
5+
These include most of the "normal Rust types", such as `Vec` and `(f32, u32)`.
6+
Such types are only "equal" to themselves (modulo aliases, see below).
7+
Scalar types (and some others) also fall into this category, despite having no
8+
substitutions: we treat them as having zero-length substitutions.
9+
Note that we group together *both* user-defined structs/enums/unions (like `Vec`)
710
as well as built-in types like `f32`, which effectively behave the
811
same.
912

10-
[`ApplicationTy`]: http://rust-lang.github.io/chalk/chalk_ir/struct.ApplicationTy.html
13+
We used to have application types in chalk as a separate notion in the codebase,
14+
but have since moved away from that; nevertheless, the term is still useful in discussions.
1115

12-
An [`ApplicationTy`] contains two fields:
16+
[`TyKind`]: https://rust-lang.github.io/chalk/chalk_ir/enum.TyKind.html
1317

14-
* a "type name" (of type [`TypeName`]); and,
15-
* a list of generic arguments (of type [`Substitution`]).
16-
17-
The [`TypeName`] itself is largely opaque to chalk. We discuss it in
18-
more detail elsewhere. The point is that it represents, semantically,
19-
either the name of some user-defined type (like `Vec`) or builtin-types
20-
like `i32`. It may also represent types like "tuple of arity 2" (`(_,
21-
_)`) or "fixed-length array" `[_; _]`. Note that the precise set of
22-
these built-in types is defined by the `Interner` and is unknown to
23-
chalk-ir.
24-
25-
## [`TypeName`] variants
18+
## Notable application types
2619

2720
### Generator
2821

@@ -36,10 +29,10 @@ to a generator:
3629
used when the generator is running.
3730
* Generator witness - see the `Generator Witness` section below.
3831

39-
Of these types, only upvars and resume/yield/return are stored directly in
40-
`TypeName::Generator`. The generator witness is implicitly associated with the generator
41-
by virtue of sharing the same `GeneratorId`. It is only used when determining auto trait
42-
impls, where it is considered a 'constituent type'.
32+
Of these types, only upvars and resume/yield/return are stored directly in `GeneratorDatum`
33+
(which is acessed via `RustIrDatabase`). The generator witness is implicitly associated with
34+
the generator by virtue of sharing the same `GeneratorId`. It is only used when determining
35+
auto trait impls, where it is considered a 'constituent type'.
4336

4437
### Generator witness types
4538

@@ -55,17 +48,12 @@ Unlike other types, witnesses include bound, existential
5548
lifetimes, which refer to lifetimes within the suspended stack frame.
5649
You can think of it as a type like `exists<'a> { (T...) }`.
5750

58-
Witnesses are very similar to an `Apply` type, but it has a binder for
59-
the erased lifetime(s), which must be handled specifically in equating
60-
and so forth. In many ways, witnesses are also quite similar to `Fn`
61-
types, and it is not out of the question that these two could be
62-
unified; however, they are quite distinct semantically and so that
63-
would be an annoying mismatch in other parts of the system.
64-
Witnesses are also similar to a `Dyn` type, in that they represent an
65-
existential type, but in contrast to `Dyn`, what we know here is
66-
not a *predicate* but rather some upper bound on the set of types
67-
contained within.
68-
69-
70-
[`TypeName`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TypeName.html
71-
[`Substitution`]: http://rust-lang.github.io/chalk/chalk_ir/struct.Substitution.html
51+
Witnesses have a binder for the erased lifetime(s), which must be
52+
handled specifically in equating and so forth. In many ways,
53+
witnesses are also quite similar to `Function` types, and it is not
54+
out of the question that these two could be unified; however, they
55+
are quite distinct semantically and so that would be an annoying
56+
mismatch in other parts of the system. Witnesses are also similar
57+
to a `Dyn` type, in that they represent an existential type, but
58+
in contrast to `Dyn`, what we know here is not a *predicate* but
59+
rather some upper bound on the set of types contained within.

0 commit comments

Comments
 (0)