|
1 | | -NB: This crate is part of the Rust compiler. For an overview of the |
2 | | -compiler as a whole, see |
3 | | -[the README.md file found in `librustc`](../librustc/README.md). |
| 1 | +For high-level intro to how type checking works in rustc, see the |
| 2 | +[type checking] chapter of the [rustc guide]. |
4 | 3 |
|
5 | | -The `rustc_typeck` crate contains the source for "type collection" and |
6 | | -"type checking", as well as a few other bits of related functionality. |
7 | | -(It draws heavily on the [type inferencing][infer] and |
8 | | -[trait solving][traits] code found in librustc.) |
9 | | - |
10 | | -[infer]: ../librustc/infer/README.md |
11 | | -[traits]: ../librustc/traits/README.md |
12 | | - |
13 | | -## Type collection |
14 | | - |
15 | | -Type "collection" is the process of converting the types found in the |
16 | | -HIR (`hir::Ty`), which represent the syntactic things that the user |
17 | | -wrote, into the **internal representation** used by the compiler |
18 | | -(`Ty<'tcx>`) -- we also do similar conversions for where-clauses and |
19 | | -other bits of the function signature. |
20 | | - |
21 | | -To try and get a sense for the difference, consider this function: |
22 | | - |
23 | | -```rust |
24 | | -struct Foo { } |
25 | | -fn foo(x: Foo, y: self::Foo) { .. } |
26 | | -// ^^^ ^^^^^^^^^ |
27 | | -``` |
28 | | - |
29 | | -Those two parameters `x` and `y` each have the same type: but they |
30 | | -will have distinct `hir::Ty` nodes. Those nodes will have different |
31 | | -spans, and of course they encode the path somewhat differently. But |
32 | | -once they are "collected" into `Ty<'tcx>` nodes, they will be |
33 | | -represented by the exact same internal type. |
34 | | - |
35 | | -Collection is defined as a bundle of queries (e.g., `type_of`) for |
36 | | -computing information about the various functions, traits, and other |
37 | | -items in the crate being compiled. Note that each of these queries is |
38 | | -concerned with *interprocedural* things -- for example, for a function |
39 | | -definition, collection will figure out the type and signature of the |
40 | | -function, but it will not visit the *body* of the function in any way, |
41 | | -nor examine type annotations on local variables (that's the job of |
42 | | -type *checking*). |
43 | | - |
44 | | -For more details, see the `collect` module. |
45 | | - |
46 | | -## Type checking |
47 | | - |
48 | | -TODO |
| 4 | +[type checking]: https://rust-lang-nursery.github.io/rustc-guide/type-checking.html |
| 5 | +[rustc guide]: https://rust-lang-nursery.github.io/rustc-guide/ |
0 commit comments