Skip to content

fix: Fix deadlock in recreate_crate_graph <-> file_line_index #16645

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

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all 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
44 changes: 22 additions & 22 deletions crates/rust-analyzer/src/reload.rs
Original file line number Diff line number Diff line change
@@ -522,13 +522,14 @@ impl GlobalState {
}

fn recreate_crate_graph(&mut self, cause: String) {
{
// crate graph construction relies on these paths, record them so when one of them gets
// deleted or created we trigger a reconstruction of the crate graph
let mut crate_graph_file_dependencies = FxHashSet::default();

let (crate_graph, proc_macro_paths, layouts, toolchains) = {
// Create crate graph from all the workspaces
let vfs = &mut self.vfs.write().0;
let loader = &mut self.loader;
// crate graph construction relies on these paths, record them so when one of them gets
// deleted or created we trigger a reconstruction of the crate graph
let mut crate_graph_file_dependencies = FxHashSet::default();

let load = |path: &AbsPath| {
let _p = tracing::span!(tracing::Level::DEBUG, "switch_workspaces::load").entered();
@@ -545,25 +546,24 @@ impl GlobalState {
}
};

let (crate_graph, proc_macro_paths, layouts, toolchains) =
ws_to_crate_graph(&self.workspaces, self.config.extra_env(), load);

let mut change = Change::new();
if self.config.expand_proc_macros() {
change.set_proc_macros(
crate_graph
.iter()
.map(|id| (id, Err("Proc-macros have not been built yet".to_owned())))
.collect(),
);
self.fetch_proc_macros_queue.request_op(cause, proc_macro_paths);
}
change.set_crate_graph(crate_graph);
change.set_target_data_layouts(layouts);
change.set_toolchains(toolchains);
self.analysis_host.apply_change(change);
self.crate_graph_file_dependencies = crate_graph_file_dependencies;
ws_to_crate_graph(&self.workspaces, self.config.extra_env(), load)
};
let mut change = Change::new();
if self.config.expand_proc_macros() {
change.set_proc_macros(
crate_graph
.iter()
.map(|id| (id, Err("Proc-macros have not been built yet".to_owned())))
.collect(),
);
self.fetch_proc_macros_queue.request_op(cause, proc_macro_paths);
}
change.set_crate_graph(crate_graph);
change.set_target_data_layouts(layouts);
change.set_toolchains(toolchains);
self.analysis_host.apply_change(change);
self.crate_graph_file_dependencies = crate_graph_file_dependencies;

self.process_changes();
self.reload_flycheck();
}