Skip to content

Commit 724537f

Browse files
committed
Shrink ModItem by usize
1 parent dfa9d68 commit 724537f

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use hir_expand::{
5151
name::Name,
5252
};
5353
use intern::Interned;
54-
use la_arena::Idx;
54+
use la_arena::{Idx, RawIdx};
5555
use rustc_hash::FxHashMap;
5656
use span::{AstIdNode, Edition, FileAstId, SyntaxContext};
5757
use stdx::never;
@@ -437,10 +437,10 @@ pub struct Use {
437437

438438
#[derive(Debug, Clone, Eq, PartialEq)]
439439
pub struct UseTree {
440-
pub index: Idx<ast::UseTree>,
441440
kind: UseTreeKind,
442441
}
443442

443+
// FIXME: Would be nice to encode `None` into this
444444
#[derive(Debug, Clone, PartialEq, Eq)]
445445
pub enum ImportAlias {
446446
/// Unnamed alias, as in `use Foo as _;`
@@ -655,15 +655,17 @@ pub enum ImportKind {
655655
TypeOnly,
656656
}
657657

658-
impl UseTree {
658+
impl Use {
659659
/// Expands the `UseTree` into individually imported `ModPath`s.
660660
pub fn expand(
661661
&self,
662662
mut cb: impl FnMut(Idx<ast::UseTree>, ModPath, ImportKind, Option<ImportAlias>),
663663
) {
664-
self.expand_impl(None, &mut cb)
664+
self.use_tree.expand_impl(None, &mut 0, &mut cb)
665665
}
666+
}
666667

668+
impl UseTree {
667669
/// The [`UseTreeKind`] of this `UseTree`.
668670
pub fn kind(&self) -> &UseTreeKind {
669671
&self.kind
@@ -672,6 +674,7 @@ impl UseTree {
672674
fn expand_impl(
673675
&self,
674676
prefix: Option<ModPath>,
677+
counting_index: &mut u32,
675678
cb: &mut impl FnMut(Idx<ast::UseTree>, ModPath, ImportKind, Option<ImportAlias>),
676679
) {
677680
fn concat_mod_paths(
@@ -707,17 +710,27 @@ impl UseTree {
707710
match &self.kind {
708711
UseTreeKind::Single { path, alias } => {
709712
if let Some((path, kind)) = concat_mod_paths(prefix, path) {
710-
cb(self.index, path, kind, alias.clone());
713+
cb(Idx::from_raw(RawIdx::from_u32(*counting_index)), path, kind, alias.clone());
711714
}
712715
}
713716
UseTreeKind::Glob { path: Some(path) } => {
714717
if let Some((path, _)) = concat_mod_paths(prefix, path) {
715-
cb(self.index, path, ImportKind::Glob, None);
718+
cb(
719+
Idx::from_raw(RawIdx::from_u32(*counting_index)),
720+
path,
721+
ImportKind::Glob,
722+
None,
723+
);
716724
}
717725
}
718726
UseTreeKind::Glob { path: None } => {
719727
if let Some(prefix) = prefix {
720-
cb(self.index, prefix, ImportKind::Glob, None);
728+
cb(
729+
Idx::from_raw(RawIdx::from_u32(*counting_index)),
730+
prefix,
731+
ImportKind::Glob,
732+
None,
733+
);
721734
}
722735
}
723736
UseTreeKind::Prefixed { prefix: additional_prefix, list } => {
@@ -729,7 +742,8 @@ impl UseTree {
729742
None => prefix,
730743
};
731744
for tree in &**list {
732-
tree.expand_impl(prefix.clone(), cb);
745+
*counting_index += 1;
746+
tree.expand_impl(prefix.clone(), counting_index, cb);
733747
}
734748
}
735749
}

src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,15 @@ impl UseTreeLowering<'_> {
424424
}
425425
};
426426

427+
self.mapping.alloc(tree.clone());
427428
let list = use_tree_list
428429
.use_trees()
429430
.filter_map(|tree| self.lower_use_tree(tree, span_for_range))
430431
.collect();
431432

432-
Some(
433-
self.use_tree(
434-
UseTreeKind::Prefixed { prefix: prefix.map(Interned::new), list },
435-
tree,
436-
),
437-
)
433+
Some(UseTree {
434+
kind: UseTreeKind::Prefixed { prefix: prefix.map(Interned::new), list },
435+
})
438436
} else {
439437
let is_glob = tree.star_token().is_some();
440438
let path = match tree.path() {
@@ -453,23 +451,20 @@ impl UseTreeLowering<'_> {
453451
if path.is_none() {
454452
cov_mark::hit!(glob_enum_group);
455453
}
456-
Some(self.use_tree(UseTreeKind::Glob { path: path.map(Interned::new) }, tree))
454+
self.mapping.alloc(tree.clone());
455+
Some(UseTree { kind: UseTreeKind::Glob { path: path.map(Interned::new) } })
457456
}
458457
// Globs can't be renamed
459458
(_, Some(_), true) | (None, None, false) => None,
460459
// `bla::{ as Name}` is invalid
461460
(None, Some(_), false) => None,
462-
(Some(path), alias, false) => Some(
463-
self.use_tree(UseTreeKind::Single { path: Interned::new(path), alias }, tree),
464-
),
461+
(Some(path), alias, false) => {
462+
self.mapping.alloc(tree.clone());
463+
Some(UseTree { kind: UseTreeKind::Single { path: Interned::new(path), alias } })
464+
}
465465
}
466466
}
467467
}
468-
469-
fn use_tree(&mut self, kind: UseTreeKind, ast: ast::UseTree) -> UseTree {
470-
let index = self.mapping.alloc(ast);
471-
UseTree { index, kind }
472-
}
473468
}
474469

475470
pub(crate) fn lower_use_tree(

src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl Import {
163163
) {
164164
let it = &tree[item];
165165
let visibility = &tree[it.visibility];
166-
it.use_tree.expand(|idx, path, kind, alias| {
166+
it.expand(|idx, path, kind, alias| {
167167
cb(Self {
168168
path,
169169
alias,

src/tools/rust-analyzer/crates/intern/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl TaggedArcPtr {
112112
}
113113
}
114114

115+
// FIXME: This should have more than one niche
115116
#[derive(PartialEq, Eq, Hash)]
116117
pub struct Symbol {
117118
repr: TaggedArcPtr,

0 commit comments

Comments
 (0)