Skip to content

Commit bd359b3

Browse files
committed
LRU body_with_source_map query
1 parent 232e555 commit bd359b3

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

crates/hir-def/src/db.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
177177
// endregion:data
178178

179179
#[salsa::invoke(Body::body_with_source_map_query)]
180+
#[salsa::lru]
180181
fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
181182

182183
#[salsa::invoke(Body::body_query)]

crates/hir-expand/src/db.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ pub trait ExpandDatabase: SourceDatabase {
6262
/// file or a macro expansion.
6363
#[salsa::transparent]
6464
fn parse_or_expand(&self, file_id: HirFileId) -> SyntaxNode;
65-
#[salsa::transparent]
66-
fn parse_or_expand_with_err(&self, file_id: HirFileId) -> ExpandResult<Parse<SyntaxNode>>;
6765
/// Implementation for the macro case.
6866
#[salsa::lru]
6967
fn parse_macro_expansion(
@@ -328,18 +326,6 @@ fn parse_or_expand(db: &dyn ExpandDatabase, file_id: HirFileId) -> SyntaxNode {
328326
}
329327
}
330328

331-
fn parse_or_expand_with_err(
332-
db: &dyn ExpandDatabase,
333-
file_id: HirFileId,
334-
) -> ExpandResult<Parse<SyntaxNode>> {
335-
match file_id.repr() {
336-
HirFileIdRepr::FileId(file_id) => ExpandResult::ok(db.parse(file_id).to_syntax()),
337-
HirFileIdRepr::MacroFile(macro_file) => {
338-
db.parse_macro_expansion(macro_file).map(|(it, _)| it)
339-
}
340-
}
341-
}
342-
343329
// FIXME: We should verify that the parsed node is one of the many macro node variants we expect
344330
// instead of having it be untyped
345331
fn parse_macro_expansion(

crates/ide-db/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ impl RootDatabase {
168168
// macro expansions are usually rather small, so we can afford to keep more of them alive
169169
hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity);
170170
hir::db::BorrowckQuery.in_db_mut(self).set_lru_capacity(base_db::DEFAULT_BORROWCK_LRU_CAP);
171+
hir::db::BodyWithSourceMapQuery.in_db_mut(self).set_lru_capacity(2048);
171172
}
172173

173174
pub fn update_lru_capacities(&mut self, lru_capacities: &FxHashMap<Box<str>, u16>) {
@@ -192,6 +193,7 @@ impl RootDatabase {
192193
.copied()
193194
.unwrap_or(base_db::DEFAULT_BORROWCK_LRU_CAP),
194195
);
196+
hir::db::BodyWithSourceMapQuery.in_db_mut(self).set_lru_capacity(2048);
195197
}
196198
}
197199

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,10 @@ impl flags::AnalysisStats {
663663
bar.println(msg());
664664
}
665665
bar.set_message(msg);
666-
let (body, sm) = db.body_with_source_map(body_id.into());
666+
let body = db.body(body_id.into());
667667
let inference_result = db.infer(body_id.into());
668+
// This query is LRU'd, so actually calling it will skew the timing results.
669+
let sm = || db.body_with_source_map(body_id.into()).1;
668670

