|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 |
| -//! Translation Item Collection |
| 11 | +//! Mono Item Collection |
12 | 12 | //! ===========================
|
13 | 13 | //!
|
14 | 14 | //! This module is responsible for discovering all items that will contribute to
|
|
22 | 22 | //! in crate X might produce monomorphizations that are compiled into crate Y.
|
23 | 23 | //! We also have to collect these here.
|
24 | 24 | //!
|
25 |
| -//! The following kinds of "translation items" are handled here: |
| 25 | +//! The following kinds of "mono items" are handled here: |
26 | 26 | //!
|
27 | 27 | //! - Functions
|
28 | 28 | //! - Methods
|
|
43 | 43 | //! -----------------
|
44 | 44 | //! Let's define some terms first:
|
45 | 45 | //!
|
46 |
| -//! - A "translation item" is something that results in a function or global in |
47 |
| -//! the LLVM IR of a codegen unit. Translation items do not stand on their |
48 |
| -//! own, they can reference other translation items. For example, if function |
49 |
| -//! `foo()` calls function `bar()` then the translation item for `foo()` |
50 |
| -//! references the translation item for function `bar()`. In general, the |
51 |
| -//! definition for translation item A referencing a translation item B is that |
| 46 | +//! - A "mono item" is something that results in a function or global in |
| 47 | +//! the LLVM IR of a codegen unit. Mono items do not stand on their |
| 48 | +//! own, they can reference other mono items. For example, if function |
| 49 | +//! `foo()` calls function `bar()` then the mono item for `foo()` |
| 50 | +//! references the mono item for function `bar()`. In general, the |
| 51 | +//! definition for mono item A referencing a mono item B is that |
52 | 52 | //! the LLVM artifact produced for A references the LLVM artifact produced
|
53 | 53 | //! for B.
|
54 | 54 | //!
|
55 |
| -//! - Translation items and the references between them form a directed graph, |
56 |
| -//! where the translation items are the nodes and references form the edges. |
57 |
| -//! Let's call this graph the "translation item graph". |
| 55 | +//! - Mono items and the references between them form a directed graph, |
| 56 | +//! where the mono items are the nodes and references form the edges. |
| 57 | +//! Let's call this graph the "mono item graph". |
58 | 58 | //!
|
59 |
| -//! - The translation item graph for a program contains all translation items |
| 59 | +//! - The mono item graph for a program contains all mono items |
60 | 60 | //! that are needed in order to produce the complete LLVM IR of the program.
|
61 | 61 | //!
|
62 | 62 | //! The purpose of the algorithm implemented in this module is to build the
|
63 |
| -//! translation item graph for the current crate. It runs in two phases: |
| 63 | +//! mono item graph for the current crate. It runs in two phases: |
64 | 64 | //!
|
65 | 65 | //! 1. Discover the roots of the graph by traversing the HIR of the crate.
|
66 | 66 | //! 2. Starting from the roots, find neighboring nodes by inspecting the MIR
|
|
69 | 69 | //!
|
70 | 70 | //! ### Discovering roots
|
71 | 71 | //!
|
72 |
| -//! The roots of the translation item graph correspond to the non-generic |
| 72 | +//! The roots of the mono item graph correspond to the non-generic |
73 | 73 | //! syntactic items in the source code. We find them by walking the HIR of the
|
74 | 74 | //! crate, and whenever we hit upon a function, method, or static item, we
|
75 |
| -//! create a translation item consisting of the items DefId and, since we only |
| 75 | +//! create a mono item consisting of the items DefId and, since we only |
76 | 76 | //! consider non-generic items, an empty type-substitution set.
|
77 | 77 | //!
|
78 | 78 | //! ### Finding neighbor nodes
|
79 |
| -//! Given a translation item node, we can discover neighbors by inspecting its |
| 79 | +//! Given a mono item node, we can discover neighbors by inspecting its |
80 | 80 | //! MIR. We walk the MIR and any time we hit upon something that signifies a
|
81 |
| -//! reference to another translation item, we have found a neighbor. Since the |
82 |
| -//! translation item we are currently at is always monomorphic, we also know the |
| 81 | +//! reference to another mono item, we have found a neighbor. Since the |
| 82 | +//! mono item we are currently at is always monomorphic, we also know the |
83 | 83 | //! concrete type arguments of its neighbors, and so all neighbors again will be
|
84 | 84 | //! monomorphic. The specific forms a reference to a neighboring node can take
|
85 | 85 | //! in MIR are quite diverse. Here is an overview:
|
86 | 86 | //!
|
87 | 87 | //! #### Calling Functions/Methods
|
88 |
| -//! The most obvious form of one translation item referencing another is a |
| 88 | +//! The most obvious form of one mono item referencing another is a |
89 | 89 | //! function or method call (represented by a CALL terminator in MIR). But
|
90 | 90 | //! calls are not the only thing that might introduce a reference between two
|
91 |
| -//! function translation items, and as we will see below, they are just a |
| 91 | +//! function mono items, and as we will see below, they are just a |
92 | 92 | //! specialized of the form described next, and consequently will don't get any
|
93 | 93 | //! special treatment in the algorithm.
|
94 | 94 | //!
|
|
112 | 112 | //! }
|
113 | 113 | //! ```
|
114 | 114 | //! The MIR of none of these functions will contain an explicit call to
|
115 |
| -//! `print_val::<i32>`. Nonetheless, in order to translate this program, we need |
| 115 | +//! `print_val::<i32>`. Nonetheless, in order to mono this program, we need |
116 | 116 | //! an instance of this function. Thus, whenever we encounter a function or
|
117 | 117 | //! method in operand position, we treat it as a neighbor of the current
|
118 |
| -//! translation item. Calls are just a special case of that. |
| 118 | +//! mono item. Calls are just a special case of that. |
119 | 119 | //!
|
120 | 120 | //! #### Closures
|
121 | 121 | //! In a way, closures are a simple case. Since every closure object needs to be
|
|
124 | 124 | //! true for closures inlined from other crates.
|
125 | 125 | //!
|
126 | 126 | //! #### Drop glue
|
127 |
| -//! Drop glue translation items are introduced by MIR drop-statements. The |
128 |
| -//! generated translation item will again have drop-glue item neighbors if the |
| 127 | +//! Drop glue mono items are introduced by MIR drop-statements. The |
| 128 | +//! generated mono item will again have drop-glue item neighbors if the |
129 | 129 | //! type to be dropped contains nested values that also need to be dropped. It
|
130 | 130 | //! might also have a function item neighbor for the explicit `Drop::drop`
|
131 | 131 | //! implementation of its type.
|
|
150 | 150 | //! defined in the source code of that crate. It will also contain monomorphic
|
151 | 151 | //! instantiations of any extern generic functions and of functions marked with
|
152 | 152 | //! #[inline].
|
153 |
| -//! The collection algorithm handles this more or less transparently. If it is |
154 |
| -//! about to create a translation item for something with an external `DefId`, |
| 153 | +//! The collection algorithm handles this more or less mono. If it is |
| 154 | +//! about to create a mono item for something with an external `DefId`, |
155 | 155 | //! it will take a look if the MIR for that item is available, and if so just
|
156 | 156 | //! proceed normally. If the MIR is not available, it assumes that the item is
|
157 | 157 | //! just linked to and no node is created; which is exactly what we want, since
|
158 | 158 | //! no machine code should be generated in the current crate for such an item.
|
159 | 159 | //!
|
160 | 160 | //! Eager and Lazy Collection Mode
|
161 | 161 | //! ------------------------------
|
162 |
| -//! Translation item collection can be performed in one of two modes: |
| 162 | +//! Mono item collection can be performed in one of two modes: |
163 | 163 | //!
|
164 | 164 | //! - Lazy mode means that items will only be instantiated when actually
|
165 | 165 | //! referenced. The goal is to produce the least amount of machine code
|
166 | 166 | //! possible.
|
167 | 167 | //!
|
168 | 168 | //! - Eager mode is meant to be used in conjunction with incremental compilation
|
169 |
| -//! where a stable set of translation items is more important than a minimal |
| 169 | +//! where a stable set of mono items is more important than a minimal |
170 | 170 | //! one. Thus, eager mode will instantiate drop-glue for every drop-able type
|
171 | 171 | //! in the crate, even of no drop call for that type exists (yet). It will
|
172 | 172 | //! also instantiate default implementations of trait methods, something that
|
|
183 | 183 | //! statics we cannot inspect these properly.
|
184 | 184 | //!
|
185 | 185 | //! ### Const Fns
|
186 |
| -//! Ideally, no translation item should be generated for const fns unless there |
| 186 | +//! Ideally, no mono item should be generated for const fns unless there |
187 | 187 | //! is a call to them that cannot be evaluated at compile time. At the moment
|
188 |
| -//! this is not implemented however: a translation item will be produced |
| 188 | +//! this is not implemented however: a mono item will be produced |
189 | 189 | //! regardless of whether it is actually needed or not.
|
190 | 190 |
|
191 | 191 | use rustc::hir;
|
@@ -218,18 +218,18 @@ pub enum MonoItemCollectionMode {
|
218 | 218 | Lazy
|
219 | 219 | }
|
220 | 220 |
|
221 |
| -/// Maps every translation item to all translation items it references in its |
| 221 | +/// Maps every mono item to all mono items it references in its |
222 | 222 | /// body.
|
223 | 223 | pub struct InliningMap<'tcx> {
|
224 |
| - // Maps a source translation item to the range of translation items |
| 224 | + // Maps a source mono item to the range of mono items |
225 | 225 | // accessed by it.
|
226 | 226 | // The two numbers in the tuple are the start (inclusive) and
|
227 | 227 | // end index (exclusive) within the `targets` vecs.
|
228 | 228 | index: FxHashMap<MonoItem<'tcx>, (usize, usize)>,
|
229 | 229 | targets: Vec<MonoItem<'tcx>>,
|
230 | 230 |
|
231 |
| - // Contains one bit per translation item in the `targets` field. That bit |
232 |
| - // is true if that translation item needs to be inlined into every CGU. |
| 231 | + // Contains one bit per mono item in the `targets` field. That bit |
| 232 | + // is true if that mono item needs to be inlined into every CGU. |
233 | 233 | inlines: BitVector,
|
234 | 234 | }
|
235 | 235 |
|
@@ -300,7 +300,7 @@ pub fn collect_crate_mono_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
300 | 300 | InliningMap<'tcx>) {
|
301 | 301 | let roots = collect_roots(tcx, mode);
|
302 | 302 |
|
303 |
| - debug!("Building translation item graph, beginning at roots"); |
| 303 | + debug!("Building mono item graph, beginning at roots"); |
304 | 304 | let mut visited = FxHashSet();
|
305 | 305 | let mut recursion_depths = DefIdMap();
|
306 | 306 | let mut inlining_map = InliningMap::new();
|
@@ -347,7 +347,7 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
347 | 347 | roots
|
348 | 348 | }
|
349 | 349 |
|
350 |
| -// Collect all monomorphized translation items reachable from `starting_point` |
| 350 | +// Collect all monomorphized items reachable from `starting_point` |
351 | 351 | fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
352 | 352 | starting_point: MonoItem<'tcx>,
|
353 | 353 | visited: &mut FxHashSet<MonoItem<'tcx>>,
|
@@ -930,7 +930,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
|
930 | 930 | self.output.push(MonoItem::Static(item.id));
|
931 | 931 | }
|
932 | 932 | hir::ItemConst(..) => {
|
933 |
| - // const items only generate translation items if they are |
| 933 | + // const items only generate mono items if they are |
934 | 934 | // actually used somewhere. Just declaring them is insufficient.
|
935 | 935 | }
|
936 | 936 | hir::ItemFn(..) => {
|
|
0 commit comments