Skip to content

Commit

Permalink
chore: Enable LSP Garbage Collection test for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kayagokalp committed Mar 8, 2024
1 parent a70c746 commit 86e597a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

20 changes: 15 additions & 5 deletions sway-core/src/decl_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,34 @@ macro_rules! decl_engine_clear_module {
self.parents.write().unwrap().retain(|key, _| {
match key {
AssociatedItemDeclId::TraitFn(decl_id) => {
self.get_trait_fn(decl_id).span().source_id().map_or(false, |src_id| &src_id.module_id() != module_id)
// WARNING: Setting to true disables garbage collection for these cases.
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
self.get_trait_fn(decl_id).span().source_id().map_or(true, |src_id| &src_id.module_id() != module_id)
},
AssociatedItemDeclId::Function(decl_id) => {
self.get_function(decl_id).span().source_id().map_or(false, |src_id| &src_id.module_id() != module_id)
// WARNING: Setting to true disables garbage collection for these cases.
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
self.get_function(decl_id).span().source_id().map_or(true, |src_id| &src_id.module_id() != module_id)
},
AssociatedItemDeclId::Type(decl_id) => {
self.get_type(decl_id).span().source_id().map_or(false, |src_id| &src_id.module_id() != module_id)
// WARNING: Setting to true disables garbage collection for these cases.
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
self.get_type(decl_id).span().source_id().map_or(true, |src_id| &src_id.module_id() != module_id)
},
AssociatedItemDeclId::Constant(decl_id) => {
self.get_constant(decl_id).span().source_id().map_or(false, |src_id| &src_id.module_id() != module_id)
// WARNING: Setting to true disables garbage collection for these cases.
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
self.get_constant(decl_id).span().source_id().map_or(true, |src_id| &src_id.module_id() != module_id)
},
}
});

$(
self.$slab.retain(|_k, ty| match ty.span().source_id() {
Some(source_id) => &source_id.module_id() != module_id,
None => false,
// WARNING: Setting to true disables garbage collection for these cases.
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
None => true,
});
)*
}
Expand Down
8 changes: 6 additions & 2 deletions sway-core/src/type_system/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,18 @@ impl TypeEngine {
pub fn clear_module(&mut self, module_id: &ModuleId) {
self.slab.retain(|_, tsi| match tsi.source_id {
Some(source_id) => &source_id.module_id() != module_id,
None => false,
// WARNING: Setting to true disables garbage collection for these cases.
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
None => true,
});
self.id_map
.write()
.unwrap()
.retain(|tsi, _| match tsi.source_id {
Some(source_id) => &source_id.module_id() != module_id,
None => false,
// WARNING: Setting to true disables garbage collection for these cases.
// This should be set back to false once this issue is solved: https://github.com/FuelLabs/sway/issues/5698
None => true,
});
}

Expand Down
1 change: 1 addition & 0 deletions sway-lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ futures = { version = "0.3", default-features = false, features = [
"async-await",
] }
pretty_assertions = "1.4.0"
rand = "0.8"
regex = "^1.10.2"
sway-lsp-test-utils = { path = "tests/utils" }
tikv-jemallocator = "0.5"
Expand Down
39 changes: 39 additions & 0 deletions sway-lsp/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,45 @@ async fn go_to_definition_for_consts() {
lsp::definition_check_with_req_offset(&server, &mut go_to, 11, 38).await;
}

#[tokio::test]
#[allow(dead_code)]
async fn did_change_stress_test_random_wait() {
std::env::set_var("RUST_BACKTRACE", "1");
let default_panic = std::panic::take_hook();
std::panic::set_hook(Box::new(move |panic_info| {
default_panic(panic_info); // Print the panic message
std::process::exit(1);
}));
let (mut service, _) = LspService::build(ServerState::new)
.custom_method("sway/metrics", ServerState::metrics)
.finish();
let example_dir = sway_workspace_dir()
.join(e2e_language_dir())
.join("generics_in_contract");
let uri = init_and_open(&mut service, example_dir.join("src/main.sw")).await;
let times = 400;
for version in 0..times {
//eprintln!("version: {}", version);
let _ = lsp::did_change_request(&mut service, &uri, version + 1).await;
if version == 0 {
service.inner().wait_for_parsing().await;
}
// wait for a random amount of time between 1-30ms
tokio::time::sleep(tokio::time::Duration::from_millis(
rand::random::<u64>() % 30 + 1,
))
.await;
// there is a 10% chance that a longer 300-1000ms wait will be added
if rand::random::<u64>() % 10 < 1 {
tokio::time::sleep(tokio::time::Duration::from_millis(
rand::random::<u64>() % 700 + 300,
))
.await;
}
}
shutdown_and_exit(&mut service).await;
}

#[tokio::test]
async fn go_to_definition_for_functions() {
let server = ServerState::default();
Expand Down

0 comments on commit 86e597a

Please sign in to comment.