Auto merge of #16339 - Veykril:hashmaps, r=Veykril

Replace SourceRootCrates hashset output with slice for deterministic order

We only iterate over the result, and its pretty small in general so no point for the `HashSet` (additionally this way we get a more defined iteration order).
This commit is contained in:
bors 2024-01-10 14:10:10 +00:00
commit e4344f5fce
5 changed files with 12 additions and 12 deletions

View file

@ -50,7 +50,7 @@ pub trait FileLoader {
/// Text of the file. /// Text of the file.
fn file_text(&self, file_id: FileId) -> Arc<str>; fn file_text(&self, file_id: FileId) -> Arc<str>;
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId>; fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId>;
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>; fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]>;
} }
/// Database which stores all significant input facts: source code and project /// Database which stores all significant input facts: source code and project
@ -85,19 +85,20 @@ pub trait SourceDatabaseExt: SourceDatabase {
#[salsa::input] #[salsa::input]
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>; fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
fn source_root_crates(&self, id: SourceRootId) -> Arc<FxHashSet<CrateId>>; fn source_root_crates(&self, id: SourceRootId) -> Arc<[CrateId]>;
} }
fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc<FxHashSet<CrateId>> { fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc<[CrateId]> {
let graph = db.crate_graph(); let graph = db.crate_graph();
let res = graph graph
.iter() .iter()
.filter(|&krate| { .filter(|&krate| {
let root_file = graph[krate].root_file_id; let root_file = graph[krate].root_file_id;
db.file_source_root(root_file) == id db.file_source_root(root_file) == id
}) })
.collect(); .collect::<FxHashSet<_>>()
Arc::new(res) .into_iter()
.collect()
} }
/// Silly workaround for cyclic deps between the traits /// Silly workaround for cyclic deps between the traits
@ -114,7 +115,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
source_root.resolve_path(path) source_root.resolve_path(path)
} }
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
let _p = profile::span("relevant_crates"); let _p = profile::span("relevant_crates");
let source_root = self.0.file_source_root(file_id); let source_root = self.0.file_source_root(file_id);
self.0.source_root_crates(source_root) self.0.source_root_crates(source_root)

View file

@ -8,7 +8,6 @@ use base_db::{
Upcast, Upcast,
}; };
use hir_expand::{db::ExpandDatabase, InFile}; use hir_expand::{db::ExpandDatabase, InFile};
use rustc_hash::FxHashSet;
use syntax::{algo, ast, AstNode}; use syntax::{algo, ast, AstNode};
use triomphe::Arc; use triomphe::Arc;
@ -76,7 +75,7 @@ impl FileLoader for TestDB {
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> { fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
FileLoaderDelegate(self).resolve_path(path) FileLoaderDelegate(self).resolve_path(path)
} }
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
FileLoaderDelegate(self).relevant_crates(file_id) FileLoaderDelegate(self).relevant_crates(file_id)
} }
} }

View file

@ -9,7 +9,6 @@ use base_db::{
use hir_def::{db::DefDatabase, ModuleId}; use hir_def::{db::DefDatabase, ModuleId};
use hir_expand::db::ExpandDatabase; use hir_expand::db::ExpandDatabase;
use nohash_hasher::IntMap; use nohash_hasher::IntMap;
use rustc_hash::FxHashSet;
use syntax::TextRange; use syntax::TextRange;
use test_utils::extract_annotations; use test_utils::extract_annotations;
use triomphe::Arc; use triomphe::Arc;
@ -81,7 +80,7 @@ impl FileLoader for TestDB {
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> { fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
FileLoaderDelegate(self).resolve_path(path) FileLoaderDelegate(self).resolve_path(path)
} }
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
FileLoaderDelegate(self).relevant_crates(file_id) FileLoaderDelegate(self).relevant_crates(file_id)
} }
} }

View file

@ -165,6 +165,7 @@ impl<'a> SymbolCollector<'a> {
// Record renamed imports. // Record renamed imports.
// FIXME: In case it imports multiple items under different namespaces we just pick one arbitrarily // FIXME: In case it imports multiple items under different namespaces we just pick one arbitrarily
// for now. // for now.
// FIXME: This parses!
for id in scope.imports() { for id in scope.imports() {
let source = id.import.child_source(self.db.upcast()); let source = id.import.child_source(self.db.upcast());
let Some(use_tree_src) = source.value.get(id.idx) else { continue }; let Some(use_tree_src) = source.value.get(id.idx) else { continue };

View file

@ -124,7 +124,7 @@ impl FileLoader for RootDatabase {
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> { fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
FileLoaderDelegate(self).resolve_path(path) FileLoaderDelegate(self).resolve_path(path)
} }
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
FileLoaderDelegate(self).relevant_crates(file_id) FileLoaderDelegate(self).relevant_crates(file_id)
} }
} }