Skip to content

Commit 39990a9

Browse files
Merge pull request #20882 from ChayimFriedman2/accurate-mem-report
internal: Clear next-solver cache before reporting memory usage in analysis-stats
2 parents 40cd34d + a791d3b commit 39990a9

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

crates/hir-ty/src/next_solver/interner.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::{fmt, ops::ControlFlow};
44

5+
pub use tls_cache::clear_tls_solver_cache;
56
pub use tls_db::{attach_db, attach_db_allow_change, with_attached_db};
67

78
use base_db::Crate;
@@ -2239,4 +2240,12 @@ mod tls_cache {
22392240
})
22402241
})
22412242
}
2243+
2244+
/// Clears the thread-local trait solver cache.
2245+
///
2246+
/// Should be called before getting memory usage estimations, as the solver cache
2247+
/// is per-revision and usually should be excluded from estimations.
2248+
pub fn clear_tls_solver_cache() {
2249+
GLOBAL_CACHE.with_borrow_mut(|handle| *handle = None);
2250+
}
22422251
}

crates/hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pub use {
171171
method_resolution::TyFingerprint,
172172
mir::{MirEvalError, MirLowerError},
173173
next_solver::abi::Safety,
174+
next_solver::clear_tls_solver_cache,
174175
},
175176
intern::{Symbol, sym},
176177
};

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ impl flags::AnalysisStats {
345345
self.run_term_search(&workspace, db, &vfs, &file_ids, verbosity);
346346
}
347347

348+
hir::clear_tls_solver_cache();
349+
348350
let db = host.raw_database_mut();
349351
db.trigger_lru_eviction();
350352

0 commit comments

Comments
 (0)