diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs index 5d2edf9f30..31c1a71303 100644 --- a/crates/hir-def/src/db.rs +++ b/crates/hir-def/src/db.rs @@ -83,9 +83,6 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast Arc; #[salsa::invoke(ItemTree::block_item_tree_query)] - // FIXME: Investigate memory usage increase if this were not transparent - // Also make sure to `shrink_to_fit` if you do - #[salsa::transparent] fn block_item_tree_query(&self, block_id: BlockId) -> Arc; #[salsa::invoke(crate_def_map_wait)] diff --git a/crates/hir-def/src/item_tree.rs b/crates/hir-def/src/item_tree.rs index 6229277957..5734f1c67b 100644 --- a/crates/hir-def/src/item_tree.rs +++ b/crates/hir-def/src/item_tree.rs @@ -148,7 +148,9 @@ impl ItemTree { let block = loc.ast_id.to_node(db.upcast()); let ctx = lower::Ctx::new(db, loc.ast_id.file_id); - Arc::new(ctx.lower_block(&block)) + let mut item_tree = ctx.lower_block(&block); + item_tree.shrink_to_fit(); + Arc::new(item_tree) } /// Returns an iterator over all items located at the top level of the `HirFileId` this @@ -383,7 +385,7 @@ impl TreeId { pub(crate) fn item_tree(&self, db: &dyn DefDatabase) -> Arc { match self.block { - Some(block) => ItemTree::block_item_tree_query(db, block), + Some(block) => db.block_item_tree_query(block), None => db.file_item_tree(self.file), } }