Skip to content

Commit b38bb14

Browse files
committed
make EII iteration faster
1 parent d8bb122 commit b38bb14

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
229229
vis_span,
230230
span: self.lower_span(i.span),
231231
has_delayed_lints: !self.delayed_lints.is_empty(),
232+
eii: find_attr!(
233+
attrs,
234+
AttributeKind::EiiImpls(..) | AttributeKind::EiiExternTarget(..)
235+
),
232236
};
233237
self.arena.alloc(item)
234238
}
@@ -679,6 +683,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
679683
vis_span,
680684
span: this.lower_span(use_tree.span),
681685
has_delayed_lints: !this.delayed_lints.is_empty(),
686+
eii: find_attr!(
687+
attrs,
688+
AttributeKind::EiiImpls(..) | AttributeKind::EiiExternTarget(..)
689+
),
682690
};
683691
hir::OwnerNode::Item(this.arena.alloc(item))
684692
});

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4163,6 +4163,9 @@ pub struct Item<'hir> {
41634163
pub span: Span,
41644164
pub vis_span: Span,
41654165
pub has_delayed_lints: bool,
4166+
/// hint to speed up collection: true if the item is a static or function and has
4167+
/// either an `EiiImpls` or `EiiExternTarget` attribute
4168+
pub eii: bool,
41664169
}
41674170

41684171
impl<'hir> Item<'hir> {

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) ->
528528
}
529529

530530
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::Result {
531-
let Item { owner_id: _, kind, span: _, vis_span: _, has_delayed_lints: _ } = item;
531+
let Item { owner_id: _, kind, span: _, vis_span: _, has_delayed_lints: _, eii: _ } = item;
532532
try_visit!(visitor.visit_id(item.hir_id()));
533533
match *kind {
534534
ItemKind::ExternCrate(orig_name, ident) => {

compiler/rustc_metadata/src/eii.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ pub(crate) fn collect<'tcx>(tcx: TyCtxt<'tcx>, LocalCrate: LocalCrate) -> EiiMap
2424
let mut eiis = EiiMap::default();
2525

2626
// iterate over all items in the current crate
27-
// FIXME(speed up)
28-
for id in tcx.hir_crate_items(()).definitions() {
27+
for id in tcx.hir_crate_items(()).eiis() {
2928
for i in
3029
find_attr!(tcx.get_all_attrs(id), AttributeKind::EiiImpls(e) => e).into_iter().flatten()
3130
{

compiler/rustc_middle/src/hir/map.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
12251225
body_owners,
12261226
opaques,
12271227
nested_bodies,
1228+
eiis,
12281229
..
12291230
} = collector;
12301231
ModuleItems {
@@ -1238,6 +1239,7 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
12381239
opaques: opaques.into_boxed_slice(),
12391240
nested_bodies: nested_bodies.into_boxed_slice(),
12401241
delayed_lint_items: Box::new([]),
1242+
eiis: eiis.into_boxed_slice(),
12411243
}
12421244
}
12431245

@@ -1260,6 +1262,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
12601262
opaques,
12611263
nested_bodies,
12621264
mut delayed_lint_items,
1265+
eiis,
12631266
..
12641267
} = collector;
12651268

@@ -1282,6 +1285,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
12821285
opaques: opaques.into_boxed_slice(),
12831286
nested_bodies: nested_bodies.into_boxed_slice(),
12841287
delayed_lint_items: delayed_lint_items.into_boxed_slice(),
1288+
eiis: eiis.into_boxed_slice(),
12851289
}
12861290
}
12871291

@@ -1299,6 +1303,7 @@ struct ItemCollector<'tcx> {
12991303
opaques: Vec<LocalDefId>,
13001304
nested_bodies: Vec<LocalDefId>,
13011305
delayed_lint_items: Vec<OwnerId>,
1306+
eiis: Vec<LocalDefId>,
13021307
}
13031308

13041309
impl<'tcx> ItemCollector<'tcx> {
@@ -1315,6 +1320,7 @@ impl<'tcx> ItemCollector<'tcx> {
13151320
opaques: Vec::default(),
13161321
nested_bodies: Vec::default(),
13171322
delayed_lint_items: Vec::default(),
1323+
eiis: Vec::default(),
13181324
}
13191325
}
13201326
}
@@ -1336,6 +1342,12 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
13361342
self.delayed_lint_items.push(item.item_id().owner_id);
13371343
}
13381344

1345+
if let ItemKind::Static(..) | ItemKind::Fn { .. } | ItemKind::Macro(..) = &item.kind
1346+
&& item.eii
1347+
{
1348+
self.eiis.push(item.owner_id.def_id)
1349+
}
1350+
13391351
// Items that are modules are handled here instead of in visit_mod.
13401352
if let ItemKind::Mod(_, module) = &item.kind {
13411353
self.submodules.push(item.owner_id);

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub struct ModuleItems {
3737
nested_bodies: Box<[LocalDefId]>,
3838
// only filled with hir_crate_items, not with hir_module_items
3939
delayed_lint_items: Box<[OwnerId]>,
40+
41+
/// Statics and functions with an `EiiImpls` or `EiiExternTarget` attribute
42+
eiis: Box<[LocalDefId]>,
4043
}
4144

4245
impl ModuleItems {
@@ -58,6 +61,10 @@ impl ModuleItems {
5861
self.delayed_lint_items.iter().copied()
5962
}
6063

64+
pub fn eiis(&self) -> impl Iterator<Item = LocalDefId> {
65+
self.eiis.iter().copied()
66+
}
67+
6168
/// Returns all items that are associated with some `impl` block (both inherent and trait impl
6269
/// blocks).
6370
pub fn impl_items(&self) -> impl Iterator<Item = ImplItemId> {

0 commit comments

Comments
 (0)