Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fast-graph): Use fxhash instead of ahash to make iteration order consistent #7133

Merged
merged 4 commits into from Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions crates/swc_fast_graph/Cargo.toml
@@ -1,18 +1,18 @@
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
description = "Faster version of petgraph"
edition = "2021"
include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "swc_fast_graph"
repository = "https://github.com/swc-project/swc.git"
version = "0.17.40"
edition = "2021"
include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "swc_fast_graph"
repository = "https://github.com/swc-project/swc.git"
version = "0.17.40"

[lib]
bench = false

[dependencies]
ahash = "0.7.6"
indexmap = "1.6.1"
petgraph = "0.6"
indexmap = "1.6.1"
petgraph = "0.6"
swc_common = { version = "0.29.39", path = "../swc_common" }
rustc-hash = "1.1.0"
11 changes: 7 additions & 4 deletions crates/swc_fast_graph/src/digraph.rs
Expand Up @@ -6,7 +6,7 @@
use std::{
cmp::Ordering,
fmt,
hash::{self, Hash},
hash::{self, BuildHasherDefault, Hash},
iter::{Cloned, DoubleEndedIterator, FromIterator},
marker::PhantomData,
ops::Deref,
Expand All @@ -25,8 +25,11 @@ use petgraph::{
},
Directed, Direction, EdgeType, Incoming, IntoWeightedEdge, Outgoing, Undirected,
};
use rustc_hash::FxHasher;
use swc_common::collections::AHashSet;

type FxBuildHasher = BuildHasherDefault<FxHasher>;

/// A `GraphMap` with directed edges.
///
/// For example, an edge from *1* to *2* is distinct from an edge from *2* to
Expand Down Expand Up @@ -59,8 +62,8 @@ pub type FastDiGraphMap<N, E> = FastGraphMap<N, E, Directed>;
/// Depends on crate feature `graphmap` (default).
#[derive(Clone)]
pub struct FastGraphMap<N, E, Ty> {
nodes: IndexMap<N, Vec<(N, CompactDirection)>, ahash::RandomState>,
edges: IndexMap<(N, N), E, ahash::RandomState>,
nodes: IndexMap<N, Vec<(N, CompactDirection)>, FxBuildHasher>,
edges: IndexMap<(N, N), E, FxBuildHasher>,
ty: PhantomData<Ty>,
}

Expand Down Expand Up @@ -584,7 +587,7 @@ where
Ty: EdgeType,
{
from: N,
edges: &'a IndexMap<(N, N), E, ahash::RandomState>,
edges: &'a IndexMap<(N, N), E, FxBuildHasher>,
iter: Neighbors<'a, N, Ty>,
}

Expand Down