669671
// region:expressions
670672
let (previous_exprs, previous_unknown, previous_partially_unknown) =
@@ -675,7 +677,8 @@ impl flags::AnalysisStats {
675677
let unknown_or_partial = if ty.is_unknown() {
676678
num_exprs_unknown += 1;
677679
if verbosity.is_spammy() {
678-
if let Some((path, start, end)) = expr_syntax_range(db, vfs, &sm, expr_id) {
680+
if let Some((path, start, end)) = expr_syntax_range(db, vfs, &sm(), expr_id)
681+
{
679682
bar.println(format!(
680683
"{} {}:{}-{}:{}: Unknown type",
681684
path,
@@ -699,7 +702,7 @@ impl flags::AnalysisStats {
699702
};
700703
if self.only.is_some() && verbosity.is_spammy() {
701704
// in super-verbose mode for just one function, we print every single expression
702-
if let Some((_, start, end)) = expr_syntax_range(db, vfs, &sm, expr_id) {
705+
if let Some((_, start, end)) = expr_syntax_range(db, vfs, &sm(), expr_id) {
703706
bar.println(format!(
704707
"{}:{}-{}:{}: {}",
705708
start.line + 1,
@@ -715,14 +718,15 @@ impl flags::AnalysisStats {
715718
if unknown_or_partial && self.output == Some(OutputFormat::Csv) {
716719
println!(
717720
r#"{},type,"{}""#,
718-
location_csv_expr(db, vfs, &sm, expr_id),
721+
location_csv_expr(db, vfs, &sm(), expr_id),
719722
ty.display(db)
720723
);
721724
}
722725
if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) {
723726
num_expr_type_mismatches += 1;
724727
if verbosity.is_verbose() {
725-
if let Some((path, start, end)) = expr_syntax_range(db, vfs, &sm, expr_id) {
728+
if let Some((path, start, end)) = expr_syntax_range(db, vfs, &sm(), expr_id)
729+
{
726730
bar.println(format!(
727731
"{} {}:{}-{}:{}: Expected {}, got {}",
728732
path,
@@ -745,7 +749,7 @@ impl flags::AnalysisStats {
745749
if self.output == Some(OutputFormat::Csv) {
746750
println!(
747751
r#"{},mismatch,"{}","{}""#,
748-
location_csv_expr(db, vfs, &sm, expr_id),
752+
location_csv_expr(db, vfs, &sm(), expr_id),
749753
mismatch.expected.display(db),
750754
mismatch.actual.display(db)
751755
);
@@ -772,7 +776,7 @@ impl flags::AnalysisStats {
772776
let unknown_or_partial = if ty.is_unknown() {
773777
num_pats_unknown += 1;
774778
if verbosity.is_spammy() {
775-
if let Some((path, start, end)) = pat_syntax_range(db, vfs, &sm, pat_id) {
779+
if let Some((path, start, end)) = pat_syntax_range(db, vfs, &sm(), pat_id) {
776780
bar.println(format!(
777781
"{} {}:{}-{}:{}: Unknown type",
778782
path,
@@ -796,7 +800,7 @@ impl flags::AnalysisStats {
796800
};
797801
if self.only.is_some() && verbosity.is_spammy() {
798802
// in super-verbose mode for just one function, we print every single pattern
799-
if let Some((_, start, end)) = pat_syntax_range(db, vfs, &sm, pat_id) {
803+
if let Some((_, start, end)) = pat_syntax_range(db, vfs, &sm(), pat_id) {
800804
bar.println(format!(
801805
"{}:{}-{}:{}: {}",
802806
start.line + 1,
@@ -812,14 +816,14 @@ impl flags::AnalysisStats {
812816
if unknown_or_partial && self.output == Some(OutputFormat::Csv) {
813817
println!(
814818
r#"{},type,"{}""#,
815-
location_csv_pat(db, vfs, &sm, pat_id),
819+
location_csv_pat(db, vfs, &sm(), pat_id),
816820
ty.display(db)
817821
);
818822
}
819823
if let Some(mismatch) = inference_result.type_mismatch_for_pat(pat_id) {
820824
num_pat_type_mismatches += 1;
821825
if verbosity.is_verbose() {
822-
if let Some((path, start, end)) = pat_syntax_range(db, vfs, &sm, pat_id) {
826+
if let Some((path, start, end)) = pat_syntax_range(db, vfs, &sm(), pat_id) {
823827
bar.println(format!(
824828
"{} {}:{}-{}:{}: Expected {}, got {}",
825829
path,
@@ -842,7 +846,7 @@ impl flags::AnalysisStats {
842846
if self.output == Some(OutputFormat::Csv) {
843847
println!(
844848
r#"{},mismatch,"{}","{}""#,
845-
location_csv_pat(db, vfs, &sm, pat_id),
849+
location_csv_pat(db, vfs, &sm(), pat_id),
846850
mismatch.expected.display(db),
847851
mismatch.actual.display(db)
848852
);
@@ -957,7 +961,7 @@ impl flags::AnalysisStats {
957961
bar.println(msg());
958962
}
959963
bar.set_message(msg);
960-
db.body_with_source_map(body_id.into());
964+
db.body(body_id.into());
961965
bar.inc(1);
962966
}
963967

0 commit comments

Comments
 (0)