@@ -179,7 +179,6 @@ use rustc_hir as hir;
179
179
use rustc_hir::def::DefKind;
180
180
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
181
181
use rustc_hir::lang_items::LangItem;
182
- use rustc_index::bit_set::GrowableBitSet;
183
182
use rustc_middle::mir::interpret::{AllocId, ConstValue};
184
183
use rustc_middle::mir::interpret::{ErrorHandled, GlobalAlloc, Scalar};
185
184
use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
@@ -220,78 +219,29 @@ pub struct InliningMap<'tcx> {
220
219
// The range selects elements within the `targets` vecs.
221
220
index: FxHashMap<MonoItem<'tcx>, Range<usize>>,
222
221
targets: Vec<MonoItem<'tcx>>,
223
-
224
- // Contains one bit per mono item in the `targets` field. That bit
225
- // is true if that mono item needs to be inlined into every CGU.
226
- inlines: GrowableBitSet<usize>,
227
- }
228
-
229
- /// Struct to store mono items in each collecting and if they should
230
- /// be inlined. We call `instantiation_mode` to get their inlining
231
- /// status when inserting new elements, which avoids calling it in
232
- /// `inlining_map.lock_mut()`. See the `collect_items_rec` implementation
233
- /// below.
234
- struct MonoItems<'tcx> {
235
- // If this is false, we do not need to compute whether items
236
- // will need to be inlined.
237
- compute_inlining: bool,
238
-
239
- // The TyCtxt used to determine whether the a item should
240
- // be inlined.
241
- tcx: TyCtxt<'tcx>,
242
-
243
- // The collected mono items. The bool field in each element
244
- // indicates whether this element should be inlined.
245
- items: Vec<(Spanned<MonoItem<'tcx>>, bool /*inlined*/)>,
246
222
}
247
223
248
- impl<'tcx> MonoItems<'tcx> {
249
- #[inline]
250
- fn push(&mut self, item: Spanned<MonoItem<'tcx>>) {
251
- self.extend([item]);
252
- }
253
-
254
- #[inline]
255
- fn extend<T: IntoIterator<Item = Spanned<MonoItem<'tcx>>>>(&mut self, iter: T) {
256
- self.items.extend(iter.into_iter().map(|mono_item| {
257
- let inlined = if !self.compute_inlining {
258
- false
259
- } else {
260
- mono_item.node.instantiation_mode(self.tcx) == InstantiationMode::LocalCopy
261
- };
262
- (mono_item, inlined)
263
- }))
264
- }
265
- }
224
+ type MonoItems<'tcx> = Vec<Spanned<MonoItem<'tcx>>>;
266
225
267
226
impl<'tcx> InliningMap<'tcx> {
268
227
fn new() -> InliningMap<'tcx> {
269
- InliningMap {
270
- index: FxHashMap::default(),
271
- targets: Vec::new(),
272
- inlines: GrowableBitSet::with_capacity(1024),
273
- }
228
+ InliningMap { index: FxHashMap::default(), targets: Vec::new() }
274
229
}
275
230
276
231
fn record_accesses<'a>(
277
232
&mut self,
278
233
source: MonoItem<'tcx>,
279
- new_targets: &'a [( Spanned<MonoItem<'tcx>>, bool) ],
234
+ new_targets: &'a [Spanned<MonoItem<'tcx>>],
280
235
) where
281
236
'tcx: 'a,
282
237
{
283
238
let start_index = self.targets.len();
284
239
let new_items_count = new_targets.len();
285
- let new_items_count_total = new_items_count + self.targets.len();
286
240
287
241
self.targets.reserve(new_items_count);
288
- self.inlines.ensure(new_items_count_total);
289
242
290
- for (i, ( Spanned { node: mono_item, .. }, inlined)) in new_targets.into_iter().enumerate () {
243
+ for Spanned { node: mono_item, .. } in new_targets.into_iter() {
291
244
self.targets.push(*mono_item);
292
- if *inlined {
293
- self.inlines.insert(i + start_index);
294
- }
295
245
}
296
246
297
247
let end_index = self.targets.len();
@@ -300,13 +250,14 @@ impl<'tcx> InliningMap<'tcx> {
300
250
301
251
/// Internally iterate over all items referenced by `source` which will be
302
252
/// made available for inlining.
303
- pub fn with_inlining_candidates<F>(&self, source: MonoItem<'tcx>, mut f: F)
253
+ pub fn with_inlining_candidates<F>(&self, tcx: TyCtxt<'tcx>, source: MonoItem<'tcx>, mut f: F)
304
254
where
305
255
F: FnMut(MonoItem<'tcx>),
306
256
{
307
257
if let Some(range) = self.index.get(&source) {
308
- for (i, candidate) in self.targets[range.clone()].iter().enumerate() {
309
- if self.inlines.contains(range.start + i) {
258
+ for candidate in self.targets[range.clone()].iter() {
259
+ let is_inlined = candidate.instantiation_mode(tcx) == InstantiationMode::LocalCopy;
260
+ if is_inlined {
310
261
f(*candidate);
311
262
}
312
263
}
@@ -367,7 +318,7 @@ pub fn collect_crate_mono_items(
367
318
#[instrument(skip(tcx, mode), level = "debug")]
368
319
fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<'_>> {
369
320
debug!("collecting roots");
370
- let mut roots = MonoItems { compute_inlining: false, tcx, items: Vec::new() } ;
321
+ let mut roots = Vec::new();
371
322
372
323
{
373
324
let entry_fn = tcx.entry_fn(());
@@ -393,9 +344,8 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<
393
344
// whose predicates hold. Luckily, items that aren't instantiable
394
345
// can't actually be used, so we can just skip codegenning them.
395
346
roots
396
- .items
397
347
.into_iter()
398
- .filter_map(|( Spanned { node: mono_item, .. }, _) | {
348
+ .filter_map(|Spanned { node: mono_item, .. }| {
399
349
mono_item.is_instantiable(tcx).then_some(mono_item)
400
350
})
401
351
.collect()
@@ -417,7 +367,7 @@ fn collect_items_rec<'tcx>(
417
367
return;
418
368
}
419
369
420
- let mut neighbors = MonoItems { compute_inlining: true, tcx, items: Vec::new() } ;
370
+ let mut neighbors = Vec::new();
421
371
let recursion_depth_reset;
422
372
423
373
//
@@ -542,9 +492,9 @@ fn collect_items_rec<'tcx>(
542
492
formatted_item,
543
493
});
544
494
}
545
- inlining_map.lock_mut().record_accesses(starting_point.node, &neighbors.items );
495
+ inlining_map.lock_mut().record_accesses(starting_point.node, &neighbors);
546
496
547
- for ( neighbour, _) in neighbors.items {
497
+ for neighbour in neighbors {
548
498
collect_items_rec(tcx, neighbour, visited, recursion_depths, recursion_limit, inlining_map);
549
499
}
550
500
0 commit comments