Unnamed repository; edit this file 'description' to name the repository.
Don't trigger GC on slow tests, take 2
Hopefully it really works this time.
Chayim Refael Friedman 8 weeks ago
parent 17e7f0c · commit 96477b0
-rw-r--r--Cargo.lock1
-rw-r--r--crates/intern/Cargo.toml3
-rw-r--r--crates/intern/src/gc.rs4
-rw-r--r--crates/rust-analyzer/Cargo.toml2
-rw-r--r--crates/rust-analyzer/src/main_loop.rs13
5 files changed, 12 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f31dda4a10..5370127ddc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2315,6 +2315,7 @@ dependencies = [
"ide-db",
"ide-ssr",
"indexmap",
+ "intern",
"itertools 0.14.0",
"load-cargo",
"lsp-server 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/crates/intern/Cargo.toml b/crates/intern/Cargo.toml
index ad73c191c0..39320ebd1c 100644
--- a/crates/intern/Cargo.toml
+++ b/crates/intern/Cargo.toml
@@ -22,3 +22,6 @@ rayon.workspace = true
[lints]
workspace = true
+
+[features]
+prevent-gc = []
diff --git a/crates/intern/src/gc.rs b/crates/intern/src/gc.rs
index 937de26831..f4e8f75e71 100644
--- a/crates/intern/src/gc.rs
+++ b/crates/intern/src/gc.rs
@@ -110,6 +110,10 @@ impl GarbageCollector {
/// the added storages must form a DAG.
/// - [`GcInternedVisit`] and [`GcInternedSliceVisit`] must mark all values reachable from the node.
pub unsafe fn collect(mut self) {
+ if cfg!(feature = "prevent-gc") {
+ return;
+ }
+
let total_nodes = self.storages.iter().map(|storage| storage.len()).sum();
self.alive.clear();
self.alive.reserve(total_nodes);
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index d1283ca59e..beb83a8173 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -94,6 +94,8 @@ test-utils.workspace = true
test-fixture.workspace = true
syntax-bridge.workspace = true
+intern = { path = "../intern", features = ["prevent-gc"] }
+
[features]
jemalloc = ["jemallocator", "profile/jemalloc"]
force-always-assert = ["stdx/force-always-assert"]
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 83edbc722b..dad321137f 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -303,15 +303,6 @@ impl GlobalState {
.map(Some)
}
- fn trigger_garbage_collection(&mut self) {
- if cfg!(test) {
- // Slow tests run the main loop in multiple threads, but GC isn't thread safe.
- return;
- }
-
- self.analysis_host.trigger_garbage_collection();
- }
-
fn handle_event(&mut self, event: Event) {
let loop_start = Instant::now();
let _p = tracing::info_span!("GlobalState::handle_event", event = %event).entered();
@@ -392,7 +383,7 @@ impl GlobalState {
));
}
PrimeCachesProgress::End { cancelled } => {
- self.trigger_garbage_collection();
+ self.analysis_host.trigger_garbage_collection();
self.prime_caches_queue.op_completed(());
if cancelled {
self.prime_caches_queue
@@ -551,7 +542,7 @@ impl GlobalState {
&& self.fmt_pool.handle.is_empty()
&& current_revision != self.last_gc_revision
{
- self.trigger_garbage_collection();
+ self.analysis_host.trigger_garbage_collection();
self.last_gc_revision = current_revision;
}
}