Skip to content

Commit a774227

Browse files
authored
Turbopack: use hashbrown HashMaps instead of now-removed std raw entry api (#78032)
[HashMap’s raw_entry api](rust-lang/rust#56167), an unstable nightly feature, was removed from the Rust compiler entirely. This migrates us to use the equivalent API in HashBrown’s HashMap.
1 parent 72af683 commit a774227

File tree

8 files changed

+12
-12
lines changed

8 files changed

+12
-12
lines changed

Diff for: Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: turbopack/crates/turbo-tasks-auto-hash-map/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(hash_raw_entry)]
21
#![feature(hash_extract_if)]
32

43
pub mod map;

Diff for: turbopack/crates/turbopack-trace-server/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bench = false
1515
anyhow = { workspace = true, features = ["backtrace"] }
1616
either = { workspace = true }
1717
flate2 = { version = "1.0.28" }
18+
hashbrown = { workspace = true, features = ["raw"] }
1819
indexmap = { workspace = true, features = ["serde"] }
1920
itertools = { workspace = true }
2021
postcard = { workspace = true }

Diff for: turbopack/crates/turbopack-trace-server/src/bottom_up.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{env, sync::Arc};
22

3-
use rustc_hash::FxHashMap;
3+
use hashbrown::HashMap;
44

55
use crate::{
66
span::{SpanBottomUp, SpanIndex},
@@ -10,15 +10,15 @@ use crate::{
1010
pub struct SpanBottomUpBuilder {
1111
// These values won't change after creation:
1212
pub self_spans: Vec<SpanIndex>,
13-
pub children: FxHashMap<String, SpanBottomUpBuilder>,
13+
pub children: HashMap<String, SpanBottomUpBuilder>,
1414
pub example_span: SpanIndex,
1515
}
1616

1717
impl SpanBottomUpBuilder {
1818
pub fn new(example_span: SpanIndex) -> Self {
1919
Self {
2020
self_spans: vec![],
21-
children: FxHashMap::default(),
21+
children: HashMap::default(),
2222
example_span,
2323
}
2424
}
@@ -42,7 +42,7 @@ pub fn build_bottom_up_graph<'a>(
4242
.ok()
4343
.and_then(|s| s.parse().ok())
4444
.unwrap_or(usize::MAX);
45-
let mut roots = FxHashMap::default();
45+
let mut roots: HashMap<String, SpanBottomUpBuilder> = HashMap::default();
4646

4747
// unfortunately there is a rustc bug that fails the typechecking here
4848
// when using Either<impl Iterator, impl Iterator>. This error appears

Diff for: turbopack/crates/turbopack-trace-server/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(iter_intersperse)]
2-
#![feature(hash_raw_entry)]
32
#![feature(box_patterns)]
43

54
use std::{hash::BuildHasherDefault, path::PathBuf, sync::Arc};

Diff for: turbopack/crates/turbopack-trace-server/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(iter_intersperse)]
2-
#![feature(hash_raw_entry)]
32
#![feature(box_patterns)]
43

54
use std::{hash::BuildHasherDefault, sync::Arc};

Diff for: turbopack/crates/turbopack-trace-server/src/span.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
sync::{Arc, OnceLock},
44
};
55

6-
use rustc_hash::FxHashMap;
6+
use hashbrown::HashMap;
77

88
use crate::timestamp::Timestamp;
99

@@ -64,7 +64,7 @@ pub struct SpanTimeData {
6464
pub struct SpanExtra {
6565
pub graph: OnceLock<Vec<SpanGraphEvent>>,
6666
pub bottom_up: OnceLock<Vec<Arc<SpanBottomUp>>>,
67-
pub search_index: OnceLock<FxHashMap<String, Vec<SpanIndex>>>,
67+
pub search_index: OnceLock<HashMap<String, Vec<SpanIndex>>>,
6868
}
6969

7070
#[derive(Default)]

Diff for: turbopack/crates/turbopack-trace-server/src/span_ref.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use std::{
55
vec,
66
};
77

8+
use hashbrown::HashMap;
89
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
9-
use rustc_hash::{FxHashMap, FxHashSet};
10+
use rustc_hash::FxHashSet;
1011

1112
use crate::{
1213
bottom_up::build_bottom_up_graph,
@@ -414,9 +415,9 @@ impl<'a> SpanRef<'a> {
414415
})
415416
}
416417

417-
fn search_index(&self) -> &FxHashMap<String, Vec<SpanIndex>> {
418+
fn search_index(&self) -> &HashMap<String, Vec<SpanIndex>> {
418419
self.extra().search_index.get_or_init(|| {
419-
let mut index: FxHashMap<String, Vec<SpanIndex>> = FxHashMap::default();
420+
let mut index: HashMap<String, Vec<SpanIndex>> = HashMap::default();
420421
let mut queue = VecDeque::with_capacity(8);
421422
queue.push_back(*self);
422423
while let Some(span) = queue.pop_front() {

0 commit comments

Comments
 (0)