Skip to content
Open
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions rust/extractor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,47 @@ impl<'a> Extractor<'a> {
}
}

/// Computes the def maps of the crates of `files` and their dependencies in dependency order on
/// `threads` threads.
///
/// Otherwise extraction workers compute them lazily, recursively including dependencies, which
/// mostly serializes the workers on them.
fn prime_def_maps<'a>(
db: &RootDatabase,
vfs: &Vfs,
files: impl IntoIterator<Item = &'a Path>,
threads: usize,
) {
if threads <= 1 {
return;
}
let before = Instant::now();
let roots = files
.into_iter()
.filter_map(|file| path_to_file_id(file, vfs))
.flat_map(|file_id| ra_ap_base_db::relevant_crates(db, file_id))
Comment thread
redsun82 marked this conversation as resolved.
Resolved
.map(|&krate| ra_ap_hir::Crate::from(krate));
let (crates, deps) = parallel::dependency_closure(roots, |krate| {
krate.dependencies(db).into_iter().map(|dep| dep.krate)
});
parallel::for_each_in_dependency_order(
threads,
&deps,
|| db.clone(),
|db, i| {
// a failure resurfaces (and is handled) when extraction needs the same def map
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
crates[i].root_module(db);
}));
},
);
Comment thread
redsun82 marked this conversation as resolved.
Resolved
info!(
"considered {} crates for def-map priming in {:?}",
crates.len(),
before.elapsed()
);
}

fn cwd() -> anyhow::Result<AbsPathBuf> {
let path = std::env::current_dir().context("current directory")?;
let utf8_path = Utf8PathBuf::from_path_buf(path)
Expand Down Expand Up @@ -359,6 +400,7 @@ fn main() -> anyhow::Result<()> {
if dependency_extraction_ambiguity {
items.extend(dependency_files(&db, &vfs, &source_files).map(|(_, f)| (f, false)));
}
prime_def_maps(&db, &vfs, items.iter().map(|(f, _)| *f), threads);
debug_assert!(items.iter().map(|(f, _)| f).all_unique());
extractor.run_parallel(
&db,
Expand Down
Loading
Loading