Skip to content

Commit dd22657

Browse files
author
Jonas Schievink
committed
ImportMap: use IndexMap internally
It iterates in insertion order, which makes the ordering more predictable.
1 parent 7e83ed9 commit dd22657

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_hir_def/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ anymap = "0.12.1"
1616
drop_bomb = "0.1.4"
1717
fst = { version = "0.4", default-features = false }
1818
itertools = "0.9.0"
19+
indexmap = "1.4.0"
1920

2021
stdx = { path = "../stdx" }
2122

crates/ra_hir_def/src/import_map.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! A map of all publicly exported items in a crate.
22
3-
use std::{cmp::Ordering, collections::hash_map::Entry, fmt, sync::Arc};
3+
use std::{cmp::Ordering, fmt, hash::BuildHasherDefault, sync::Arc};
44

55
use fst::{self, Streamer};
6+
use indexmap::{map::Entry, IndexMap};
67
use ra_db::CrateId;
7-
use rustc_hash::FxHashMap;
8+
use rustc_hash::FxHasher;
89

910
use crate::{
1011
db::DefDatabase,
@@ -14,6 +15,8 @@ use crate::{
1415
ModuleDefId, ModuleId,
1516
};
1617

18+
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
19+
1720
/// A map from publicly exported items to the path needed to import/name them from a downstream
1821
/// crate.
1922
///
@@ -23,7 +26,7 @@ use crate::{
2326
/// Note that all paths are relative to the containing crate's root, so the crate name still needs
2427
/// to be prepended to the `ModPath` before the path is valid.
2528
pub struct ImportMap {
26-
map: FxHashMap<ItemInNs, ModPath>,
29+
map: FxIndexMap<ItemInNs, ModPath>,
2730

2831
/// List of keys stored in `map`, sorted lexicographically by their `ModPath`. Indexed by the
2932
/// values returned by running `fst`.
@@ -39,7 +42,7 @@ impl ImportMap {
3942
pub fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
4043
let _p = ra_prof::profile("import_map_query");
4144
let def_map = db.crate_def_map(krate);
42-
let mut import_map = FxHashMap::with_capacity_and_hasher(64, Default::default());
45+
let mut import_map = FxIndexMap::with_capacity_and_hasher(64, Default::default());
4346

4447
// We look only into modules that are public(ly reexported), starting with the crate root.
4548
let empty = ModPath { kind: PathKind::Plain, segments: vec![] };
@@ -588,19 +591,19 @@ mod tests {
588591

589592
let res = search_dependencies_of(ra_fixture, "main", Query::new("fmt"));
590593
assert_snapshot!(res, @r###"
591-
dep::Fmt (v)
592594
dep::fmt (t)
593595
dep::Fmt (t)
596+
dep::Fmt (v)
594597
dep::Fmt (m)
595598
dep::fmt::Display (t)
596599
dep::format (v)
597600
"###);
598601

599602
let res = search_dependencies_of(ra_fixture, "main", Query::new("fmt").anchor_end());
600603
assert_snapshot!(res, @r###"
601-
dep::Fmt (v)
602604
dep::fmt (t)
603605
dep::Fmt (t)
606+
dep::Fmt (v)
604607
dep::Fmt (m)
605608
"###);
606609
}
@@ -618,17 +621,17 @@ mod tests {
618621
let res = search_dependencies_of(ra_fixture, "main", Query::new("FMT"));
619622

620623
assert_snapshot!(res, @r###"
621-
dep::FMT (v)
622-
dep::FMT (t)
623624
dep::fmt (t)
624625
dep::fmt (v)
626+
dep::FMT (t)
627+
dep::FMT (v)
625628
"###);
626629

627630
let res = search_dependencies_of(ra_fixture, "main", Query::new("FMT").case_sensitive());
628631

629632
assert_snapshot!(res, @r###"
630-
dep::FMT (v)
631633
dep::FMT (t)
634+
dep::FMT (v)
632635
"###);
633636
}
634637

0 commit comments

Comments
 (0)