refactor: Use ahash from swc_common in more places (#7815)

**Description:**

Uses ahash from swc_common in more places. This allows for more easily
swapping out ahash with rustc_hash.
This commit is contained in:
David Sherret 2023-08-16 10:16:52 -04:00 committed by GitHub
parent 2dc88ef147
commit b43e38d3f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 82 additions and 88 deletions

14
Cargo.lock generated
View File

@ -3527,7 +3527,6 @@ dependencies = [
name = "swc" name = "swc"
version = "0.264.57" version = "0.264.57"
dependencies = [ dependencies = [
"ahash 0.8.3",
"ansi_term", "ansi_term",
"anyhow", "anyhow",
"base64 0.13.1", "base64 0.13.1",
@ -3598,7 +3597,6 @@ dependencies = [
name = "swc_bundler" name = "swc_bundler"
version = "0.217.48" version = "0.217.48"
dependencies = [ dependencies = [
"ahash 0.8.3",
"anyhow", "anyhow",
"crc", "crc",
"dashmap", "dashmap",
@ -4026,7 +4024,6 @@ dependencies = [
name = "swc_ecma_lints" name = "swc_ecma_lints"
version = "0.85.21" version = "0.85.21"
dependencies = [ dependencies = [
"ahash 0.8.3",
"auto_impl", "auto_impl",
"dashmap", "dashmap",
"parking_lot", "parking_lot",
@ -4049,7 +4046,6 @@ dependencies = [
name = "swc_ecma_loader" name = "swc_ecma_loader"
version = "0.43.21" version = "0.43.21"
dependencies = [ dependencies = [
"ahash 0.8.3",
"anyhow", "anyhow",
"dashmap", "dashmap",
"lazy_static", "lazy_static",
@ -4070,7 +4066,6 @@ dependencies = [
name = "swc_ecma_minifier" name = "swc_ecma_minifier"
version = "0.184.48" version = "0.184.48"
dependencies = [ dependencies = [
"ahash 0.8.3",
"ansi_term", "ansi_term",
"anyhow", "anyhow",
"arrayvec", "arrayvec",
@ -4138,7 +4133,6 @@ dependencies = [
name = "swc_ecma_preset_env" name = "swc_ecma_preset_env"
version = "0.198.37" version = "0.198.37"
dependencies = [ dependencies = [
"ahash 0.8.3",
"anyhow", "anyhow",
"criterion", "criterion",
"dashmap", "dashmap",
@ -4269,7 +4263,6 @@ dependencies = [
name = "swc_ecma_transforms_compat" name = "swc_ecma_transforms_compat"
version = "0.156.28" version = "0.156.28"
dependencies = [ dependencies = [
"ahash 0.8.3",
"arrayvec", "arrayvec",
"indexmap", "indexmap",
"is-macro", "is-macro",
@ -4310,7 +4303,6 @@ name = "swc_ecma_transforms_module"
version = "0.173.33" version = "0.173.33"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"ahash 0.8.3",
"anyhow", "anyhow",
"bitflags 2.3.2", "bitflags 2.3.2",
"indexmap", "indexmap",
@ -4339,7 +4331,6 @@ dependencies = [
name = "swc_ecma_transforms_optimization" name = "swc_ecma_transforms_optimization"
version = "0.190.35" version = "0.190.35"
dependencies = [ dependencies = [
"ahash 0.8.3",
"dashmap", "dashmap",
"indexmap", "indexmap",
"once_cell", "once_cell",
@ -4394,7 +4385,6 @@ dependencies = [
name = "swc_ecma_transforms_react" name = "swc_ecma_transforms_react"
version = "0.176.33" version = "0.176.33"
dependencies = [ dependencies = [
"ahash 0.8.3",
"base64 0.13.1", "base64 0.13.1",
"dashmap", "dashmap",
"indexmap", "indexmap",
@ -4468,7 +4458,6 @@ dependencies = [
name = "swc_ecma_usage_analyzer" name = "swc_ecma_usage_analyzer"
version = "0.16.20" version = "0.16.20"
dependencies = [ dependencies = [
"ahash 0.8.3",
"indexmap", "indexmap",
"rustc-hash", "rustc-hash",
"swc_atoms", "swc_atoms",
@ -4600,9 +4589,9 @@ dependencies = [
name = "swc_graph_analyzer" name = "swc_graph_analyzer"
version = "0.20.22" version = "0.20.22"
dependencies = [ dependencies = [
"ahash 0.8.3",
"auto_impl", "auto_impl",
"petgraph", "petgraph",
"swc_common",
"swc_fast_graph", "swc_fast_graph",
"testing", "testing",
"tracing", "tracing",
@ -4778,7 +4767,6 @@ dependencies = [
name = "swc_node_comments" name = "swc_node_comments"
version = "0.18.19" version = "0.18.19"
dependencies = [ dependencies = [
"ahash 0.8.3",
"dashmap", "dashmap",
"swc_atoms", "swc_atoms",
"swc_common", "swc_common",

View File

@ -48,7 +48,6 @@ plugin_transform_host_native = [
] ]
[dependencies] [dependencies]
ahash = "0.8.3"
anyhow = "1" anyhow = "1"
base64 = "0.13.0" base64 = "0.13.0"
dashmap = "5.4.0" dashmap = "5.4.0"

View File

@ -24,7 +24,7 @@ use swc_atoms::JsWord;
use swc_cached::regex::CachedRegex; use swc_cached::regex::CachedRegex;
use swc_common::{ use swc_common::{
chain, chain,
collections::{AHashMap, AHashSet}, collections::{AHashMap, AHashSet, ARandomState},
comments::{Comments, SingleThreadedComments}, comments::{Comments, SingleThreadedComments},
errors::Handler, errors::Handler,
plugin::metadata::TransformPluginMetadataContext, plugin::metadata::TransformPluginMetadataContext,
@ -1497,7 +1497,7 @@ impl Default for ErrorFormat {
} }
/// `paths` section of `tsconfig.json`. /// `paths` section of `tsconfig.json`.
pub type Paths = IndexMap<String, Vec<String>, ahash::RandomState>; pub type Paths = IndexMap<String, Vec<String>, ARandomState>;
pub(crate) type CompiledPaths = Vec<(String, Vec<String>)>; pub(crate) type CompiledPaths = Vec<(String, Vec<String>)>;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@ -1746,7 +1746,7 @@ pub struct ErrorConfig {
#[serde(deny_unknown_fields, rename_all = "camelCase")] #[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct GlobalPassOption { pub struct GlobalPassOption {
#[serde(default)] #[serde(default)]
pub vars: IndexMap<JsWord, JsWord, ahash::RandomState>, pub vars: IndexMap<JsWord, JsWord, ARandomState>,
#[serde(default)] #[serde(default)]
pub envs: GlobalInliningPassEnvs, pub envs: GlobalInliningPassEnvs,
@ -1826,7 +1826,7 @@ impl GlobalPassOption {
} else { } else {
match &self.envs { match &self.envs {
GlobalInliningPassEnvs::List(env_list) => { GlobalInliningPassEnvs::List(env_list) => {
static CACHE: Lazy<DashMap<Vec<String>, ValuesMap, ahash::RandomState>> = static CACHE: Lazy<DashMap<Vec<String>, ValuesMap, ARandomState>> =
Lazy::new(Default::default); Lazy::new(Default::default);
let cache_key = env_list.iter().cloned().collect::<Vec<_>>(); let cache_key = env_list.iter().cloned().collect::<Vec<_>>();
@ -1847,9 +1847,8 @@ impl GlobalPassOption {
} }
GlobalInliningPassEnvs::Map(map) => { GlobalInliningPassEnvs::Map(map) => {
static CACHE: Lazy< static CACHE: Lazy<DashMap<Vec<(JsWord, JsWord)>, ValuesMap, ARandomState>> =
DashMap<Vec<(JsWord, JsWord)>, ValuesMap, ahash::RandomState>, Lazy::new(Default::default);
> = Lazy::new(Default::default);
let cache_key = self let cache_key = self
.vars .vars
@ -1873,7 +1872,7 @@ impl GlobalPassOption {
}; };
let global_exprs = { let global_exprs = {
static CACHE: Lazy<DashMap<Vec<(JsWord, JsWord)>, GlobalExprMap, ahash::RandomState>> = static CACHE: Lazy<DashMap<Vec<(JsWord, JsWord)>, GlobalExprMap, ARandomState>> =
Lazy::new(Default::default); Lazy::new(Default::default);
let cache_key = self let cache_key = self
@ -1904,7 +1903,7 @@ impl GlobalPassOption {
}; };
let global_map = { let global_map = {
static CACHE: Lazy<DashMap<Vec<(JsWord, JsWord)>, ValuesMap, ahash::RandomState>> = static CACHE: Lazy<DashMap<Vec<(JsWord, JsWord)>, ValuesMap, ARandomState>> =
Lazy::new(Default::default); Lazy::new(Default::default);
let cache_key = self let cache_key = self
@ -1943,7 +1942,7 @@ fn default_env_name() -> String {
} }
fn build_resolver(base_url: PathBuf, paths: CompiledPaths) -> Box<SwcImportResolver> { fn build_resolver(base_url: PathBuf, paths: CompiledPaths) -> Box<SwcImportResolver> {
static CACHE: Lazy<DashMap<(PathBuf, CompiledPaths), SwcImportResolver, ahash::RandomState>> = static CACHE: Lazy<DashMap<(PathBuf, CompiledPaths), SwcImportResolver, ARandomState>> =
Lazy::new(Default::default); Lazy::new(Default::default);
if let Some(cached) = CACHE.get(&(base_url.clone(), paths.clone())) { if let Some(cached) = CACHE.get(&(base_url.clone(), paths.clone())) {

View File

@ -24,7 +24,6 @@ concurrent = ["swc_common/concurrent", "dashmap", "rayon", "indexmap/rayon"]
default = [] default = []
[dependencies] [dependencies]
ahash = "0.8"
anyhow = "1" anyhow = "1"
crc = "2.1.0" crc = "2.1.0"
dashmap = { version = "5.4.0", optional = true } dashmap = { version = "5.4.0", optional = true }

View File

@ -5,7 +5,7 @@ use indexmap::IndexSet;
use petgraph::EdgeDirection; use petgraph::EdgeDirection;
use swc_atoms::js_word; use swc_atoms::js_word;
use swc_common::{ use swc_common::{
collections::{AHashMap, AHashSet}, collections::{AHashMap, AHashSet, ARandomState},
sync::Lock, sync::Lock,
FileName, SyntaxContext, DUMMY_SP, FileName, SyntaxContext, DUMMY_SP,
}; };
@ -138,7 +138,7 @@ where
graph: &ModuleGraph, graph: &ModuleGraph,
start: ModuleId, start: ModuleId,
dejavu: &mut AHashSet<ModuleId>, dejavu: &mut AHashSet<ModuleId>,
) -> IndexSet<ModuleId, ahash::RandomState> { ) -> IndexSet<ModuleId, ARandomState> {
let mut set = IndexSet::default(); let mut set = IndexSet::default();
for dep in graph.neighbors_directed(start, Outgoing) { for dep in graph.neighbors_directed(start, Outgoing) {

View File

@ -1,6 +1,6 @@
use indexmap::IndexMap; use indexmap::IndexMap;
use swc_atoms::{js_word, JsWord}; use swc_atoms::{js_word, JsWord};
use swc_common::{FileName, SyntaxContext}; use swc_common::{collections::ARandomState, FileName, SyntaxContext};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_utils::find_pat_ids; use swc_ecma_utils::find_pat_ids;
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
@ -42,7 +42,7 @@ where
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub(super) struct RawExports { pub(super) struct RawExports {
/// Key is None if it's exported from the module itself. /// Key is None if it's exported from the module itself.
pub items: IndexMap<Option<Str>, Vec<Specifier>, ahash::RandomState>, pub items: IndexMap<Option<Str>, Vec<Specifier>, ARandomState>,
} }
#[derive(Debug, Default)] #[derive(Debug, Default)]

View File

@ -1,10 +1,9 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use ahash::AHashMap;
use anyhow::Error; use anyhow::Error;
use relative_path::RelativePath; use relative_path::RelativePath;
use swc_atoms::js_word; use swc_atoms::js_word;
use swc_common::{util::move_map::MoveMap, FileName, Mark, DUMMY_SP}; use swc_common::{collections::AHashMap, util::move_map::MoveMap, FileName, Mark, DUMMY_SP};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_transforms_base::{ use swc_ecma_transforms_base::{
fixer::fixer, fixer::fixer,

View File

@ -3,7 +3,7 @@ use std::path::PathBuf;
use anyhow::Error; use anyhow::Error;
use indexmap::IndexMap; use indexmap::IndexMap;
use swc_common::{sync::Lrc, FileName, SourceMap, Span, GLOBALS}; use swc_common::{collections::ARandomState, sync::Lrc, FileName, SourceMap, Span, GLOBALS};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_parser::{lexer::Lexer, Parser, StringInput}; use swc_ecma_parser::{lexer::Lexer, Parser, StringInput};
use swc_ecma_utils::drop_span; use swc_ecma_utils::drop_span;
@ -19,7 +19,7 @@ pub(crate) struct Tester<'a> {
pub struct Loader { pub struct Loader {
cm: Lrc<SourceMap>, cm: Lrc<SourceMap>,
files: IndexMap<String, String, ahash::RandomState>, files: IndexMap<String, String, ARandomState>,
} }
impl Load for Loader { impl Load for Loader {
@ -108,7 +108,7 @@ pub(crate) fn suite() -> TestBuilder {
#[derive(Default)] #[derive(Default)]
pub(crate) struct TestBuilder { pub(crate) struct TestBuilder {
files: IndexMap<String, String, ahash::RandomState>, files: IndexMap<String, String, ARandomState>,
} }
impl TestBuilder { impl TestBuilder {

View File

@ -2,7 +2,11 @@ use std::{collections::VecDeque, iter::from_fn, mem::take, time::Instant};
use indexmap::IndexSet; use indexmap::IndexSet;
use petgraph::EdgeDirection::Outgoing; use petgraph::EdgeDirection::Outgoing;
use swc_common::{collections::AHashSet, sync::Lrc, SourceMap, SyntaxContext}; use swc_common::{
collections::{AHashSet, ARandomState},
sync::Lrc,
SourceMap, SyntaxContext,
};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_utils::prepend_stmts; use swc_ecma_utils::prepend_stmts;
@ -133,7 +137,7 @@ fn cycles_for(
cycles: &[Vec<ModuleId>], cycles: &[Vec<ModuleId>],
id: ModuleId, id: ModuleId,
checked: &mut Vec<ModuleId>, checked: &mut Vec<ModuleId>,
) -> IndexSet<ModuleId, ahash::RandomState> { ) -> IndexSet<ModuleId, ARandomState> {
checked.push(id); checked.push(id);
let mut v = cycles let mut v = cycles
.iter() .iter()

View File

@ -4,7 +4,7 @@ use indexmap::IndexSet;
use petgraph::EdgeDirection::{Incoming as Dependants, Outgoing as Dependencies}; use petgraph::EdgeDirection::{Incoming as Dependants, Outgoing as Dependencies};
use swc_atoms::js_word; use swc_atoms::js_word;
use swc_common::{ use swc_common::{
collections::{AHashMap, AHashSet}, collections::{AHashMap, AHashSet, ARandomState},
sync::Lrc, sync::Lrc,
util::take::Take, util::take::Take,
SourceMap, Spanned, SyntaxContext, SourceMap, Spanned, SyntaxContext,
@ -501,11 +501,11 @@ impl Visit for InitializerFinder {
/// But we care about modifications. /// But we care about modifications.
#[derive(Default)] #[derive(Default)]
struct RequirementCalculator { struct RequirementCalculator {
required_ids: IndexSet<(Id, Required), ahash::RandomState>, required_ids: IndexSet<(Id, Required), ARandomState>,
/// While bundling, there can be two bindings with same name and syntax /// While bundling, there can be two bindings with same name and syntax
/// context, in case of wrapped es modules. We exclude them from dependency /// context, in case of wrapped es modules. We exclude them from dependency
/// graph. /// graph.
excluded: IndexSet<Id, ahash::RandomState>, excluded: IndexSet<Id, ARandomState>,
in_weak: bool, in_weak: bool,
in_var_decl: bool, in_var_decl: bool,

View File

@ -101,7 +101,7 @@ where
V: Clone, V: Clone,
{ {
#[cfg(feature = "concurrent")] #[cfg(feature = "concurrent")]
inner: dashmap::DashMap<K, V, ahash::RandomState>, inner: dashmap::DashMap<K, V, swc_common::collections::ARandomState>,
#[cfg(not(feature = "concurrent"))] #[cfg(not(feature = "concurrent"))]
inner: std::cell::RefCell<swc_common::collections::AHashMap<K, V>>, inner: std::cell::RefCell<swc_common::collections::AHashMap<K, V>>,
} }

View File

@ -23,7 +23,7 @@ concurrent = ["parking_lot"]
debug = [] debug = []
default = [] default = []
diagnostic-serde = [] diagnostic-serde = []
perf = ["parking_lot"] perf = []
plugin-base = ["__plugin", "anyhow", "rkyv-impl", "diagnostic-serde"] plugin-base = ["__plugin", "anyhow", "rkyv-impl", "diagnostic-serde"]
plugin-mode = ["__plugin_mode", "plugin-base"] plugin-mode = ["__plugin_mode", "plugin-base"]
plugin-rt = ["__plugin_rt", "plugin-base"] plugin-rt = ["__plugin_rt", "plugin-base"]

View File

@ -12,16 +12,20 @@ mod fxhash {
use rustc_hash::FxHasher; use rustc_hash::FxHasher;
pub type AHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>; pub type ARandomState = BuildHasherDefault<FxHasher>;
pub type AHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>; pub type AHashMap<K, V> = HashMap<K, V, ARandomState>;
pub type AHashSet<V> = HashSet<V, ARandomState>;
} }
#[cfg(not(feature = "perf"))] #[cfg(not(feature = "perf"))]
mod ahash { mod ahash {
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
pub type AHashMap<K, V> = HashMap<K, V, ahash::RandomState>; pub type ARandomState = ahash::RandomState;
pub type AHashSet<V> = HashSet<V, ahash::RandomState>; pub type AHashMap<K, V> = HashMap<K, V, ARandomState>;
pub type AHashSet<V> = HashSet<V, ARandomState>;
} }

View File

@ -13,7 +13,6 @@ version = "0.85.21"
bench = false bench = false
[dependencies] [dependencies]
ahash = "0.8"
auto_impl = "1.1.0" auto_impl = "1.1.0"
dashmap = "5.4.0" dashmap = "5.4.0"
parking_lot = "0.12.1" parking_lot = "0.12.1"

View File

@ -1,7 +1,7 @@
use dashmap::DashMap; use dashmap::DashMap;
use regex::Regex; use regex::Regex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use swc_common::{errors::HANDLER, sync::Lazy, Span}; use swc_common::{collections::ARandomState, errors::HANDLER, sync::Lazy, Span};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
@ -76,7 +76,7 @@ impl DotNotation {
} }
if let Some(pattern) = &self.pattern { if let Some(pattern) = &self.pattern {
static REGEX_CACHE: Lazy<DashMap<String, Regex, ahash::RandomState>> = static REGEX_CACHE: Lazy<DashMap<String, Regex, ARandomState>> =
Lazy::new(Default::default); Lazy::new(Default::default);
if !REGEX_CACHE.contains_key(pattern) { if !REGEX_CACHE.contains_key(pattern) {

View File

@ -2,7 +2,7 @@ use dashmap::DashMap;
use regex::Regex; use regex::Regex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use swc_common::{ use swc_common::{
collections::{AHashMap, AHashSet}, collections::{AHashMap, AHashSet, ARandomState},
errors::HANDLER, errors::HANDLER,
sync::Lazy, sync::Lazy,
Span, Span,
@ -121,7 +121,7 @@ impl NoParamReassign {
} }
if let Some(ignore_names_patterns) = &self.ignore_names_patterns { if let Some(ignore_names_patterns) = &self.ignore_names_patterns {
static REGEX_CACHE: Lazy<DashMap<String, Regex, ahash::RandomState>> = static REGEX_CACHE: Lazy<DashMap<String, Regex, ARandomState>> =
Lazy::new(Default::default); Lazy::new(Default::default);
let sym = &*ident.sym; let sym = &*ident.sym;

View File

@ -25,7 +25,6 @@ node = ["normpath", "serde_json", "dashmap", "once_cell", "path-clean"]
tsc = ["dashmap", "once_cell", "swc_cached"] tsc = ["dashmap", "once_cell", "swc_cached"]
[dependencies] [dependencies]
ahash = "0.8.3"
anyhow = "1.0.71" anyhow = "1.0.71"
dashmap = { version = "5.4.0", optional = true } dashmap = { version = "5.4.0", optional = true }
lru = { version = "0.10.0", optional = true } lru = { version = "0.10.0", optional = true }

View File

@ -18,7 +18,7 @@ use path_clean::PathClean;
use pathdiff::diff_paths; use pathdiff::diff_paths;
use serde::Deserialize; use serde::Deserialize;
use swc_common::{ use swc_common::{
collections::{AHashMap, AHashSet}, collections::{AHashMap, AHashSet, ARandomState},
FileName, FileName,
}; };
use tracing::{debug, trace, Level}; use tracing::{debug, trace, Level};
@ -33,7 +33,7 @@ static PACKAGE: &str = "package.json";
/// directory containing the package.json file which is important /// directory containing the package.json file which is important
/// to ensure we only apply these `browser` rules to modules in /// to ensure we only apply these `browser` rules to modules in
/// the owning package. /// the owning package.
static BROWSER_CACHE: Lazy<DashMap<PathBuf, BrowserCache, ahash::RandomState>> = static BROWSER_CACHE: Lazy<DashMap<PathBuf, BrowserCache, ARandomState>> =
Lazy::new(Default::default); Lazy::new(Default::default);
#[derive(Debug, Default)] #[derive(Debug, Default)]

View File

@ -33,7 +33,6 @@ serde-impl = []
trace-ast = [] trace-ast = []
[dependencies] [dependencies]
ahash = "0.8.3"
arrayvec = "0.7.2" arrayvec = "0.7.2"
backtrace = { version = "0.3.61", optional = true } backtrace = { version = "0.3.61", optional = true }
indexmap = "1.9.3" indexmap = "1.9.3"

View File

@ -7,7 +7,7 @@ use indexmap::IndexSet;
use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
use swc_atoms::JsWord; use swc_atoms::JsWord;
use swc_common::{ use swc_common::{
collections::{AHashMap, AHashSet}, collections::{AHashMap, AHashSet, ARandomState},
SyntaxContext, SyntaxContext,
}; };
use swc_ecma_ast::*; use swc_ecma_ast::*;
@ -38,7 +38,7 @@ pub(crate) struct ProgramData {
pub(crate) scopes: FxHashMap<SyntaxContext, ScopeData>, pub(crate) scopes: FxHashMap<SyntaxContext, ScopeData>,
initialized_vars: IndexSet<Id, ahash::RandomState>, initialized_vars: IndexSet<Id, ARandomState>,
} }
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]

View File

@ -16,7 +16,6 @@ default = ["serde-impl"]
serde-impl = ["serde"] serde-impl = ["serde"]
[dependencies] [dependencies]
ahash = "0.8.3"
anyhow = "1" anyhow = "1"
dashmap = "5.4.0" dashmap = "5.4.0"
indexmap = "1.9.3" indexmap = "1.9.3"

View File

@ -1,7 +1,7 @@
use indexmap::IndexSet; use indexmap::IndexSet;
use preset_env_base::{version::should_enable, Versions}; use preset_env_base::{version::should_enable, Versions};
use swc_atoms::js_word; use swc_atoms::js_word;
use swc_common::DUMMY_SP; use swc_common::{collections::ARandomState, DUMMY_SP};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
@ -11,7 +11,7 @@ use super::builtin::BUILTINS;
pub struct Entry { pub struct Entry {
is_any_target: bool, is_any_target: bool,
target: Versions, target: Versions,
pub imports: IndexSet<&'static str, ahash::RandomState>, pub imports: IndexSet<&'static str, ARandomState>,
} }
impl Entry { impl Entry {

View File

@ -1,7 +1,7 @@
use indexmap::IndexSet; use indexmap::IndexSet;
use preset_env_base::{version::should_enable, Versions}; use preset_env_base::{version::should_enable, Versions};
use swc_atoms::{js_word, JsWord}; use swc_atoms::{js_word, JsWord};
use swc_common::DUMMY_SP; use swc_common::{collections::ARandomState, DUMMY_SP};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
@ -19,7 +19,7 @@ mod entry;
pub(crate) struct UsageVisitor { pub(crate) struct UsageVisitor {
is_any_target: bool, is_any_target: bool,
target: Versions, target: Versions,
pub required: IndexSet<&'static str, ahash::RandomState>, pub required: IndexSet<&'static str, ARandomState>,
} }
impl UsageVisitor { impl UsageVisitor {

View File

@ -5,7 +5,10 @@ use preset_env_base::{
Versions, Versions,
}; };
use swc_atoms::js_word; use swc_atoms::js_word;
use swc_common::{collections::AHashMap, DUMMY_SP}; use swc_common::{
collections::{AHashMap, ARandomState},
DUMMY_SP,
};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_visit::VisitMut; use swc_ecma_visit::VisitMut;
@ -33,7 +36,7 @@ pub struct Entry {
is_any_target: bool, is_any_target: bool,
target: Versions, target: Versions,
corejs_version: Version, corejs_version: Version,
pub imports: IndexSet<&'static str, ahash::RandomState>, pub imports: IndexSet<&'static str, ARandomState>,
remove_regenerator: bool, remove_regenerator: bool,
} }

View File

@ -1,7 +1,7 @@
use indexmap::IndexSet; use indexmap::IndexSet;
use preset_env_base::version::{should_enable, Version}; use preset_env_base::version::{should_enable, Version};
use swc_atoms::{js_word, JsWord}; use swc_atoms::{js_word, JsWord};
use swc_common::DUMMY_SP; use swc_common::{collections::ARandomState, DUMMY_SP};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
@ -20,7 +20,7 @@ pub(crate) struct UsageVisitor {
is_any_target: bool, is_any_target: bool,
target: Versions, target: Versions,
corejs_version: Version, corejs_version: Version,
pub required: IndexSet<&'static str, ahash::RandomState>, pub required: IndexSet<&'static str, ARandomState>,
} }
impl UsageVisitor { impl UsageVisitor {

View File

@ -20,7 +20,6 @@ concurrent = [
] ]
[dependencies] [dependencies]
ahash = "0.8.3"
arrayvec = "0.7.2" arrayvec = "0.7.2"
indexmap = "1.9.3" indexmap = "1.9.3"
is-macro = "0.3.0" is-macro = "0.3.0"

View File

@ -1,11 +1,13 @@
use std::mem::take; use std::mem::take;
use ahash::AHashSet;
use indexmap::IndexMap; use indexmap::IndexMap;
use smallvec::SmallVec; use smallvec::SmallVec;
use swc_atoms::{js_word, JsWord}; use swc_atoms::{js_word, JsWord};
use swc_common::{ use swc_common::{
chain, collections::AHashMap, util::take::Take, Mark, Spanned, SyntaxContext, DUMMY_SP, chain,
collections::{AHashMap, AHashSet},
util::take::Take,
Mark, Spanned, SyntaxContext, DUMMY_SP,
}; };
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_transforms_base::helper; use swc_ecma_transforms_base::helper;
@ -160,7 +162,7 @@ impl BlockScoping {
has_return: false, has_return: false,
has_yield: false, has_yield: false,
label: IndexMap::new(), label: IndexMap::new(),
inner_label: AHashSet::new(), inner_label: AHashSet::default(),
mutated, mutated,
in_switch_case: false, in_switch_case: false,
in_nested_loop: false, in_nested_loop: false,

View File

@ -1,6 +1,9 @@
use indexmap::IndexMap; use indexmap::IndexMap;
use swc_atoms::JsWord; use swc_atoms::JsWord;
use swc_common::{collections::AHashMap, Mark, SyntaxContext}; use swc_common::{
collections::{AHashMap, ARandomState},
Mark, SyntaxContext,
};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_transforms_base::scope::ScopeKind; use swc_ecma_transforms_base::scope::ScopeKind;
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
@ -24,7 +27,7 @@ struct BlockScopedVars {
struct Scope { struct Scope {
kind: ScopeKind, kind: ScopeKind,
vars: IndexMap<Id, VarDeclKind, ahash::RandomState>, vars: IndexMap<Id, VarDeclKind, ARandomState>,
usages: Vec<Id>, usages: Vec<Id>,
children: Vec<Scope>, children: Vec<Scope>,
@ -34,7 +37,7 @@ struct Scope {
struct ParentScope<'a> { struct ParentScope<'a> {
parent: Option<&'a ParentScope<'a>>, parent: Option<&'a ParentScope<'a>>,
vars: &'a IndexMap<Id, VarDeclKind, ahash::RandomState>, vars: &'a IndexMap<Id, VarDeclKind, ARandomState>,
} }
#[swc_trace] #[swc_trace]

View File

@ -1,7 +1,10 @@
use std::iter; use std::iter;
use serde::Deserialize; use serde::Deserialize;
use swc_common::{comments::Comments, util::take::Take, BytePos, Mark, Span, Spanned, DUMMY_SP}; use swc_common::{
collections::ARandomState, comments::Comments, util::take::Take, BytePos, Mark, Span, Spanned,
DUMMY_SP,
};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_transforms_base::{helper, native::is_native, perf::Check}; use swc_ecma_transforms_base::{helper, native::is_native, perf::Check};
use swc_ecma_transforms_classes::super_field::SuperFieldAccessFolder; use swc_ecma_transforms_classes::super_field::SuperFieldAccessFolder;
@ -42,7 +45,7 @@ where
}) })
} }
type IndexMap<K, V> = indexmap::IndexMap<K, V, ahash::RandomState>; type IndexMap<K, V> = indexmap::IndexMap<K, V, ARandomState>;
/// `@babel/plugin-transform-classes` /// `@babel/plugin-transform-classes`
/// ///

View File

@ -14,7 +14,6 @@ bench = false
[dependencies] [dependencies]
Inflector = "0.11.4" Inflector = "0.11.4"
ahash = "0.8.3"
anyhow = "1.0.71" anyhow = "1.0.71"
bitflags = "2.3.2" bitflags = "2.3.2"
indexmap = "1.9.3" indexmap = "1.9.3"

View File

@ -22,7 +22,6 @@ concurrent = [
debug = [] debug = []
[dependencies] [dependencies]
ahash = "0.8.3"
dashmap = "5.4.0" dashmap = "5.4.0"
indexmap = "1.9.3" indexmap = "1.9.3"
once_cell = "1.18.0" once_cell = "1.18.0"

View File

@ -8,6 +8,7 @@ use once_cell::sync::Lazy;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use swc_atoms::{js_word, JsWord}; use swc_atoms::{js_word, JsWord};
use swc_common::{ use swc_common::{
collections::ARandomState,
errors::HANDLER, errors::HANDLER,
sync::Lrc, sync::Lrc,
util::{move_map::MoveMap, take::Take}, util::{move_map::MoveMap, take::Take},
@ -43,8 +44,7 @@ pub fn const_modules(
} }
fn parse_option(cm: &SourceMap, name: &str, src: String) -> Arc<Expr> { fn parse_option(cm: &SourceMap, name: &str, src: String) -> Arc<Expr> {
static CACHE: Lazy<DashMap<String, Arc<Expr>, ahash::RandomState>> = static CACHE: Lazy<DashMap<String, Arc<Expr>, ARandomState>> = Lazy::new(DashMap::default);
Lazy::new(DashMap::default);
let fm = cm.new_source_file(FileName::Custom(format!("<const-module-{}.js>", name)), src); let fm = cm.new_source_file(FileName::Custom(format!("<const-module-{}.js>", name)), src);
if let Some(expr) = CACHE.get(&**fm.src) { if let Some(expr) = CACHE.get(&**fm.src) {

View File

@ -5,7 +5,7 @@ use petgraph::{algo::tarjan_scc, Direction::Incoming};
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use swc_atoms::{js_word, JsWord}; use swc_atoms::{js_word, JsWord};
use swc_common::{ use swc_common::{
collections::{AHashMap, AHashSet}, collections::{AHashMap, AHashSet, ARandomState},
pass::{CompilerPass, Repeated}, pass::{CompilerPass, Repeated},
util::take::Take, util::take::Take,
Mark, SyntaxContext, DUMMY_SP, Mark, SyntaxContext, DUMMY_SP,
@ -113,7 +113,7 @@ struct Data {
/// Entrypoints. /// Entrypoints.
entries: FxHashSet<u32>, entries: FxHashSet<u32>,
graph_ix: IndexSet<Id, ahash::RandomState>, graph_ix: IndexSet<Id, ARandomState>,
} }
impl Data { impl Data {

View File

@ -8,7 +8,7 @@ use std::{
use indexmap::map::{Entry, IndexMap}; use indexmap::map::{Entry, IndexMap};
use swc_atoms::js_word; use swc_atoms::js_word;
use swc_common::collections::{AHashMap, AHashSet}; use swc_common::collections::{AHashMap, AHashSet, ARandomState};
use swc_ecma_ast::*; use swc_ecma_ast::*;
use swc_ecma_transforms_base::ext::ExprRefExt; use swc_ecma_transforms_base::ext::ExprRefExt;
use tracing::{span, Level}; use tracing::{span, Level};
@ -243,7 +243,7 @@ pub(super) struct Scope<'a> {
pub kind: ScopeKind, pub kind: ScopeKind,
inline_barriers: RefCell<VecDeque<usize>>, inline_barriers: RefCell<VecDeque<usize>>,
bindings: IndexMap<Id, VarInfo, ahash::RandomState>, bindings: IndexMap<Id, VarInfo, ARandomState>,
unresolved_usages: AHashSet<Id>, unresolved_usages: AHashSet<Id>,
/// Simple optimization. We don't need complex scope analysis. /// Simple optimization. We don't need complex scope analysis.

View File

@ -18,7 +18,6 @@ default = ["serde-impl"]
serde-impl = ["serde"] serde-impl = ["serde"]
[dependencies] [dependencies]
ahash = "0.8.3"
base64 = "0.13.0" base64 = "0.13.0"
dashmap = "5.4.0" dashmap = "5.4.0"
indexmap = "1.9.3" indexmap = "1.9.3"

View File

@ -22,7 +22,6 @@ concurrent = ["swc_common/concurrent", "indexmap/rayon"]
trace-ast = [] trace-ast = []
[dependencies] [dependencies]
ahash = "0.8.3"
indexmap = "1.9.3" indexmap = "1.9.3"
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
tracing = "0.1.37" tracing = "0.1.37"

View File

@ -12,9 +12,9 @@ version = "0.20.22"
bench = false bench = false
[dependencies] [dependencies]
ahash = "0.8.3"
auto_impl = "1.1.0" auto_impl = "1.1.0"
petgraph = "0.6.0" petgraph = "0.6.0"
swc_common = {version = "0.31.18", path = "../swc_common/"}
swc_fast_graph = {version = "0.19.19", path = "../swc_fast_graph/"} swc_fast_graph = {version = "0.19.19", path = "../swc_fast_graph/"}
tracing = "0.1.37" tracing = "0.1.37"

View File

@ -1,7 +1,7 @@
use std::{fmt::Debug, hash::Hash, marker::PhantomData}; use std::{fmt::Debug, hash::Hash, marker::PhantomData};
use ahash::AHashSet;
use auto_impl::auto_impl; use auto_impl::auto_impl;
use swc_common::collections::AHashSet;
use swc_fast_graph::digraph::FastDiGraphMap; use swc_fast_graph::digraph::FastDiGraphMap;
#[auto_impl(&, Box, Rc, Arc)] #[auto_impl(&, Box, Rc, Arc)]

View File

@ -15,7 +15,6 @@ version = "0.18.19"
bench = false bench = false
[dependencies] [dependencies]
ahash = "0.8.3"
dashmap = "5.4.0" dashmap = "5.4.0"
swc_atoms = { version = "0.5.8", path = "../swc_atoms" } swc_atoms = { version = "0.5.8", path = "../swc_atoms" }

View File

@ -5,11 +5,12 @@ use std::sync::Arc;
use dashmap::DashMap; use dashmap::DashMap;
use swc_atoms::atom; use swc_atoms::atom;
use swc_common::{ use swc_common::{
collections::ARandomState,
comments::{Comment, CommentKind, Comments}, comments::{Comment, CommentKind, Comments},
BytePos, DUMMY_SP, BytePos, DUMMY_SP,
}; };
type CommentMap = Arc<DashMap<BytePos, Vec<Comment>, ahash::RandomState>>; type CommentMap = Arc<DashMap<BytePos, Vec<Comment>, ARandomState>>;
/// Multi-threaded implementation of [Comments] /// Multi-threaded implementation of [Comments]
#[derive(Clone, Default)] #[derive(Clone, Default)]