Shrink `ModItem` by usize
diff --git a/crates/hir-def/src/item_tree.rs b/crates/hir-def/src/item_tree.rs
index 79f4b17..2a277e4 100644
--- a/crates/hir-def/src/item_tree.rs
+++ b/crates/hir-def/src/item_tree.rs
@@ -51,7 +51,7 @@
name::Name,
};
use intern::Interned;
-use la_arena::Idx;
+use la_arena::{Idx, RawIdx};
use rustc_hash::FxHashMap;
use span::{AstIdNode, Edition, FileAstId, SyntaxContext};
use stdx::never;
@@ -437,10 +437,10 @@
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct UseTree {
- pub index: Idx<ast::UseTree>,
kind: UseTreeKind,
}
+// FIXME: Would be nice to encode `None` into this
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ImportAlias {
/// Unnamed alias, as in `use Foo as _;`
@@ -655,15 +655,17 @@
TypeOnly,
}
-impl UseTree {
+impl Use {
/// Expands the `UseTree` into individually imported `ModPath`s.
pub fn expand(
&self,
mut cb: impl FnMut(Idx<ast::UseTree>, ModPath, ImportKind, Option<ImportAlias>),
) {
- self.expand_impl(None, &mut cb)
+ self.use_tree.expand_impl(None, &mut 0, &mut cb)
}
+}
+impl UseTree {
/// The [`UseTreeKind`] of this `UseTree`.
pub fn kind(&self) -> &UseTreeKind {
&self.kind
@@ -672,6 +674,7 @@
fn expand_impl(
&self,
prefix: Option<ModPath>,
+ counting_index: &mut u32,
cb: &mut impl FnMut(Idx<ast::UseTree>, ModPath, ImportKind, Option<ImportAlias>),
) {
fn concat_mod_paths(
@@ -707,17 +710,27 @@
match &self.kind {
UseTreeKind::Single { path, alias } => {
if let Some((path, kind)) = concat_mod_paths(prefix, path) {
- cb(self.index, path, kind, alias.clone());
+ cb(Idx::from_raw(RawIdx::from_u32(*counting_index)), path, kind, alias.clone());
}
}
UseTreeKind::Glob { path: Some(path) } => {
if let Some((path, _)) = concat_mod_paths(prefix, path) {
- cb(self.index, path, ImportKind::Glob, None);
+ cb(
+ Idx::from_raw(RawIdx::from_u32(*counting_index)),
+ path,
+ ImportKind::Glob,
+ None,
+ );
}
}
UseTreeKind::Glob { path: None } => {
if let Some(prefix) = prefix {
- cb(self.index, prefix, ImportKind::Glob, None);
+ cb(
+ Idx::from_raw(RawIdx::from_u32(*counting_index)),
+ prefix,
+ ImportKind::Glob,
+ None,
+ );
}
}
UseTreeKind::Prefixed { prefix: additional_prefix, list } => {
@@ -729,7 +742,8 @@
None => prefix,
};
for tree in &**list {
- tree.expand_impl(prefix.clone(), cb);
+ *counting_index += 1;
+ tree.expand_impl(prefix.clone(), counting_index, cb);
}
}
}
diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs
index c3089ee..ab60b7a 100644
--- a/crates/hir-def/src/item_tree/lower.rs
+++ b/crates/hir-def/src/item_tree/lower.rs
@@ -424,17 +424,15 @@
}
};
+ self.mapping.alloc(tree.clone());
let list = use_tree_list
.use_trees()
.filter_map(|tree| self.lower_use_tree(tree, span_for_range))
.collect();
- Some(
- self.use_tree(
- UseTreeKind::Prefixed { prefix: prefix.map(Interned::new), list },
- tree,
- ),
- )
+ Some(UseTree {
+ kind: UseTreeKind::Prefixed { prefix: prefix.map(Interned::new), list },
+ })
} else {
let is_glob = tree.star_token().is_some();
let path = match tree.path() {
@@ -453,23 +451,20 @@
if path.is_none() {
cov_mark::hit!(glob_enum_group);
}
- Some(self.use_tree(UseTreeKind::Glob { path: path.map(Interned::new) }, tree))
+ self.mapping.alloc(tree.clone());
+ Some(UseTree { kind: UseTreeKind::Glob { path: path.map(Interned::new) } })
}
// Globs can't be renamed
(_, Some(_), true) | (None, None, false) => None,
// `bla::{ as Name}` is invalid
(None, Some(_), false) => None,
- (Some(path), alias, false) => Some(
- self.use_tree(UseTreeKind::Single { path: Interned::new(path), alias }, tree),
- ),
+ (Some(path), alias, false) => {
+ self.mapping.alloc(tree.clone());
+ Some(UseTree { kind: UseTreeKind::Single { path: Interned::new(path), alias } })
+ }
}
}
}
-
- fn use_tree(&mut self, kind: UseTreeKind, ast: ast::UseTree) -> UseTree {
- let index = self.mapping.alloc(ast);
- UseTree { index, kind }
- }
}
pub(crate) fn lower_use_tree(
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs
index a6be3f1..9801875 100644
--- a/crates/hir-def/src/nameres/collector.rs
+++ b/crates/hir-def/src/nameres/collector.rs
@@ -163,7 +163,7 @@
) {
let it = &tree[item];
let visibility = &tree[it.visibility];
- it.use_tree.expand(|idx, path, kind, alias| {
+ it.expand(|idx, path, kind, alias| {
cb(Self {
path,
alias,
diff --git a/crates/intern/src/symbol.rs b/crates/intern/src/symbol.rs
index 8b2d6e8..3b962a8 100644
--- a/crates/intern/src/symbol.rs
+++ b/crates/intern/src/symbol.rs
@@ -112,6 +112,7 @@
}
}
+// FIXME: This should have more than one niche
#[derive(PartialEq, Eq, Hash)]
pub struct Symbol {
repr: TaggedArcPtr,