|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 |
| -/* |
12 |
| -
|
13 |
| -# Collect phase |
14 |
| -
|
15 |
| -The collect phase of type check has the job of visiting all items, |
16 |
| -determining their type, and writing that type into the `tcx.types` |
17 |
| -table. Despite its name, this table does not really operate as a |
18 |
| -*cache*, at least not for the types of items defined within the |
19 |
| -current crate: we assume that after the collect phase, the types of |
20 |
| -all local items will be present in the table. |
21 |
| -
|
22 |
| -Unlike most of the types that are present in Rust, the types computed |
23 |
| -for each item are in fact type schemes. This means that they are |
24 |
| -generic types that may have type parameters. TypeSchemes are |
25 |
| -represented by a pair of `Generics` and `Ty`. Type |
26 |
| -parameters themselves are represented as `ty_param()` instances. |
27 |
| -
|
28 |
| -The phasing of type conversion is somewhat complicated. There is no |
29 |
| -clear set of phases we can enforce (e.g., converting traits first, |
30 |
| -then types, or something like that) because the user can introduce |
31 |
| -arbitrary interdependencies. So instead we generally convert things |
32 |
| -lazilly and on demand, and include logic that checks for cycles. |
33 |
| -Demand is driven by calls to `AstConv::get_item_type_scheme` or |
34 |
| -`AstConv::trait_def`. |
35 |
| -
|
36 |
| -Currently, we "convert" types and traits in two phases (note that |
37 |
| -conversion only affects the types of items / enum variants / methods; |
38 |
| -it does not e.g. compute the types of individual expressions): |
39 |
| -
|
40 |
| -0. Intrinsics |
41 |
| -1. Trait/Type definitions |
42 |
| -
|
43 |
| -Conversion itself is done by simply walking each of the items in turn |
44 |
| -and invoking an appropriate function (e.g., `trait_def_of_item` or |
45 |
| -`convert_item`). However, it is possible that while converting an |
46 |
| -item, we may need to compute the *type scheme* or *trait definition* |
47 |
| -for other items. |
48 |
| -
|
49 |
| -There are some shortcomings in this design: |
50 |
| -- Because the item generics include defaults, cycles through type |
51 |
| - parameter defaults are illegal even if those defaults are never |
52 |
| - employed. This is not necessarily a bug. |
53 |
| -
|
54 |
| -*/ |
| 11 | +//! "Collection" is the process of determining the type and other external |
| 12 | +//! details of each item in Rust. Collection is specifically concerned |
| 13 | +//! with *interprocedural* things -- for example, for a function |
| 14 | +//! definition, collection will figure out the type and signature of the |
| 15 | +//! function, but it will not visit the *body* of the function in any way, |
| 16 | +//! nor examine type annotations on local variables (that's the job of |
| 17 | +//! type *checking*). |
| 18 | +//! |
| 19 | +//! Collecting is ultimately defined by a bundle of queries that |
| 20 | +//! inquire after various facts about the items in the crate (e.g., |
| 21 | +//! `type_of`, `generics_of`, `predicates_of`, etc). See the `provide` function |
| 22 | +//! for the full set. |
| 23 | +//! |
| 24 | +//! At present, however, we do run collection across all items in the |
| 25 | +//! crate as a kind of pass. This should eventually be factored away. |
55 | 26 |
|
56 | 27 | use astconv::{AstConv, Bounds};
|
57 | 28 | use lint;
|
|
0 commit comments