Skip to content

Commit f30b62b

Browse files
Merge #10479
10479: fix: fix "index out of bounds" panic in name resolution r=jonas-schievink a=jonas-schievink Closes #10084 Closes #9163 This is really just a salsa update to a version that removes the problematic code (see #10084 (comment)) bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents 12d33ea + cda9668 commit f30b62b

File tree

5 files changed

+13
-70
lines changed

5 files changed

+13
-70
lines changed

Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/base_db/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2018"
99
doctest = false
1010

1111
[dependencies]
12-
salsa = "0.17.0-pre.1"
12+
salsa = "0.17.0-pre.2"
1313
rustc-hash = "1.1.0"
1414

1515
syntax = { path = "../syntax", version = "0.0.0" }

crates/hir_def/src/nameres/tests/incremental.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use base_db::{salsa::SweepStrategy, SourceDatabaseExt};
3+
use base_db::SourceDatabaseExt;
44

55
use crate::{AdtId, ModuleDefId};
66

@@ -199,8 +199,7 @@ pub type Ty = ();
199199
}
200200

201201
// Delete the parse tree.
202-
let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
203-
base_db::ParseQuery.in_db(&db).sweep(sweep);
202+
base_db::ParseQuery.in_db(&db).purge();
204203

205204
{
206205
let events = db.log_executed(|| {

crates/ide/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ impl AnalysisHost {
161161
self.db.apply_change(change)
162162
}
163163

164-
pub fn collect_garbage(&mut self) {
165-
self.db.collect_garbage();
166-
}
167164
/// NB: this clears the database
168165
pub fn per_query_memory_usage(&mut self) -> Vec<(String, profile::Bytes)> {
169166
self.db.per_query_memory_usage()

crates/ide_db/src/apply_change.rs

+6-59
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::sync::Arc;
44

55
use base_db::{
6-
salsa::{Database, Durability, SweepStrategy},
6+
salsa::{Database, Durability},
77
Change, SourceRootId,
88
};
99
use profile::{memory_usage, Bytes};
@@ -38,32 +38,6 @@ impl RootDatabase {
3838
change.apply(self);
3939
}
4040

41-
pub fn collect_garbage(&mut self) {
42-
if cfg!(target_arch = "wasm32") {
43-
return;
44-
}
45-
46-
let _p = profile::span("RootDatabase::collect_garbage");
47-
48-
let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
49-
50-
base_db::ParseQuery.in_db(self).sweep(sweep);
51-
hir::db::ParseMacroExpansionQuery.in_db(self).sweep(sweep);
52-
53-
// Macros do take significant space, but less then the syntax trees
54-
// self.query(hir::db::MacroDefQuery).sweep(sweep);
55-
// self.query(hir::db::MacroArgTextQuery).sweep(sweep);
56-
// self.query(hir::db::MacroExpandQuery).sweep(sweep);
57-
58-
hir::db::AstIdMapQuery.in_db(self).sweep(sweep);
59-
60-
hir::db::BodyWithSourceMapQuery.in_db(self).sweep(sweep);
61-
62-
hir::db::ExprScopesQuery.in_db(self).sweep(sweep);
63-
hir::db::InferQueryQuery.in_db(self).sweep(sweep);
64-
hir::db::BodyQuery.in_db(self).sweep(sweep);
65-
}
66-
6741
// Feature: Memory Usage
6842
//
6943
// Clears rust-analyzer's internal database and prints memory usage statistics.
@@ -76,32 +50,17 @@ impl RootDatabase {
7650
// image::https://user-images.githubusercontent.com/48062697/113065592-08559f00-91b1-11eb-8c96-64b88068ec02.gif[]
7751
pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
7852
let mut acc: Vec<(String, Bytes)> = vec![];
79-
let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
80-
macro_rules! sweep_each_query {
53+
macro_rules! purge_each_query {
8154
($($q:path)*) => {$(
82-
let before = memory_usage().allocated;
83-
$q.in_db(self).sweep(sweep);
84-
let after = memory_usage().allocated;
85-
let q: $q = Default::default();
86-
let name = format!("{:?}", q);
87-
acc.push((name, before - after));
88-
89-
let before = memory_usage().allocated;
90-
$q.in_db(self).sweep(sweep.discard_everything());
91-
let after = memory_usage().allocated;
92-
let q: $q = Default::default();
93-
let name = format!("{:?} (deps)", q);
94-
acc.push((name, before - after));
95-
9655
let before = memory_usage().allocated;
9756
$q.in_db(self).purge();
9857
let after = memory_usage().allocated;
9958
let q: $q = Default::default();
100-
let name = format!("{:?} (purge)", q);
59+
let name = format!("{:?}", q);
10160
acc.push((name, before - after));
10261
)*}
10362
}
104-
sweep_each_query![
63+
purge_each_query![
10564
// SourceDatabase
10665
base_db::ParseQuery
10766
base_db::CrateGraphQuery
@@ -119,6 +78,7 @@ impl RootDatabase {
11978
hir::db::ParseMacroExpansionQuery
12079
hir::db::MacroExpandQuery
12180
hir::db::HygieneFrameQuery
81+
hir::db::InternMacroQuery
12282

12383
// DefDatabase
12484
hir::db::FileItemTreeQuery
@@ -174,6 +134,7 @@ impl RootDatabase {
174134
hir::db::InternClosureQuery
175135
hir::db::AssociatedTyValueQuery
176136
hir::db::TraitSolveQueryQuery
137+
hir::db::InternTypeParamIdQuery
177138

178139
// SymbolsDatabase
179140
crate::symbol_index::FileSymbolsQuery
@@ -183,17 +144,6 @@ impl RootDatabase {
183144

184145
// LineIndexDatabase
185146
crate::LineIndexQuery
186-
];
187-
188-
// To collect interned data, we need to bump the revision counter by performing a synthetic
189-
// write.
190-
// We do this after collecting the non-interned queries to correctly attribute memory used
191-
// by interned data.
192-
self.salsa_runtime_mut().synthetic_write(Durability::HIGH);
193-
194-
sweep_each_query![
195-
// AstDatabase
196-
hir::db::InternMacroQuery
197147

198148
// InternDatabase
199149
hir::db::InternFunctionQuery
@@ -205,9 +155,6 @@ impl RootDatabase {
205155
hir::db::InternTraitQuery
206156
hir::db::InternTypeAliasQuery
207157
hir::db::InternImplQuery
208-
209-
// HirDatabase
210-
hir::db::InternTypeParamIdQuery
211158
];
212159

213160
acc.sort_by_key(|it| std::cmp::Reverse(it.1));

0 commit comments

Comments
 (0)