From e7aa17b5605bdf393c76549ff1507110a94b4cca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 00:35:13 +0300 Subject: Gc syntax trees after every modification --- crates/ra_analysis/src/imp.rs | 21 +++++++++++++++++---- crates/ra_hir/src/db.rs | 4 ---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 03d17de0d..843f28d05 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -10,7 +10,7 @@ use ra_syntax::{ SyntaxKind::*, SyntaxNodeRef, TextRange, TextUnit, }; -use ra_db::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE, SyntaxDatabase, SourceFileQuery}; +use ra_db::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE, SyntaxDatabase}; use rayon::prelude::*; use rustc_hash::FxHashSet; use salsa::{Database, ParallelDatabase}; @@ -43,6 +43,7 @@ impl AnalysisHostImpl { } pub fn apply_change(&mut self, change: AnalysisChange) { log::info!("apply_change {:?}", change); + self.gc_syntax_trees(); for (file_id, text) in change.files_changed { self.db @@ -115,6 +116,21 @@ impl AnalysisHostImpl { .set((), Arc::new(crate_graph)) } } + + fn gc_syntax_trees(&mut self) { + self.db + .query(ra_db::SourceFileQuery) + .sweep(salsa::SweepStrategy::default().discard_values()); + self.db + .query(hir::db::FnSyntaxQuery) + .sweep(salsa::SweepStrategy::default().discard_values()); + self.db + .query(hir::db::SourceFileItemsQuery) + .sweep(salsa::SweepStrategy::default().discard_values()); + self.db + .query(hir::db::FileItemQuery) + .sweep(salsa::SweepStrategy::default().discard_values()); + } } pub(crate) struct AnalysisImpl { @@ -160,9 +176,6 @@ impl AnalysisImpl { .filter_map(|it| it.ok()) .collect() }; - self.db - .query(SourceFileQuery) - .sweep(salsa::SweepStrategy::default().discard_values()); Ok(query.search(&buf)) } /// This returns `Vec` because a module may be included from several places. We diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index ff41fd326..62cf9ab17 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -27,20 +27,16 @@ pub trait HirDatabase: SyntaxDatabase } fn fn_syntax(fn_id: FnId) -> FnDefNode { type FnSyntaxQuery; - // Don't retain syntax trees in memory - storage dependencies; use fn query_definitions::fn_syntax; } fn file_items(file_id: FileId) -> Arc { type SourceFileItemsQuery; - storage dependencies; use fn query_definitions::file_items; } fn file_item(source_item_id: SourceItemId) -> SyntaxNode { type FileItemQuery; - storage dependencies; use fn query_definitions::file_item; } -- cgit v1.2.3