Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable LSP Garbage Collection test for CI #5704

Merged
merged 7 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 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,24 @@ 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)
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)
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)
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)
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,
None => true,
});
)*
}
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/decl_engine/parsed_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ macro_rules! decl_engine_clear_module {
let span = $getter(item);
match span.source_id() {
Some(source_id) => &source_id.module_id() != module_id,
None => false,
None => true,
}
});
)*
Expand Down
4 changes: 2 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,14 @@ 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,
None => true,
});
self.id_map
.write()
.unwrap()
.retain(|tsi, _| match tsi.source_id {
Some(source_id) => &source_id.module_id() != module_id,
None => false,
None => true,
});
}

Expand Down
15 changes: 8 additions & 7 deletions sway-lsp/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async fn open(server: &ServerState, entry_point: PathBuf) -> Url {
async fn init_and_open(service: &mut LspService<ServerState>, entry_point: PathBuf) -> Url {
let _ = lsp::initialize_request(service).await;
lsp::initialized_notification(service).await;
eprintln!("entry_point: {:?}", entry_point);
let (uri, sway_program) = load_sway_example(entry_point);
lsp::did_open_notification(service, &uri, &sway_program).await;
uri
Expand Down Expand Up @@ -138,7 +139,7 @@ async fn did_change_stress_test() {
shutdown_and_exit(&mut service).await;
}

// #[tokio::test]
#[tokio::test]
#[allow(dead_code)]
async fn did_change_stress_test_random_wait() {
std::env::set_var("RUST_BACKTRACE", "1");
Expand All @@ -147,15 +148,16 @@ async fn did_change_stress_test_random_wait() {
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 bench_dir = sway_workspace_dir().join("sway-lsp/tests/fixtures/benchmark");
let uri = init_and_open(&mut service, bench_dir.join("src/main.sw")).await;
let times = 40000;
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);
//eprintln!("version: {}", version);
let _ = lsp::did_change_request(&mut service, &uri, version + 1).await;
if version == 0 {
service.inner().wait_for_parsing().await;
Expand All @@ -165,7 +167,6 @@ async fn did_change_stress_test_random_wait() {
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(
Expand Down
Loading