Change ids strategy

this is a part of larghish hir refactoring which aims to

* replace per-source-root module trees with per crate trees
* switch from a monotyped DedId to type-specific ids
This commit is contained in:
Aleksey Kladov 2019-01-23 23:14:13 +03:00
parent cfb085ded8
commit 3ab1519cb2
26 changed files with 365 additions and 430 deletions

View file

@ -160,6 +160,7 @@ pub trait FilesDatabase: salsa::Database {
/// Contents of the source root.
#[salsa::input]
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>;
/// The set of "local" (that is, from the current workspace) roots.
/// Files in local roots are assumed to change frequently.
#[salsa::input]
@ -173,6 +174,17 @@ pub trait FilesDatabase: salsa::Database {
fn crate_graph(&self) -> Arc<CrateGraph>;
}
fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
let root = db.source_root(id);
let graph = db.crate_graph();
let res = root
.files
.values()
.filter_map(|&it| graph.crate_id_for_crate_root(it))
.collect::<Vec<_>>();
Arc::new(res)
}
#[cfg(test)]
mod tests {
use super::{CrateGraph, FileId, SmolStr};