Skip to content

Commit 86e597a

Browse files
committed
chore: Enable LSP Garbage Collection test for CI
1 parent a70c746 commit 86e597a

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sway-core/src/decl_engine/engine.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,34 @@ macro_rules! decl_engine_clear_module {
190190
self.parents.write().unwrap().retain(|key, _| {
191191
match key {
192192
AssociatedItemDeclId::TraitFn(decl_id) => {
193-
self.get_trait_fn(decl_id).span().source_id().map_or(false, |src_id| &src_id.module_id() != module_id)
193+
// WARNING: Setting to true disables garbage collection for these cases.
194+
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
195+
self.get_trait_fn(decl_id).span().source_id().map_or(true, |src_id| &src_id.module_id() != module_id)
194196
},
195197
AssociatedItemDeclId::Function(decl_id) => {
196-
self.get_function(decl_id).span().source_id().map_or(false, |src_id| &src_id.module_id() != module_id)
198+
// WARNING: Setting to true disables garbage collection for these cases.
199+
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
200+
self.get_function(decl_id).span().source_id().map_or(true, |src_id| &src_id.module_id() != module_id)
197201
},
198202
AssociatedItemDeclId::Type(decl_id) => {
199-
self.get_type(decl_id).span().source_id().map_or(false, |src_id| &src_id.module_id() != module_id)
203+
// WARNING: Setting to true disables garbage collection for these cases.
204+
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
205+
self.get_type(decl_id).span().source_id().map_or(true, |src_id| &src_id.module_id() != module_id)
200206
},
201207
AssociatedItemDeclId::Constant(decl_id) => {
202-
self.get_constant(decl_id).span().source_id().map_or(false, |src_id| &src_id.module_id() != module_id)
208+
// WARNING: Setting to true disables garbage collection for these cases.
209+
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
210+
self.get_constant(decl_id).span().source_id().map_or(true, |src_id| &src_id.module_id() != module_id)
203211
},
204212
}
205213
});
206214

207215
$(
208216
self.$slab.retain(|_k, ty| match ty.span().source_id() {
209217
Some(source_id) => &source_id.module_id() != module_id,
210-
None => false,
218+
// WARNING: Setting to true disables garbage collection for these cases.
219+
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
220+
None => true,
211221
});
212222
)*
213223
}

sway-core/src/type_system/engine.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ impl TypeEngine {
7272
pub fn clear_module(&mut self, module_id: &ModuleId) {
7373
self.slab.retain(|_, tsi| match tsi.source_id {
7474
Some(source_id) => &source_id.module_id() != module_id,
75-
None => false,
75+
// WARNING: Setting to true disables garbage collection for these cases.
76+
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
77+
None => true,
7678
});
7779
self.id_map
7880
.write()
7981
.unwrap()
8082
.retain(|tsi, _| match tsi.source_id {
8183
Some(source_id) => &source_id.module_id() != module_id,
82-
None => false,
84+
// WARNING: Setting to true disables garbage collection for these cases.
85+
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
86+
None => true,
8387
});
8488
}
8589

sway-lsp/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ futures = { version = "0.3", default-features = false, features = [
6060
"async-await",
6161
] }
6262
pretty_assertions = "1.4.0"
63+
rand = "0.8"
6364
regex = "^1.10.2"
6465
sway-lsp-test-utils = { path = "tests/utils" }
6566
tikv-jemallocator = "0.5"

sway-lsp/tests/lib.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,45 @@ async fn go_to_definition_for_consts() {
10161016
lsp::definition_check_with_req_offset(&server, &mut go_to, 11, 38).await;
10171017
}
10181018

1019+
#[tokio::test]
1020+
#[allow(dead_code)]
1021+
async fn did_change_stress_test_random_wait() {
1022+
std::env::set_var("RUST_BACKTRACE", "1");
1023+
let default_panic = std::panic::take_hook();
1024+
std::panic::set_hook(Box::new(move |panic_info| {
1025+
default_panic(panic_info); // Print the panic message
1026+
std::process::exit(1);
1027+
}));
1028+
let (mut service, _) = LspService::build(ServerState::new)
1029+
.custom_method("sway/metrics", ServerState::metrics)
1030+
.finish();
1031+
let example_dir = sway_workspace_dir()
1032+
.join(e2e_language_dir())
1033+
.join("generics_in_contract");
1034+
let uri = init_and_open(&mut service, example_dir.join("src/main.sw")).await;
1035+
let times = 400;
1036+
for version in 0..times {
1037+
//eprintln!("version: {}", version);
1038+
let _ = lsp::did_change_request(&mut service, &uri, version + 1).await;
1039+
if version == 0 {
1040+
service.inner().wait_for_parsing().await;
1041+
}
1042+
// wait for a random amount of time between 1-30ms
1043+
tokio::time::sleep(tokio::time::Duration::from_millis(
1044+
rand::random::<u64>() % 30 + 1,
1045+
))
1046+
.await;
1047+
// there is a 10% chance that a longer 300-1000ms wait will be added
1048+
if rand::random::<u64>() % 10 < 1 {
1049+
tokio::time::sleep(tokio::time::Duration::from_millis(
1050+
rand::random::<u64>() % 700 + 300,
1051+
))
1052+
.await;
1053+
}
1054+
}
1055+
shutdown_and_exit(&mut service).await;
1056+
}
1057+
10191058
#[tokio::test]
10201059
async fn go_to_definition_for_functions() {
10211060
let server = ServerState::default();

0 commit comments

Comments
 (0)