Skip to content

Commit

Permalink
Update salsa
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Oct 6, 2021
1 parent 86c534f commit cda9668
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 70 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/base_db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
doctest = false

[dependencies]
salsa = "0.17.0-pre.1"
salsa = "0.17.0-pre.2"
rustc-hash = "1.1.0"

syntax = { path = "../syntax", version = "0.0.0" }
Expand Down
5 changes: 2 additions & 3 deletions crates/hir_def/src/nameres/tests/incremental.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use base_db::{salsa::SweepStrategy, SourceDatabaseExt};
use base_db::SourceDatabaseExt;

use crate::{AdtId, ModuleDefId};

Expand Down Expand Up @@ -199,8 +199,7 @@ pub type Ty = ();
}

// Delete the parse tree.
let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
base_db::ParseQuery.in_db(&db).sweep(sweep);
base_db::ParseQuery.in_db(&db).purge();

{
let events = db.log_executed(|| {
Expand Down
3 changes: 0 additions & 3 deletions crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ impl AnalysisHost {
self.db.apply_change(change)
}

pub fn collect_garbage(&mut self) {
self.db.collect_garbage();
}
/// NB: this clears the database
pub fn per_query_memory_usage(&mut self) -> Vec<(String, profile::Bytes)> {
self.db.per_query_memory_usage()
Expand Down
65 changes: 6 additions & 59 deletions crates/ide_db/src/apply_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::sync::Arc;

use base_db::{
salsa::{Database, Durability, SweepStrategy},
salsa::{Database, Durability},
Change, SourceRootId,
};
use profile::{memory_usage, Bytes};
Expand Down Expand Up @@ -38,32 +38,6 @@ impl RootDatabase {
change.apply(self);
}

pub fn collect_garbage(&mut self) {
if cfg!(target_arch = "wasm32") {
return;
}

let _p = profile::span("RootDatabase::collect_garbage");

let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();

base_db::ParseQuery.in_db(self).sweep(sweep);
hir::db::ParseMacroExpansionQuery.in_db(self).sweep(sweep);

// Macros do take significant space, but less then the syntax trees
// self.query(hir::db::MacroDefQuery).sweep(sweep);
// self.query(hir::db::MacroArgTextQuery).sweep(sweep);
// self.query(hir::db::MacroExpandQuery).sweep(sweep);

hir::db::AstIdMapQuery.in_db(self).sweep(sweep);

hir::db::BodyWithSourceMapQuery.in_db(self).sweep(sweep);

hir::db::ExprScopesQuery.in_db(self).sweep(sweep);
hir::db::InferQueryQuery.in_db(self).sweep(sweep);
hir::db::BodyQuery.in_db(self).sweep(sweep);
}

// Feature: Memory Usage
//
// Clears rust-analyzer's internal database and prints memory usage statistics.
Expand All @@ -76,32 +50,17 @@ impl RootDatabase {
// image::https://user-images.githubusercontent.com/48062697/113065592-08559f00-91b1-11eb-8c96-64b88068ec02.gif[]
pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
let mut acc: Vec<(String, Bytes)> = vec![];
let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
macro_rules! sweep_each_query {
macro_rules! purge_each_query {
($($q:path)*) => {$(
let before = memory_usage().allocated;
$q.in_db(self).sweep(sweep);
let after = memory_usage().allocated;
let q: $q = Default::default();
let name = format!("{:?}", q);
acc.push((name, before - after));

let before = memory_usage().allocated;
$q.in_db(self).sweep(sweep.discard_everything());
let after = memory_usage().allocated;
let q: $q = Default::default();
let name = format!("{:?} (deps)", q);
acc.push((name, before - after));

let before = memory_usage().allocated;
$q.in_db(self).purge();
let after = memory_usage().allocated;
let q: $q = Default::default();
let name = format!("{:?} (purge)", q);
let name = format!("{:?}", q);
acc.push((name, before - after));
)*}
}
sweep_each_query![
purge_each_query![
// SourceDatabase
base_db::ParseQuery
base_db::CrateGraphQuery
Expand All @@ -119,6 +78,7 @@ impl RootDatabase {
hir::db::ParseMacroExpansionQuery
hir::db::MacroExpandQuery
hir::db::HygieneFrameQuery
hir::db::InternMacroQuery

// DefDatabase
hir::db::FileItemTreeQuery
Expand Down Expand Up @@ -174,6 +134,7 @@ impl RootDatabase {
hir::db::InternClosureQuery
hir::db::AssociatedTyValueQuery
hir::db::TraitSolveQueryQuery
hir::db::InternTypeParamIdQuery

// SymbolsDatabase
crate::symbol_index::FileSymbolsQuery
Expand All @@ -183,17 +144,6 @@ impl RootDatabase {

// LineIndexDatabase
crate::LineIndexQuery
];

// To collect interned data, we need to bump the revision counter by performing a synthetic
// write.
// We do this after collecting the non-interned queries to correctly attribute memory used
// by interned data.
self.salsa_runtime_mut().synthetic_write(Durability::HIGH);

sweep_each_query![
// AstDatabase
hir::db::InternMacroQuery

// InternDatabase
hir::db::InternFunctionQuery
Expand All @@ -205,9 +155,6 @@ impl RootDatabase {
hir::db::InternTraitQuery
hir::db::InternTypeAliasQuery
hir::db::InternImplQuery

// HirDatabase
hir::db::InternTypeParamIdQuery
];

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

0 comments on commit cda9668

Please sign in to comment.