Skip to content

Commit

Permalink
Auto merge of #16645 - Veykril:deadlock, r=Veykril
Browse files Browse the repository at this point in the history
fix: Fix deadlock in `recreate_crate_graph` <-> `file_line_index`

Fixes rust-lang/rust-analyzer#16614
  • Loading branch information
bors committed Feb 23, 2024
2 parents 1f54f71 + 9b7284d commit 6648f19
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions crates/rust-analyzer/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
Expand Down

0 comments on commit 6648f19

Please sign in to comment.