Skip to content

Commit ce73b7c

Browse files
committed
Auto merge of #17771 - Veykril:parallel-vfs-config, r=Veykril
internal: Load VFS config changes in parallel Simple attempt to make some progress f or #17373 No clue if those atomic orderings are right, though I don't think they are really too relevant either. A more complete fix would probably need to replace our `ProjectFolders` handling a bit.
2 parents 25d9e05 + e437db2 commit ce73b7c

File tree

10 files changed

+183
-113
lines changed

10 files changed

+183
-113
lines changed

Cargo.lock

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

crates/load-cargo/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ use project_model::{
1919
CargoConfig, PackageRoot, ProjectManifest, ProjectWorkspace, ProjectWorkspaceKind,
2020
};
2121
use span::Span;
22-
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
22+
use vfs::{
23+
file_set::FileSetConfig,
24+
loader::{Handle, LoadingProgress},
25+
AbsPath, AbsPathBuf, VfsPath,
26+
};
2327

2428
pub struct LoadCargoConfig {
2529
pub load_out_dirs_from_check: bool,
@@ -409,8 +413,8 @@ fn load_crate_graph(
409413
// wait until Vfs has loaded all roots
410414
for task in receiver {
411415
match task {
412-
vfs::loader::Message::Progress { n_done, n_total, .. } => {
413-
if n_done == Some(n_total) {
416+
vfs::loader::Message::Progress { n_done, .. } => {
417+
if n_done == LoadingProgress::Finished {
414418
break;
415419
}
416420
}

crates/rust-analyzer/src/global_state.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::{
3333
lsp_ext,
3434
main_loop::Task,
3535
mem_docs::MemDocs,
36-
op_queue::OpQueue,
36+
op_queue::{Cause, OpQueue},
3737
reload,
3838
target_spec::{CargoTargetSpec, ProjectJsonTargetSpec, TargetSpec},
3939
task_pool::{TaskPool, TaskQueue},
@@ -108,8 +108,8 @@ pub(crate) struct GlobalState {
108108
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, IntMap<FileId, LineEndings>)>>,
109109
pub(crate) vfs_config_version: u32,
110110
pub(crate) vfs_progress_config_version: u32,
111-
pub(crate) vfs_progress_n_total: usize,
112-
pub(crate) vfs_progress_n_done: usize,
111+
pub(crate) vfs_done: bool,
112+
pub(crate) wants_to_switch: Option<Cause>,
113113

114114
/// `workspaces` field stores the data we actually use, while the `OpQueue`
115115
/// stores the result of the last fetch.
@@ -252,8 +252,8 @@ impl GlobalState {
252252
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), IntMap::default()))),
253253
vfs_config_version: 0,
254254
vfs_progress_config_version: 0,
255-
vfs_progress_n_total: 0,
256-
vfs_progress_n_done: 0,
255+
vfs_done: true,
256+
wants_to_switch: None,
257257

258258
workspaces: Arc::from(Vec::new()),
259259
crate_graph_file_dependencies: FxHashSet::default(),

crates/rust-analyzer/src/main_loop.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use lsp_server::{Connection, Notification, Request};
1515
use lsp_types::{notification::Notification as _, TextDocumentIdentifier};
1616
use stdx::thread::ThreadIntent;
1717
use tracing::{error, span, Level};
18-
use vfs::{AbsPathBuf, FileId};
18+
use vfs::{loader::LoadingProgress, AbsPathBuf, FileId};
1919

2020
use crate::{
2121
config::Config,
@@ -381,9 +381,14 @@ impl GlobalState {
381381
}
382382
}
383383
let event_handling_duration = loop_start.elapsed();
384-
385-
let state_changed = self.process_changes();
386-
let memdocs_added_or_removed = self.mem_docs.take_changes();
384+
let (state_changed, memdocs_added_or_removed) = if self.vfs_done {
385+
if let Some(cause) = self.wants_to_switch.take() {
386+
self.switch_workspaces(cause);
387+
}
388+
(self.process_changes(), self.mem_docs.take_changes())
389+
} else {
390+
(false, false)
391+
};
387392

388393
if self.is_quiescent() {
389394
let became_quiescent = !was_quiescent;
@@ -691,7 +696,7 @@ impl GlobalState {
691696
if let Err(e) = self.fetch_workspace_error() {
692697
error!("FetchWorkspaceError:\n{e}");
693698
}
694-
self.switch_workspaces("fetched workspace".to_owned());
699+
self.wants_to_switch = Some("fetched workspace".to_owned());
695700
(Progress::End, None)
696701
}
697702
};
@@ -737,8 +742,9 @@ impl GlobalState {
737742
error!("FetchBuildDataError:\n{e}");
738743
}
739744

740-
self.switch_workspaces("fetched build data".to_owned());
741-
745+
if self.wants_to_switch.is_none() {
746+
self.wants_to_switch = Some("fetched build data".to_owned());
747+
}
742748
(Some(Progress::End), None)
743749
}
744750
};
@@ -791,16 +797,14 @@ impl GlobalState {
791797
let _p = tracing::info_span!("GlobalState::handle_vfs_mgs/progress").entered();
792798
always!(config_version <= self.vfs_config_version);
793799

794-
let state = match n_done {
795-
None => Progress::Begin,
796-
Some(done) if done == n_total => Progress::End,
797-
Some(_) => Progress::Report,
800+
let (n_done, state) = match n_done {
801+
LoadingProgress::Started => (0, Progress::Begin),
802+
LoadingProgress::Progress(n_done) => (n_done.min(n_total), Progress::Report),
803+
LoadingProgress::Finished => (n_total, Progress::End),
798804
};
799-
let n_done = n_done.unwrap_or_default();
800805

801806
self.vfs_progress_config_version = config_version;
802-
self.vfs_progress_n_total = n_total;
803-
self.vfs_progress_n_done = n_done;
807+
self.vfs_done = state == Progress::End;
804808

805809
let mut message = format!("{n_done}/{n_total}");
806810
if let Some(dir) = dir {

crates/rust-analyzer/src/reload.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ pub(crate) enum ProcMacroProgress {
6262

6363
impl GlobalState {
6464
pub(crate) fn is_quiescent(&self) -> bool {
65-
!(self.last_reported_status.is_none()
66-
|| self.fetch_workspaces_queue.op_in_progress()
67-
|| self.fetch_build_data_queue.op_in_progress()
68-
|| self.fetch_proc_macros_queue.op_in_progress()
69-
|| self.discover_workspace_queue.op_in_progress()
70-
|| self.vfs_progress_config_version < self.vfs_config_version
71-
|| self.vfs_progress_n_done < self.vfs_progress_n_total)
65+
self.vfs_done
66+
&& self.last_reported_status.is_some()
67+
&& !self.fetch_workspaces_queue.op_in_progress()
68+
&& !self.fetch_build_data_queue.op_in_progress()
69+
&& !self.fetch_proc_macros_queue.op_in_progress()
70+
&& !self.discover_workspace_queue.op_in_progress()
71+
&& self.vfs_progress_config_version >= self.vfs_config_version
7272
}
7373

7474
pub(crate) fn update_configuration(&mut self, config: Config) {
@@ -102,15 +102,13 @@ impl GlobalState {
102102
}
103103

104104
pub(crate) fn current_status(&self) -> lsp_ext::ServerStatusParams {
105-
let mut status = lsp_ext::ServerStatusParams {
106-
health: lsp_ext::Health::Ok,
107-
quiescent: self.is_quiescent(),
108-
message: None,
109-
};
105+
let quiescent = self.is_quiescent();
106+
let mut status =
107+
lsp_ext::ServerStatusParams { health: lsp_ext::Health::Ok, quiescent, message: None };
110108
let mut message = String::new();
111109

112110
if !self.config.cargo_autoreload(None)
113-
&& self.is_quiescent()
111+
&& quiescent
114112
&& self.fetch_workspaces_queue.op_requested()
115113
&& self.config.discover_workspace_config().is_none()
116114
{
@@ -242,7 +240,7 @@ impl GlobalState {
242240
let discover_command = self.config.discover_workspace_config().cloned();
243241
let is_quiescent = !(self.discover_workspace_queue.op_in_progress()
244242
|| self.vfs_progress_config_version < self.vfs_config_version
245-
|| self.vfs_progress_n_done < self.vfs_progress_n_total);
243+
|| !self.vfs_done);
246244

247245
move |sender| {
248246
let progress = {

crates/rust-analyzer/tests/slow-tests/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ version = \"0.0.0\"
909909

910910
fn out_dirs_check_impl(root_contains_symlink: bool) {
911911
if skip_slow_tests() {
912-
// return;
912+
return;
913913
}
914914

915915
let mut server = Project::with_fixture(

crates/vfs-notify/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ tracing.workspace = true
1616
walkdir = "2.3.2"
1717
crossbeam-channel = "0.5.5"
1818
notify = "6.1.1"
19+
rayon = "1.10.0"
1920

2021
stdx.workspace = true
2122
vfs.workspace = true
2223
paths.workspace = true
24+
rustc-hash.workspace = true
2325

2426
[lints]
25-
workspace = true
27+
workspace = true

0 commit comments

Comments
 (0)