|
2 | 2 | //! metadata` or `rust-project.json`) into representation stored in the salsa |
3 | 3 | //! database -- `CrateGraph`. |
4 | 4 |
|
| 5 | +use std::thread::Builder; |
5 | 6 | use std::{collections::VecDeque, fmt, fs, iter, ops::Deref, sync, thread}; |
6 | 7 |
|
7 | 8 | use anyhow::Context; |
@@ -301,31 +302,39 @@ impl ProjectWorkspace { |
301 | 302 | // We can speed up loading a bit by spawning all of these processes in parallel (especially |
302 | 303 | // on systems were process spawning is delayed) |
303 | 304 | let join = thread::scope(|s| { |
304 | | - let rustc_cfg = s.spawn(|| { |
305 | | - rustc_cfg::get(toolchain_config, targets.first().map(Deref::deref), extra_env) |
306 | | - }); |
307 | | - let target_data = s.spawn(|| { |
308 | | - target_data::get( |
309 | | - toolchain_config, |
310 | | - targets.first().map(Deref::deref), |
311 | | - extra_env, |
312 | | - ).inspect_err(|e| { |
313 | | - tracing::error!(%e, "failed fetching data layout for {cargo_toml:?} workspace") |
| 305 | + let rustc_cfg = Builder::new() |
| 306 | + .name("ProjectWorkspace::rustc_cfg".to_owned()) |
| 307 | + .spawn_scoped(s, || { |
| 308 | + rustc_cfg::get(toolchain_config, targets.first().map(Deref::deref), extra_env) |
314 | 309 | }) |
315 | | - }); |
316 | | - |
317 | | - let rustc_dir = s.spawn(|| { |
318 | | - let rustc_dir = match rustc_source { |
319 | | - Some(RustLibSource::Path(path)) => ManifestPath::try_from(path.clone()) |
320 | | - .map_err(|p| Some(format!("rustc source path is not absolute: {p}"))), |
321 | | - Some(RustLibSource::Discover) => { |
322 | | - sysroot.discover_rustc_src().ok_or_else(|| { |
323 | | - Some("Failed to discover rustc source for sysroot.".to_owned()) |
| 310 | + .expect("failed to spawn thread"); |
| 311 | + let target_data = Builder::new() |
| 312 | + .name("ProjectWorkspace::target_data".to_owned()) |
| 313 | + .spawn_scoped(s, || { |
| 314 | + target_data::get(toolchain_config, targets.first().map(Deref::deref), extra_env) |
| 315 | + .inspect_err(|e| { |
| 316 | + tracing::error!(%e, |
| 317 | + "failed fetching data layout for \ |
| 318 | + {cargo_toml:?} workspace" |
| 319 | + ) |
324 | 320 | }) |
325 | | - } |
326 | | - None => Err(None), |
327 | | - }; |
328 | | - rustc_dir.and_then(|rustc_dir| { |
| 321 | + }) |
| 322 | + .expect("failed to spawn thread"); |
| 323 | + |
| 324 | + let rustc_dir = Builder::new() |
| 325 | + .name("ProjectWorkspace::rustc_dir".to_owned()) |
| 326 | + .spawn_scoped(s, || { |
| 327 | + let rustc_dir = match rustc_source { |
| 328 | + Some(RustLibSource::Path(path)) => ManifestPath::try_from(path.clone()) |
| 329 | + .map_err(|p| Some(format!("rustc source path is not absolute: {p}"))), |
| 330 | + Some(RustLibSource::Discover) => { |
| 331 | + sysroot.discover_rustc_src().ok_or_else(|| { |
| 332 | + Some("Failed to discover rustc source for sysroot.".to_owned()) |
| 333 | + }) |
| 334 | + } |
| 335 | + None => Err(None), |
| 336 | + }; |
| 337 | + rustc_dir.and_then(|rustc_dir| { |
329 | 338 | info!(workspace = %cargo_toml, rustc_dir = %rustc_dir, "Using rustc source"); |
330 | 339 | match FetchMetadata::new( |
331 | 340 | &rustc_dir, |
@@ -359,31 +368,44 @@ impl ProjectWorkspace { |
359 | 368 | Err(e) => { |
360 | 369 | tracing::error!( |
361 | 370 | %e, |
362 | | - "Failed to read Cargo metadata from rustc source at {rustc_dir}", |
| 371 | + "Failed to read Cargo metadata from rustc source \ |
| 372 | + at {rustc_dir}", |
363 | 373 | ); |
364 | 374 | Err(Some(format!( |
365 | | - "Failed to read Cargo metadata from rustc source at {rustc_dir}: {e}" |
| 375 | + "Failed to read Cargo metadata from rustc source \ |
| 376 | + at {rustc_dir}: {e}" |
366 | 377 | ))) |
367 | 378 | } |
368 | 379 | } |
369 | 380 | }) |
370 | | - }); |
371 | | - |
372 | | - let cargo_metadata = s.spawn(|| fetch_metadata.exec(false, progress)); |
373 | | - let loaded_sysroot = s.spawn(|| { |
374 | | - sysroot.load_workspace( |
375 | | - &RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config( |
376 | | - config, |
377 | | - workspace_dir, |
378 | | - &targets, |
379 | | - toolchain.clone(), |
380 | | - )), |
381 | | - config.no_deps, |
382 | | - progress, |
383 | | - ) |
384 | | - }); |
385 | | - let cargo_env = |
386 | | - s.spawn(move || cargo_config_env(cargo_toml, &config_file, &config.extra_env)); |
| 381 | + }) |
| 382 | + .expect("failed to spawn thread"); |
| 383 | + |
| 384 | + let cargo_metadata = Builder::new() |
| 385 | + .name("ProjectWorkspace::cargo_metadata".to_owned()) |
| 386 | + .spawn_scoped(s, || fetch_metadata.exec(false, progress)) |
| 387 | + .expect("failed to spawn thread"); |
| 388 | + let loaded_sysroot = Builder::new() |
| 389 | + .name("ProjectWorkspace::loaded_sysroot".to_owned()) |
| 390 | + .spawn_scoped(s, || { |
| 391 | + sysroot.load_workspace( |
| 392 | + &RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config( |
| 393 | + config, |
| 394 | + workspace_dir, |
| 395 | + &targets, |
| 396 | + toolchain.clone(), |
| 397 | + )), |
| 398 | + config.no_deps, |
| 399 | + progress, |
| 400 | + ) |
| 401 | + }) |
| 402 | + .expect("failed to spawn thread"); |
| 403 | + let cargo_env = Builder::new() |
| 404 | + .name("ProjectWorkspace::cargo_env".to_owned()) |
| 405 | + .spawn_scoped(s, move || { |
| 406 | + cargo_config_env(cargo_toml, &config_file, &config.extra_env) |
| 407 | + }) |
| 408 | + .expect("failed to spawn thread"); |
387 | 409 | thread::Result::Ok(( |
388 | 410 | rustc_cfg.join()?, |
389 | 411 | target_data.join()?, |
|
0 commit comments