Skip to content

Commit e4344f5

Browse files
committed
Auto merge of rust-lang#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).
2 parents e5a1118 + 4d3a0dc commit e4344f5

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

crates/base-db/src/lib.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub trait FileLoader {
5050
/// Text of the file.
5151
fn file_text(&self, file_id: FileId) -> Arc<str>;
5252
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId>;
53-
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
53+
fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]>;
5454
}
5555

5656
/// Database which stores all significant input facts: source code and project
@@ -85,19 +85,20 @@ pub trait SourceDatabaseExt: SourceDatabase {
8585
#[salsa::input]
8686
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
8787

88-
fn source_root_crates(&self, id: SourceRootId) -> Arc<FxHashSet<CrateId>>;
88+
fn source_root_crates(&self, id: SourceRootId) -> Arc<[CrateId]>;
8989
}
9090

91-
fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc<FxHashSet<CrateId>> {
91+
fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc<[CrateId]> {
9292
let graph = db.crate_graph();
93-
let res = graph
93+
graph
9494
.iter()
9595
.filter(|&krate| {
9696
let root_file = graph[krate].root_file_id;
9797
db.file_source_root(root_file) == id
9898
})
99-
.collect();
100-
Arc::new(res)
99+
.collect::<FxHashSet<_>>()
100+
.into_iter()
101+
.collect()
101102
}
102103

103104
/// Silly workaround for cyclic deps between the traits
@@ -114,7 +115,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
114115
source_root.resolve_path(path)
115116
}
116117

117-
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
118+
fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
118119
let _p = profile::span("relevant_crates");
119120
let source_root = self.0.file_source_root(file_id);
120121
self.0.source_root_crates(source_root)

crates/hir-def/src/test_db.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use base_db::{
88
Upcast,
99
};
1010
use hir_expand::{db::ExpandDatabase, InFile};
11-
use rustc_hash::FxHashSet;
1211
use syntax::{algo, ast, AstNode};
1312
use triomphe::Arc;
1413

@@ -76,7 +75,7 @@ impl FileLoader for TestDB {
7675
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
7776
FileLoaderDelegate(self).resolve_path(path)
7877
}
79-
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
78+
fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
8079
FileLoaderDelegate(self).relevant_crates(file_id)
8180
}
8281
}

crates/hir-ty/src/test_db.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use base_db::{
99
use hir_def::{db::DefDatabase, ModuleId};
1010
use hir_expand::db::ExpandDatabase;
1111
use nohash_hasher::IntMap;
12-
use rustc_hash::FxHashSet;
1312
use syntax::TextRange;
1413
use test_utils::extract_annotations;
1514
use triomphe::Arc;
@@ -81,7 +80,7 @@ impl FileLoader for TestDB {
8180
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
8281
FileLoaderDelegate(self).resolve_path(path)
8382
}
84-
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
83+
fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
8584
FileLoaderDelegate(self).relevant_crates(file_id)
8685
}
8786
}

crates/hir/src/symbols.rs

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

crates/ide-db/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl FileLoader for RootDatabase {
124124
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
125125
FileLoaderDelegate(self).resolve_path(path)
126126
}
127-
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
127+
fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
128128
FileLoaderDelegate(self).relevant_crates(file_id)
129129
}
130130
}

0 commit comments

Comments
 (0)