Skip to content

Commit b732030

Browse files
committed
make EII iteration faster
1 parent 1cbdaf2 commit b732030

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
@@ -227,6 +227,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
227227
vis_span,
228228
span: self.lower_span(i.span),
229229
has_delayed_lints: !self.delayed_lints.is_empty(),
230+
eii: find_attr!(
231+
attrs,
232+
AttributeKind::EiiImpls(..) | AttributeKind::EiiExternTarget(..)
233+
),
230234
};
231235
self.arena.alloc(item)
232236
}
@@ -670,6 +674,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
670674
vis_span,
671675
span: this.lower_span(use_tree.span),
672676
has_delayed_lints: !this.delayed_lints.is_empty(),
677+
eii: find_attr!(
678+
attrs,
679+
AttributeKind::EiiImpls(..) | AttributeKind::EiiExternTarget(..)
680+
),
673681
};
674682
hir::OwnerNode::Item(this.arena.alloc(item))
675683
});

compiler/rustc_hir/src/hir.rs

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

41694172
impl<'hir> Item<'hir> {

compiler/rustc_hir/src/intravisit.rs

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

534534
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::Result {
535-
let Item { owner_id: _, kind, span: _, vis_span: _, has_delayed_lints: _ } = item;
535+
let Item { owner_id: _, kind, span: _, vis_span: _, has_delayed_lints: _, eii: _ } = item;
536536
try_visit!(visitor.visit_id(item.hir_id()));
537537
match *kind {
538538
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
@@ -1224,6 +1224,7 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
12241224
body_owners,
12251225
opaques,
12261226
nested_bodies,
1227+
eiis,
12271228
..
12281229
} = collector;
12291230
ModuleItems {
@@ -1237,6 +1238,7 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
12371238
opaques: opaques.into_boxed_slice(),
12381239
nested_bodies: nested_bodies.into_boxed_slice(),
12391240
delayed_lint_items: Box::new([]),
1241+
eiis: eiis.into_boxed_slice(),
12401242
}
12411243
}
12421244

@@ -1259,6 +1261,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
12591261
opaques,
12601262
nested_bodies,
12611263
mut delayed_lint_items,
1264+
eiis,
12621265
..
12631266
} = collector;
12641267

@@ -1281,6 +1284,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
12811284
opaques: opaques.into_boxed_slice(),
12821285
nested_bodies: nested_bodies.into_boxed_slice(),
12831286
delayed_lint_items: delayed_lint_items.into_boxed_slice(),
1287+
eiis: eiis.into_boxed_slice(),
12841288
}
12851289
}
12861290

@@ -1298,6 +1302,7 @@ struct ItemCollector<'tcx> {
12981302
opaques: Vec<LocalDefId>,
12991303
nested_bodies: Vec<LocalDefId>,
13001304
delayed_lint_items: Vec<OwnerId>,
1305+
eiis: Vec<LocalDefId>,
13011306
}
13021307

13031308
impl<'tcx> ItemCollector<'tcx> {
@@ -1314,6 +1319,7 @@ impl<'tcx> ItemCollector<'tcx> {
13141319
opaques: Vec::default(),
13151320
nested_bodies: Vec::default(),
13161321
delayed_lint_items: Vec::default(),
1322+
eiis: Vec::default(),
13171323
}
13181324
}
13191325
}
@@ -1335,6 +1341,12 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
13351341
self.delayed_lint_items.push(item.item_id().owner_id);
13361342
}
13371343

1344+
if let ItemKind::Static(..) | ItemKind::Fn { .. } | ItemKind::Macro(..) = &item.kind
1345+
&& item.eii
1346+
{
1347+
self.eiis.push(item.owner_id.def_id)
1348+
}
1349+
13381350
// Items that are modules are handled here instead of in visit_mod.
13391351
if let ItemKind::Mod(_, module) = &item.kind {
13401352
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)