From ad708fdbd1a20949eed7f475300b0aa1dac3e3be Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Thu, 10 Jul 2025 05:18:43 +0300 Subject: [PATCH] Put the expression stuff in the expression store behind an `Option` And leave only the type stuff without it. This is because most expression stores don't have anything but types (e.g. generics, fields, signatures) so this saves a lot of memory. This saves 58mb on `analysis-stats .`. --- crates/hir-def/src/expr_store.rs | 479 ++++++++++++------ crates/hir-def/src/expr_store/body.rs | 6 +- crates/hir-def/src/expr_store/lower.rs | 139 +++-- crates/hir-def/src/expr_store/lower/asm.rs | 2 +- .../src/expr_store/lower/path/tests.rs | 2 +- crates/hir-def/src/expr_store/pretty.rs | 4 +- crates/hir-def/src/expr_store/scope.rs | 13 +- crates/hir-def/src/expr_store/tests/body.rs | 11 +- crates/hir-def/src/signatures.rs | 20 +- crates/hir-ty/src/consteval.rs | 4 +- crates/hir-ty/src/diagnostics/decl_check.rs | 5 +- crates/hir-ty/src/diagnostics/expr.rs | 8 +- crates/hir-ty/src/diagnostics/match_check.rs | 2 +- crates/hir-ty/src/diagnostics/unsafe_check.rs | 6 +- crates/hir-ty/src/infer/mutability.rs | 2 +- crates/hir-ty/src/infer/pat.rs | 4 +- crates/hir-ty/src/layout/tests.rs | 3 +- crates/hir-ty/src/mir.rs | 7 +- crates/hir-ty/src/mir/lower.rs | 14 +- crates/hir-ty/src/mir/lower/as_place.rs | 2 +- .../hir-ty/src/mir/lower/pattern_matching.rs | 4 +- crates/hir-ty/src/mir/pretty.rs | 2 +- crates/hir-ty/src/tests.rs | 4 +- crates/hir/src/lib.rs | 2 +- crates/hir/src/semantics.rs | 3 +- crates/hir/src/source_analyzer.rs | 10 +- crates/ide/src/inlay_hints/implicit_drop.rs | 2 +- .../rust-analyzer/src/cli/analysis_stats.rs | 4 +- 28 files changed, 456 insertions(+), 308 deletions(-) diff --git a/crates/hir-def/src/expr_store.rs b/crates/hir-def/src/expr_store.rs index 51612f341a..d3dfc05eb2 100644 --- a/crates/hir-def/src/expr_store.rs +++ b/crates/hir-def/src/expr_store.rs @@ -22,6 +22,7 @@ use rustc_hash::FxHashMap; use smallvec::SmallVec; use span::{Edition, SyntaxContext}; use syntax::{AstPtr, SyntaxNodePtr, ast}; +use thin_vec::ThinVec; use triomphe::Arc; use tt::TextRange; @@ -93,17 +94,17 @@ pub type TypeSource = InFile; pub type LifetimePtr = AstPtr; pub type LifetimeSource = InFile; +// We split the store into types-only and expressions, because most stores (e.g. generics) +// don't store any expressions and this saves memory. Same thing for the source map. #[derive(Debug, PartialEq, Eq)] -pub struct ExpressionStore { - pub exprs: Arena, - pub pats: Arena, - pub bindings: Arena, - pub labels: Arena