From 6765db0dfef953d841fe414480c7c635d740dbd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sat, 1 Feb 2025 20:46:03 +0900 Subject: [PATCH] perf: Update `rustc-hash` to `v2` and drop `ahash` (#9982) --- .changeset/young-items-retire.md | 10 + Cargo.lock | 119 +++++----- Cargo.toml | 3 +- bindings/Cargo.lock | 104 ++++----- bindings/Cargo.toml | 1 + bindings/binding_core_node/Cargo.toml | 1 + bindings/binding_core_node/src/bundle.rs | 11 +- bindings/binding_core_node/src/minify.rs | 5 +- bindings/binding_js_interop_node/Cargo.toml | 2 +- bindings/binding_minifier_node/Cargo.toml | 1 + bindings/binding_minifier_node/src/minify.rs | 4 +- crates/preset_env_base/Cargo.toml | 2 +- crates/preset_env_base/src/query.rs | 8 +- crates/swc/Cargo.toml | 1 - crates/swc/src/config/mod.rs | 27 ++- crates/swc/src/lib.rs | 6 +- crates/swc/tests/tsc.rs | 13 +- crates/swc_allocator/src/collections.rs | 13 -- crates/swc_bundler/Cargo.toml | 1 + crates/swc_bundler/src/bundler/chunk/cjs.rs | 5 +- crates/swc_bundler/src/bundler/chunk/merge.rs | 21 +- crates/swc_bundler/src/bundler/chunk/mod.rs | 8 +- .../swc_bundler/src/bundler/chunk/plan/mod.rs | 8 +- .../src/bundler/chunk/plan/tests.rs | 10 +- crates/swc_bundler/src/bundler/export.rs | 5 +- crates/swc_bundler/src/bundler/finalize.rs | 7 +- crates/swc_bundler/src/bundler/import/mod.rs | 15 +- crates/swc_bundler/src/bundler/keywords.rs | 5 +- crates/swc_bundler/src/bundler/mod.rs | 7 +- crates/swc_bundler/src/bundler/tests.rs | 7 +- crates/swc_bundler/src/id.rs | 5 +- crates/swc_bundler/src/inline.rs | 5 +- crates/swc_bundler/src/modules/mod.rs | 7 +- crates/swc_bundler/src/modules/sort/chunk.rs | 13 +- crates/swc_bundler/src/modules/sort/graph.rs | 8 +- crates/swc_bundler/src/modules/sort/stmt.rs | 22 +- crates/swc_bundler/src/util.rs | 7 +- crates/swc_bundler/tests/deno.rs | 7 +- crates/swc_cached/Cargo.toml | 12 +- crates/swc_cached/src/regex.rs | 3 +- crates/swc_common/Cargo.toml | 2 - crates/swc_common/src/collections.rs | 31 --- crates/swc_common/src/errors/mod.rs | 8 +- crates/swc_common/src/lib.rs | 6 - crates/swc_common/src/plugin/metadata.rs | 7 +- crates/swc_common/src/source_map.rs | 4 +- crates/swc_common/src/syntax_pos/hygiene.rs | 5 +- crates/swc_compiler_base/src/lib.rs | 9 +- crates/swc_core/Cargo.toml | 3 - crates/swc_css_lints/Cargo.toml | 1 + .../rules/font_family_no_duplicate_names.rs | 5 +- .../src/rules/no_duplicate_at_import_rules.rs | 4 +- crates/swc_css_minifier/Cargo.toml | 3 +- .../src/compressor/calc_sum.rs | 15 +- .../swc_css_minifier/src/compressor/rules.rs | 11 +- .../charset/invalid/leading-comments.json | 16 +- .../at-rule/document/leading-comments.json | 20 +- .../at-rule/import/leading-comments.json | 164 +++++++------- .../at-rule/keyframe/leading-comments.json | 12 +- .../at-rule/layer/leading-comments.json | 20 +- .../at-rule/scope/basic/leading-comments.json | 12 +- .../at-rule/unknown/leading-comments.json | 206 ++++++++--------- .../fixture/comment/leading-comments.json | 212 +++++++++--------- .../fixture/declaration/leading-comments.json | 16 +- .../function/calc/leading-comments.json | 24 +- .../important/basic/leading-comments.json | 30 +-- .../selector/comments/leading-comments.json | 116 +++++----- .../selector/nesting/leading-comments.json | 20 +- .../an-plus-b/leading-comments.json | 48 ++-- .../custom-property/leading-comments.json | 22 +- .../value/urange/leading-comments.json | 22 +- .../csstree/basic/leading-comments.json | 32 +-- .../vendor/rome/comment/leading-comments.json | 16 +- .../vendor/rome/smoke/leading-comments.json | 20 +- crates/swc_css_prefixer/Cargo.toml | 1 + crates/swc_css_prefixer/src/prefixer.rs | 7 +- crates/swc_css_utils/Cargo.toml | 1 + crates/swc_css_utils/src/lib.rs | 4 +- crates/swc_ecma_codegen/Cargo.toml | 1 + .../src/text_writer/basic_impl.rs | 5 +- crates/swc_ecma_codegen/tests/sourcemap.rs | 5 +- crates/swc_ecma_compat_bugfixes/Cargo.toml | 4 +- ...turing_collision_in_function_expression.rs | 5 +- .../src/block_scoping/mod.rs | 17 +- .../src/block_scoping/vars.rs | 8 +- .../swc_ecma_compat_es2015/src/classes/mod.rs | 8 +- .../src/duplicate_keys.rs | 9 +- crates/swc_ecma_compat_es2022/Cargo.toml | 3 +- .../src/class_properties/mod.rs | 7 +- .../src/class_properties/private_field.rs | 8 +- .../src/private_in_object.rs | 16 +- .../src/static_blocks.rs | 7 +- crates/swc_ecma_lints/Cargo.toml | 1 + .../swc_ecma_lints/src/rules/const_assign.rs | 19 +- .../swc_ecma_lints/src/rules/dot_notation.rs | 5 +- .../src/rules/duplicate_bindings.rs | 15 +- .../src/rules/duplicate_exports.rs | 5 +- crates/swc_ecma_lints/src/rules/no_bitwise.rs | 11 +- crates/swc_ecma_lints/src/rules/no_console.rs | 7 +- .../swc_ecma_lints/src/rules/no_dupe_args.rs | 5 +- .../src/rules/no_empty_function.rs | 21 +- .../swc_ecma_lints/src/rules/no_loop_func.rs | 13 +- .../src/rules/no_param_reassign.rs | 16 +- .../src/rules/no_use_before_define.rs | 17 +- .../swc_ecma_lints/src/rules/prefer_const.rs | 5 +- crates/swc_ecma_loader/Cargo.toml | 1 + crates/swc_ecma_loader/src/resolvers/node.rs | 24 +- crates/swc_ecma_loader/tests/tsc_resolver.rs | 5 +- .../src/compress/hoist_decls.rs | 5 +- .../src/compress/optimize/inline.rs | 6 +- .../src/compress/optimize/mod.rs | 5 +- .../src/compress/optimize/util.rs | 4 +- crates/swc_ecma_minifier/src/eval.rs | 5 +- crates/swc_ecma_minifier/src/option/mod.rs | 4 +- crates/swc_ecma_minifier/src/option/terser.rs | 5 +- .../src/pass/hygiene/vars.rs | 6 +- .../src/pass/mangle_names/private_name.rs | 4 +- .../src/pass/mangle_props.rs | 12 +- crates/swc_ecma_minifier/src/program_data.rs | 13 +- crates/swc_ecma_parser/Cargo.toml | 1 + crates/swc_ecma_parser/src/parser/expr.rs | 3 +- crates/swc_ecma_parser/src/parser/mod.rs | 5 +- .../src/corejs2/builtin.rs | 6 +- .../swc_ecma_preset_env/src/corejs2/entry.rs | 5 +- crates/swc_ecma_preset_env/src/corejs2/mod.rs | 4 +- .../swc_ecma_preset_env/src/corejs3/compat.rs | 4 +- .../swc_ecma_preset_env/src/corejs3/data.rs | 6 +- .../swc_ecma_preset_env/src/corejs3/entry.rs | 12 +- .../swc_ecma_preset_env/src/corejs3/usage.rs | 4 +- crates/swc_ecma_preset_env/src/lib.rs | 14 +- .../swc_ecma_preset_env/src/transform_data.rs | 10 +- crates/swc_ecma_preset_env/tests/test.rs | 6 +- crates/swc_ecma_quote_macros/Cargo.toml | 1 + crates/swc_ecma_quote_macros/src/ctxt.rs | 10 +- .../src/hygiene/tests.rs | 7 +- .../src/rename/analyzer/scope.rs | 2 +- .../src/rename/mod.rs | 1 - .../src/resolver/mod.rs | 11 +- crates/swc_ecma_transforms_module/Cargo.toml | 1 + .../src/common_js.rs | 8 +- .../src/import_analysis.rs | 4 +- .../src/module_decl_strip.rs | 13 +- .../src/module_ref_rewriter.rs | 12 +- .../src/system_js.rs | 5 +- .../src/const_modules.rs | 5 +- .../src/inline_globals.rs | 38 ++-- .../src/simplify/const_propagation.rs | 5 +- .../src/simplify/dce/mod.rs | 11 +- .../src/simplify/inlining/scope.rs | 8 +- .../src/decorators/legacy/metadata.rs | 4 +- .../src/decorators/legacy/mod.rs | 5 +- .../src/pure_annotations/mod.rs | 5 +- .../src/refresh/mod.rs | 7 +- .../src/refresh/util.rs | 9 +- .../swc_ecma_transforms_typescript/Cargo.toml | 7 +- .../src/strip_import_export.rs | 16 +- .../src/transform.rs | 16 +- .../src/ts_enum.rs | 5 +- .../src/typescript.rs | 10 +- .../src/analyzer/mod.rs | 7 +- .../src/function/fn_env_hoister.rs | 7 +- crates/swc_ecma_utils/src/lib.rs | 14 +- crates/swc_estree_compat/Cargo.toml | 2 +- crates/swc_fast_graph/src/digraph.rs | 13 +- crates/swc_graph_analyzer/Cargo.toml | 1 + crates/swc_graph_analyzer/src/lib.rs | 4 +- crates/swc_html_minifier/Cargo.toml | 10 +- crates/swc_html_minifier/src/lib.rs | 9 +- crates/swc_html_parser/Cargo.toml | 2 + crates/swc_html_parser/src/lexer/mod.rs | 5 +- .../swc_html_parser/tests/html5lib_tests.rs | 4 +- crates/swc_html_utils/Cargo.toml | 1 + crates/swc_html_utils/src/lib.rs | 16 +- crates/swc_node_bundler/Cargo.toml | 1 + crates/swc_node_bundler/src/loaders/swc.rs | 6 +- crates/swc_node_bundler/src/v1/mod.rs | 7 +- crates/swc_node_comments/Cargo.toml | 3 +- crates/swc_node_comments/src/lib.rs | 4 +- crates/swc_plugin_proxy/Cargo.toml | 10 +- .../src/metadata/transform_plugin_metadata.rs | 6 +- crates/swc_plugin_runner/Cargo.toml | 1 + .../swc_plugin_runner/benches/ecma_invoke.rs | 8 +- crates/swc_plugin_runner/src/cache.rs | 12 +- crates/swc_plugin_runner/tests/css_rkyv.rs | 10 +- .../tests/ecma_integration.rs | 8 +- crates/swc_plugin_runner/tests/ecma_rkyv.rs | 10 +- crates/swc_plugin_runner/tests/issues.rs | 5 +- crates/swc_xml_parser/Cargo.toml | 2 + crates/swc_xml_parser/src/lexer/mod.rs | 5 +- crates/testing/Cargo.toml | 1 + crates/testing/src/lib.rs | 4 +- 191 files changed, 1240 insertions(+), 1280 deletions(-) create mode 100644 .changeset/young-items-retire.md delete mode 100644 crates/swc_common/src/collections.rs diff --git a/.changeset/young-items-retire.md b/.changeset/young-items-retire.md new file mode 100644 index 000000000000..d3305b3763f4 --- /dev/null +++ b/.changeset/young-items-retire.md @@ -0,0 +1,10 @@ +--- +swc_allocator: major +swc_common: major +swc_cached: major +swc_fast_graph: major +swc_graph_analyzer: major +swc_plugin_proxy: major +--- + +perf: Update `rustc-hash` to `v2` diff --git a/Cargo.lock b/Cargo.lock index 0fdb11ed5b7d..438ce949b577 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,7 +45,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", - "const-random", "getrandom", "once_cell", "serde", @@ -334,7 +333,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "syn 2.0.87", ] @@ -841,26 +840,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "const-random" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaf16c9c2c612020bcfd042e170f6e32de9b9d75adb5277cdbbd2e2c8c8299a" -dependencies = [ - "const-random-macro", -] - -[[package]] -name = "const-random-macro" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" -dependencies = [ - "getrandom", - "once_cell", - "tiny-keccak", -] - [[package]] name = "constant_time_eq" version = "0.3.1" @@ -959,7 +938,7 @@ dependencies = [ "hashbrown 0.14.5", "log", "regalloc2", - "rustc-hash", + "rustc-hash 1.1.0", "smallvec", "target-lexicon", ] @@ -2017,7 +1996,7 @@ dependencies = [ "rand", "rayon", "rkyv", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "smartstring", "smol_str", @@ -3453,12 +3432,12 @@ dependencies = [ name = "preset_env_base" version = "2.0.0" dependencies = [ - "ahash", "anyhow", "browserslist-rs", "dashmap 5.5.3", "from_variant", "once_cell", + "rustc-hash 2.1.0", "semver 1.0.23", "serde", "st-map", @@ -3707,7 +3686,7 @@ checksum = "ad156d539c879b7a24a363a2016d77961786e71f48f2e2fc8302a92abd2429a6" dependencies = [ "hashbrown 0.13.2", "log", - "rustc-hash", + "rustc-hash 1.1.0", "slice-group-by", "smallvec", ] @@ -3886,6 +3865,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" + [[package]] name = "rustc_version" version = "0.2.3" @@ -4383,7 +4368,7 @@ dependencies = [ "data-encoding", "debugid", "if_chain", - "rustc-hash", + "rustc-hash 1.1.0", "rustc_version 0.2.3", "serde", "serde_json", @@ -4510,7 +4495,7 @@ dependencies = [ "pathdiff", "rayon", "regex", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "serde_json", "sourcemap", @@ -4573,7 +4558,7 @@ dependencies = [ "ptr_meta 0.3.0", "rancor", "rkyv", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "swc_malloc", "triomphe", @@ -4589,7 +4574,7 @@ dependencies = [ "once_cell", "rancor", "rkyv", - "rustc-hash", + "rustc-hash 2.1.0", "serde", ] @@ -4612,6 +4597,7 @@ dependencies = [ "rayon", "relative-path", "reqwest", + "rustc-hash 2.1.0", "sha1", "swc_atoms", "swc_common", @@ -4640,11 +4626,11 @@ dependencies = [ name = "swc_cached" version = "1.0.0" dependencies = [ - "ahash", "anyhow", "dashmap 5.5.3", "once_cell", "regex", + "rustc-hash 2.1.0", "serde", ] @@ -4675,7 +4661,6 @@ dependencies = [ name = "swc_common" version = "5.0.1" dependencies = [ - "ahash", "anyhow", "arbitrary", "ast_node", @@ -4693,7 +4678,7 @@ dependencies = [ "rancor", "rayon", "rkyv", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "serde_json", "siphasher 0.3.11", @@ -4718,7 +4703,7 @@ dependencies = [ "napi-derive", "once_cell", "pathdiff", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "serde_json", "sourcemap", @@ -4847,7 +4832,7 @@ version = "5.0.0" dependencies = [ "auto_impl", "bitflags 2.6.0", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "swc_atoms", "swc_common", @@ -4894,6 +4879,7 @@ dependencies = [ "auto_impl", "parking_lot", "rayon", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -4912,6 +4898,7 @@ version = "5.0.0" dependencies = [ "codspeed-criterion-compat", "criterion", + "rustc-hash 2.1.0", "serde", "swc_atoms", "swc_common", @@ -4929,7 +4916,7 @@ name = "swc_css_modules" version = "5.0.0" dependencies = [ "indexmap 2.7.1", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -4965,6 +4952,7 @@ version = "6.0.0" dependencies = [ "once_cell", "preset_env_base", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -4982,6 +4970,7 @@ name = "swc_css_utils" version = "5.0.0" dependencies = [ "once_cell", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -5034,6 +5023,7 @@ dependencies = [ "num-bigint", "once_cell", "regex", + "rustc-hash 2.1.0", "serde", "serde_json", "sourcemap", @@ -5063,6 +5053,7 @@ dependencies = [ name = "swc_ecma_compat_bugfixes" version = "8.0.0" dependencies = [ + "rustc-hash 2.1.0", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -5094,7 +5085,7 @@ dependencies = [ "arrayvec", "indexmap 2.7.1", "is-macro", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "serde_derive", "smallvec", @@ -5220,6 +5211,7 @@ dependencies = [ name = "swc_ecma_compat_es2022" version = "9.0.0" dependencies = [ + "rustc-hash 2.1.0", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -5272,6 +5264,7 @@ dependencies = [ "parking_lot", "pretty_assertions", "regex", + "rustc-hash 2.1.0", "serde", "swc_atoms", "swc_common", @@ -5302,6 +5295,7 @@ dependencies = [ "parking_lot", "path-clean 0.1.0", "pathdiff", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -5330,7 +5324,7 @@ dependencies = [ "radix_fmt", "rayon", "regex", - "rustc-hash", + "rustc-hash 2.1.0", "ryu-js", "serde", "serde_json", @@ -5367,6 +5361,7 @@ dependencies = [ "num-traits", "phf", "pretty_assertions", + "rustc-hash 2.1.0", "serde", "serde_json", "smallvec", @@ -5395,7 +5390,7 @@ dependencies = [ "once_cell", "preset_env_base", "pretty_assertions", - "rustc-hash", + "rustc-hash 2.1.0", "semver 1.0.23", "serde", "serde_json", @@ -5430,6 +5425,7 @@ dependencies = [ "anyhow", "proc-macro2", "quote", + "rustc-hash 2.1.0", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -5486,7 +5482,7 @@ dependencies = [ "once_cell", "phf", "rayon", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "smallvec", "swc_atoms", @@ -5576,6 +5572,7 @@ dependencies = [ "path-clean 1.0.1", "pathdiff", "regex", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -5603,7 +5600,7 @@ dependencies = [ "once_cell", "petgraph", "rayon", - "rustc-hash", + "rustc-hash 2.1.0", "serde_json", "swc_atoms", "swc_common", @@ -5629,7 +5626,7 @@ name = "swc_ecma_transforms_proposal" version = "8.0.0" dependencies = [ "either", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "serde_json", "smallvec", @@ -5658,7 +5655,7 @@ dependencies = [ "indexmap 2.7.1", "once_cell", "rayon", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "sha1", "string_enum", @@ -5710,6 +5707,7 @@ dependencies = [ "codspeed-criterion-compat", "criterion", "once_cell", + "rustc-hash 2.1.0", "ryu-js", "serde", "swc_atoms", @@ -5732,7 +5730,7 @@ name = "swc_ecma_usage_analyzer" version = "9.0.0" dependencies = [ "indexmap 2.7.1", - "rustc-hash", + "rustc-hash 2.1.0", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -5750,7 +5748,7 @@ dependencies = [ "num_cpus", "once_cell", "rayon", - "rustc-hash", + "rustc-hash 2.1.0", "ryu-js", "stacker", "swc_atoms", @@ -5828,12 +5826,12 @@ dependencies = [ name = "swc_estree_compat" version = "8.0.0" dependencies = [ - "ahash", "anyhow", "codspeed-criterion-compat", "copyless", "criterion", "pretty_assertions", + "rustc-hash 2.1.0", "serde", "serde_json", "swc", @@ -5856,7 +5854,7 @@ version = "6.0.0" dependencies = [ "indexmap 2.7.1", "petgraph", - "rustc-hash", + "rustc-hash 2.1.0", "swc_common", ] @@ -5886,6 +5884,7 @@ version = "5.0.0" dependencies = [ "auto_impl", "petgraph", + "rustc-hash 2.1.0", "swc_common", "swc_fast_graph", "testing", @@ -5922,7 +5921,7 @@ version = "5.0.0" dependencies = [ "auto_impl", "bitflags 2.6.0", - "rustc-hash", + "rustc-hash 2.1.0", "swc_atoms", "swc_common", "swc_html_ast", @@ -5950,6 +5949,7 @@ dependencies = [ "codspeed-criterion-compat", "criterion", "once_cell", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -5980,6 +5980,7 @@ version = "5.0.0" dependencies = [ "codspeed-criterion-compat", "criterion", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -5996,6 +5997,7 @@ name = "swc_html_utils" version = "5.0.0" dependencies = [ "once_cell", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -6062,6 +6064,7 @@ dependencies = [ "once_cell", "pretty_assertions", "regex", + "rustc-hash 2.1.0", "serde", "serde_json", "string_enum", @@ -6086,6 +6089,7 @@ name = "swc_node_comments" version = "5.0.0" dependencies = [ "dashmap 5.5.3", + "rustc-hash 2.1.0", "swc_atoms", "swc_common", ] @@ -6137,6 +6141,7 @@ dependencies = [ "bytecheck 0.8.0", "rancor", "rkyv", + "rustc-hash 2.1.0", "swc_common", "swc_ecma_ast", "swc_trace_macro", @@ -6154,6 +6159,7 @@ dependencies = [ "futures", "once_cell", "parking_lot", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -6204,7 +6210,7 @@ version = "1.0.0" dependencies = [ "better_scoped_tls", "once_cell", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "serde_json", ] @@ -6214,7 +6220,7 @@ name = "swc_typescript" version = "7.0.0" dependencies = [ "petgraph", - "rustc-hash", + "rustc-hash 2.1.0", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -6266,7 +6272,7 @@ version = "5.0.0" dependencies = [ "auto_impl", "bitflags 2.6.0", - "rustc-hash", + "rustc-hash 2.1.0", "swc_atoms", "swc_common", "swc_xml_ast", @@ -6290,6 +6296,7 @@ dependencies = [ name = "swc_xml_parser" version = "5.0.0" dependencies = [ + "rustc-hash 2.1.0", "serde", "serde_json", "swc_atoms", @@ -6460,6 +6467,7 @@ dependencies = [ "once_cell", "pretty_assertions", "regex", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_common", @@ -6578,15 +6586,6 @@ dependencies = [ "time-core", ] -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - [[package]] name = "tinystr" version = "0.7.6" diff --git a/Cargo.toml b/Cargo.toml index ded27b007211..1a5e5a629260 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ resolver = "2" Inflector = "0.11.4" - ahash = "0.8.8" allocator-api2 = "0.2.18" ansi_term = "0.12.1" anyhow = "1.0.81" @@ -86,7 +85,7 @@ resolver = "2" regex = "1.5.4" relative-path = "1.6.1" reqwest = "0.11.14" - rustc-hash = "1.1.0" + rustc-hash = "2" ryu-js = "1.0.0" scoped-tls = "1.0.1" semver = "1.0.20" diff --git a/bindings/Cargo.lock b/bindings/Cargo.lock index 46c182ed3c9c..d8afe8a32bfa 100644 --- a/bindings/Cargo.lock +++ b/bindings/Cargo.lock @@ -249,13 +249,13 @@ dependencies = [ "bitflags 2.6.0", "cexpr", "clang-sys", - "itertools 0.10.5", + "itertools 0.13.0", "log", "prettyplease", "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "syn 2.0.90", ] @@ -271,6 +271,7 @@ dependencies = [ "napi-derive", "node_macro_deps", "path-clean 1.0.1", + "rustc-hash 2.1.0", "serde", "serde_json", "swc_core", @@ -335,6 +336,8 @@ dependencies = [ "serde", "serde_json", "swc_core", + "swc_interop_babel", + "swc_interop_nodejs", "swc_malloc", "tracing", "tracing-chrome 0.7.2", @@ -374,6 +377,7 @@ dependencies = [ "napi-derive", "node_macro_deps", "path-clean 1.0.1", + "rustc-hash 2.1.0", "serde", "serde_json", "sourcemap 8.0.1", @@ -887,7 +891,7 @@ dependencies = [ "hashbrown 0.14.5", "log", "regalloc2", - "rustc-hash", + "rustc-hash 1.1.0", "smallvec", "target-lexicon", ] @@ -1056,7 +1060,7 @@ dependencies = [ "cssparser-macros", "dtoa-short", "itoa", - "phf 0.10.1", + "phf 0.11.2", "smallvec", ] @@ -1837,7 +1841,7 @@ dependencies = [ "new_debug_unreachable", "once_cell", "phf 0.11.2", - "rustc-hash", + "rustc-hash 1.1.0", "triomphe", ] @@ -2621,6 +2625,7 @@ dependencies = [ "once_cell", "serde", "serde_json", + "tokio", ] [[package]] @@ -2964,9 +2969,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" dependencies = [ - "phf_macros 0.10.0", "phf_shared 0.10.0", - "proc-macro-hack", ] [[package]] @@ -2975,7 +2978,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ - "phf_macros 0.11.2", + "phf_macros", "phf_shared 0.11.2", ] @@ -3009,20 +3012,6 @@ dependencies = [ "rand", ] -[[package]] -name = "phf_macros" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fdf3184dd560f160dd73922bea2d5cd6e8f064bf4b13110abd81b03697b4e0" -dependencies = [ - "phf_generator 0.10.0", - "phf_shared 0.10.0", - "proc-macro-hack", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "phf_macros" version = "0.11.2" @@ -3197,12 +3186,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" version = "1.0.92" @@ -3378,7 +3361,7 @@ checksum = "ad156d539c879b7a24a363a2016d77961786e71f48f2e2fc8302a92abd2429a6" dependencies = [ "hashbrown 0.13.2", "log", - "rustc-hash", + "rustc-hash 1.1.0", "slice-group-by", "smallvec", ] @@ -3555,6 +3538,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" + [[package]] name = "rustc_version" version = "0.2.3" @@ -3995,7 +3984,7 @@ dependencies = [ "data-encoding", "debugid", "if_chain", - "rustc-hash", + "rustc-hash 1.1.0", "rustc_version 0.2.3", "serde", "serde_json", @@ -4014,7 +4003,7 @@ dependencies = [ "data-encoding", "debugid", "if_chain", - "rustc-hash", + "rustc-hash 1.1.0", "rustc_version 0.2.3", "serde", "serde_json", @@ -4126,7 +4115,7 @@ dependencies = [ "parking_lot", "pathdiff", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "serde_json", "sourcemap 9.0.0", @@ -4171,7 +4160,7 @@ dependencies = [ "bumpalo", "hashbrown 0.14.5", "ptr_meta 0.3.0", - "rustc-hash", + "rustc-hash 1.1.0", "triomphe", ] @@ -4186,7 +4175,7 @@ dependencies = [ "once_cell", "rancor", "rkyv 0.8.9", - "rustc-hash", + "rustc-hash 1.1.0", "serde", ] @@ -4287,7 +4276,7 @@ dependencies = [ "parking_lot", "rancor", "rkyv 0.8.9", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "siphasher", "sourcemap 9.0.0", @@ -4312,7 +4301,7 @@ dependencies = [ "napi-derive", "once_cell", "pathdiff", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "serde_json", "sourcemap 9.0.0", @@ -4403,7 +4392,7 @@ checksum = "fbbb22067f61df47fef4f8a59594386780928eb451df85066e384ca796d8921a" dependencies = [ "auto_impl", "bitflags 2.6.0", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "swc_atoms", "swc_common", @@ -4572,7 +4561,7 @@ dependencies = [ "arrayvec", "indexmap 2.7.1", "is-macro", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "serde_derive", "smallvec", @@ -4800,7 +4789,7 @@ dependencies = [ "radix_fmt", "rayon", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "ryu-js", "serde", "serde_json", @@ -4854,7 +4843,7 @@ dependencies = [ "indexmap 2.7.1", "once_cell", "preset_env_base", - "rustc-hash", + "rustc-hash 1.1.0", "semver 1.0.23", "serde", "serde_json", @@ -4900,7 +4889,7 @@ dependencies = [ "once_cell", "phf 0.11.2", "rayon", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "smallvec", "swc_atoms", @@ -5014,7 +5003,7 @@ dependencies = [ "once_cell", "petgraph", "rayon", - "rustc-hash", + "rustc-hash 1.1.0", "serde_json", "swc_atoms", "swc_common", @@ -5035,7 +5024,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31eb5778754b4c0854ccfc5f5e3ca73098ed6782dd3cbc1d5862efe31ecd2a74" dependencies = [ "either", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "smallvec", "swc_atoms", @@ -5059,7 +5048,7 @@ dependencies = [ "indexmap 2.7.1", "once_cell", "rayon", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "sha1", "string_enum", @@ -5100,7 +5089,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "289f228d757aa06792ef4bcef13877cbfb4a727cfff6f23be6f08a12a7454457" dependencies = [ "indexmap 2.7.1", - "rustc-hash", + "rustc-hash 1.1.0", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -5120,7 +5109,7 @@ dependencies = [ "num_cpus", "once_cell", "rayon", - "rustc-hash", + "rustc-hash 1.1.0", "ryu-js", "swc_atoms", "swc_common", @@ -5179,7 +5168,7 @@ checksum = "c22e0a0478b1b06610453a97c8371cafa742e371a79aff860ccfbabe1ab160a7" dependencies = [ "indexmap 2.7.1", "petgraph", - "rustc-hash", + "rustc-hash 1.1.0", "swc_common", ] @@ -5248,7 +5237,7 @@ checksum = "d3dd8c3e3fee342a0a936fcf8996e66987add060f07e1f2e5e130b9341bcc6d0" dependencies = [ "auto_impl", "bitflags 2.6.0", - "rustc-hash", + "rustc-hash 1.1.0", "swc_atoms", "swc_common", "swc_html_ast", @@ -5335,6 +5324,21 @@ dependencies = [ "swc_visit", ] +[[package]] +name = "swc_interop_babel" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93e4dbc7d95428117dab24e3855000bcb6c31742946a8575f6202c4df801b532" +dependencies = [ + "swc_interop_nodejs", +] + +[[package]] +name = "swc_interop_nodejs" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce3abed2181a16c5bb94026de4ebe805b025353f71425cc65c5f29f145139fd" + [[package]] name = "swc_macros_common" version = "1.0.0" @@ -5489,7 +5493,7 @@ checksum = "f23ade45bb0d8b5299022dc0f674c2125512412f5b26f42cfaffa16dcc00d56b" dependencies = [ "better_scoped_tls", "once_cell", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "serde_json", ] @@ -5501,7 +5505,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a0eb6bb9e77d2d71e96b4b9c5bc0acc83e39c4fc7f05c93ff56ccf1e9aba2c4" dependencies = [ "petgraph", - "rustc-hash", + "rustc-hash 1.1.0", "swc_atoms", "swc_common", "swc_ecma_ast", diff --git a/bindings/Cargo.toml b/bindings/Cargo.toml index 1bd1be154657..04b20fcb4aea 100644 --- a/bindings/Cargo.toml +++ b/bindings/Cargo.toml @@ -27,6 +27,7 @@ resolver = "2" napi-derive = { version = "2", default-features = false } path-clean = "1.0" quote = "1" + rustc-hash = "2" serde = "1" serde-wasm-bindgen = "0.6.5" serde_json = "1.0.120" diff --git a/bindings/binding_core_node/Cargo.toml b/bindings/binding_core_node/Cargo.toml index 1436f1f2e35d..4090954a763a 100644 --- a/bindings/binding_core_node/Cargo.toml +++ b/bindings/binding_core_node/Cargo.toml @@ -39,6 +39,7 @@ napi = { workspace = true, features = ["napi3", "serde-json"] } napi-derive = { workspace = true, features = ["type-def"] } node_macro_deps = { path = "../node_macro_deps" } path-clean = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["unbounded_depth"] } tracing = { workspace = true, features = ["release_max_level_info"] } diff --git a/bindings/binding_core_node/src/bundle.rs b/bindings/binding_core_node/src/bundle.rs index 93c05d3f1d8b..82b4e5a242f3 100644 --- a/bindings/binding_core_node/src/bundle.rs +++ b/bindings/binding_core_node/src/bundle.rs @@ -8,6 +8,7 @@ use napi::{ bindgen_prelude::{AbortSignal, AsyncTask, Buffer}, Env, Status, Task, }; +use rustc_hash::FxHashMap; use serde::Deserialize; use swc_core::{ atoms::JsWord, @@ -17,7 +18,7 @@ use swc_core::{ Compiler, PrintArgs, TransformOutput, }, bundler::{BundleKind, Bundler, Load, ModuleRecord, Resolve}, - common::{collections::AHashMap, Globals, Span, GLOBALS}, + common::{Globals, Span, GLOBALS}, ecma::{ ast::{ Bool, Expr, IdentName, KeyValueProp, Lit, MemberExpr, MemberProp, MetaPropExpr, @@ -52,8 +53,8 @@ pub(crate) struct BundleTask { #[cfg(feature = "swc_v1")] #[napi] impl Task for BundleTask { - type JsValue = AHashMap; - type Output = AHashMap; + type JsValue = FxHashMap; + type Output = FxHashMap; fn compute(&mut self) -> napi::Result { let builtins = if let TargetEnv::Node = self.config.static_items.config.target { @@ -172,8 +173,8 @@ impl Task for BundleTask { #[cfg(feature = "swc_v2")] impl Task for BundleTask { - type JsValue = AHashMap; - type Output = AHashMap; + type JsValue = FxHashMap; + type Output = FxHashMap; fn compute(&mut self) -> napi::Result { todo!() diff --git a/bindings/binding_core_node/src/minify.rs b/bindings/binding_core_node/src/minify.rs index ef7ba2778d5d..057de97d4138 100644 --- a/bindings/binding_core_node/src/minify.rs +++ b/bindings/binding_core_node/src/minify.rs @@ -4,13 +4,14 @@ use napi::{ bindgen_prelude::{AbortSignal, AsyncTask, Buffer, External}, Env, JsExternal, JsObject, JsUnknown, Task, }; +use rustc_hash::FxHashMap; use serde::Deserialize; use swc_core::{ base::{ config::{ErrorFormat, JsMinifyOptions}, JsMinifyExtras, TransformOutput, }, - common::{collections::AHashMap, sync::Lrc, FileName, SourceFile, SourceMap}, + common::{sync::Lrc, FileName, SourceFile, SourceMap}, ecma::minifier::option::{MangleCache, SimpleMangleCache}, node::{deserialize_json, get_deserialized, MapErr}, }; @@ -36,7 +37,7 @@ enum MinifyTarget { /// Code to minify. Single(String), /// `{ filename: code }` - Map(AHashMap), + Map(FxHashMap), } impl MinifyTarget { diff --git a/bindings/binding_js_interop_node/Cargo.toml b/bindings/binding_js_interop_node/Cargo.toml index 24cf8e47bd98..8385492121cc 100644 --- a/bindings/binding_js_interop_node/Cargo.toml +++ b/bindings/binding_js_interop_node/Cargo.toml @@ -23,7 +23,7 @@ napi-build = { workspace = true } [dependencies] anyhow = { workspace = true } backtrace = { workspace = true } -napi = { workspace = true, features = ["napi3", "serde-json"] } +napi = { workspace = true, features = ["napi3", "serde-json", "tokio_rt"] } napi-derive = { workspace = true, features = ["type-def"] } node_macro_deps = { path = "../node_macro_deps" } path-clean = { workspace = true } diff --git a/bindings/binding_minifier_node/Cargo.toml b/bindings/binding_minifier_node/Cargo.toml index cc30275372a6..1bdb977a24a6 100644 --- a/bindings/binding_minifier_node/Cargo.toml +++ b/bindings/binding_minifier_node/Cargo.toml @@ -22,6 +22,7 @@ napi = { workspace = true, features = ["napi3", "serde-json"] } napi-derive = { workspace = true, features = ["type-def"] } node_macro_deps = { path = "../node_macro_deps" } path-clean = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["unbounded_depth"] } sourcemap = { workspace = true } diff --git a/bindings/binding_minifier_node/src/minify.rs b/bindings/binding_minifier_node/src/minify.rs index 4bac8d46e51f..3bd72b76e944 100644 --- a/bindings/binding_minifier_node/src/minify.rs +++ b/bindings/binding_minifier_node/src/minify.rs @@ -5,6 +5,7 @@ use napi::{ bindgen_prelude::{AbortSignal, AsyncTask, Buffer, External}, JsObject, Task, }; +use rustc_hash::FxHashMap; use serde::Deserialize; use swc_compiler_base::{ minify_file_comments, parse_js, IdentCollector, PrintArgs, SourceMapsConfig, TransformOutput, @@ -13,7 +14,6 @@ use swc_config::config_types::BoolOr; use swc_core::{ base::JsMinifyExtras, common::{ - collections::AHashMap, comments::{Comments, SingleThreadedComments}, sync::Lrc, FileName, Mark, SourceFile, SourceMap, @@ -50,7 +50,7 @@ enum MinifyTarget { /// Code to minify. Single(String), /// `{ filename: code }` - Map(AHashMap), + Map(FxHashMap), } impl MinifyTarget { diff --git a/crates/preset_env_base/Cargo.toml b/crates/preset_env_base/Cargo.toml index 975d0133b67d..b3804ed57cec 100644 --- a/crates/preset_env_base/Cargo.toml +++ b/crates/preset_env_base/Cargo.toml @@ -12,11 +12,11 @@ version = "2.0.0" bench = false [dependencies] -ahash = { workspace = true } anyhow = { workspace = true } browserslist-rs = { workspace = true } dashmap = { workspace = true } once_cell = { workspace = true } +rustc-hash = { workspace = true } semver = { workspace = true, features = ["serde"] } serde = { workspace = true, features = ["derive"] } st-map = { workspace = true } diff --git a/crates/preset_env_base/src/query.rs b/crates/preset_env_base/src/query.rs index c3ac9353b135..0660ad474264 100644 --- a/crates/preset_env_base/src/query.rs +++ b/crates/preset_env_base/src/query.rs @@ -7,6 +7,7 @@ use anyhow::{Context, Error}; use dashmap::DashMap; use from_variant::FromVariant; use once_cell::sync::Lazy; +use rustc_hash::FxBuildHasher; use serde::Deserialize; use crate::{version::Version, BrowserData, Versions}; @@ -18,10 +19,7 @@ pub enum Targets { Query(Query), EsModules(EsModules), Versions(Versions), - /// This uses `ahash` directly to reduce build time. - /// - /// This type is identical to `swc_common::collections::AHashMap` - HashMap(HashMap), + HashMap(HashMap), } #[derive(Debug, Clone, Copy, Deserialize)] @@ -73,7 +71,7 @@ impl Query { Ok(Arc::new(versions)) } - static CACHE: Lazy, ahash::RandomState>> = + static CACHE: Lazy, FxBuildHasher>> = Lazy::new(Default::default); if let Some(v) = CACHE.get(self) { diff --git a/crates/swc/Cargo.toml b/crates/swc/Cargo.toml index 90a378d79ec7..7a47c59f2c8f 100644 --- a/crates/swc/Cargo.toml +++ b/crates/swc/Cargo.toml @@ -72,7 +72,6 @@ url = { workspace = true } swc_atoms = { version = "3.0.4", path = "../swc_atoms" } swc_cached = { version = "1.0.0", path = "../swc_cached" } swc_common = { version = "5.0.1", path = "../swc_common", features = [ - "ahash", "sourcemap", "parking_lot", ] } diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index b6e17b8c9652..96303157ebc0 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -9,14 +9,13 @@ use anyhow::{bail, Context, Error}; use dashmap::DashMap; use indexmap::IndexMap; use once_cell::sync::Lazy; -use rustc_hash::FxHashMap; +use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; use serde::{Deserialize, Serialize}; use swc_atoms::JsWord; use swc_cached::regex::CachedRegex; #[allow(unused)] use swc_common::plugin::metadata::TransformPluginMetadataContext; use swc_common::{ - collections::{AHashMap, AHashSet, ARandomState}, comments::{Comments, SingleThreadedComments}, errors::Handler, FileName, Mark, SourceMap, SyntaxContext, @@ -1310,7 +1309,7 @@ impl Default for ErrorFormat { } /// `paths` section of `tsconfig.json`. -pub type Paths = IndexMap, ARandomState>; +pub type Paths = IndexMap, FxBuildHasher>; pub(crate) type CompiledPaths = Vec<(String, Vec)>; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -1552,19 +1551,19 @@ pub struct ErrorConfig { #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct GlobalPassOption { #[serde(default)] - pub vars: IndexMap, + pub vars: IndexMap, #[serde(default)] pub envs: GlobalInliningPassEnvs, #[serde(default)] - pub typeofs: AHashMap, + pub typeofs: FxHashMap, } #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GlobalInliningPassEnvs { - List(AHashSet), - Map(AHashMap), + List(FxHashSet), + Map(FxHashMap), } impl Default for GlobalInliningPassEnvs { @@ -1579,7 +1578,7 @@ impl Default for GlobalInliningPassEnvs { impl GlobalPassOption { pub fn build(self, cm: &SourceMap, handler: &Handler) -> impl 'static + Pass { - type ValuesMap = Arc>; + type ValuesMap = Arc>; fn expr(cm: &SourceMap, handler: &Handler, src: String) -> Box { let fm = cm.new_source_file(FileName::Anon.into(), src); @@ -1632,7 +1631,7 @@ impl GlobalPassOption { } else { match &self.envs { GlobalInliningPassEnvs::List(env_list) => { - static CACHE: Lazy, ValuesMap, ARandomState>> = + static CACHE: Lazy, ValuesMap, FxBuildHasher>> = Lazy::new(Default::default); let cache_key = env_list.iter().cloned().collect::>(); @@ -1653,7 +1652,7 @@ impl GlobalPassOption { } GlobalInliningPassEnvs::Map(map) => { - static CACHE: Lazy, ValuesMap, ARandomState>> = + static CACHE: Lazy, ValuesMap, FxBuildHasher>> = Lazy::new(Default::default); let cache_key = self @@ -1678,7 +1677,7 @@ impl GlobalPassOption { }; let global_exprs = { - static CACHE: Lazy, GlobalExprMap, ARandomState>> = + static CACHE: Lazy, GlobalExprMap, FxBuildHasher>> = Lazy::new(Default::default); let cache_key = self @@ -1701,7 +1700,7 @@ impl GlobalPassOption { *expr(cm, handler, v.to_string()), ) }) - .collect::>(); + .collect::>(); let map = Arc::new(map); CACHE.insert(cache_key, map.clone()); map @@ -1709,7 +1708,7 @@ impl GlobalPassOption { }; let global_map = { - static CACHE: Lazy, ValuesMap, ARandomState>> = + static CACHE: Lazy, ValuesMap, FxBuildHasher>> = Lazy::new(Default::default); let cache_key = self @@ -1753,7 +1752,7 @@ fn build_resolver( resolve_fully: bool, file_extension: &str, ) -> SwcImportResolver { - static CACHE: Lazy> = + static CACHE: Lazy> = Lazy::new(Default::default); // On Windows, we need to normalize path as UNC path. diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index 463423131162..5f2a4849d4df 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -173,7 +173,7 @@ mod plugin; pub mod resolver { use std::path::PathBuf; - use swc_common::collections::AHashMap; + use rustc_hash::FxHashMap; use swc_ecma_loader::{ resolvers::{lru::CachingResolver, node::NodeModulesResolver, tsc::TsConfigResolver}, TargetEnv, @@ -185,7 +185,7 @@ pub mod resolver { pub fn paths_resolver( target_env: TargetEnv, - alias: AHashMap, + alias: FxHashMap, base_url: PathBuf, paths: CompiledPaths, preserve_symlinks: bool, @@ -200,7 +200,7 @@ pub mod resolver { pub fn environment_resolver( target_env: TargetEnv, - alias: AHashMap, + alias: FxHashMap, preserve_symlinks: bool, ) -> NodeResolver { CachingResolver::new( diff --git a/crates/swc/tests/tsc.rs b/crates/swc/tests/tsc.rs index eed32e6d6fc4..5243e745a4e9 100644 --- a/crates/swc/tests/tsc.rs +++ b/crates/swc/tests/tsc.rs @@ -11,6 +11,7 @@ use std::{ use once_cell::sync::Lazy; use regex::Regex; +use rustc_hash::FxHashSet; use serde::de::DeserializeOwned; use serde_json::from_str; use swc::{ @@ -19,9 +20,7 @@ use swc::{ }, try_with_handler, Compiler, }; -use swc_common::{ - collections::AHashSet, errors::ColorConfig, FileName, SourceFile, SourceMap, GLOBALS, -}; +use swc_common::{errors::ColorConfig, FileName, SourceFile, SourceMap, GLOBALS}; use swc_ecma_ast::EsVersion; use swc_ecma_parser::{Syntax, TsSyntax}; use testing::NormalizedOutput; @@ -216,8 +215,8 @@ fn matrix(input: &Path) -> Vec { // "ES3", "ES5", "ES6", "ES2015", "ES2016", "ES2017", "ES2018", "ES2019", // "ES2020", "ES2021", "ES2022", "ESNext" - fn target(value: &str) -> AHashSet { - let mut versions = AHashSet::::default(); + fn target(value: &str) -> FxHashSet { + let mut versions = FxHashSet::::default(); value.split(',').for_each(|v| { let mut v = v.trim(); @@ -262,8 +261,8 @@ fn matrix(input: &Path) -> Vec { // "CommonJS", "AMD", "System", "UMD", "ES6", "ES2015", "ES2020", "ESNext", // "None", "ES2022", "Node16", "NodeNext" - fn module(value: &str) -> AHashSet { - let mut modules = AHashSet::::default(); + fn module(value: &str) -> FxHashSet { + let mut modules = FxHashSet::::default(); value.split(',').for_each(|v| { let v = v.trim(); diff --git a/crates/swc_allocator/src/collections.rs b/crates/swc_allocator/src/collections.rs index fd7e5732b0ed..4621ef5d0176 100644 --- a/crates/swc_allocator/src/collections.rs +++ b/crates/swc_allocator/src/collections.rs @@ -1,9 +1,5 @@ //! Various collections. -use std::hash::BuildHasherDefault; - -use rustc_hash::FxHasher; - #[cfg(feature = "nightly")] use crate::FastAlloc; @@ -23,14 +19,5 @@ pub type HashMap = hashbrown::HashMap; /// See [std::collections::HashSet]. pub type HashSet = hashbrown::HashSet; -/// Used for `FxHashMap` and `FxHashSet`. -pub type FxBuildHasher = BuildHasherDefault; - -/// Faster `HashMap` which uses `FxHasher`. -pub type FxHashMap = HashMap; - -/// Faster `HashSet` which uses `FxHasher`. -pub type FxHashSet = HashSet; - /// Re-export for convenience. pub use hashbrown::hash_map; diff --git a/crates/swc_bundler/Cargo.toml b/crates/swc_bundler/Cargo.toml index 80c310574f7b..55e00d9ae942 100644 --- a/crates/swc_bundler/Cargo.toml +++ b/crates/swc_bundler/Cargo.toml @@ -35,6 +35,7 @@ petgraph = { workspace = true } radix_fmt = { workspace = true } rayon = { workspace = true, optional = true } relative-path = { workspace = true } +rustc-hash = { workspace = true } tracing = { workspace = true } swc_atoms = { version = "3.0.4", path = "../swc_atoms" } diff --git a/crates/swc_bundler/src/bundler/chunk/cjs.rs b/crates/swc_bundler/src/bundler/chunk/cjs.rs index 9b27a7423df3..cb758679ef0c 100644 --- a/crates/swc_bundler/src/bundler/chunk/cjs.rs +++ b/crates/swc_bundler/src/bundler/chunk/cjs.rs @@ -1,7 +1,8 @@ use std::{collections::HashMap, sync::atomic::Ordering}; use anyhow::Error; -use swc_common::{collections::AHashMap, Span, SyntaxContext, DUMMY_SP}; +use rustc_hash::FxHashMap; +use swc_common::{Span, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{quote_ident, ExprFactory}; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; @@ -371,7 +372,7 @@ impl VisitMut for DefaultHandler { } struct Remapper { - vars: AHashMap, + vars: FxHashMap, } impl VisitMut for Remapper { diff --git a/crates/swc_bundler/src/bundler/chunk/merge.rs b/crates/swc_bundler/src/bundler/chunk/merge.rs index 28d1ae1b7855..f2caef943de4 100644 --- a/crates/swc_bundler/src/bundler/chunk/merge.rs +++ b/crates/swc_bundler/src/bundler/chunk/merge.rs @@ -3,11 +3,8 @@ use std::sync::atomic::Ordering; use anyhow::Error; use indexmap::IndexSet; use petgraph::EdgeDirection; -use swc_common::{ - collections::{AHashMap, AHashSet, ARandomState}, - sync::Lock, - FileName, SyntaxContext, DUMMY_SP, -}; +use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; +use swc_common::{sync::Lock, FileName, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::helpers::Helpers; use swc_ecma_utils::{find_pat_ids, prepend_stmt, private_ident, quote_ident, ExprFactory}; @@ -31,7 +28,7 @@ pub(super) struct Ctx { pub graph: ModuleGraph, pub cycles: Vec>, pub transitive_remap: CloneMap, - pub export_stars_in_wrapped: Lock>>, + pub export_stars_in_wrapped: Lock>>, } impl Ctx { @@ -90,7 +87,7 @@ where ctx: &Ctx, entry_id: ModuleId, entry: &mut Modules, - all: &mut AHashMap, + all: &mut FxHashMap, ) { self.run(|| { let injected_ctxt = self.injected_ctxt; @@ -145,8 +142,8 @@ where &self, graph: &ModuleGraph, start: ModuleId, - dejavu: &mut AHashSet, - ) -> IndexSet { + dejavu: &mut FxHashSet, + ) -> IndexSet { let mut set = IndexSet::default(); for dep in graph.neighbors_directed(start, Outgoing) { @@ -200,7 +197,7 @@ where fn add_var( injected_ctxt: SyntaxContext, vars: &mut Vec<(ModuleId, ModuleItem)>, - declared: &mut AHashSet, + declared: &mut FxHashSet, map: &CloneMap, module_id: ModuleId, id: Id, @@ -241,7 +238,7 @@ where // If an user import and export from D, the transitive syntax context map // contains a entry from D to foo because it's reexported and // the variable (reexported from D) exist because it's imported. - let mut declared_ids = AHashSet::<_>::default(); + let mut declared_ids = FxHashSet::<_>::default(); for (_, stmt) in entry.iter() { if let ModuleItem::Stmt(Stmt::Decl(Decl::Var(decl))) = stmt { @@ -323,7 +320,7 @@ where { let mut map = ctx.export_stars_in_wrapped.lock(); - let mut additional_props = AHashMap::<_, Vec<_>>::default(); + let mut additional_props = FxHashMap::<_, Vec<_>>::default(); // Handle `export *` for wrapped modules. for (module_id, ctxts) in map.drain() { for (_, stmt) in entry.iter() { diff --git a/crates/swc_bundler/src/bundler/chunk/mod.rs b/crates/swc_bundler/src/bundler/chunk/mod.rs index 0b6d4442033e..d187720bdacc 100644 --- a/crates/swc_bundler/src/bundler/chunk/mod.rs +++ b/crates/swc_bundler/src/bundler/chunk/mod.rs @@ -3,7 +3,7 @@ use std::time::Instant; use anyhow::{Context, Error}; #[cfg(feature = "rayon")] use rayon::iter::ParallelIterator; -use swc_common::collections::AHashMap; +use rustc_hash::FxHashMap; use super::{load::TransformedModule, Bundler}; use crate::{ @@ -27,7 +27,7 @@ where /// For first, we load all dependencies and determine all entries. pub(super) fn chunk( &self, - entries: AHashMap, + entries: FxHashMap, ) -> Result, Error> { #[cfg(not(target_arch = "wasm32"))] let start = Instant::now(); @@ -73,7 +73,7 @@ where Ok((*id, module)) }) }) - .collect::, _>>()?; + .collect::, _>>()?; #[cfg(not(target_arch = "wasm32"))] let dur = Instant::now() - start; @@ -172,7 +172,7 @@ mod tests { .bundler .load_transformed(&FileName::Real("main.js".into()))? .unwrap(); - let mut entries = AHashMap::default(); + let mut entries = FxHashMap::default(); entries.insert("main.js".to_string(), module); let chunked = t.bundler.chunk(entries)?; diff --git a/crates/swc_bundler/src/bundler/chunk/plan/mod.rs b/crates/swc_bundler/src/bundler/chunk/plan/mod.rs index 99a31da0ac06..5a6bd3287c9b 100644 --- a/crates/swc_bundler/src/bundler/chunk/plan/mod.rs +++ b/crates/swc_bundler/src/bundler/chunk/plan/mod.rs @@ -1,5 +1,5 @@ use anyhow::{bail, Error}; -use swc_common::collections::AHashMap; +use rustc_hash::FxHashMap; use swc_graph_analyzer::{DepGraph, GraphAnalyzer}; use crate::{ @@ -13,12 +13,12 @@ mod tests; #[derive(Debug, Default)] struct PlanBuilder { - kinds: AHashMap, + kinds: FxHashMap, } #[derive(Debug, Default)] pub(super) struct Plan { - pub entries: AHashMap, + pub entries: FxHashMap, /// Id of all modules. pub all: Vec, @@ -46,7 +46,7 @@ where { pub(super) fn determine_entries( &self, - entries: AHashMap, + entries: FxHashMap, ) -> Result<(Plan, ModuleGraph, Vec>), Error> { let mut builder = PlanBuilder::default(); let mut analyzer = GraphAnalyzer::new(&self.scope); diff --git a/crates/swc_bundler/src/bundler/chunk/plan/tests.rs b/crates/swc_bundler/src/bundler/chunk/plan/tests.rs index ce8b2f9514bb..8a522bfcfd23 100644 --- a/crates/swc_bundler/src/bundler/chunk/plan/tests.rs +++ b/crates/swc_bundler/src/bundler/chunk/plan/tests.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; -use swc_common::collections::{AHashMap, AHashSet}; +use rustc_hash::{FxHashMap, FxHashSet}; use crate::bundler::tests::suite; -fn assert_cycles(map: AHashMap, cycle_entries: Vec<&str>) { +fn assert_cycles(map: FxHashMap, cycle_entries: Vec<&str>) { let mut tester = suite(); for (k, v) in map { @@ -12,15 +12,15 @@ fn assert_cycles(map: AHashMap, cycle_entries: Vec<&str>) { } tester.run(|tester| { - let mut entries = AHashMap::default(); + let mut entries = FxHashMap::default(); entries.insert("main.js".to_string(), tester.module("main.js")); let (_plan, _graph, cycles) = tester.bundler.determine_entries(entries).unwrap(); dbg!(&cycles); - let actual: AHashSet<_> = cycles.into_iter().flatten().collect(); + let actual: FxHashSet<_> = cycles.into_iter().flatten().collect(); - let expected: AHashSet<_> = cycle_entries + let expected: FxHashSet<_> = cycle_entries .iter() .map(|name| tester.module(name).id) .collect(); diff --git a/crates/swc_bundler/src/bundler/export.rs b/crates/swc_bundler/src/bundler/export.rs index c9b777635510..ee2e45b9fc8f 100644 --- a/crates/swc_bundler/src/bundler/export.rs +++ b/crates/swc_bundler/src/bundler/export.rs @@ -1,6 +1,7 @@ use indexmap::IndexMap; +use rustc_hash::FxBuildHasher; use swc_atoms::JsWord; -use swc_common::{collections::ARandomState, FileName, SyntaxContext}; +use swc_common::{FileName, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_utils::find_pat_ids; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; @@ -42,7 +43,7 @@ where #[derive(Debug, Default)] pub(super) struct RawExports { /// Key is None if it's exported from the module itself. - pub items: IndexMap, Vec, ARandomState>, + pub items: IndexMap, Vec, FxBuildHasher>, } #[derive(Debug, Default)] diff --git a/crates/swc_bundler/src/bundler/finalize.rs b/crates/swc_bundler/src/bundler/finalize.rs index d558b6c55199..583ba46dff55 100644 --- a/crates/swc_bundler/src/bundler/finalize.rs +++ b/crates/swc_bundler/src/bundler/finalize.rs @@ -2,7 +2,8 @@ use std::path::{Path, PathBuf}; use anyhow::Error; use relative_path::RelativePath; -use swc_common::{collections::AHashMap, util::move_map::MoveMap, FileName, Mark, DUMMY_SP}; +use rustc_hash::FxHashMap; +use swc_common::{util::move_map::MoveMap, FileName, Mark, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{ fixer::fixer, @@ -31,7 +32,7 @@ where ) -> Result, Error> { self.run(|| { let mut new = Vec::with_capacity(bundles.len()); - let mut renamed = AHashMap::default(); + let mut renamed = FxHashMap::default(); for mut bundle in bundles { bundle.module = self.optimize(bundle.module); @@ -384,7 +385,7 @@ where { resolver: R, base: &'a PathBuf, - renamed: &'a AHashMap, + renamed: &'a FxHashMap, } impl Fold for Renamer<'_, R> diff --git a/crates/swc_bundler/src/bundler/import/mod.rs b/crates/swc_bundler/src/bundler/import/mod.rs index 53244ebcfee4..db9749f402e2 100644 --- a/crates/swc_bundler/src/bundler/import/mod.rs +++ b/crates/swc_bundler/src/bundler/import/mod.rs @@ -1,10 +1,7 @@ use anyhow::{Context, Error}; +use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; -use swc_common::{ - collections::{AHashMap, AHashSet}, - sync::Lrc, - FileName, Mark, Spanned, SyntaxContext, DUMMY_SP, -}; +use swc_common::{sync::Lrc, FileName, Mark, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::find_pat_ids; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; @@ -95,7 +92,7 @@ pub(super) struct RawImports { /// function bar() {} /// foo[bar()] /// ``` - pub forced_ns: AHashSet, + pub forced_ns: FxHashSet, } /// This type implements two operation (analysis, deglobbing) to reduce binary @@ -115,13 +112,13 @@ where /// HashMap from the local identifier of a namespace import to used /// properties. - usages: AHashMap>, + usages: FxHashMap>, /// While deglobbing, we also marks imported identifiers. - imported_idents: AHashMap, + imported_idents: FxHashMap, deglob_phase: bool, - idents_to_deglob: AHashSet, + idents_to_deglob: FxHashSet, /// `true` while folding objects of a member expression. /// diff --git a/crates/swc_bundler/src/bundler/keywords.rs b/crates/swc_bundler/src/bundler/keywords.rs index 63f13040b938..53112c77f4f3 100644 --- a/crates/swc_bundler/src/bundler/keywords.rs +++ b/crates/swc_bundler/src/bundler/keywords.rs @@ -1,4 +1,5 @@ -use swc_common::{collections::AHashMap, util::take::Take}; +use rustc_hash::FxHashMap; +use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_utils::private_ident; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; @@ -7,7 +8,7 @@ use crate::id::Id; #[derive(Default)] pub struct KeywordRenamer { - renamed: AHashMap, + renamed: FxHashMap, } impl KeywordRenamer { diff --git a/crates/swc_bundler/src/bundler/mod.rs b/crates/swc_bundler/src/bundler/mod.rs index 3829400058fb..ecc138a37546 100644 --- a/crates/swc_bundler/src/bundler/mod.rs +++ b/crates/swc_bundler/src/bundler/mod.rs @@ -1,10 +1,9 @@ use std::collections::HashMap; use anyhow::{Context, Error}; +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::{ - collections::AHashMap, sync::Lrc, FileName, Globals, Mark, SourceMap, SyntaxContext, GLOBALS, -}; +use swc_common::{sync::Lrc, FileName, Globals, Mark, SourceMap, SyntaxContext, GLOBALS}; use swc_ecma_ast::Module; use self::scope::Scope; @@ -179,7 +178,7 @@ where // TODO: Handle dynamic imports let local = { - let mut output = AHashMap::default(); + let mut output = FxHashMap::default(); for res in results { let (name, m) = res?; diff --git a/crates/swc_bundler/src/bundler/tests.rs b/crates/swc_bundler/src/bundler/tests.rs index d9c4969a832c..c7f7e7007093 100644 --- a/crates/swc_bundler/src/bundler/tests.rs +++ b/crates/swc_bundler/src/bundler/tests.rs @@ -3,7 +3,8 @@ use std::path::PathBuf; use anyhow::Error; use indexmap::IndexMap; -use swc_common::{collections::ARandomState, sync::Lrc, FileName, SourceMap, Span, GLOBALS}; +use rustc_hash::FxBuildHasher; +use swc_common::{sync::Lrc, FileName, SourceMap, Span, GLOBALS}; use swc_ecma_ast::*; use swc_ecma_loader::resolve::Resolution; use swc_ecma_parser::{lexer::Lexer, Parser, StringInput}; @@ -20,7 +21,7 @@ pub(crate) struct Tester<'a> { pub struct Loader { cm: Lrc, - files: IndexMap, + files: IndexMap, } impl Load for Loader { @@ -112,7 +113,7 @@ pub(crate) fn suite() -> TestBuilder { #[derive(Default)] pub(crate) struct TestBuilder { - files: IndexMap, + files: IndexMap, } impl TestBuilder { diff --git a/crates/swc_bundler/src/id.rs b/crates/swc_bundler/src/id.rs index 393837adb037..50aff42dc124 100644 --- a/crates/swc_bundler/src/id.rs +++ b/crates/swc_bundler/src/id.rs @@ -3,8 +3,9 @@ use std::{ sync::atomic::{AtomicU32, Ordering::SeqCst}, }; +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, sync::Lock, FileName, Mark, SyntaxContext, DUMMY_SP}; +use swc_common::{sync::Lock, FileName, Mark, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::{Expr, Ident}; use swc_ecma_utils::ident::IdentLike; @@ -28,7 +29,7 @@ impl fmt::Debug for ModuleId { pub(crate) struct ModuleIdGenerator { v: AtomicU32, /// `(module_id, local_mark, export_mark)` - cache: Lock>, + cache: Lock>, } impl ModuleIdGenerator { diff --git a/crates/swc_bundler/src/inline.rs b/crates/swc_bundler/src/inline.rs index 2fa15f1daf74..6545db636344 100644 --- a/crates/swc_bundler/src/inline.rs +++ b/crates/swc_bundler/src/inline.rs @@ -1,4 +1,5 @@ -use swc_common::{collections::AHashMap, SyntaxContext, DUMMY_SP}; +use rustc_hash::FxHashMap; +use swc_common::{SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_visit::{ noop_visit_mut_type, noop_visit_type, visit_mut_obj_and_computed, Visit, VisitMut, @@ -9,7 +10,7 @@ use crate::{id::Id, modules::Modules, util::Readonly}; #[derive(Debug, Default)] pub(crate) struct InlineData { - ids: AHashMap, + ids: FxHashMap, } /// Inline **injected** variables. diff --git a/crates/swc_bundler/src/modules/mod.rs b/crates/swc_bundler/src/modules/mod.rs index f0d9a6167e5e..ac2b1a9e9fe9 100644 --- a/crates/swc_bundler/src/modules/mod.rs +++ b/crates/swc_bundler/src/modules/mod.rs @@ -1,6 +1,7 @@ use std::mem::take; -use swc_common::{collections::AHashMap, SourceMap, SyntaxContext, DUMMY_SP}; +use rustc_hash::FxHashMap; +use swc_common::{SourceMap, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_visit::{Fold, FoldWith, Visit, VisitMut, VisitMutWith, VisitWith}; @@ -17,8 +18,8 @@ pub struct Modules { // We will change this into `Vec`. modules: Vec<(ModuleId, Module)>, - prepended_stmts: AHashMap>, - appended_stmts: AHashMap>, + prepended_stmts: FxHashMap>, + appended_stmts: FxHashMap>, } impl Modules { diff --git a/crates/swc_bundler/src/modules/sort/chunk.rs b/crates/swc_bundler/src/modules/sort/chunk.rs index 755c1cb360ef..d1ede6dd8ff8 100644 --- a/crates/swc_bundler/src/modules/sort/chunk.rs +++ b/crates/swc_bundler/src/modules/sort/chunk.rs @@ -2,11 +2,8 @@ use std::{collections::VecDeque, iter::from_fn, mem::take, time::Instant}; use indexmap::IndexSet; use petgraph::EdgeDirection::Outgoing; -use swc_common::{ - collections::{AHashSet, ARandomState}, - sync::Lrc, - SourceMap, SyntaxContext, -}; +use rustc_hash::{FxBuildHasher, FxHashSet}; +use swc_common::{sync::Lrc, SourceMap, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_utils::prepend_stmts; @@ -137,7 +134,7 @@ fn cycles_for( cycles: &[Vec], id: ModuleId, checked: &mut Vec, -) -> IndexSet { +) -> IndexSet { checked.push(id); let mut v = cycles .iter() @@ -163,8 +160,8 @@ fn toposort_real_module_ids<'a>( graph: &'a ModuleGraph, cycles: &'a [Vec], ) -> impl 'a + Iterator> { - let mut done = AHashSet::::default(); - let mut errorred = AHashSet::::default(); + let mut done = FxHashSet::::default(); + let mut errorred = FxHashSet::::default(); from_fn(move || { while let Some(id) = queue.pop_front() { diff --git a/crates/swc_bundler/src/modules/sort/graph.rs b/crates/swc_bundler/src/modules/sort/graph.rs index 18385c1fff12..d97e89eedbb2 100644 --- a/crates/swc_bundler/src/modules/sort/graph.rs +++ b/crates/swc_bundler/src/modules/sort/graph.rs @@ -4,7 +4,7 @@ use petgraph::{ EdgeDirection, EdgeDirection::{Incoming, Outgoing}, }; -use swc_common::collections::AHashSet; +use rustc_hash::FxHashSet; use swc_fast_graph::digraph::FastDiGraphMap; /// Is dependency between nodes hard? @@ -23,7 +23,7 @@ pub(super) struct StmtDepGraph { inner: FastDiGraphMap, /// Read-optimized hashset which contains all direct dependencies and /// transitive dependencies. - paths: Vec>, + paths: Vec>, } impl StmtDepGraph { @@ -45,8 +45,8 @@ impl StmtDepGraph { self.insert_transitives(a, b); } - fn calc_transitives(&self, id: usize, dir: EdgeDirection) -> AHashSet { - let mut set = AHashSet::default(); + fn calc_transitives(&self, id: usize, dir: EdgeDirection) -> FxHashSet { + let mut set = FxHashSet::default(); let mut queue = VecDeque::default(); queue.push_front(id); diff --git a/crates/swc_bundler/src/modules/sort/stmt.rs b/crates/swc_bundler/src/modules/sort/stmt.rs index c68d5251f48e..2f98386f093a 100644 --- a/crates/swc_bundler/src/modules/sort/stmt.rs +++ b/crates/swc_bundler/src/modules/sort/stmt.rs @@ -2,12 +2,8 @@ use std::{collections::VecDeque, iter::from_fn, ops::Range}; use indexmap::IndexSet; use petgraph::EdgeDirection::{Incoming as Dependants, Outgoing as Dependencies}; -use swc_common::{ - collections::{AHashMap, AHashSet, ARandomState}, - sync::Lrc, - util::take::Take, - SourceMap, SyntaxContext, -}; +use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; +use swc_common::{sync::Lrc, util::take::Take, SourceMap, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_utils::find_pat_ids; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -115,8 +111,8 @@ fn iter<'a>( // dbg!(&free); // dbg!(&module_starts); - let mut moves = AHashSet::default(); - let mut done = AHashSet::default(); + let mut moves = FxHashSet::default(); + let mut done = FxHashSet::default(); let mut stack = VecDeque::new(); stack.extend(module_starts.iter().copied()); @@ -353,7 +349,7 @@ fn iter<'a>( struct FieldInitFinder { in_object_assign: bool, in_rhs: bool, - accessed: AHashSet, + accessed: FxHashSet, } impl FieldInitFinder { @@ -518,11 +514,11 @@ impl Visit for InitializerFinder { /// But we care about modifications. #[derive(Default)] struct RequirementCalculator { - required_ids: IndexSet<(Id, Required), ARandomState>, + required_ids: IndexSet<(Id, Required), FxBuildHasher>, /// While bundling, there can be two bindings with same name and syntax /// context, in case of wrapped es modules. We exclude them from dependency /// graph. - excluded: IndexSet, + excluded: IndexSet, in_weak: bool, in_var_decl: bool, @@ -659,8 +655,8 @@ fn calc_deps(new: &[ModuleItem]) -> StmtDepGraph { tracing::debug!("Analyzing dependencies between statements"); let mut graph = StmtDepGraph::default(); - let mut declared_by = AHashMap::>::default(); - let mut uninitialized_ids = AHashMap::::default(); + let mut declared_by = FxHashMap::>::default(); + let mut uninitialized_ids = FxHashMap::::default(); for (idx, item) in new.iter().enumerate() { graph.add_node(idx); diff --git a/crates/swc_bundler/src/util.rs b/crates/swc_bundler/src/util.rs index 0bf3ea4a0ff1..fb27bb103663 100644 --- a/crates/swc_bundler/src/util.rs +++ b/crates/swc_bundler/src/util.rs @@ -2,6 +2,9 @@ use std::hash::Hash; +use rustc_hash::FxBuildHasher; +#[cfg(not(feature = "concurrent"))] +use rustc_hash::FxHashMap; use swc_common::{SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::ident::IdentLike; @@ -103,9 +106,9 @@ where V: Clone, { #[cfg(feature = "concurrent")] - inner: dashmap::DashMap, + inner: dashmap::DashMap, #[cfg(not(feature = "concurrent"))] - inner: std::cell::RefCell>, + inner: std::cell::RefCell>, } impl Default for CloneMap diff --git a/crates/swc_bundler/tests/deno.rs b/crates/swc_bundler/tests/deno.rs index 6cee599ff199..a80e639fe378 100644 --- a/crates/swc_bundler/tests/deno.rs +++ b/crates/swc_bundler/tests/deno.rs @@ -7,8 +7,9 @@ use std::{collections::HashMap, fs::write, path::PathBuf, process::Command}; use anyhow::Error; use ntest::timeout; +use rustc_hash::FxHashSet; use swc_bundler::{Bundler, Load, ModuleRecord}; -use swc_common::{collections::AHashSet, errors::HANDLER, FileName, Mark, Span, GLOBALS}; +use swc_common::{errors::HANDLER, FileName, Mark, Span, GLOBALS}; use swc_ecma_ast::*; use swc_ecma_codegen::{ text_writer::{omit_trailing_semi, JsWriter, WriteJs}, @@ -1139,7 +1140,7 @@ impl swc_bundler::Hook for Hook { } } -fn collect_exports(module: &Module) -> AHashSet { +fn collect_exports(module: &Module) -> FxHashSet { let mut v = ExportCollector::default(); module.visit_with(&mut v); @@ -1148,7 +1149,7 @@ fn collect_exports(module: &Module) -> AHashSet { #[derive(Default)] struct ExportCollector { - exports: AHashSet, + exports: FxHashSet, } impl Visit for ExportCollector { diff --git a/crates/swc_cached/Cargo.toml b/crates/swc_cached/Cargo.toml index c395538db3d8..f7eca2c9a53b 100644 --- a/crates/swc_cached/Cargo.toml +++ b/crates/swc_cached/Cargo.toml @@ -13,9 +13,9 @@ version = "1.0.0" bench = false [dependencies] -ahash = { workspace = true } -anyhow = { workspace = true } -dashmap = { workspace = true } -once_cell = { workspace = true } -regex = { workspace = true } -serde = { workspace = true } +anyhow = { workspace = true } +dashmap = { workspace = true } +once_cell = { workspace = true } +regex = { workspace = true } +rustc-hash = { workspace = true } +serde = { workspace = true } diff --git a/crates/swc_cached/src/regex.rs b/crates/swc_cached/src/regex.rs index 18b19f28f1e1..cb2cf2d03037 100644 --- a/crates/swc_cached/src/regex.rs +++ b/crates/swc_cached/src/regex.rs @@ -7,6 +7,7 @@ use anyhow::{Context, Result}; use dashmap::DashMap; use once_cell::sync::Lazy; use regex::Regex; +use rustc_hash::FxBuildHasher; use serde::{Deserialize, Serialize}; /// A regex which can be used as a configuration. @@ -30,7 +31,7 @@ impl CachedRegex { /// Get or create a cached regex. This will return the previous instance if /// it's already cached. pub fn new(input: &str) -> Result { - static CACHE: Lazy, ahash::RandomState>> = + static CACHE: Lazy, FxBuildHasher>> = Lazy::new(Default::default); if let Some(cache) = CACHE.get(input).as_deref().cloned() { diff --git a/crates/swc_common/Cargo.toml b/crates/swc_common/Cargo.toml index bb7d5e4c364c..6cf1e16b02d7 100644 --- a/crates/swc_common/Cargo.toml +++ b/crates/swc_common/Cargo.toml @@ -19,7 +19,6 @@ bench = false __plugin = [] __plugin_mode = [] __plugin_rt = [] -ahash = ["dep:ahash"] concurrent = ["parking_lot"] debug = [] default = [] @@ -37,7 +36,6 @@ __rkyv = [] rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "bytecheck", "rancor"] [dependencies] -ahash = { workspace = true, optional = true } anyhow = { workspace = true, optional = true } arbitrary = { workspace = true, features = ["derive"], optional = true } bytecheck = { workspace = true, optional = true } diff --git a/crates/swc_common/src/collections.rs b/crates/swc_common/src/collections.rs deleted file mode 100644 index 6f2fd28724ac..000000000000 --- a/crates/swc_common/src/collections.rs +++ /dev/null @@ -1,31 +0,0 @@ -#[cfg(feature = "ahash")] -pub use self::ahash::*; -#[cfg(not(feature = "ahash"))] -pub use self::rustchash::*; - -#[cfg(not(feature = "ahash"))] -mod rustchash { - use std::{ - collections::{HashMap, HashSet}, - hash::BuildHasherDefault, - }; - - use rustc_hash::FxHasher; - - pub type ARandomState = BuildHasherDefault; - - pub type AHashMap = HashMap; - - pub type AHashSet = HashSet; -} - -#[cfg(feature = "ahash")] -mod ahash { - use std::collections::{HashMap, HashSet}; - - pub type ARandomState = ahash::RandomState; - - pub type AHashMap = HashMap; - - pub type AHashSet = HashSet; -} diff --git a/crates/swc_common/src/errors/mod.rs b/crates/swc_common/src/errors/mod.rs index 13f40dd23fa4..109170486af7 100644 --- a/crates/swc_common/src/errors/mod.rs +++ b/crates/swc_common/src/errors/mod.rs @@ -17,6 +17,7 @@ use std::{ sync::atomic::{AtomicUsize, Ordering::SeqCst}, }; +use rustc_hash::FxHashSet; #[cfg(feature = "tty-emitter")] use termcolor::{Color, ColorSpec}; @@ -27,7 +28,6 @@ pub use self::{ emitter::{ColorConfig, Emitter, EmitterWriter}, }; use crate::{ - collections::AHashSet, rustc_data_structures::stable_hasher::StableHasher, sync::{Lock, LockCell, Lrc}, syntax_pos::{BytePos, FileLinesResult, FileName, Loc, MultiSpan, Span}, @@ -361,15 +361,15 @@ pub struct Handler { // This set contains the `DiagnosticId` of all emitted diagnostics to avoid // emitting the same diagnostic with extended help (`--teach`) twice, which // would be unnecessary repetition. - taught_diagnostics: Lock>, + taught_diagnostics: Lock>, /// Used to suggest rustc --explain - emitted_diagnostic_codes: Lock>, + emitted_diagnostic_codes: Lock>, // This set contains a hash of every diagnostic that has been emitted by // this handler. These hashes is used to avoid emitting the same error // twice. - emitted_diagnostics: Lock>, + emitted_diagnostics: Lock>, } fn default_track_diagnostic(_: &Diagnostic) {} diff --git a/crates/swc_common/src/lib.rs b/crates/swc_common/src/lib.rs index 3d9d59b1fca3..8d09e8cc960d 100644 --- a/crates/swc_common/src/lib.rs +++ b/crates/swc_common/src/lib.rs @@ -26,11 +26,6 @@ //! ## `plugin-mode` //! //! Allows replacing operations related to thread-local variables with a trait. -//! -//! -//! ## `ahash` -//! -//! Use `ahash` instead of `rustc_hash` for `AHashMap` and `AHashSet`. #![deny(clippy::all)] #![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(not(test), allow(unused))] @@ -59,7 +54,6 @@ pub trait AstNode: Debug + PartialEq + Clone + Spanned { } pub mod cache; -pub mod collections; pub mod comments; mod eq; pub mod errors; diff --git a/crates/swc_common/src/plugin/metadata.rs b/crates/swc_common/src/plugin/metadata.rs index a4d6ed7160fd..a52a940f9748 100644 --- a/crates/swc_common/src/plugin/metadata.rs +++ b/crates/swc_common/src/plugin/metadata.rs @@ -1,8 +1,7 @@ use std::env; use once_cell::sync::Lazy; - -use crate::collections::AHashMap; +use rustc_hash::FxHashMap; /// Indexable key to the metadata context for a transform plugin. /// @@ -41,14 +40,14 @@ pub struct TransformPluginMetadataContext { pub env: String, /// The current working directory. pub cwd: Option, - pub experimental: AHashMap, + pub experimental: FxHashMap, } impl TransformPluginMetadataContext { pub fn new( filename: Option, env: String, - experimental: Option>, + experimental: Option>, ) -> Self { static CWD: Lazy> = Lazy::new(|| { env::current_dir() diff --git a/crates/swc_common/src/source_map.rs b/crates/swc_common/src/source_map.rs index ef89f797b847..17231e0d72cd 100644 --- a/crates/swc_common/src/source_map.rs +++ b/crates/swc_common/src/source_map.rs @@ -28,13 +28,13 @@ use std::{ }; use once_cell::sync::Lazy; +use rustc_hash::FxHashMap; #[cfg(feature = "sourcemap")] use sourcemap::SourceMapBuilder; use tracing::debug; pub use crate::syntax_pos::*; use crate::{ - collections::AHashMap, errors::SourceMapper, rustc_data_structures::stable_hasher::StableHasher, sync::{Lock, LockGuard, Lrc, MappedLockGuard}, @@ -104,7 +104,7 @@ impl StableSourceFileId { #[derive(Default)] pub(super) struct SourceMapFiles { pub(super) source_files: Vec>, - stable_id_to_source_file: AHashMap>, + stable_id_to_source_file: FxHashMap>, } /// The interner for spans. diff --git a/crates/swc_common/src/syntax_pos/hygiene.rs b/crates/swc_common/src/syntax_pos/hygiene.rs index 5fb3bba233fd..5b1cb6527106 100644 --- a/crates/swc_common/src/syntax_pos/hygiene.rs +++ b/crates/swc_common/src/syntax_pos/hygiene.rs @@ -21,10 +21,11 @@ use std::{ fmt, }; +use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use super::GLOBALS; -use crate::{collections::AHashMap, EqIgnoreSpan}; +use crate::EqIgnoreSpan; /// A SyntaxContext represents a chain of macro expansions (represented by /// marks). @@ -269,7 +270,7 @@ impl Mark { #[derive(Debug)] pub(crate) struct HygieneData { syntax_contexts: Vec, - markings: AHashMap<(SyntaxContext, Mark), SyntaxContext>, + markings: FxHashMap<(SyntaxContext, Mark), SyntaxContext>, } impl Default for HygieneData { diff --git a/crates/swc_compiler_base/src/lib.rs b/crates/swc_compiler_base/src/lib.rs index a572412bdf6a..acb0dac5f063 100644 --- a/crates/swc_compiler_base/src/lib.rs +++ b/crates/swc_compiler_base/src/lib.rs @@ -12,7 +12,6 @@ use serde::{Deserialize, Serialize}; use swc_allocator::maybe::vec::Vec; use swc_atoms::JsWord; use swc_common::{ - collections::AHashMap, comments::{Comment, CommentKind, Comments, SingleThreadedComments}, errors::Handler, source_map::SourceMapGenConfig, @@ -109,7 +108,7 @@ pub struct PrintArgs<'a> { pub output_path: Option, pub inline_sources_content: bool, pub source_map: SourceMapsConfig, - pub source_map_names: &'a AHashMap, + pub source_map_names: &'a FxHashMap, pub orig: Option<&'a sourcemap::SourceMap>, pub comments: Option<&'a dyn Comments>, pub emit_source_map_columns: bool, @@ -120,7 +119,7 @@ pub struct PrintArgs<'a> { impl Default for PrintArgs<'_> { fn default() -> Self { - static DUMMY_NAMES: Lazy> = Lazy::new(Default::default); + static DUMMY_NAMES: Lazy> = Lazy::new(Default::default); PrintArgs { source_root: None, @@ -282,7 +281,7 @@ struct SwcSourceMapConfig<'a> { /// Output path of the `.map` file. output_path: Option<&'a Path>, - names: &'a AHashMap, + names: &'a FxHashMap, inline_sources_content: bool, @@ -407,7 +406,7 @@ impl Default for SourceMapsConfig { } pub struct IdentCollector { - pub names: AHashMap, + pub names: FxHashMap, } impl Visit for IdentCollector { diff --git a/crates/swc_core/Cargo.toml b/crates/swc_core/Cargo.toml index 615b041bf21f..d042ca3f651b 100644 --- a/crates/swc_core/Cargo.toml +++ b/crates/swc_core/Cargo.toml @@ -40,9 +40,6 @@ doctest = false scoped-alloc = ["swc_allocator/scoped"] -# swc_common/ahash -common_ahash = ["swc_common/ahash"] - transform_common = [] # swc_ecma_loader/cache* diff --git a/crates/swc_css_lints/Cargo.toml b/crates/swc_css_lints/Cargo.toml index fb6812933f57..442ca26dd950 100644 --- a/crates/swc_css_lints/Cargo.toml +++ b/crates/swc_css_lints/Cargo.toml @@ -16,6 +16,7 @@ bench = false auto_impl = { workspace = true } parking_lot = { workspace = true } rayon = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } thiserror = { workspace = true } diff --git a/crates/swc_css_lints/src/rules/font_family_no_duplicate_names.rs b/crates/swc_css_lints/src/rules/font_family_no_duplicate_names.rs index ea20c6e9a906..17dddefd89a7 100644 --- a/crates/swc_css_lints/src/rules/font_family_no_duplicate_names.rs +++ b/crates/swc_css_lints/src/rules/font_family_no_duplicate_names.rs @@ -1,5 +1,6 @@ +use rustc_hash::FxHashSet; use serde::{Deserialize, Serialize}; -use swc_common::{collections::AHashSet, Span}; +use swc_common::Span; use swc_css_ast::*; use swc_css_visit::{Visit, VisitWith}; @@ -77,7 +78,7 @@ impl FontFamilyNoDuplicateNames { fonts .iter() - .fold(AHashSet::default(), |mut seen, (font, span)| { + .fold(FxHashSet::default(), |mut seen, (font, span)| { let name = font.name(); if seen.contains(&font) && self.ignored.iter().all(|item| !item.is_match(name)) { self.ctx diff --git a/crates/swc_css_lints/src/rules/no_duplicate_at_import_rules.rs b/crates/swc_css_lints/src/rules/no_duplicate_at_import_rules.rs index 39704776ecbe..cb632d726f21 100644 --- a/crates/swc_css_lints/src/rules/no_duplicate_at_import_rules.rs +++ b/crates/swc_css_lints/src/rules/no_duplicate_at_import_rules.rs @@ -1,7 +1,7 @@ use std::fmt::Display; +use rustc_hash::FxHashSet; use swc_atoms::JsWord; -use swc_common::collections::AHashSet; use swc_css_ast::*; use swc_css_visit::{Visit, VisitWith}; @@ -28,7 +28,7 @@ where #[derive(Debug, Default)] struct NoDuplicateAtImportRules { ctx: LintRuleContext<()>, - imports: AHashSet<(JsWord, Option)>, + imports: FxHashSet<(JsWord, Option)>, import_at_rules: Option, } diff --git a/crates/swc_css_minifier/Cargo.toml b/crates/swc_css_minifier/Cargo.toml index 39fcb909a6b9..1ccda5df649c 100644 --- a/crates/swc_css_minifier/Cargo.toml +++ b/crates/swc_css_minifier/Cargo.toml @@ -13,7 +13,8 @@ version = "5.0.0" bench = false [dependencies] -serde = { workspace = true } +rustc-hash = { workspace = true } +serde = { workspace = true } swc_atoms = { version = "3.0.4", path = "../swc_atoms" } swc_common = { version = "5.0.1", path = "../swc_common" } diff --git a/crates/swc_css_minifier/src/compressor/calc_sum.rs b/crates/swc_css_minifier/src/compressor/calc_sum.rs index ea30b2a317b8..422caa840b22 100644 --- a/crates/swc_css_minifier/src/compressor/calc_sum.rs +++ b/crates/swc_css_minifier/src/compressor/calc_sum.rs @@ -1,5 +1,6 @@ +use rustc_hash::FxHashMap; use swc_atoms::Atom; -use swc_common::{collections::AHashMap, Span}; +use swc_common::Span; use swc_css_ast::*; use super::Compressor; @@ -315,7 +316,7 @@ fn simplify_calc_operator_node_sum(nodes: &[CalcNode]) -> CalcNode { // combine numbers, combine percentages, combine px values, etc.) let mut number: Option = None; let mut percentage: Option = None; - let mut dimensions: AHashMap = AHashMap::default(); + let mut dimensions: FxHashMap = FxHashMap::default(); let mut idx = 0; while idx < nodes.len() { match &nodes[idx] { @@ -441,7 +442,7 @@ fn try_to_switch_sign_of_nodes(nodes: &[CalcNode]) -> Option { } fn try_to_reduce_node_with_dimensions( - dimensions: &mut AHashMap, + dimensions: &mut FxHashMap, nodes: &mut Vec, ) { try_to_reduce_node_with_absolute_lengths(dimensions, nodes); @@ -452,7 +453,7 @@ fn try_to_reduce_node_with_dimensions( // https://www.w3.org/TR/css-values-4/#absolute-lengths fn try_to_reduce_node_with_absolute_lengths( - dimensions: &mut AHashMap, + dimensions: &mut FxHashMap, nodes: &mut Vec, ) { if let (Some(idx_cm), Some(idx_mm)) = (dimensions.get("cm"), dimensions.get("mm")) { @@ -521,7 +522,7 @@ fn try_to_reduce_node_with_absolute_lengths( // https://www.w3.org/TR/css-values-4/#time fn try_to_reduce_node_with_durations( - dimensions: &mut AHashMap, + dimensions: &mut FxHashMap, nodes: &mut Vec, ) { if let (Some(idx_ms), Some(idx_s)) = (dimensions.get("ms"), dimensions.get("s")) { @@ -537,7 +538,7 @@ fn try_to_reduce_node_with_durations( // https://www.w3.org/TR/css-values-4/#frequency fn try_to_reduce_node_with_frequencies( - dimensions: &mut AHashMap, + dimensions: &mut FxHashMap, nodes: &mut Vec, ) { if let (Some(idx_hz), Some(idx_khz)) = (dimensions.get("hz"), dimensions.get("khz")) { @@ -553,7 +554,7 @@ fn try_to_reduce_node_with_frequencies( // https://www.w3.org/TR/css-values-4/#resolution fn try_to_reduce_node_with_resolutions( - dimensions: &mut AHashMap, + dimensions: &mut FxHashMap, nodes: &mut Vec, ) { match (dimensions.get("dppx"), dimensions.get("x")) { diff --git a/crates/swc_css_minifier/src/compressor/rules.rs b/crates/swc_css_minifier/src/compressor/rules.rs index 874c3ab429c3..5e7da067819e 100644 --- a/crates/swc_css_minifier/src/compressor/rules.rs +++ b/crates/swc_css_minifier/src/compressor/rules.rs @@ -1,7 +1,8 @@ use std::mem::take; +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, util::take::Take, EqIgnoreSpan, Span, Spanned}; +use swc_common::{util::take::Take, EqIgnoreSpan, Span, Spanned}; use swc_css_ast::*; use swc_css_visit::{Visit, VisitMutWith, VisitWith}; @@ -78,7 +79,7 @@ impl Compressor { } } - fn collect_names(&self, at_rule: &AtRule, names: &mut AHashMap) { + fn collect_names(&self, at_rule: &AtRule, names: &mut FxHashMap) { let Some(prelude) = &at_rule.prelude else { return; }; @@ -113,7 +114,7 @@ impl Compressor { fn discard_overridden( &self, parent_node: ParentNode, - names: &mut AHashMap, + names: &mut FxHashMap, remove_rules_list: &mut Vec, ) { let mut discarder = |at_rule: &AtRule| { @@ -372,7 +373,7 @@ impl Compressor { } pub(super) fn compress_stylesheet(&mut self, stylesheet: &mut Stylesheet) { - let mut names: AHashMap = Default::default(); + let mut names: FxHashMap = Default::default(); let mut prev_rule_idx = None; let mut remove_rules_list = Vec::new(); let mut prev_index = 0; @@ -509,7 +510,7 @@ impl Compressor { } pub(super) fn compress_simple_block(&mut self, simple_block: &mut SimpleBlock) { - let mut names: AHashMap = Default::default(); + let mut names: FxHashMap = Default::default(); let mut prev_rule_idx = None; let mut remove_rules_list = Vec::new(); let mut prev_index = 0; diff --git a/crates/swc_css_parser/tests/fixture/at-rule/charset/invalid/leading-comments.json b/crates/swc_css_parser/tests/fixture/at-rule/charset/invalid/leading-comments.json index 2124cca26c0b..349d0b7ecbc4 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/charset/invalid/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/charset/invalid/leading-comments.json @@ -9,24 +9,24 @@ "text": "/* Invalid, more than one space */" } ], - "65": [ + "212": [ { "kind": "Block", "span": { - "start": 24, - "end": 64 + "start": 141, + "end": 211 }, - "text": "/* Invalid, wrong quoting style used */" + "text": "/* Invalid, there is a character (a space) before the at-rule */" } ], - "212": [ + "65": [ { "kind": "Block", "span": { - "start": 141, - "end": 211 + "start": 24, + "end": 64 }, - "text": "/* Invalid, there is a character (a space) before the at-rule */" + "text": "/* Invalid, wrong quoting style used */" } ] } diff --git a/crates/swc_css_parser/tests/fixture/at-rule/document/leading-comments.json b/crates/swc_css_parser/tests/fixture/at-rule/document/leading-comments.json index 3a4f4df3df23..47a071b934b5 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/document/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/document/leading-comments.json @@ -1,14 +1,4 @@ { - "432": [ - { - "kind": "Block", - "span": { - "start": 419, - "end": 432 - }, - "text": "/* filter */" - } - ], "461": [ { "kind": "Block", @@ -28,5 +18,15 @@ }, "text": "/* near */" } + ], + "432": [ + { + "kind": "Block", + "span": { + "start": 419, + "end": 432 + }, + "text": "/* filter */" + } ] } diff --git a/crates/swc_css_parser/tests/fixture/at-rule/import/leading-comments.json b/crates/swc_css_parser/tests/fixture/at-rule/import/leading-comments.json index 0f5d64da3532..3c22bdb369a8 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/import/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/import/leading-comments.json @@ -1,236 +1,236 @@ { - "4957": [ + "5236": [ { "kind": "Block", "span": { - "start": 4937, - "end": 4957 + "start": 5222, + "end": 5236 }, "text": "/* Comment */" } ], - "4989": [ + "5055": [ { "kind": "Block", "span": { - "start": 4972, - "end": 4989 + "start": 5041, + "end": 5055 }, "text": "/* Comment */" } ], - "5236": [ + "5321": [ { "kind": "Block", "span": { - "start": 5222, - "end": 5236 + "start": 5307, + "end": 5321 }, "text": "/* Comment */" } ], - "4971": [ + "5293": [ { "kind": "Block", "span": { - "start": 4957, - "end": 4971 + "start": 5279, + "end": 5293 }, "text": "/* Comment */" } ], - "5003": [ + "4989": [ { "kind": "Block", "span": { - "start": 4989, - "end": 5003 + "start": 4972, + "end": 4989 }, "text": "/* Comment */" } ], - "5023": [ + "5077": [ { "kind": "Block", "span": { - "start": 5004, - "end": 5023 + "start": 5055, + "end": 5077 }, "text": "/* Comment */" } ], - "5055": [ + "5023": [ { "kind": "Block", "span": { - "start": 5041, - "end": 5055 + "start": 5004, + "end": 5023 }, "text": "/* Comment */" } ], - "5148": [ + "5092": [ { "kind": "Block", "span": { - "start": 5134, - "end": 5148 + "start": 5078, + "end": 5092 }, "text": "/* Comment */" } ], - "5110": [ + "4957": [ { "kind": "Block", "span": { - "start": 5092, - "end": 5110 + "start": 4937, + "end": 4957 }, "text": "/* Comment */" } ], - "5171": [ + "5003": [ { "kind": "Block", "span": { - "start": 5157, - "end": 5171 + "start": 4989, + "end": 5003 }, "text": "/* Comment */" } ], - "5040": [ + "4899": [ { "kind": "Block", "span": { - "start": 5024, - "end": 5040 + "start": 4879, + "end": 4899 }, "text": "/* Comment */" } ], - "5293": [ + "5199": [ { "kind": "Block", "span": { - "start": 5279, - "end": 5293 + "start": 5185, + "end": 5199 }, "text": "/* Comment */" } ], - "6591": [ + "4937": [ { "kind": "Block", "span": { - "start": 6544, - "end": 6556 + "start": 4915, + "end": 4937 }, - "text": "/*.foo {*/" - }, + "text": "/* Comment */" + } + ], + "4914": [ { "kind": "Block", "span": { - "start": 6544, - "end": 6584 + "start": 4900, + "end": 4914 }, - "text": "/* @import 'path.css';*/" - }, + "text": "/* Comment */" + } + ], + "5110": [ { "kind": "Block", "span": { - "start": 6544, - "end": 6590 + "start": 5092, + "end": 5110 }, - "text": "/*}*/" + "text": "/* Comment */" } ], - "5092": [ + "4879": [ { "kind": "Block", "span": { - "start": 5078, - "end": 5092 + "start": 4860, + "end": 4879 }, "text": "/* Comment */" } ], - "4859": [ + "6591": [ { "kind": "Block", "span": { - "start": 4845, - "end": 4859 + "start": 6544, + "end": 6556 }, - "text": "/* Comment */" - } - ], - "5077": [ + "text": "/*.foo {*/" + }, { "kind": "Block", "span": { - "start": 5055, - "end": 5077 + "start": 6544, + "end": 6584 }, - "text": "/* Comment */" - } - ], - "4914": [ + "text": "/* @import 'path.css';*/" + }, { "kind": "Block", "span": { - "start": 4900, - "end": 4914 + "start": 6544, + "end": 6590 }, - "text": "/* Comment */" + "text": "/*}*/" } ], - "4879": [ + "5148": [ { "kind": "Block", "span": { - "start": 4860, - "end": 4879 + "start": 5134, + "end": 5148 }, "text": "/* Comment */" } ], - "5199": [ + "4971": [ { "kind": "Block", "span": { - "start": 5185, - "end": 5199 + "start": 4957, + "end": 4971 }, "text": "/* Comment */" } ], - "4937": [ + "5171": [ { "kind": "Block", "span": { - "start": 4915, - "end": 4937 + "start": 5157, + "end": 5171 }, "text": "/* Comment */" } ], - "5321": [ + "5040": [ { "kind": "Block", "span": { - "start": 5307, - "end": 5321 + "start": 5024, + "end": 5040 }, "text": "/* Comment */" } ], - "4899": [ + "4859": [ { "kind": "Block", "span": { - "start": 4879, - "end": 4899 + "start": 4845, + "end": 4859 }, "text": "/* Comment */" } diff --git a/crates/swc_css_parser/tests/fixture/at-rule/keyframe/leading-comments.json b/crates/swc_css_parser/tests/fixture/at-rule/keyframe/leading-comments.json index dc1948c2c436..fa0789f0c108 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/keyframe/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/keyframe/leading-comments.json @@ -1,20 +1,20 @@ { - "93": [ + "58": [ { "kind": "Block", "span": { - "start": 83, - "end": 93 + "start": 48, + "end": 58 }, "text": "/* ... */" } ], - "58": [ + "93": [ { "kind": "Block", "span": { - "start": 48, - "end": 58 + "start": 83, + "end": 93 }, "text": "/* ... */" } diff --git a/crates/swc_css_parser/tests/fixture/at-rule/layer/leading-comments.json b/crates/swc_css_parser/tests/fixture/at-rule/layer/leading-comments.json index db9f955697eb..f5b022855c19 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/layer/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/layer/leading-comments.json @@ -1,14 +1,4 @@ { - "365": [ - { - "kind": "Block", - "span": { - "start": 351, - "end": 365 - }, - "text": "/* layer 1 */" - } - ], "390": [ { "kind": "Block", @@ -28,5 +18,15 @@ }, "text": "/* These styles will be added to the theme layer inside the framework layer */" } + ], + "365": [ + { + "kind": "Block", + "span": { + "start": 351, + "end": 365 + }, + "text": "/* layer 1 */" + } ] } diff --git a/crates/swc_css_parser/tests/fixture/at-rule/scope/basic/leading-comments.json b/crates/swc_css_parser/tests/fixture/at-rule/scope/basic/leading-comments.json index d3fc4a74df05..c14bd8ea3b3e 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/scope/basic/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/scope/basic/leading-comments.json @@ -1,20 +1,20 @@ { - "179": [ + "59": [ { "kind": "Block", "span": { - "start": 129, - "end": 179 + "start": 9, + "end": 59 }, "text": "/* Only match links inside a light-scheme */" } ], - "59": [ + "179": [ { "kind": "Block", "span": { - "start": 9, - "end": 59 + "start": 129, + "end": 179 }, "text": "/* Only match links inside a light-scheme */" } diff --git a/crates/swc_css_parser/tests/fixture/at-rule/unknown/leading-comments.json b/crates/swc_css_parser/tests/fixture/at-rule/unknown/leading-comments.json index dd8ea47ef6ee..45862b4629d1 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/unknown/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/unknown/leading-comments.json @@ -1,162 +1,162 @@ { - "938": [ + "300": [ { "kind": "Block", "span": { - "start": 929, - "end": 938 + "start": 291, + "end": 300 }, "text": "/*test*/" } ], - "893": [ + "527": [ { "kind": "Block", "span": { - "start": 884, - "end": 893 + "start": 393, + "end": 526 }, - "text": "/*test*/" + "text": "/*@unknown !*test*!x!*test*!,!*test*!y!*test*! x(!*test*!1!*test*!+!*test*!2!*test*!)!*test*!{!*test*!p!*test*!:!*test*!v!*test*!}*/" } ], - "1109": [ + "346": [ { "kind": "Block", "span": { - "start": 948, - "end": 1108 + "start": 337, + "end": 346 }, - "text": "/*@unknown !*test*!x!*test*!,!*test*!y!*test*! f(!*test*!1!*test*!+!*test*!2!*test*!)!*test*!{!*test*!s!*test*!{!*test*!p!*test*!:!*test*!v!*test*!}!*test*!}*/" + "text": "/*test*/" } ], - "884": [ + "365": [ { "kind": "Block", "span": { - "start": 875, - "end": 884 + "start": 356, + "end": 365 }, "text": "/*test*/" } ], - "318": [ + "392": [ { "kind": "Block", "span": { - "start": 309, - "end": 318 + "start": 383, + "end": 392 }, "text": "/*test*/" } ], - "309": [ + "792": [ { "kind": "Block", "span": { - "start": 300, - "end": 309 + "start": 783, + "end": 792 }, "text": "/*test*/" } ], - "300": [ + "819": [ { "kind": "Block", "span": { - "start": 291, - "end": 300 + "start": 810, + "end": 819 }, "text": "/*test*/" } ], - "291": [ + "846": [ { "kind": "Block", "span": { - "start": 282, - "end": 291 + "start": 837, + "end": 846 }, "text": "/*test*/" } ], - "282": [ + "865": [ { "kind": "Block", "span": { - "start": 266, - "end": 282 + "start": 856, + "end": 865 }, "text": "/*test*/" } ], - "346": [ + "884": [ { "kind": "Block", "span": { - "start": 337, - "end": 346 + "start": 875, + "end": 884 }, "text": "/*test*/" } ], - "337": [ + "911": [ { "kind": "Block", "span": { - "start": 328, - "end": 337 + "start": 902, + "end": 911 }, "text": "/*test*/" } ], - "78": [ + "938": [ { "kind": "Block", "span": { - "start": 69, - "end": 78 + "start": 929, + "end": 938 }, "text": "/*test*/" } ], - "846": [ + "106": [ { "kind": "Block", "span": { - "start": 837, - "end": 846 + "start": 97, + "end": 106 }, "text": "/*test*/" } ], - "392": [ + "309": [ { "kind": "Block", "span": { - "start": 383, - "end": 392 + "start": 300, + "end": 309 }, "text": "/*test*/" } ], - "837": [ + "282": [ { "kind": "Block", "span": { - "start": 828, - "end": 837 + "start": 266, + "end": 282 }, "text": "/*test*/" } ], - "383": [ + "1109": [ { "kind": "Block", "span": { - "start": 374, - "end": 383 + "start": 948, + "end": 1108 }, - "text": "/*test*/" + "text": "/*@unknown !*test*!x!*test*!,!*test*!y!*test*! f(!*test*!1!*test*!+!*test*!2!*test*!)!*test*!{!*test*!s!*test*!{!*test*!p!*test*!:!*test*!v!*test*!}!*test*!}*/" } ], "828": [ @@ -179,172 +179,172 @@ "text": "/*test*/" } ], - "819": [ + "801": [ { "kind": "Block", "span": { - "start": 810, - "end": 819 + "start": 792, + "end": 801 }, "text": "/*test*/" } ], - "947": [ + "874": [ { "kind": "Block", "span": { - "start": 938, - "end": 947 + "start": 865, + "end": 874 }, "text": "/*test*/" } ], - "365": [ + "893": [ { "kind": "Block", "span": { - "start": 356, - "end": 365 + "start": 884, + "end": 893 }, "text": "/*test*/" } ], - "106": [ + "920": [ { "kind": "Block", "span": { - "start": 97, - "end": 106 + "start": 911, + "end": 920 }, "text": "/*test*/" } ], - "810": [ + "947": [ { "kind": "Block", "span": { - "start": 801, - "end": 810 + "start": 938, + "end": 947 }, "text": "/*test*/" } ], - "356": [ + "318": [ { "kind": "Block", "span": { - "start": 347, - "end": 356 + "start": 309, + "end": 318 }, "text": "/*test*/" } ], - "97": [ + "291": [ { "kind": "Block", "span": { - "start": 88, - "end": 97 + "start": 282, + "end": 291 }, "text": "/*test*/" } ], - "801": [ + "337": [ { "kind": "Block", "span": { - "start": 792, - "end": 801 + "start": 328, + "end": 337 }, "text": "/*test*/" } ], - "865": [ + "837": [ { "kind": "Block", "span": { - "start": 856, - "end": 865 + "start": 828, + "end": 837 }, "text": "/*test*/" } ], - "792": [ + "383": [ { "kind": "Block", "span": { - "start": 783, - "end": 792 + "start": 374, + "end": 383 }, "text": "/*test*/" } ], - "874": [ + "356": [ { "kind": "Block", "span": { - "start": 865, - "end": 874 + "start": 347, + "end": 356 }, "text": "/*test*/" } ], - "920": [ + "783": [ { "kind": "Block", "span": { - "start": 911, - "end": 920 + "start": 767, + "end": 783 }, "text": "/*test*/" } ], - "527": [ + "810": [ { "kind": "Block", "span": { - "start": 393, - "end": 526 + "start": 801, + "end": 810 }, - "text": "/*@unknown !*test*!x!*test*!,!*test*!y!*test*! x(!*test*!1!*test*!+!*test*!2!*test*!)!*test*!{!*test*!p!*test*!:!*test*!v!*test*!}*/" + "text": "/*test*/" } ], - "783": [ + "902": [ { "kind": "Block", "span": { - "start": 767, - "end": 783 + "start": 893, + "end": 902 }, "text": "/*test*/" } ], - "911": [ + "929": [ { "kind": "Block", "span": { - "start": 902, - "end": 911 + "start": 920, + "end": 929 }, "text": "/*test*/" } ], - "902": [ + "78": [ { "kind": "Block", "span": { - "start": 893, - "end": 902 + "start": 69, + "end": 78 }, "text": "/*test*/" } ], - "929": [ + "97": [ { "kind": "Block", "span": { - "start": 920, - "end": 929 + "start": 88, + "end": 97 }, "text": "/*test*/" } diff --git a/crates/swc_css_parser/tests/fixture/comment/leading-comments.json b/crates/swc_css_parser/tests/fixture/comment/leading-comments.json index 94ba434633eb..c0a5da3ad419 100644 --- a/crates/swc_css_parser/tests/fixture/comment/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/comment/leading-comments.json @@ -1,78 +1,52 @@ { - "506": [ - { - "kind": "Block", - "span": { - "start": 360, - "end": 371 - }, - "text": "/*!test*/" - }, - { - "kind": "Block", - "span": { - "start": 360, - "end": 382 - }, - "text": "/*!te\nst*/" - }, - { - "kind": "Block", - "span": { - "start": 360, - "end": 395 - }, - "text": "/*!te\n\n\nst*/" - }, - { - "kind": "Block", - "span": { - "start": 360, - "end": 407 - }, - "text": "/*!te**st*/" - }, + "92": [ { "kind": "Block", "span": { - "start": 360, - "end": 438 + "start": 76, + "end": 92 }, - "text": "/****************************/" - }, + "text": "/* comment */" + } + ], + "238": [ { "kind": "Block", "span": { - "start": 360, - "end": 478 + "start": 228, + "end": 236 }, - "text": "/*************** FOO *****************/" - }, + "text": "/* b */" + } + ], + "357": [ { "kind": "Block", "span": { - "start": 360, - "end": 492 + "start": 343, + "end": 357 }, "text": "/* comment */" - }, + } + ], + "76": [ { "kind": "Block", "span": { - "start": 360, - "end": 505 + "start": 62, + "end": 76 }, - "text": "/* comment *//* comment */" + "text": "/* comment */" } ], - "238": [ + "226": [ { "kind": "Block", "span": { - "start": 228, - "end": 236 + "start": 212, + "end": 226 }, - "text": "/* b */" + "text": "/* end */" } ], "14": [ @@ -85,6 +59,16 @@ "text": "/* comment */" } ], + "191": [ + { + "kind": "Block", + "span": { + "start": 173, + "end": 191 + }, + "text": "/* between */" + } + ], "133": [ { "kind": "Block", @@ -111,132 +95,148 @@ "text": "/* */" } ], - "226": [ + "506": [ { "kind": "Block", "span": { - "start": 212, - "end": 226 + "start": 360, + "end": 371 }, - "text": "/* end */" - } - ], - "191": [ + "text": "/*!test*/" + }, { "kind": "Block", "span": { - "start": 173, - "end": 191 + "start": 360, + "end": 382 }, - "text": "/* between */" - } - ], - "92": [ + "text": "/*!te\nst*/" + }, { "kind": "Block", "span": { - "start": 76, - "end": 92 + "start": 360, + "end": 395 }, - "text": "/* comment */" - } - ], - "313": [ + "text": "/*!te\n\n\nst*/" + }, { "kind": "Block", "span": { - "start": 294, - "end": 313 + "start": 360, + "end": 407 }, - "text": "/* comment */" - } - ], - "28": [ + "text": "/*!te**st*/" + }, { "kind": "Block", "span": { - "start": 14, - "end": 28 + "start": 360, + "end": 438 + }, + "text": "/****************************/" + }, + { + "kind": "Block", + "span": { + "start": 360, + "end": 478 + }, + "text": "/*************** FOO *****************/" + }, + { + "kind": "Block", + "span": { + "start": 360, + "end": 492 }, "text": "/* comment */" + }, + { + "kind": "Block", + "span": { + "start": 360, + "end": 505 + }, + "text": "/* comment *//* comment */" } ], - "357": [ + "271": [ { "kind": "Block", "span": { - "start": 343, - "end": 357 + "start": 259, + "end": 271 }, - "text": "/* comment */" + "text": "/* c */" } ], - "336": [ + "44": [ { "kind": "Block", "span": { - "start": 322, - "end": 336 + "start": 30, + "end": 44 }, "text": "/* comment */" } ], - "62": [ + "294": [ { "kind": "Block", "span": { - "start": 44, - "end": 62 + "start": 275, + "end": 294 }, "text": "/* comment */" } ], - "155": [ + "313": [ { "kind": "Block", "span": { - "start": 138, - "end": 155 + "start": 294, + "end": 313 }, - "text": "/* inside */" + "text": "/* comment */" } ], - "271": [ + "336": [ { "kind": "Block", "span": { - "start": 259, - "end": 271 + "start": 322, + "end": 336 }, - "text": "/* c */" + "text": "/* comment */" } ], - "76": [ + "155": [ { "kind": "Block", "span": { - "start": 62, - "end": 76 + "start": 138, + "end": 155 }, - "text": "/* comment */" + "text": "/* inside */" } ], - "44": [ + "28": [ { "kind": "Block", "span": { - "start": 30, - "end": 44 + "start": 14, + "end": 28 }, "text": "/* comment */" } ], - "294": [ + "62": [ { "kind": "Block", "span": { - "start": 275, - "end": 294 + "start": 44, + "end": 62 }, "text": "/* comment */" } diff --git a/crates/swc_css_parser/tests/fixture/declaration/leading-comments.json b/crates/swc_css_parser/tests/fixture/declaration/leading-comments.json index cf1c78bf3e67..42a69e322381 100644 --- a/crates/swc_css_parser/tests/fixture/declaration/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/declaration/leading-comments.json @@ -1,22 +1,22 @@ { - "601": [ + "527": [ { "kind": "Block", "span": { - "start": 593, - "end": 601 + "start": 519, + "end": 527 }, - "text": "/* ; */" + "text": "/**/" } ], - "527": [ + "601": [ { "kind": "Block", "span": { - "start": 519, - "end": 527 + "start": 593, + "end": 601 }, - "text": "/**/" + "text": "/* ; */" } ] } diff --git a/crates/swc_css_parser/tests/fixture/function/calc/leading-comments.json b/crates/swc_css_parser/tests/fixture/function/calc/leading-comments.json index 34446812f942..402fe5d87f8f 100644 --- a/crates/swc_css_parser/tests/fixture/function/calc/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/function/calc/leading-comments.json @@ -1,12 +1,12 @@ { - "1779": [ + "1659": [ { "kind": "Block", "span": { - "start": 1718, - "end": 1779 + "start": 1561, + "end": 1659 }, - "text": "/* Force the font-size to stay between 12px and 100px */" + "text": "/* Set font-size to 10x the average of vw and vh,\n but don’t let it go below 12px. */" } ], "1277": [ @@ -19,24 +19,24 @@ "text": "/*height: -webkit-calc(9/16 * 100%)!important;*/" } ], - "1319": [ + "1779": [ { "kind": "Block", "span": { - "start": 1277, - "end": 1319 + "start": 1718, + "end": 1779 }, - "text": "/*width: -moz-calc((50px - 50%)*2);*/" + "text": "/* Force the font-size to stay between 12px and 100px */" } ], - "1659": [ + "1319": [ { "kind": "Block", "span": { - "start": 1561, - "end": 1659 + "start": 1277, + "end": 1319 }, - "text": "/* Set font-size to 10x the average of vw and vh,\n but don’t let it go below 12px. */" + "text": "/*width: -moz-calc((50px - 50%)*2);*/" } ] } diff --git a/crates/swc_css_parser/tests/fixture/important/basic/leading-comments.json b/crates/swc_css_parser/tests/fixture/important/basic/leading-comments.json index 12af469695c3..7d9f653a8c36 100644 --- a/crates/swc_css_parser/tests/fixture/important/basic/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/important/basic/leading-comments.json @@ -1,42 +1,42 @@ { - "416": [ + "375": [ { "kind": "Block", "span": { - "start": 404, - "end": 416 + "start": 363, + "end": 375 }, "text": "/*! test */" } ], - "483": [ + "416": [ { "kind": "Block", "span": { - "start": 471, - "end": 483 + "start": 404, + "end": 416 }, - "text": "/* sep */" + "text": "/*! test */" } ], - "375": [ + "331": [ { "kind": "Block", "span": { - "start": 363, - "end": 375 + "start": 319, + "end": 331 }, - "text": "/*! test */" + "text": "/* test */" } ], - "331": [ + "483": [ { "kind": "Block", "span": { - "start": 319, - "end": 331 + "start": 471, + "end": 483 }, - "text": "/* test */" + "text": "/* sep */" } ] } diff --git a/crates/swc_css_parser/tests/fixture/selector/comments/leading-comments.json b/crates/swc_css_parser/tests/fixture/selector/comments/leading-comments.json index c46cbfa81626..22a1f1072bc4 100644 --- a/crates/swc_css_parser/tests/fixture/selector/comments/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/selector/comments/leading-comments.json @@ -1,34 +1,44 @@ { - "256": [ + "27": [ { "kind": "Block", "span": { - "start": 245, - "end": 256 + "start": 16, + "end": 27 }, "text": "/* test */" } ], - "285": [ + "215": [ { "kind": "Block", "span": { - "start": 274, - "end": 285 + "start": 205, + "end": 215 }, - "text": "/* test */" + "text": "/* { } */" } ], - "215": [ + "111": [ { "kind": "Block", "span": { - "start": 205, - "end": 215 + "start": 101, + "end": 111 }, "text": "/* { } */" } ], + "199": [ + { + "kind": "Block", + "span": { + "start": 188, + "end": 199 + }, + "text": "/* test */" + } + ], "95": [ { "kind": "Block", @@ -39,22 +49,22 @@ "text": "/* test */" } ], - "147": [ + "245": [ { "kind": "Block", "span": { - "start": 137, - "end": 147 + "start": 234, + "end": 245 }, - "text": "/* { } */" + "text": "/* test */" } ], - "272": [ + "164": [ { "kind": "Block", "span": { - "start": 261, - "end": 272 + "start": 153, + "end": 164 }, "text": "/* test */" } @@ -69,24 +79,24 @@ "text": "/* { } */" } ], - "199": [ + "272": [ { "kind": "Block", "span": { - "start": 188, - "end": 199 + "start": 261, + "end": 272 }, "text": "/* test */" } ], - "164": [ + "79": [ { "kind": "Block", "span": { - "start": 153, - "end": 164 + "start": 69, + "end": 79 }, - "text": "/* test */" + "text": "/* { } */" } ], "129": [ @@ -99,84 +109,74 @@ "text": "/* test */" } ], - "62": [ - { - "kind": "Block", - "span": { - "start": 50, - "end": 61 - }, - "text": "/* test */" - } - ], - "27": [ + "256": [ { "kind": "Block", "span": { - "start": 16, - "end": 27 + "start": 245, + "end": 256 }, "text": "/* test */" } ], - "231": [ + "44": [ { "kind": "Block", "span": { - "start": 220, - "end": 231 + "start": 33, + "end": 43 }, - "text": "/* test */" + "text": "/* { } */" } ], - "181": [ + "147": [ { "kind": "Block", "span": { - "start": 171, - "end": 181 + "start": 137, + "end": 147 }, "text": "/* { } */" } ], - "245": [ + "62": [ { "kind": "Block", "span": { - "start": 234, - "end": 245 + "start": 50, + "end": 61 }, "text": "/* test */" } ], - "111": [ + "285": [ { "kind": "Block", "span": { - "start": 101, - "end": 111 + "start": 274, + "end": 285 }, - "text": "/* { } */" + "text": "/* test */" } ], - "79": [ + "181": [ { "kind": "Block", "span": { - "start": 69, - "end": 79 + "start": 171, + "end": 181 }, "text": "/* { } */" } ], - "44": [ + "231": [ { "kind": "Block", "span": { - "start": 33, - "end": 43 + "start": 220, + "end": 231 }, - "text": "/* { } */" + "text": "/* test */" } ] } diff --git a/crates/swc_css_parser/tests/fixture/selector/nesting/leading-comments.json b/crates/swc_css_parser/tests/fixture/selector/nesting/leading-comments.json index e6632b7b9bd2..9b674e762622 100644 --- a/crates/swc_css_parser/tests/fixture/selector/nesting/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/selector/nesting/leading-comments.json @@ -1,14 +1,4 @@ { - "1393": [ - { - "kind": "Block", - "span": { - "start": 1311, - "end": 1393 - }, - "text": "/* valid, starts with a colon,\n and equivalent to the previous rule. */" - } - ], "1278": [ { "kind": "Block", @@ -60,5 +50,15 @@ }, "text": "/*}*/" } + ], + "1393": [ + { + "kind": "Block", + "span": { + "start": 1311, + "end": 1393 + }, + "text": "/* valid, starts with a colon,\n and equivalent to the previous rule. */" + } ] } diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/an-plus-b/leading-comments.json b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/an-plus-b/leading-comments.json index 589af6f1a71d..1bd311b43c80 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/an-plus-b/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/an-plus-b/leading-comments.json @@ -1,80 +1,80 @@ { - "1505": [ + "1477": [ { "kind": "Block", "span": { - "start": 1496, - "end": 1505 + "start": 1459, + "end": 1477 }, "text": "/*test*/" } ], - "1534": [ + "1554": [ { "kind": "Block", "span": { - "start": 1511, - "end": 1534 + "start": 1545, + "end": 1554 }, "text": "/*test*/" } ], - "1563": [ + "1496": [ { "kind": "Block", "span": { - "start": 1554, - "end": 1563 + "start": 1487, + "end": 1496 }, "text": "/*test*/" } ], - "1496": [ + "1563": [ { "kind": "Block", "span": { - "start": 1487, - "end": 1496 + "start": 1554, + "end": 1563 }, "text": "/*test*/" } ], - "1477": [ + "1534": [ { "kind": "Block", "span": { - "start": 1459, - "end": 1477 + "start": 1511, + "end": 1534 }, "text": "/*test*/" } ], - "1554": [ + "1505": [ { "kind": "Block", "span": { - "start": 1545, - "end": 1554 + "start": 1496, + "end": 1505 }, "text": "/*test*/" } ], - "1487": [ + "1545": [ { "kind": "Block", "span": { - "start": 1477, - "end": 1487 + "start": 1534, + "end": 1545 }, "text": "/*test*/" } ], - "1545": [ + "1487": [ { "kind": "Block", "span": { - "start": 1534, - "end": 1545 + "start": 1477, + "end": 1487 }, "text": "/*test*/" } diff --git a/crates/swc_css_parser/tests/fixture/value/custom-property/leading-comments.json b/crates/swc_css_parser/tests/fixture/value/custom-property/leading-comments.json index 2a9a05643c44..61dfb9a89ac4 100644 --- a/crates/swc_css_parser/tests/fixture/value/custom-property/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/value/custom-property/leading-comments.json @@ -1,12 +1,12 @@ { - "280": [ + "321": [ { "kind": "Block", "span": { - "start": 275, - "end": 280 + "start": 313, + "end": 321 }, - "text": "/**/" + "text": "/* 2 */" } ], "313": [ @@ -19,22 +19,22 @@ "text": "/* 1 */" } ], - "321": [ + "235": [ { "kind": "Block", "span": { - "start": 313, - "end": 321 + "start": 230, + "end": 235 }, - "text": "/* 2 */" + "text": "/**/" } ], - "235": [ + "280": [ { "kind": "Block", "span": { - "start": 230, - "end": 235 + "start": 275, + "end": 280 }, "text": "/**/" } diff --git a/crates/swc_css_parser/tests/fixture/value/urange/leading-comments.json b/crates/swc_css_parser/tests/fixture/value/urange/leading-comments.json index a01f285fd0d4..27e75da404e6 100644 --- a/crates/swc_css_parser/tests/fixture/value/urange/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/value/urange/leading-comments.json @@ -1,20 +1,20 @@ { - "253": [ + "455": [ { "kind": "Block", "span": { - "start": 224, - "end": 253 + "start": 433, + "end": 455 }, - "text": "/* codepoint range */" + "text": "/* multiple values */" } ], - "455": [ + "374": [ { "kind": "Block", "span": { - "start": 433, - "end": 455 + "start": 352, + "end": 374 }, "text": "/* multiple values */" } @@ -39,14 +39,14 @@ "text": "/* wildcard range */" } ], - "374": [ + "253": [ { "kind": "Block", "span": { - "start": 352, - "end": 374 + "start": 224, + "end": 253 }, - "text": "/* multiple values */" + "text": "/* codepoint range */" } ] } diff --git a/crates/swc_css_parser/tests/fixture/vendor/csstree/basic/leading-comments.json b/crates/swc_css_parser/tests/fixture/vendor/csstree/basic/leading-comments.json index a260c77df9bc..9ea17fb21d4d 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/csstree/basic/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/vendor/csstree/basic/leading-comments.json @@ -1,42 +1,42 @@ { - "493": [ + "527": [ { "kind": "Block", "span": { - "start": 371, - "end": 493 + "start": 493, + "end": 527 }, - "text": "/*filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img.png',sizingMethod='scale') alpha(opacity=80);*/" + "text": "/*width: expression(1 + 2);*/" } ], - "1114": [ + "17": [ { "kind": "Block", "span": { - "start": 1099, - "end": 1113 + "start": 1, + "end": 17 }, - "text": "/* CDO/CDC */" + "text": "/*! something */" } ], - "527": [ + "493": [ { "kind": "Block", "span": { - "start": 493, - "end": 527 + "start": 371, + "end": 493 }, - "text": "/*width: expression(1 + 2);*/" + "text": "/*filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img.png',sizingMethod='scale') alpha(opacity=80);*/" } ], - "17": [ + "1114": [ { "kind": "Block", "span": { - "start": 1, - "end": 17 + "start": 1099, + "end": 1113 }, - "text": "/*! something */" + "text": "/* CDO/CDC */" } ] } diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/comment/leading-comments.json b/crates/swc_css_parser/tests/fixture/vendor/rome/comment/leading-comments.json index 106a5bc4c022..01ace51be02d 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/comment/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/comment/leading-comments.json @@ -1,12 +1,12 @@ { - "53": [ + "19": [ { "kind": "Block", "span": { - "start": 39, - "end": 53 + "start": 1, + "end": 19 }, - "text": "/* comment */" + "text": "/*\n * comments\n */" } ], "82": [ @@ -29,14 +29,14 @@ "text": "/* comment */" } ], - "19": [ + "53": [ { "kind": "Block", "span": { - "start": 1, - "end": 19 + "start": 39, + "end": 53 }, - "text": "/*\n * comments\n */" + "text": "/* comment */" } ] } diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/smoke/leading-comments.json b/crates/swc_css_parser/tests/fixture/vendor/rome/smoke/leading-comments.json index 2efcdf1f1051..09265a5762a8 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/smoke/leading-comments.json +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/smoke/leading-comments.json @@ -1,4 +1,14 @@ { + "22": [ + { + "kind": "Block", + "span": { + "start": 1, + "end": 22 + }, + "text": "/*This is a comment*/" + } + ], "221": [ { "kind": "Block", @@ -48,15 +58,5 @@ }, "text": "/*}*/" } - ], - "22": [ - { - "kind": "Block", - "span": { - "start": 1, - "end": 22 - }, - "text": "/*This is a comment*/" - } ] } diff --git a/crates/swc_css_prefixer/Cargo.toml b/crates/swc_css_prefixer/Cargo.toml index f6844300fedf..32347f2d3be9 100644 --- a/crates/swc_css_prefixer/Cargo.toml +++ b/crates/swc_css_prefixer/Cargo.toml @@ -14,6 +14,7 @@ bench = false [dependencies] once_cell = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } diff --git a/crates/swc_css_prefixer/src/prefixer.rs b/crates/swc_css_prefixer/src/prefixer.rs index 8da3c18daec6..b4e8b974b2d6 100644 --- a/crates/swc_css_prefixer/src/prefixer.rs +++ b/crates/swc_css_prefixer/src/prefixer.rs @@ -5,8 +5,9 @@ use std::{mem::take, sync::Arc}; use once_cell::sync::Lazy; use preset_env_base::{query::targets_to_versions, version::Version, BrowserData, Versions}; +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, EqIgnoreSpan, DUMMY_SP}; +use swc_common::{EqIgnoreSpan, DUMMY_SP}; use swc_css_ast::*; use swc_css_utils::{ replace_function_name, replace_ident, replace_pseudo_class_selector_name, @@ -16,9 +17,9 @@ use swc_css_visit::{VisitMut, VisitMutWith}; use crate::options::Options; -static PREFIXES_AND_BROWSERS: Lazy>; 2]>> = +static PREFIXES_AND_BROWSERS: Lazy>; 2]>> = Lazy::new(|| { - let map: AHashMap>; 2]> = + let map: FxHashMap>; 2]> = serde_json::from_str(include_str!("../data/prefixes_and_browsers.json")) .expect("failed to parse json"); diff --git a/crates/swc_css_utils/Cargo.toml b/crates/swc_css_utils/Cargo.toml index 9ba15fb397e1..461913ec4af6 100644 --- a/crates/swc_css_utils/Cargo.toml +++ b/crates/swc_css_utils/Cargo.toml @@ -14,6 +14,7 @@ bench = false [dependencies] once_cell = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } diff --git a/crates/swc_css_utils/src/lib.rs b/crates/swc_css_utils/src/lib.rs index 6fbe461405ad..ff05965c6dab 100644 --- a/crates/swc_css_utils/src/lib.rs +++ b/crates/swc_css_utils/src/lib.rs @@ -3,9 +3,9 @@ use std::{borrow::Cow, f64::consts::PI, str}; use once_cell::sync::Lazy; +use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use swc_atoms::{Atom, StaticString}; -use swc_common::collections::AHashMap; use swc_css_ast::*; use swc_css_visit::{VisitMut, VisitMutWith}; @@ -152,7 +152,7 @@ pub struct NamedColor { pub rgb: Vec, } -pub static NAMED_COLORS: Lazy> = Lazy::new(|| { +pub static NAMED_COLORS: Lazy> = Lazy::new(|| { serde_json::from_str(include_str!("./named-colors.json")) .expect("failed to parse named-colors.json for html entities") }); diff --git a/crates/swc_ecma_codegen/Cargo.toml b/crates/swc_ecma_codegen/Cargo.toml index aa6863615bf1..6dcc99bb4b91 100644 --- a/crates/swc_ecma_codegen/Cargo.toml +++ b/crates/swc_ecma_codegen/Cargo.toml @@ -21,6 +21,7 @@ memchr = { workspace = true } num-bigint = { workspace = true, features = ["serde"] } once_cell = { workspace = true } regex = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true } sourcemap = { workspace = true } tracing = { workspace = true } diff --git a/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs b/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs index 69ab4981fd3b..4acac6d7a6a6 100644 --- a/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs +++ b/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs @@ -1,6 +1,7 @@ use std::io::Write; -use swc_allocator::{collections::FxHashSet, maybe::vec::Vec}; +use rustc_hash::FxBuildHasher; +use swc_allocator::{collections::HashSet, maybe::vec::Vec}; use swc_common::{sync::Lrc, BytePos, LineCol, SourceMap, Span}; use super::{Result, WriteJs}; @@ -19,7 +20,7 @@ pub struct JsWriter<'a, W: Write> { line_pos: usize, new_line: &'a str, srcmap: Option<&'a mut Vec<(BytePos, LineCol)>>, - srcmap_done: FxHashSet<(BytePos, u32, u32)>, + srcmap_done: HashSet<(BytePos, u32, u32), FxBuildHasher>, /// Used to avoid including whitespaces created by indention. pending_srcmap: Option, wr: W, diff --git a/crates/swc_ecma_codegen/tests/sourcemap.rs b/crates/swc_ecma_codegen/tests/sourcemap.rs index 574813568c5f..cfcb80b167dd 100644 --- a/crates/swc_ecma_codegen/tests/sourcemap.rs +++ b/crates/swc_ecma_codegen/tests/sourcemap.rs @@ -1,8 +1,9 @@ use std::{fs::read_to_string, path::PathBuf}; use base64::prelude::{Engine, BASE64_STANDARD}; +use rustc_hash::FxBuildHasher; use sourcemap::SourceMap; -use swc_allocator::{collections::FxHashSet, maybe::vec::Vec}; +use swc_allocator::{collections::HashSet, maybe::vec::Vec}; use swc_common::{comments::SingleThreadedComments, source_map::SourceMapGenConfig}; use swc_ecma_ast::EsVersion; use swc_ecma_codegen::{text_writer::WriteJs, Emitter}; @@ -368,7 +369,7 @@ fn identity(entry: PathBuf) { .iter() .filter(|a| expected_tokens.contains(&**a)) .map(|v| v.to_string()) - .collect::>(); + .collect::>(); let actual_tokens_diff = actual_tokens .iter() diff --git a/crates/swc_ecma_compat_bugfixes/Cargo.toml b/crates/swc_ecma_compat_bugfixes/Cargo.toml index 68dc064f9105..2cb991a94f83 100644 --- a/crates/swc_ecma_compat_bugfixes/Cargo.toml +++ b/crates/swc_ecma_compat_bugfixes/Cargo.toml @@ -11,6 +11,9 @@ version = "8.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +rustc-hash = { workspace = true } +tracing = { workspace = true } + swc_atoms = { version = "3.0.4", path = "../swc_atoms" } swc_common = { version = "5.0.1", path = "../swc_common" } swc_ecma_ast = { version = "5.1.0", path = "../swc_ecma_ast" } @@ -19,7 +22,6 @@ swc_ecma_transforms_base = { version = "8.0.0", path = "../swc_ecma_transforms_b swc_ecma_utils = { version = "8.0.0", path = "../swc_ecma_utils" } swc_ecma_visit = { version = "5.0.0", path = "../swc_ecma_visit" } swc_trace_macro = { version = "2.0.0", path = "../swc_trace_macro" } -tracing = { workspace = true } [dev-dependencies] swc_ecma_parser = { version = "7.0.1", path = "../swc_ecma_parser" } diff --git a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs index fe0fa5d2e56a..fd9370be10ad 100644 --- a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs +++ b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs @@ -1,7 +1,8 @@ use std::collections::HashMap; +use rustc_hash::FxHashSet; use swc_atoms::JsWord; -use swc_common::{collections::AHashSet, SyntaxContext}; +use swc_common::SyntaxContext; use swc_ecma_ast::*; use swc_ecma_transforms_base::hygiene::rename; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; @@ -15,7 +16,7 @@ pub fn safari_id_destructuring_collision_in_function_expression() -> impl Pass { struct SafariIdDestructuringCollisionInFunctionExpression { fn_expr_name: JsWord, destructured_id_span: Option, - other_ident_symbols: AHashSet, + other_ident_symbols: FxHashSet, in_body: bool, } diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs index 40c0f05b82cb..5d6199ea8b66 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs @@ -1,13 +1,10 @@ use std::{iter::once, mem::take}; use indexmap::IndexMap; +use rustc_hash::{FxHashMap, FxHashSet}; use smallvec::SmallVec; use swc_atoms::JsWord; -use swc_common::{ - collections::{AHashMap, AHashSet}, - util::take::Take, - Mark, Spanned, SyntaxContext, DUMMY_SP, -}; +use swc_common::{util::take::Take, Mark, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::{ @@ -56,7 +53,7 @@ enum ScopeKind { /// Produced by identifier reference and consumed by for-of/in loop. used: Vec, /// Map of original identifier to modified syntax context - mutated: AHashMap, + mutated: FxHashMap, }, Fn, Block, @@ -167,7 +164,7 @@ impl BlockScoping { has_yield: false, has_await: false, label: IndexMap::new(), - inner_label: AHashSet::default(), + inner_label: FxHashSet::default(), mutated, in_switch_case: false, in_nested_loop: false, @@ -651,9 +648,9 @@ struct FlowHelper<'a> { // label cannot be shadowed, so it's pretty safe to use JsWord label: IndexMap, - inner_label: AHashSet, + inner_label: FxHashSet, all: &'a Vec, - mutated: AHashMap, + mutated: FxHashMap, in_switch_case: bool, in_nested_loop: bool, @@ -880,7 +877,7 @@ impl VisitMut for FlowHelper<'_> { } struct MutationHandler<'a> { - map: &'a mut AHashMap, + map: &'a mut FxHashMap, in_function: bool, } diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs index 0035b359ca8f..48dc4038db5c 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs @@ -1,7 +1,7 @@ use indexmap::IndexMap; -use rustc_hash::FxHashMap; +use rustc_hash::{FxBuildHasher, FxHashMap}; use swc_atoms::JsWord; -use swc_common::{collections::ARandomState, Mark, SyntaxContext}; +use swc_common::{Mark, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{rename::remap, scope::ScopeKind}; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; @@ -23,7 +23,7 @@ struct BlockScopedVars { struct Scope { kind: ScopeKind, - vars: IndexMap, + vars: IndexMap, usages: Vec, children: Vec, @@ -33,7 +33,7 @@ struct Scope { struct ParentScope<'a> { parent: Option<&'a ParentScope<'a>>, - vars: &'a IndexMap, + vars: &'a IndexMap, } #[swc_trace] diff --git a/crates/swc_ecma_compat_es2015/src/classes/mod.rs b/crates/swc_ecma_compat_es2015/src/classes/mod.rs index b654fa6d3fbd..8feb97e4b09c 100644 --- a/crates/swc_ecma_compat_es2015/src/classes/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/classes/mod.rs @@ -1,10 +1,8 @@ use std::iter; +use rustc_hash::FxBuildHasher; use serde::Deserialize; -use swc_common::{ - collections::ARandomState, util::take::Take, BytePos, Mark, Span, Spanned, SyntaxContext, - DUMMY_SP, -}; +use swc_common::{util::take::Take, BytePos, Mark, Span, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, native::is_native, perf::Check}; use swc_ecma_transforms_classes::super_field::SuperFieldAccessFolder; @@ -37,7 +35,7 @@ pub fn classes(config: Config) -> impl Pass { }) } -type IndexMap = indexmap::IndexMap; +type IndexMap = indexmap::IndexMap; /// `@babel/plugin-transform-classes` /// diff --git a/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs b/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs index cfa66eca96d5..70c113f3437a 100644 --- a/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs +++ b/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs @@ -1,5 +1,6 @@ +use rustc_hash::FxHashSet; use swc_atoms::JsWord; -use swc_common::{collections::AHashSet, Spanned}; +use swc_common::Spanned; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_str; @@ -36,8 +37,8 @@ impl VisitMut for DuplicateKeys { #[derive(Default)] struct PropFolder { - getter_props: AHashSet, - setter_props: AHashSet, + getter_props: FxHashSet, + setter_props: FxHashSet, } #[swc_trace] @@ -85,7 +86,7 @@ impl VisitMut for PropFolder { } struct PropNameFolder<'a> { - props: &'a mut AHashSet, + props: &'a mut FxHashSet, } #[swc_trace] diff --git a/crates/swc_ecma_compat_es2022/Cargo.toml b/crates/swc_ecma_compat_es2022/Cargo.toml index 44f61d572222..caf3ac38baa7 100644 --- a/crates/swc_ecma_compat_es2022/Cargo.toml +++ b/crates/swc_ecma_compat_es2022/Cargo.toml @@ -13,7 +13,8 @@ version = "9.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tracing = { workspace = true } +rustc-hash = { workspace = true } +tracing = { workspace = true } swc_atoms = { version = "3.0.4", path = "../swc_atoms" } diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs index 6a64c7bd6250..00d629df6f26 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs @@ -1,6 +1,7 @@ +use rustc_hash::FxHashMap; use swc_common::{ - collections::AHashMap, errors::HANDLER, source_map::PURE_SP, util::take::Take, Mark, Span, - Spanned, SyntaxContext, DUMMY_SP, + errors::HANDLER, source_map::PURE_SP, util::take::Take, Mark, Span, Spanned, SyntaxContext, + DUMMY_SP, }; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Check}; @@ -429,7 +430,7 @@ impl ClassProperties { mark: Mark::fresh(Mark::root()), class_name: class_ident.clone(), ident: { - let mut private_map = AHashMap::default(); + let mut private_map = FxHashMap::default(); for member in class.body.iter() { match member { diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/private_field.rs b/crates/swc_ecma_compat_es2022/src/class_properties/private_field.rs index c729894c923d..ce2ed940fe28 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/private_field.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/private_field.rs @@ -1,10 +1,8 @@ use std::iter; +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::{ - collections::AHashMap, errors::HANDLER, util::take::Take, Mark, Span, Spanned, SyntaxContext, - DUMMY_SP, -}; +use swc_common::{errors::HANDLER, util::take::Take, Mark, Span, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::{alias_ident_for, alias_if_required, prepend_stmt, quote_ident, ExprFactory}; @@ -17,7 +15,7 @@ use crate::optional_chaining_impl::optional_chaining_impl; pub(super) struct Private { pub mark: Mark, pub class_name: Ident, - pub ident: AHashMap, + pub ident: FxHashMap, } pub(super) struct PrivateRecord(Vec); diff --git a/crates/swc_ecma_compat_es2022/src/private_in_object.rs b/crates/swc_ecma_compat_es2022/src/private_in_object.rs index dbd04b13fc97..c99332925aed 100644 --- a/crates/swc_ecma_compat_es2022/src/private_in_object.rs +++ b/crates/swc_ecma_compat_es2022/src/private_in_object.rs @@ -3,11 +3,9 @@ use std::{ mem::{replace, take}, }; +use rustc_hash::FxHashSet; use swc_atoms::JsWord; -use swc_common::{ - collections::AHashSet, pass::CompilerPass, util::take::Take, Mark, Spanned, SyntaxContext, - DUMMY_SP, -}; +use swc_common::{pass::CompilerPass, util::take::Take, Mark, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{ default_constructor_with_span, prepend_stmt, private_ident, quote_ident, ExprFactory, @@ -79,7 +77,7 @@ struct PrivateInObject { vars: Vec, prepend_exprs: Vec>, - injected_vars: AHashSet, + injected_vars: FxHashSet, cls: ClassData, } @@ -94,7 +92,7 @@ struct ClassData { /// This is modified by the class visitor. mark: Mark, - privates: AHashSet, + privates: FxHashSet, /// Name of private methods. methods: Vec, @@ -104,7 +102,7 @@ struct ClassData { constructor_exprs: Vec>, - names_used_for_brand_checks: AHashSet, + names_used_for_brand_checks: FxHashSet, } impl CompilerPass for PrivateInObject { @@ -252,7 +250,7 @@ impl VisitMut for PrivateInObject { p.left.visit_mut_with(self); { - let mut buf = AHashSet::default(); + let mut buf = FxHashSet::default(); let mut v = ClassAnalyzer { brand_check_names: &mut buf, ignore_class: false, @@ -493,7 +491,7 @@ impl VisitMut for PrivateInObject { } struct ClassAnalyzer<'a> { - brand_check_names: &'a mut AHashSet, + brand_check_names: &'a mut FxHashSet, ignore_class: bool, } diff --git a/crates/swc_ecma_compat_es2022/src/static_blocks.rs b/crates/swc_ecma_compat_es2022/src/static_blocks.rs index f0ddef1d472b..817643a53ddf 100644 --- a/crates/swc_ecma_compat_es2022/src/static_blocks.rs +++ b/crates/swc_ecma_compat_es2022/src/static_blocks.rs @@ -1,5 +1,6 @@ +use rustc_hash::FxHashSet; use swc_atoms::JsWord; -use swc_common::{collections::AHashSet, source_map::PLACEHOLDER_SP, util::take::Take}; +use swc_common::{source_map::PLACEHOLDER_SP, util::take::Take}; use swc_ecma_ast::*; use swc_ecma_utils::ExprFactory; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; @@ -61,7 +62,7 @@ impl VisitMut for ClassStaticBlock { fn visit_mut_class(&mut self, class: &mut Class) { class.visit_mut_children_with(self); - let mut private_names = AHashSet::default(); + let mut private_names = FxHashSet::default(); for member in &class.body { if let ClassMember::PrivateProp(private_property) = member { private_names.insert(private_property.key.name.clone()); @@ -85,7 +86,7 @@ impl VisitMut for ClassStaticBlock { } } -fn generate_uid(deny_list: &AHashSet, i: &mut u32) -> JsWord { +fn generate_uid(deny_list: &FxHashSet, i: &mut u32) -> JsWord { *i += 1; let mut uid: JsWord = if *i == 1 { diff --git a/crates/swc_ecma_lints/Cargo.toml b/crates/swc_ecma_lints/Cargo.toml index 8ae8218cdaf2..4da25a38d2db 100644 --- a/crates/swc_ecma_lints/Cargo.toml +++ b/crates/swc_ecma_lints/Cargo.toml @@ -17,6 +17,7 @@ auto_impl = { workspace = true } dashmap = { workspace = true } parking_lot = { workspace = true } regex = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } swc_atoms = { version = "3.0.4", path = "../swc_atoms" } diff --git a/crates/swc_ecma_lints/src/rules/const_assign.rs b/crates/swc_ecma_lints/src/rules/const_assign.rs index dfb470d622ee..75d69871f038 100644 --- a/crates/swc_ecma_lints/src/rules/const_assign.rs +++ b/crates/swc_ecma_lints/src/rules/const_assign.rs @@ -1,4 +1,5 @@ -use swc_common::{collections::AHashMap, errors::HANDLER, Span}; +use rustc_hash::FxHashMap; +use swc_common::{errors::HANDLER, Span}; use swc_ecma_ast::*; use swc_ecma_utils::parallel::{cpu_count, Parallel, ParallelExt}; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -14,8 +15,8 @@ struct ConstAssignRule; impl Rule for ConstAssignRule { fn lint_module(&mut self, program: &Module) { - let mut const_vars = AHashMap::default(); - let mut import_binding = AHashMap::default(); + let mut const_vars = FxHashMap::default(); + let mut import_binding = FxHashMap::default(); program.visit_children_with(&mut Collector { const_vars: &mut const_vars, @@ -31,8 +32,8 @@ impl Rule for ConstAssignRule { } fn lint_script(&mut self, program: &Script) { - let mut const_vars = AHashMap::default(); - let mut import_binding = AHashMap::default(); + let mut const_vars = FxHashMap::default(); + let mut import_binding = FxHashMap::default(); program.visit_children_with(&mut Collector { const_vars: &mut const_vars, @@ -52,8 +53,8 @@ impl Rule for ConstAssignRule { #[derive(Clone, Copy)] struct ConstAssign<'a> { - const_vars: &'a AHashMap, - import_binding: &'a AHashMap, + const_vars: &'a FxHashMap, + import_binding: &'a FxHashMap, is_pat_decl: bool, } @@ -169,8 +170,8 @@ impl Visit for ConstAssign<'_> { } struct Collector<'a> { - const_vars: &'a mut AHashMap, - import_binding: &'a mut AHashMap, + const_vars: &'a mut FxHashMap, + import_binding: &'a mut FxHashMap, var_decl_kind: Option, } diff --git a/crates/swc_ecma_lints/src/rules/dot_notation.rs b/crates/swc_ecma_lints/src/rules/dot_notation.rs index 4fa7bb678419..e9794a9a993f 100644 --- a/crates/swc_ecma_lints/src/rules/dot_notation.rs +++ b/crates/swc_ecma_lints/src/rules/dot_notation.rs @@ -1,7 +1,8 @@ use dashmap::DashMap; use regex::Regex; +use rustc_hash::FxBuildHasher; use serde::{Deserialize, Serialize}; -use swc_common::{collections::ARandomState, errors::HANDLER, sync::Lazy, Span}; +use swc_common::{errors::HANDLER, sync::Lazy, Span}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -76,7 +77,7 @@ impl DotNotation { } if let Some(pattern) = &self.pattern { - static REGEX_CACHE: Lazy> = + static REGEX_CACHE: Lazy> = Lazy::new(Default::default); if !REGEX_CACHE.contains_key(pattern) { diff --git a/crates/swc_ecma_lints/src/rules/duplicate_bindings.rs b/crates/swc_ecma_lints/src/rules/duplicate_bindings.rs index 3d0d5bb10d68..6a5c0a8f145b 100644 --- a/crates/swc_ecma_lints/src/rules/duplicate_bindings.rs +++ b/crates/swc_ecma_lints/src/rules/duplicate_bindings.rs @@ -1,11 +1,8 @@ use std::collections::hash_map::Entry; +use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; -use swc_common::{ - collections::{AHashMap, AHashSet}, - errors::HANDLER, - Span, SyntaxContext, -}; +use swc_common::{errors::HANDLER, Span, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -25,8 +22,8 @@ struct BindingInfo { #[derive(Debug, Default)] struct DuplicateBindings { - bindings: AHashMap, - type_bindings: AHashSet, + bindings: FxHashMap, + type_bindings: FxHashSet, var_decl_kind: Option, is_pat_decl: bool, @@ -87,7 +84,7 @@ impl DuplicateBindings { s: &[T], get_fn_ident: F, ) { - let mut fn_name = AHashMap::default(); + let mut fn_name = FxHashMap::default(); for s in s { if let Some(ident) = get_fn_ident(s) { if let Some(prev) = fn_name.get(&ident.sym) { @@ -400,7 +397,7 @@ impl Visit for DuplicateBindings { } struct TypeCollector<'a> { - type_bindings: &'a mut AHashSet, + type_bindings: &'a mut FxHashSet, } impl Visit for TypeCollector<'_> { diff --git a/crates/swc_ecma_lints/src/rules/duplicate_exports.rs b/crates/swc_ecma_lints/src/rules/duplicate_exports.rs index 0362ad6899fd..366d67bd9185 100644 --- a/crates/swc_ecma_lints/src/rules/duplicate_exports.rs +++ b/crates/swc_ecma_lints/src/rules/duplicate_exports.rs @@ -1,7 +1,8 @@ use std::{collections::hash_map::Entry, mem}; +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, errors::HANDLER, Span}; +use swc_common::{errors::HANDLER, Span}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -13,7 +14,7 @@ pub fn duplicate_exports() -> Box { #[derive(Debug, Default)] struct DuplicateExports { - exports: AHashMap, + exports: FxHashMap, export_assign: Option, } diff --git a/crates/swc_ecma_lints/src/rules/no_bitwise.rs b/crates/swc_ecma_lints/src/rules/no_bitwise.rs index db11367c944d..530adfaf4078 100644 --- a/crates/swc_ecma_lints/src/rules/no_bitwise.rs +++ b/crates/swc_ecma_lints/src/rules/no_bitwise.rs @@ -1,5 +1,6 @@ +use rustc_hash::FxHashSet; use serde::{Deserialize, Serialize}; -use swc_common::{collections::AHashSet, errors::HANDLER, Span}; +use swc_common::{errors::HANDLER, Span}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -25,8 +26,8 @@ pub fn no_bitwise(config: &RuleConfig) -> Option> #[derive(Debug, Default)] struct NoBitwise { expected_reaction: LintRuleReaction, - allow_binary_ops: Option>, - allow_assign_ops: Option>, + allow_binary_ops: Option>, + allow_assign_ops: Option>, allow_bitwise_not: bool, allow_int_32_hint: bool, } @@ -35,8 +36,8 @@ impl NoBitwise { fn new(config: &RuleConfig) -> Self { let rule_config = config.get_rule_config(); - let mut allow_binary_ops: Option> = None; - let mut allow_assign_ops: Option> = None; + let mut allow_binary_ops: Option> = None; + let mut allow_assign_ops: Option> = None; let mut allow_bitwise_not: bool = false; if let Some(allow) = &rule_config.allow { diff --git a/crates/swc_ecma_lints/src/rules/no_console.rs b/crates/swc_ecma_lints/src/rules/no_console.rs index 2523f2c4279f..bbfa81593ac4 100644 --- a/crates/swc_ecma_lints/src/rules/no_console.rs +++ b/crates/swc_ecma_lints/src/rules/no_console.rs @@ -1,6 +1,7 @@ +use rustc_hash::FxHashSet; use serde::{Deserialize, Serialize}; use swc_atoms::JsWord; -use swc_common::{collections::AHashSet, errors::HANDLER, Span, SyntaxContext}; +use swc_common::{errors::HANDLER, Span, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -13,7 +14,7 @@ const MESSAGE: &str = "Unexpected console statement"; #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct NoConsoleConfig { - allow: Option>, + allow: Option>, } pub fn no_console( @@ -30,7 +31,7 @@ pub fn no_console( struct NoConsole { expected_reaction: LintRuleReaction, unresolved_ctxt: SyntaxContext, - allow: Option>, + allow: Option>, } impl NoConsole { diff --git a/crates/swc_ecma_lints/src/rules/no_dupe_args.rs b/crates/swc_ecma_lints/src/rules/no_dupe_args.rs index eec0e278ee1d..fa92c754f8e0 100644 --- a/crates/swc_ecma_lints/src/rules/no_dupe_args.rs +++ b/crates/swc_ecma_lints/src/rules/no_dupe_args.rs @@ -1,6 +1,7 @@ use std::collections::hash_map::Entry; -use swc_common::{collections::AHashMap, errors::HANDLER}; +use rustc_hash::FxHashMap; +use swc_common::errors::HANDLER; use swc_ecma_ast::*; use swc_ecma_utils::{ for_each_binding_ident, @@ -84,7 +85,7 @@ macro_rules! check { }); if hash_mode { - let mut map = AHashMap::default(); + let mut map = FxHashMap::default(); for_each_binding_ident($node, |id| { // diff --git a/crates/swc_ecma_lints/src/rules/no_empty_function.rs b/crates/swc_ecma_lints/src/rules/no_empty_function.rs index 8f040b4452bf..f5d0028d2c72 100644 --- a/crates/swc_ecma_lints/src/rules/no_empty_function.rs +++ b/crates/swc_ecma_lints/src/rules/no_empty_function.rs @@ -3,8 +3,9 @@ use std::{ sync::Arc, }; +use rustc_hash::FxHashSet; use serde::{Deserialize, Serialize}; -use swc_common::{collections::AHashSet, errors::HANDLER, SourceMap, Span}; +use swc_common::{errors::HANDLER, SourceMap, Span}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -50,10 +51,10 @@ impl FunctionModifiers { #[serde(rename_all = "camelCase")] pub struct NoEmptyFunctionConfig { consider_comments: Option, - functions: Option>, - arrow_functions: Option>, - methods: Option>, - constructors: Option>, + functions: Option>, + arrow_functions: Option>, + methods: Option>, + constructors: Option>, } pub fn no_empty_function( @@ -75,10 +76,10 @@ struct NoEmptyFunction { expected_reaction: LintRuleReaction, consider_comments: bool, - functions: Option>, - arrow_functions: Option>, - methods: Option>, - constructors: Option>, + functions: Option>, + arrow_functions: Option>, + methods: Option>, + constructors: Option>, } impl Debug for NoEmptyFunction { @@ -211,7 +212,7 @@ impl NoEmptyFunction { &self, span: Span, target_type: &str, - allowed: Option<&AHashSet>, + allowed: Option<&FxHashSet>, modifiers: &[FunctionModifiers], ) { if let Some(allowed) = allowed { diff --git a/crates/swc_ecma_lints/src/rules/no_loop_func.rs b/crates/swc_ecma_lints/src/rules/no_loop_func.rs index 427b9897d125..06b6a588704d 100644 --- a/crates/swc_ecma_lints/src/rules/no_loop_func.rs +++ b/crates/swc_ecma_lints/src/rules/no_loop_func.rs @@ -1,9 +1,6 @@ +use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; -use swc_common::{ - collections::{AHashMap, AHashSet}, - errors::HANDLER, - Span, DUMMY_SP, -}; +use swc_common::{errors::HANDLER, Span, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -29,15 +26,15 @@ struct NoLoopFunc { function_depth: usize, inside_loop_decl: bool, scopes: Vec, - scoped_unsafe_vars: AHashMap>, - current_fn_unsafe_vars: AHashSet, + scoped_unsafe_vars: FxHashMap>, + current_fn_unsafe_vars: FxHashSet, } impl NoLoopFunc { fn new(expected_reaction: LintRuleReaction) -> Self { let root_scope = DUMMY_SP; - let mut scoped_vars: AHashMap> = Default::default(); + let mut scoped_vars: FxHashMap> = Default::default(); scoped_vars.insert(root_scope, Default::default()); Self { diff --git a/crates/swc_ecma_lints/src/rules/no_param_reassign.rs b/crates/swc_ecma_lints/src/rules/no_param_reassign.rs index da884d9d7add..fd50747b6e40 100644 --- a/crates/swc_ecma_lints/src/rules/no_param_reassign.rs +++ b/crates/swc_ecma_lints/src/rules/no_param_reassign.rs @@ -1,12 +1,8 @@ use dashmap::DashMap; use regex::Regex; +use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; use serde::{Deserialize, Serialize}; -use swc_common::{ - collections::{AHashMap, AHashSet, ARandomState}, - errors::HANDLER, - sync::Lazy, - Span, -}; +use swc_common::{errors::HANDLER, sync::Lazy, Span}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -21,7 +17,7 @@ const INVALID_REGEX_MESSAGE: &str = "no-param-reassign: invalid regex pattern in #[serde(rename_all = "camelCase")] pub struct NoParamReassignConfig { props: Option, - ignore_property_modifications_for: Option>, + ignore_property_modifications_for: Option>, ignore_property_modifications_for_regex: Option>, } @@ -35,10 +31,10 @@ pub fn no_param_reassign(config: &RuleConfig) -> Option>, + scoped_params: FxHashMap>, scopes: Vec, check_props: bool, - ignore_names: Option>, + ignore_names: Option>, ignore_names_patterns: Option>, } @@ -120,7 +116,7 @@ impl NoParamReassign { } if let Some(ignore_names_patterns) = &self.ignore_names_patterns { - static REGEX_CACHE: Lazy> = + static REGEX_CACHE: Lazy> = Lazy::new(Default::default); let sym = &*ident.sym; diff --git a/crates/swc_ecma_lints/src/rules/no_use_before_define.rs b/crates/swc_ecma_lints/src/rules/no_use_before_define.rs index d98eb3dedc79..bbc0def2c303 100644 --- a/crates/swc_ecma_lints/src/rules/no_use_before_define.rs +++ b/crates/swc_ecma_lints/src/rules/no_use_before_define.rs @@ -1,9 +1,6 @@ +use rustc_hash::{FxHashMap, FxHashSet}; use serde::{Deserialize, Serialize}; -use swc_common::{ - collections::{AHashMap, AHashSet}, - errors::HANDLER, - Span, DUMMY_SP, -}; +use swc_common::{errors::HANDLER, Span, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -41,9 +38,9 @@ struct NoUseBeforeDefine { check_functions: bool, check_classes: bool, - scoped_indents: AHashMap>, + scoped_indents: FxHashMap>, scope: Vec, - scoped_spans: AHashMap>, + scoped_spans: FxHashMap>, } impl NoUseBeforeDefine { @@ -52,7 +49,7 @@ impl NoUseBeforeDefine { let root_scope = DUMMY_SP; - let mut scoped_indents: AHashMap> = Default::default(); + let mut scoped_indents: FxHashMap> = Default::default(); scoped_indents.insert(root_scope, Default::default()); @@ -83,7 +80,7 @@ impl NoUseBeforeDefine { if let Some(spans) = self.scoped_spans.get_mut(&spans_block_id) { spans.insert(span); } else { - let mut spans: AHashSet = Default::default(); + let mut spans: FxHashSet = Default::default(); spans.insert(span); @@ -97,7 +94,7 @@ impl NoUseBeforeDefine { self.scoped_indents.get(current_scope).unwrap().contains(id) } - fn get_ident_spans_in_current_scope(&self, id: &Id) -> &AHashSet { + fn get_ident_spans_in_current_scope(&self, id: &Id) -> &FxHashSet { let current_block = self.scope.last().unwrap(); let spans_block_id = SpansScopeId { diff --git a/crates/swc_ecma_lints/src/rules/prefer_const.rs b/crates/swc_ecma_lints/src/rules/prefer_const.rs index aa9c5b18be41..5d41d0faef6e 100644 --- a/crates/swc_ecma_lints/src/rules/prefer_const.rs +++ b/crates/swc_ecma_lints/src/rules/prefer_const.rs @@ -1,5 +1,6 @@ +use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; -use swc_common::{collections::AHashMap, errors::HANDLER, Span}; +use swc_common::{errors::HANDLER, Span}; use swc_ecma_ast::*; use swc_ecma_visit::{Visit, VisitWith}; @@ -54,7 +55,7 @@ struct VariableMeta { #[derive(Debug, Default)] struct PreferConst { expected_reaction: LintRuleReaction, - vars_meta: AHashMap, + vars_meta: FxHashMap, scope_vars_idx: usize, block_depth: usize, cycle_head_depth: usize, diff --git a/crates/swc_ecma_loader/Cargo.toml b/crates/swc_ecma_loader/Cargo.toml index 0145d9008fe9..743b813c08e0 100644 --- a/crates/swc_ecma_loader/Cargo.toml +++ b/crates/swc_ecma_loader/Cargo.toml @@ -32,6 +32,7 @@ once_cell = { workspace = true, optional = true } parking_lot = { workspace = true, optional = true } path-clean = { version = "=0.1.0", optional = true } pathdiff = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, optional = true } tracing = { workspace = true } diff --git a/crates/swc_ecma_loader/src/resolvers/node.rs b/crates/swc_ecma_loader/src/resolvers/node.rs index 7eaabb4f9bbb..324f4a99fe2c 100644 --- a/crates/swc_ecma_loader/src/resolvers/node.rs +++ b/crates/swc_ecma_loader/src/resolvers/node.rs @@ -16,11 +16,9 @@ use normpath::BasePath; use once_cell::sync::Lazy; use path_clean::PathClean; use pathdiff::diff_paths; +use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; use serde::Deserialize; -use swc_common::{ - collections::{AHashMap, AHashSet, ARandomState}, - FileName, -}; +use swc_common::FileName; use tracing::{debug, trace, Level}; use crate::{ @@ -36,15 +34,15 @@ static PACKAGE: &str = "package.json"; /// directory containing the package.json file which is important /// to ensure we only apply these `browser` rules to modules in /// the owning package. -static BROWSER_CACHE: Lazy> = +static BROWSER_CACHE: Lazy> = Lazy::new(Default::default); #[derive(Debug, Default)] struct BrowserCache { - rewrites: AHashMap, - ignores: AHashSet, - module_rewrites: AHashMap, - module_ignores: AHashSet, + rewrites: FxHashMap, + ignores: FxHashSet, + module_rewrites: FxHashMap, + module_ignores: FxHashSet, } /// Helper to find the nearest `package.json` file to get @@ -90,7 +88,7 @@ struct PackageJson { #[serde(untagged)] enum Browser { Str(String), - Obj(AHashMap), + Obj(FxHashMap), } #[derive(Deserialize, Clone)] @@ -103,7 +101,7 @@ enum StringOrBool { #[derive(Debug, Default)] pub struct NodeModulesResolver { target_env: TargetEnv, - alias: AHashMap, + alias: FxHashMap, // if true do not resolve symlink preserve_symlinks: bool, ignore_node_modules: bool, @@ -115,7 +113,7 @@ impl NodeModulesResolver { /// Create a node modules resolver for the target runtime environment. pub fn new( target_env: TargetEnv, - alias: AHashMap, + alias: FxHashMap, preserve_symlinks: bool, ) -> Self { Self { @@ -129,7 +127,7 @@ impl NodeModulesResolver { /// Create a node modules resolver which does not care about `node_modules` pub fn without_node_modules( target_env: TargetEnv, - alias: AHashMap, + alias: FxHashMap, preserve_symlinks: bool, ) -> Self { Self { diff --git a/crates/swc_ecma_loader/tests/tsc_resolver.rs b/crates/swc_ecma_loader/tests/tsc_resolver.rs index 5d02a683f6cf..e0641c52f98f 100644 --- a/crates/swc_ecma_loader/tests/tsc_resolver.rs +++ b/crates/swc_ecma_loader/tests/tsc_resolver.rs @@ -3,7 +3,8 @@ use std::collections::HashMap; use anyhow::{anyhow, Error}; -use swc_common::{collections::AHashMap, FileName}; +use rustc_hash::FxHashMap; +use swc_common::FileName; use swc_ecma_loader::{ resolve::{Resolution, Resolve}, resolvers::tsc::TsConfigResolver, @@ -280,7 +281,7 @@ fn pattern_length_precedence() { } } -struct TestResolver(AHashMap); +struct TestResolver(FxHashMap); impl Resolve for TestResolver { fn resolve(&self, _: &FileName, src: &str) -> Result { diff --git a/crates/swc_ecma_minifier/src/compress/hoist_decls.rs b/crates/swc_ecma_minifier/src/compress/hoist_decls.rs index a2317a240909..0b476ae0b439 100644 --- a/crates/swc_ecma_minifier/src/compress/hoist_decls.rs +++ b/crates/swc_ecma_minifier/src/compress/hoist_decls.rs @@ -1,6 +1,7 @@ #[cfg(feature = "concurrent")] use rayon::prelude::*; -use swc_common::{collections::AHashSet, pass::Repeated, util::take::Take, DUMMY_SP}; +use rustc_hash::FxHashSet; +use swc_common::{pass::Repeated, util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_usage_analyzer::analyzer::UsageAnalyzer; use swc_ecma_utils::{find_pat_ids, StmtLike}; @@ -105,7 +106,7 @@ impl Hoister<'_> { let mut var_decls = Vec::new(); let mut fn_decls = Vec::with_capacity(stmts.len()); let mut new_stmts = Vec::with_capacity(stmts.len()); - let mut done = AHashSet::default(); + let mut done = FxHashSet::default(); let mut found_non_var_decl = false; for stmt in stmts.take() { diff --git a/crates/swc_ecma_minifier/src/compress/optimize/inline.rs b/crates/swc_ecma_minifier/src/compress/optimize/inline.rs index 5dd251395efd..f30776b6842c 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/inline.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/inline.rs @@ -1,5 +1,5 @@ -use rustc_hash::FxHashMap; -use swc_common::{collections::AHashSet, util::take::Take, EqIgnoreSpan, Mark}; +use rustc_hash::{FxHashMap, FxHashSet}; +use swc_common::{util::take::Take, EqIgnoreSpan, Mark}; use swc_ecma_ast::*; use swc_ecma_transforms_optimization::simplify::expr_simplifier; use swc_ecma_usage_analyzer::alias::{collect_infects_from, AliasConfig}; @@ -848,7 +848,7 @@ impl Optimizer<'_> { // currently renamer relies on the fact no distinct var has same ctxt, we need // to remap all new bindings. - let bindings: AHashSet = collect_decls(&*value); + let bindings: FxHashSet = collect_decls(&*value); let new_mark = Mark::new(); let mut cache = FxHashMap::default(); let mut remap = FxHashMap::default(); diff --git a/crates/swc_ecma_minifier/src/compress/optimize/mod.rs b/crates/swc_ecma_minifier/src/compress/optimize/mod.rs index 3679b542ccec..61b0304cd155 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/mod.rs @@ -5,8 +5,7 @@ use std::iter::once; use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; use swc_common::{ - collections::AHashMap, iter::IdentifyLast, pass::Repeated, util::take::Take, Spanned, - SyntaxContext, DUMMY_SP, + iter::IdentifyLast, pass::Repeated, util::take::Take, Spanned, SyntaxContext, DUMMY_SP, }; use swc_ecma_ast::*; use swc_ecma_transforms_optimization::debug_assert_valid; @@ -230,7 +229,7 @@ struct Optimizer<'a> { vars: Vars, - typeofs: Box>, + typeofs: Box>, /// This information is created by analyzing identifier usages. /// /// This is calculated multiple time, but only once per one diff --git a/crates/swc_ecma_minifier/src/compress/optimize/util.rs b/crates/swc_ecma_minifier/src/compress/optimize/util.rs index 8aaee66a64ec..2c6d58bdb2e8 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/util.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/util.rs @@ -5,7 +5,7 @@ use std::{ use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; -use swc_common::{collections::AHashSet, util::take::Take, Mark, SyntaxContext, DUMMY_SP}; +use swc_common::{util::take::Take, Mark, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{Parallel, ParallelExt}; use swc_ecma_utils::{collect_decls, ExprCtx, ExprExt, Remapper}; @@ -247,7 +247,7 @@ impl Finalizer<'_> { let mut value = self.simple_functions.get(i).cloned()?; let mut cache = FxHashMap::default(); let mut remap = FxHashMap::default(); - let bindings: AHashSet = collect_decls(&*value); + let bindings: FxHashSet = collect_decls(&*value); let new_mark = Mark::new(); // at this point, var usage no longer matter diff --git a/crates/swc_ecma_minifier/src/eval.rs b/crates/swc_ecma_minifier/src/eval.rs index 80baf8b93835..ca8a3fb2be96 100644 --- a/crates/swc_ecma_minifier/src/eval.rs +++ b/crates/swc_ecma_minifier/src/eval.rs @@ -1,8 +1,9 @@ use std::sync::Arc; use parking_lot::Mutex; +use rustc_hash::FxHashMap; use swc_atoms::js_word; -use swc_common::{collections::AHashMap, SyntaxContext, DUMMY_SP}; +use swc_common::{SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_optimization::simplify::{expr_simplifier, ExprSimplifierConfig}; use swc_ecma_usage_analyzer::marks::Marks; @@ -50,7 +51,7 @@ struct Eval { #[derive(Default)] struct EvalStore { - cache: AHashMap>, + cache: FxHashMap>, } #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/swc_ecma_minifier/src/option/mod.rs b/crates/swc_ecma_minifier/src/option/mod.rs index 6dda8d32686d..9e32b30971b1 100644 --- a/crates/swc_ecma_minifier/src/option/mod.rs +++ b/crates/swc_ecma_minifier/src/option/mod.rs @@ -6,7 +6,7 @@ use parking_lot::RwLock; use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use swc_atoms::{Atom, JsWord}; -use swc_common::{collections::AHashMap, Mark}; +use swc_common::Mark; use swc_config::{merge::Merge, CachedRegex}; use swc_ecma_ast::{EsVersion, Expr, Id}; @@ -188,7 +188,7 @@ pub struct CompressOptions { /// to remove spans. #[cfg_attr(feature = "extra-serde", serde(skip))] #[cfg_attr(feature = "extra-serde", serde(alias = "global_defs"))] - pub global_defs: AHashMap, Box>, + pub global_defs: FxHashMap, Box>, #[cfg_attr(feature = "extra-serde", serde(default))] #[cfg_attr(feature = "extra-serde", serde(alias = "hoist_funs"))] diff --git a/crates/swc_ecma_minifier/src/option/terser.rs b/crates/swc_ecma_minifier/src/option/terser.rs index 704fd8676327..4e0a3404a495 100644 --- a/crates/swc_ecma_minifier/src/option/terser.rs +++ b/crates/swc_ecma_minifier/src/option/terser.rs @@ -1,9 +1,10 @@ //! Compatibility for terser config. +use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use serde_json::Value; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, sync::Lrc, FileName, SourceMap, DUMMY_SP}; +use swc_common::{sync::Lrc, FileName, SourceMap, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_parser::parse_file_as_expr; use swc_ecma_utils::drop_span; @@ -120,7 +121,7 @@ pub struct TerserCompressorOptions { pub expression: bool, #[serde(default)] - pub global_defs: AHashMap, + pub global_defs: FxHashMap, #[serde(default)] pub hoist_funs: bool, diff --git a/crates/swc_ecma_minifier/src/pass/hygiene/vars.rs b/crates/swc_ecma_minifier/src/pass/hygiene/vars.rs index 07e802e04f4d..e777602469df 100644 --- a/crates/swc_ecma_minifier/src/pass/hygiene/vars.rs +++ b/crates/swc_ecma_minifier/src/pass/hygiene/vars.rs @@ -1,6 +1,6 @@ use std::cell::RefCell; -use fxhash::{AHashMap, AHashSet}; +use fxhash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; use swc_common::{SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; @@ -8,7 +8,7 @@ use swc_ecma_visit::{noop_visit_type, Node, Visit, VisitWith}; #[derive(Default)] pub(super) struct All { - pub scopes: AHashMap, + pub scopes: FxHashMap, } pub(super) fn analyze(node: &N) -> All @@ -27,7 +27,7 @@ where #[derive(Debug, Default)] pub(super) struct VarHygieneData { - pub decls: AHashMap>, + pub decls: FxHashMap>, } #[derive(Default)] diff --git a/crates/swc_ecma_minifier/src/pass/mangle_names/private_name.rs b/crates/swc_ecma_minifier/src/pass/mangle_names/private_name.rs index 79def22eb1ac..e3ad2d233e88 100644 --- a/crates/swc_ecma_minifier/src/pass/mangle_names/private_name.rs +++ b/crates/swc_ecma_minifier/src/pass/mangle_names/private_name.rs @@ -1,5 +1,5 @@ +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; @@ -19,7 +19,7 @@ struct PrivateNameMangler { keep_private_props: bool, private_n: usize, - renamed_private: AHashMap, + renamed_private: FxHashMap, } impl PrivateNameMangler { diff --git a/crates/swc_ecma_minifier/src/pass/mangle_props.rs b/crates/swc_ecma_minifier/src/pass/mangle_props.rs index 591e73c9a7c7..7761ede068ee 100644 --- a/crates/swc_ecma_minifier/src/pass/mangle_props.rs +++ b/crates/swc_ecma_minifier/src/pass/mangle_props.rs @@ -1,8 +1,8 @@ use std::collections::HashSet; use once_cell::sync::Lazy; +use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; -use swc_common::collections::{AHashMap, AHashSet}; use swc_ecma_ast::{ CallExpr, Callee, Expr, IdentName, KeyValueProp, Lit, MemberExpr, MemberProp, Program, Prop, PropName, Str, SuperProp, SuperPropExpr, @@ -15,14 +15,14 @@ use crate::{ util::base54::Base54Chars, }; -pub static JS_ENVIRONMENT_PROPS: Lazy> = Lazy::new(|| { +pub static JS_ENVIRONMENT_PROPS: Lazy> = Lazy::new(|| { let domprops: Vec = serde_json::from_str(include_str!("../lists/domprops.json")) .expect("failed to parse domprops.json for property mangler"); let jsprops: Vec = serde_json::from_str(include_str!("../lists/jsprops.json")) .expect("Failed to parse jsprops.json for property mangler"); - let mut word_set: AHashSet = HashSet::default(); + let mut word_set: FxHashSet = HashSet::default(); for name in domprops.iter().chain(jsprops.iter()) { word_set.insert(name.clone()); @@ -35,11 +35,11 @@ struct ManglePropertiesState { chars: Base54Chars, options: ManglePropertiesOptions, - names_to_mangle: AHashSet, - unmangleable: AHashSet, + names_to_mangle: FxHashSet, + unmangleable: FxHashSet, // Cache of already mangled names - cache: AHashMap, + cache: FxHashMap, // Numbers to pass to base54() n: usize, diff --git a/crates/swc_ecma_minifier/src/program_data.rs b/crates/swc_ecma_minifier/src/program_data.rs index df8e6c3dfb17..64178234a2fb 100644 --- a/crates/swc_ecma_minifier/src/program_data.rs +++ b/crates/swc_ecma_minifier/src/program_data.rs @@ -1,12 +1,9 @@ use std::collections::hash_map::Entry; use indexmap::IndexSet; -use rustc_hash::FxHashMap; +use rustc_hash::{FxBuildHasher, FxHashMap}; use swc_atoms::JsWord; -use swc_common::{ - collections::{AHashMap, ARandomState}, - SyntaxContext, -}; +use swc_common::SyntaxContext; use swc_ecma_ast::*; use swc_ecma_usage_analyzer::{ alias::{Access, AccessKind}, @@ -37,7 +34,7 @@ pub(crate) struct ProgramData { pub(crate) scopes: FxHashMap, - initialized_vars: IndexSet, + initialized_vars: IndexSet, } #[derive(Debug, Default, Clone)] @@ -123,7 +120,7 @@ pub(crate) struct VarUsageInfo { /// PR. (because it's hard to review) infects_to: Vec, /// Only **string** properties. - pub(crate) accessed_props: Box>, + pub(crate) accessed_props: Box>, pub(crate) used_recursively: bool, } @@ -386,7 +383,7 @@ impl Storage for ProgramData { e.usage_count = e.usage_count.saturating_sub(1); } - let mut to_visit: IndexSet = + let mut to_visit: IndexSet = IndexSet::from_iter(e.infects_to.clone().into_iter().map(|i| i.0)); let mut idx = 0; diff --git a/crates/swc_ecma_parser/Cargo.toml b/crates/swc_ecma_parser/Cargo.toml index a6ff7e50ac22..ac3d66c60c94 100644 --- a/crates/swc_ecma_parser/Cargo.toml +++ b/crates/swc_ecma_parser/Cargo.toml @@ -28,6 +28,7 @@ verify = ["swc_ecma_visit"] either = { workspace = true } num-bigint = { workspace = true } num-traits = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } smallvec = { workspace = true } smartstring = { workspace = true } diff --git a/crates/swc_ecma_parser/src/parser/expr.rs b/crates/swc_ecma_parser/src/parser/expr.rs index d782df1d3784..e7d1f2b34615 100644 --- a/crates/swc_ecma_parser/src/parser/expr.rs +++ b/crates/swc_ecma_parser/src/parser/expr.rs @@ -1,4 +1,5 @@ use either::Either; +use rustc_hash::FxHashMap; use swc_common::{ast_node, util::take::Take, Spanned}; use super::{pat::PatType, util::ExprExt, *}; @@ -339,7 +340,7 @@ impl Parser { let span = span!(self, start); let mut flags_count = flags.chars().fold( - AHashMap::::default(), + FxHashMap::::default(), |mut map, flag| { let key = match flag { // https://tc39.es/ecma262/#sec-isvalidregularexpressionliteral diff --git a/crates/swc_ecma_parser/src/parser/mod.rs b/crates/swc_ecma_parser/src/parser/mod.rs index 5510a7a6db50..e7674fd48673 100644 --- a/crates/swc_ecma_parser/src/parser/mod.rs +++ b/crates/swc_ecma_parser/src/parser/mod.rs @@ -3,8 +3,9 @@ use std::ops::{Deref, DerefMut}; +use rustc_hash::FxHashMap; use swc_atoms::{Atom, JsWord}; -use swc_common::{collections::AHashMap, comments::Comments, input::StringInput, BytePos, Span}; +use swc_common::{comments::Comments, input::StringInput, BytePos, Span}; use swc_ecma_ast::*; pub use self::input::{Capturing, Tokens, TokensInput}; @@ -56,7 +57,7 @@ struct State { found_module_item: bool, /// Start position of an AST node and the span of its trailing comma. - trailing_commas: AHashMap, + trailing_commas: FxHashMap, } impl<'a> Parser> { diff --git a/crates/swc_ecma_preset_env/src/corejs2/builtin.rs b/crates/swc_ecma_preset_env/src/corejs2/builtin.rs index 4fd6d2323ce8..47c3c4f851d2 100644 --- a/crates/swc_ecma_preset_env/src/corejs2/builtin.rs +++ b/crates/swc_ecma_preset_env/src/corejs2/builtin.rs @@ -1,10 +1,10 @@ use once_cell::sync::Lazy; -use swc_common::collections::AHashMap; +use rustc_hash::FxHashMap; use crate::{BrowserData, Versions}; -pub(crate) static BUILTINS: Lazy> = Lazy::new(|| { - let map: AHashMap<_, BrowserData>> = +pub(crate) static BUILTINS: Lazy> = Lazy::new(|| { + let map: FxHashMap<_, BrowserData>> = serde_json::from_str(include_str!("builtin.json")).expect("failed to parse json"); map.into_iter() diff --git a/crates/swc_ecma_preset_env/src/corejs2/entry.rs b/crates/swc_ecma_preset_env/src/corejs2/entry.rs index dcc3aac15d2f..f0df6fc889c5 100644 --- a/crates/swc_ecma_preset_env/src/corejs2/entry.rs +++ b/crates/swc_ecma_preset_env/src/corejs2/entry.rs @@ -2,8 +2,9 @@ use std::sync::Arc; use indexmap::IndexSet; use preset_env_base::{version::should_enable, Versions}; +use rustc_hash::FxBuildHasher; use swc_atoms::js_word; -use swc_common::{collections::ARandomState, DUMMY_SP}; +use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; @@ -13,7 +14,7 @@ use super::builtin::BUILTINS; pub struct Entry { is_any_target: bool, target: Arc, - pub imports: IndexSet<&'static str, ARandomState>, + pub imports: IndexSet<&'static str, FxBuildHasher>, } impl Entry { diff --git a/crates/swc_ecma_preset_env/src/corejs2/mod.rs b/crates/swc_ecma_preset_env/src/corejs2/mod.rs index da69800451eb..825e5d2696d9 100644 --- a/crates/swc_ecma_preset_env/src/corejs2/mod.rs +++ b/crates/swc_ecma_preset_env/src/corejs2/mod.rs @@ -2,8 +2,8 @@ use std::sync::Arc; use indexmap::IndexSet; use preset_env_base::{version::should_enable, Versions}; +use rustc_hash::FxBuildHasher; use swc_atoms::JsWord; -use swc_common::collections::ARandomState; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -21,7 +21,7 @@ mod entry; pub(crate) struct UsageVisitor { is_any_target: bool, target: Arc, - pub required: IndexSet<&'static str, ARandomState>, + pub required: IndexSet<&'static str, FxBuildHasher>, } impl UsageVisitor { diff --git a/crates/swc_ecma_preset_env/src/corejs3/compat.rs b/crates/swc_ecma_preset_env/src/corejs3/compat.rs index 2984943bf669..f634298a83d8 100644 --- a/crates/swc_ecma_preset_env/src/corejs3/compat.rs +++ b/crates/swc_ecma_preset_env/src/corejs3/compat.rs @@ -1,11 +1,11 @@ //! Ported from https://github.com/zloirock/core-js/tree/master/packages/core-js-compat use once_cell::sync::Lazy; -use swc_common::collections::AHashMap; +use rustc_hash::FxHashMap; use crate::Versions; -pub static DATA: Lazy> = Lazy::new(|| { +pub static DATA: Lazy> = Lazy::new(|| { serde_json::from_str(include_str!("../../data/core-js-compat/data.json")) .expect("failed parse corejs3-compat data.json") }); diff --git a/crates/swc_ecma_preset_env/src/corejs3/data.rs b/crates/swc_ecma_preset_env/src/corejs3/data.rs index b9bd982d3df8..acb8293782ec 100644 --- a/crates/swc_ecma_preset_env/src/corejs3/data.rs +++ b/crates/swc_ecma_preset_env/src/corejs3/data.rs @@ -1,11 +1,11 @@ use once_cell::sync::Lazy; use preset_env_base::version::Version; -use swc_common::collections::AHashMap; +use rustc_hash::FxHashMap; pub static POSSIBLE_GLOBAL_OBJECTS: &[&str] = &["global", "globalThis", "self", "window"]; -pub static MODULES_BY_VERSION: Lazy> = Lazy::new(|| { - serde_json::from_str::>(include_str!( +pub static MODULES_BY_VERSION: Lazy> = Lazy::new(|| { + serde_json::from_str::>(include_str!( "../../data/core-js-compat/modules-by-versions.json" )) .expect("failed to parse modules-by-versions.json") diff --git a/crates/swc_ecma_preset_env/src/corejs3/entry.rs b/crates/swc_ecma_preset_env/src/corejs3/entry.rs index 32be423bc947..4c9a5fc34e56 100644 --- a/crates/swc_ecma_preset_env/src/corejs3/entry.rs +++ b/crates/swc_ecma_preset_env/src/corejs3/entry.rs @@ -6,18 +6,16 @@ use preset_env_base::{ version::{should_enable, Version}, Versions, }; +use rustc_hash::{FxBuildHasher, FxHashMap}; use swc_atoms::js_word; -use swc_common::{ - collections::{AHashMap, ARandomState}, - DUMMY_SP, -}; +use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_visit::VisitMut; use super::{compat::DATA as CORE_JS_COMPAT_DATA, data::MODULES_BY_VERSION}; -static ENTRIES: Lazy>> = Lazy::new(|| { - serde_json::from_str::>>(include_str!( +static ENTRIES: Lazy>> = Lazy::new(|| { + serde_json::from_str::>>(include_str!( "../../data/core-js-compat/entries.json" )) .expect("failed to parse entries.json from core js 3") @@ -38,7 +36,7 @@ pub struct Entry { is_any_target: bool, target: Arc, corejs_version: Version, - pub imports: IndexSet<&'static str, ARandomState>, + pub imports: IndexSet<&'static str, FxBuildHasher>, remove_regenerator: bool, } diff --git a/crates/swc_ecma_preset_env/src/corejs3/usage.rs b/crates/swc_ecma_preset_env/src/corejs3/usage.rs index 3e5530bfdbc8..bcfba71e435d 100644 --- a/crates/swc_ecma_preset_env/src/corejs3/usage.rs +++ b/crates/swc_ecma_preset_env/src/corejs3/usage.rs @@ -2,8 +2,8 @@ use std::sync::Arc; use indexmap::IndexSet; use preset_env_base::version::{should_enable, Version}; +use rustc_hash::FxBuildHasher; use swc_atoms::JsWord; -use swc_common::collections::ARandomState; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -22,7 +22,7 @@ pub(crate) struct UsageVisitor { is_any_target: bool, target: Arc, corejs_version: Version, - pub required: IndexSet<&'static str, ARandomState>, + pub required: IndexSet<&'static str, FxBuildHasher>, } impl UsageVisitor { diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index ae751fd1971c..0c34fb8fd65e 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -6,12 +6,10 @@ use std::{path::PathBuf, sync::Arc}; use preset_env_base::query::targets_to_versions; pub use preset_env_base::{query::Targets, version::Version, BrowserData, Versions}; +use rustc_hash::FxHashSet; use serde::Deserialize; use swc_atoms::{js_word, JsWord}; -use swc_common::{ - collections::AHashSet, comments::Comments, pass::Optional, FromVariant, Mark, SyntaxContext, - DUMMY_SP, -}; +use swc_common::{comments::Comments, pass::Optional, FromVariant, Mark, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms::{ compat::{ @@ -359,8 +357,8 @@ struct Polyfills { shipped_proposals: bool, corejs: Version, regenerator: bool, - includes: AHashSet, - excludes: AHashSet, + includes: FxHashSet, + excludes: FxHashSet, unresolved_mark: Mark, } impl Polyfills { @@ -627,9 +625,9 @@ pub enum FeatureOrModule { } impl FeatureOrModule { - pub fn split(vec: Vec) -> (Vec, AHashSet) { + pub fn split(vec: Vec) -> (Vec, FxHashSet) { let mut features: Vec<_> = Default::default(); - let mut modules: AHashSet<_> = Default::default(); + let mut modules: FxHashSet<_> = Default::default(); for v in vec { match v { diff --git a/crates/swc_ecma_preset_env/src/transform_data.rs b/crates/swc_ecma_preset_env/src/transform_data.rs index feb0829e61b5..c96cda73739d 100644 --- a/crates/swc_ecma_preset_env/src/transform_data.rs +++ b/crates/swc_ecma_preset_env/src/transform_data.rs @@ -3,8 +3,8 @@ use preset_env_base::{ version::{should_enable, Version}, BrowserData, Versions, }; +use rustc_hash::FxHashMap; use string_enum::StringEnum; -use swc_common::collections::AHashMap; impl Feature { pub fn should_enable(self, target: &Versions, bugfixes: bool, default: bool) -> bool { @@ -204,9 +204,9 @@ pub enum Feature { BugfixTransformSafariClassFieldInitializerScope, // TODO } -pub(crate) static FEATURES: Lazy>>> = +pub(crate) static FEATURES: Lazy>>> = Lazy::new(|| { - let map: AHashMap>> = + let map: FxHashMap>> = serde_json::from_str(include_str!("../data/@babel/compat-data/data/plugins.json")) .expect("failed to parse json"); @@ -230,9 +230,9 @@ pub(crate) static FEATURES: Lazy>> .collect() }); -pub(crate) static BUGFIX_FEATURES: Lazy>>> = +pub(crate) static BUGFIX_FEATURES: Lazy>>> = Lazy::new(|| { - let map: AHashMap>> = serde_json::from_str( + let map: FxHashMap>> = serde_json::from_str( include_str!("../data/@babel/compat-data/data/plugin-bugfixes.json"), ) .expect("failed to parse json"); diff --git a/crates/swc_ecma_preset_env/tests/test.rs b/crates/swc_ecma_preset_env/tests/test.rs index a4401e9b2ff5..1c243d0a95d8 100644 --- a/crates/swc_ecma_preset_env/tests/test.rs +++ b/crates/swc_ecma_preset_env/tests/test.rs @@ -10,11 +10,11 @@ use std::{ }; use pretty_assertions::assert_eq; +use rustc_hash::FxHashMap; use serde::Deserialize; use serde_json::Value; use swc_common::{ - collections::AHashMap, comments::SingleThreadedComments, errors::HANDLER, input::StringInput, - FromVariant, Mark, + comments::SingleThreadedComments, errors::HANDLER, input::StringInput, FromVariant, Mark, }; use swc_ecma_ast::*; use swc_ecma_codegen::Emitter; @@ -70,7 +70,7 @@ struct PresetConfig { #[serde(untagged)] pub enum CoreJs { Ver(Version), - Val(AHashMap), + Val(FxHashMap), } impl Default for CoreJs { diff --git a/crates/swc_ecma_quote_macros/Cargo.toml b/crates/swc_ecma_quote_macros/Cargo.toml index 5f510daf3101..2c05c0f503c7 100644 --- a/crates/swc_ecma_quote_macros/Cargo.toml +++ b/crates/swc_ecma_quote_macros/Cargo.toml @@ -16,6 +16,7 @@ proc-macro = true anyhow = { workspace = true } proc-macro2 = { workspace = true } quote = { workspace = true } +rustc-hash = { workspace = true } syn = { workspace = true } swc_atoms = { version = "3.0.4", path = "../swc_atoms" } diff --git a/crates/swc_ecma_quote_macros/src/ctxt.rs b/crates/swc_ecma_quote_macros/src/ctxt.rs index 14b4ac369d66..874b96ba3782 100644 --- a/crates/swc_ecma_quote_macros/src/ctxt.rs +++ b/crates/swc_ecma_quote_macros/src/ctxt.rs @@ -2,7 +2,7 @@ use std::cell::RefCell; -use swc_common::collections::AHashMap; +use rustc_hash::FxHashMap; use swc_macros_common::call_site; use syn::{parse_quote, punctuated::Punctuated, ExprPath, ExprReference, Ident, Token}; @@ -10,7 +10,7 @@ use crate::{ast::ToCode, input::QuoteVar}; #[derive(Debug)] pub(crate) struct Ctx { - pub(crate) vars: AHashMap, + pub(crate) vars: FxHashMap, } impl Ctx { @@ -76,14 +76,14 @@ impl VarData { } } -pub type Vars = AHashMap; +pub type Vars = FxHashMap; pub(super) fn prepare_vars( src: &dyn ToCode, vars: Punctuated, -) -> (Vec, AHashMap) { +) -> (Vec, FxHashMap) { let mut stmts = Vec::new(); - let mut init_map = AHashMap::<_, Vars>::default(); + let mut init_map = FxHashMap::<_, Vars>::default(); for var in vars { let value = var.value; diff --git a/crates/swc_ecma_transforms_base/src/hygiene/tests.rs b/crates/swc_ecma_transforms_base/src/hygiene/tests.rs index 2e4b77679e8d..b1870308a305 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/tests.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/tests.rs @@ -1,5 +1,6 @@ +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, hygiene::*, DUMMY_SP}; +use swc_common::{hygiene::*, DUMMY_SP}; use swc_ecma_parser::Syntax; use swc_ecma_utils::quote_ident; use swc_ecma_visit::{Fold, FoldWith}; @@ -9,7 +10,7 @@ use super::*; use crate::tests::{HygieneVisualizer, Tester}; struct Marker { - map: AHashMap, + map: FxHashMap, } fn marker(markers: &[(&str, Mark)]) -> Marker { @@ -29,7 +30,7 @@ impl Fold for Marker { } struct OnceMarker { - map: AHashMap>, + map: FxHashMap>, } impl OnceMarker { diff --git a/crates/swc_ecma_transforms_base/src/rename/analyzer/scope.rs b/crates/swc_ecma_transforms_base/src/rename/analyzer/scope.rs index 007981b2cdae..60bfbbdd0d36 100644 --- a/crates/swc_ecma_transforms_base/src/rename/analyzer/scope.rs +++ b/crates/swc_ecma_transforms_base/src/rename/analyzer/scope.rs @@ -11,7 +11,7 @@ use indexmap::IndexSet; use rayon::prelude::*; use rustc_hash::{FxHashSet, FxHasher}; use swc_atoms::{atom, Atom}; -use swc_common::{collections::AHashMap, util::take::Take, Mark, SyntaxContext}; +use swc_common::{util::take::Take, Mark, SyntaxContext}; use swc_ecma_ast::*; use tracing::debug; diff --git a/crates/swc_ecma_transforms_base/src/rename/mod.rs b/crates/swc_ecma_transforms_base/src/rename/mod.rs index ae0bbec7756b..aca03466f431 100644 --- a/crates/swc_ecma_transforms_base/src/rename/mod.rs +++ b/crates/swc_ecma_transforms_base/src/rename/mod.rs @@ -4,7 +4,6 @@ use std::{borrow::Cow, collections::hash_map::Entry}; use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::Atom; -use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; use swc_ecma_visit::{ diff --git a/crates/swc_ecma_transforms_base/src/resolver/mod.rs b/crates/swc_ecma_transforms_base/src/resolver/mod.rs index 30cd3fc2212f..29f7c4add584 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/mod.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/mod.rs @@ -1,9 +1,6 @@ -use rustc_hash::FxHashSet; +use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; -use swc_common::{ - collections::{AHashMap, AHashSet}, - Mark, SyntaxContext, -}; +use swc_common::{Mark, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_utils::{find_pat_ids, stack_size::maybe_grow_default}; use swc_ecma_visit::{ @@ -172,10 +169,10 @@ struct Scope<'a> { mark: Mark, /// All declarations in the scope - declared_symbols: AHashMap, + declared_symbols: FxHashMap, /// All types declared in the scope - declared_types: AHashSet, + declared_types: FxHashSet, } impl<'a> Scope<'a> { diff --git a/crates/swc_ecma_transforms_module/Cargo.toml b/crates/swc_ecma_transforms_module/Cargo.toml index 1445b0276c64..38bdc6b4412f 100644 --- a/crates/swc_ecma_transforms_module/Cargo.toml +++ b/crates/swc_ecma_transforms_module/Cargo.toml @@ -21,6 +21,7 @@ is-macro = { workspace = true } path-clean = "1.0.1" pathdiff = { workspace = true } regex = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } tracing = { workspace = true } diff --git a/crates/swc_ecma_transforms_module/src/common_js.rs b/crates/swc_ecma_transforms_module/src/common_js.rs index f85b0e7b1a2e..fed2a74011c2 100644 --- a/crates/swc_ecma_transforms_module/src/common_js.rs +++ b/crates/swc_ecma_transforms_module/src/common_js.rs @@ -1,7 +1,5 @@ -use swc_common::{ - collections::AHashSet, source_map::PURE_SP, util::take::Take, Mark, Span, SyntaxContext, - DUMMY_SP, -}; +use rustc_hash::FxHashSet; +use swc_common::{source_map::PURE_SP, util::take::Take, Mark, Span, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ @@ -226,7 +224,7 @@ impl Cjs { fn handle_import_export( &mut self, import_map: &mut ImportMap, - lazy_record: &mut AHashSet, + lazy_record: &mut FxHashSet, link: Link, export: Export, is_export_assign: bool, diff --git a/crates/swc_ecma_transforms_module/src/import_analysis.rs b/crates/swc_ecma_transforms_module/src/import_analysis.rs index e3fe05397304..0b58c3ac089e 100644 --- a/crates/swc_ecma_transforms_module/src/import_analysis.rs +++ b/crates/swc_ecma_transforms_module/src/import_analysis.rs @@ -1,5 +1,5 @@ +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_transforms_base::enable_helper; use swc_ecma_visit::{ @@ -21,7 +21,7 @@ pub struct ImportAnalyzer { import_interop: ImportInterop, ignore_dynamic: bool, - flag_record: AHashMap, + flag_record: FxHashMap, dynamic_import_found: bool, } diff --git a/crates/swc_ecma_transforms_module/src/module_decl_strip.rs b/crates/swc_ecma_transforms_module/src/module_decl_strip.rs index d9712a3de1c4..169e2ae4d070 100644 --- a/crates/swc_ecma_transforms_module/src/module_decl_strip.rs +++ b/crates/swc_ecma_transforms_module/src/module_decl_strip.rs @@ -1,10 +1,7 @@ use indexmap::IndexMap; +use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; -use swc_common::{ - collections::{AHashMap, AHashSet}, - util::take::Take, - Mark, Span, SyntaxContext, -}; +use swc_common::{util::take::Take, Mark, Span, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_utils::{find_pat_ids, private_ident, quote_ident, ExprFactory}; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; @@ -14,7 +11,7 @@ use crate::{module_ref_rewriter::ImportMap, SpanCtx}; /// key: module path pub type Link = IndexMap; /// key: export binding name -pub type Export = AHashMap; +pub type Export = FxHashMap; #[derive(Debug)] pub struct ModuleDeclStrip { @@ -498,7 +495,7 @@ impl From for LinkSpecifier { } #[derive(Debug, Default)] -pub struct LinkItem(pub SpanCtx, pub AHashSet, pub LinkFlag); +pub struct LinkItem(pub SpanCtx, pub FxHashSet, pub LinkFlag); use bitflags::bitflags; @@ -642,7 +639,7 @@ pub(crate) trait LinkSpecifierReducer { ); } -impl LinkSpecifierReducer for AHashSet { +impl LinkSpecifierReducer for FxHashSet { fn reduce( self, import_map: &mut ImportMap, diff --git a/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs b/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs index 492a54a91cfb..6a4bbec891e0 100644 --- a/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs +++ b/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs @@ -1,8 +1,6 @@ +use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; -use swc_common::{ - collections::{AHashMap, AHashSet}, - SyntaxContext, -}; +use swc_common::SyntaxContext; use swc_ecma_ast::*; use swc_ecma_transforms_base::helpers::HELPERS; use swc_ecma_utils::{ExprFactory, QueryRef, RefRewriter}; @@ -10,7 +8,7 @@ use swc_ecma_visit::VisitMutWith; use crate::util::prop_name; -pub type ImportMap = AHashMap)>; +pub type ImportMap = FxHashMap)>; pub(crate) struct ImportQuery { /// ```javascript @@ -32,7 +30,7 @@ pub(crate) struct ImportQuery { /// ) /// ``` import_map: ImportMap, - lazy_record: AHashSet, + lazy_record: FxHashSet, helper_ctxt: Option, } @@ -91,7 +89,7 @@ impl QueryRef for ImportQuery { pub(crate) fn rewrite_import_bindings( node: &mut V, import_map: ImportMap, - lazy_record: AHashSet, + lazy_record: FxHashSet, ) where V: VisitMutWith>, { diff --git a/crates/swc_ecma_transforms_module/src/system_js.rs b/crates/swc_ecma_transforms_module/src/system_js.rs index c160e77525d9..35326b0d0e7d 100644 --- a/crates/swc_ecma_transforms_module/src/system_js.rs +++ b/crates/swc_ecma_transforms_module/src/system_js.rs @@ -1,7 +1,8 @@ use anyhow::Context; +use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, Mark, Span, SyntaxContext, DUMMY_SP}; +use swc_common::{Mark, Span, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{ member_expr, private_ident, quote_ident, quote_str, var::VarCollector, ExprFactory, @@ -30,7 +31,7 @@ struct SystemJs { config: Config, declare_var_idents: Vec, - export_map: AHashMap>, + export_map: FxHashMap>, export_names: Vec, export_values: Vec>, tla: bool, diff --git a/crates/swc_ecma_transforms_optimization/src/const_modules.rs b/crates/swc_ecma_transforms_optimization/src/const_modules.rs index cd7ed4fc6682..91fa0d09d96e 100644 --- a/crates/swc_ecma_transforms_optimization/src/const_modules.rs +++ b/crates/swc_ecma_transforms_optimization/src/const_modules.rs @@ -5,10 +5,9 @@ use std::{ use dashmap::DashMap; use once_cell::sync::Lazy; -use rustc_hash::FxHashMap; +use rustc_hash::{FxBuildHasher, FxHashMap}; use swc_atoms::{atom, JsWord}; use swc_common::{ - collections::ARandomState, errors::HANDLER, sync::Lrc, util::{move_map::MoveMap, take::Take}, @@ -44,7 +43,7 @@ pub fn const_modules( } fn parse_option(cm: &SourceMap, name: &str, src: String) -> Arc { - static CACHE: Lazy, ARandomState>> = Lazy::new(DashMap::default); + static CACHE: Lazy, FxBuildHasher>> = Lazy::new(DashMap::default); let fm = cm.new_source_file( FileName::Internal(format!("", name)).into(), diff --git a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs index 23522e2f5d10..3b94247b2dee 100644 --- a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs +++ b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs @@ -1,8 +1,6 @@ +use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; -use swc_common::{ - collections::{AHashMap, AHashSet}, - sync::Lrc, -}; +use swc_common::sync::Lrc; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{ParVisitMut, Parallel}; use swc_ecma_utils::{collect_decls, parallel::cpu_count, NodeIgnoringSpan}; @@ -10,14 +8,14 @@ use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith /// The key will be compared using [EqIgnoreSpan::eq_ignore_span], and matched /// expressions will be replaced with the value. -pub type GlobalExprMap = Lrc, Expr>>; +pub type GlobalExprMap = Lrc, Expr>>; /// Create a global inlining pass, which replaces expressions with the specified /// value. pub fn inline_globals( - envs: Lrc>, - globals: Lrc>, - typeofs: Lrc>, + envs: Lrc>, + globals: Lrc>, + typeofs: Lrc>, ) -> impl Pass { inline_globals2(envs, globals, Default::default(), typeofs) } @@ -29,10 +27,10 @@ pub fn inline_globals( /// /// Note: Values specified in `global_exprs` have higher precedence than pub fn inline_globals2( - envs: Lrc>, - globals: Lrc>, + envs: Lrc>, + globals: Lrc>, global_exprs: GlobalExprMap, - typeofs: Lrc>, + typeofs: Lrc>, ) -> impl Pass { visit_mut_pass(InlineGlobals { envs, @@ -45,13 +43,13 @@ pub fn inline_globals2( #[derive(Clone)] struct InlineGlobals { - envs: Lrc>, - globals: Lrc>, - global_exprs: Lrc, Expr>>, + envs: Lrc>, + globals: Lrc>, + global_exprs: Lrc, Expr>>, - typeofs: Lrc>, + typeofs: Lrc>, - bindings: Lrc>, + bindings: Lrc>, } impl Parallel for InlineGlobals { @@ -214,8 +212,8 @@ mod tests { tester: &mut Tester<'_>, values: &[(&str, &str)], is_env: bool, - ) -> AHashMap { - let mut m = AHashMap::default(); + ) -> FxHashMap { + let mut m = FxHashMap::default(); for (k, v) in values { let v = if is_env { @@ -250,11 +248,11 @@ mod tests { m } - fn envs(tester: &mut Tester<'_>, values: &[(&str, &str)]) -> Lrc> { + fn envs(tester: &mut Tester<'_>, values: &[(&str, &str)]) -> Lrc> { Lrc::new(mk_map(tester, values, true)) } - fn globals(tester: &mut Tester<'_>, values: &[(&str, &str)]) -> Lrc> { + fn globals(tester: &mut Tester<'_>, values: &[(&str, &str)]) -> Lrc> { Lrc::new(mk_map(tester, values, false)) } diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs index 6b3391343376..a9b2a97486c8 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs @@ -1,6 +1,7 @@ #![allow(clippy::borrowed_box)] -use swc_common::{collections::AHashMap, util::take::Take}; +use rustc_hash::FxHashMap; +use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; @@ -17,7 +18,7 @@ struct ConstPropagation<'a> { struct Scope<'a> { parent: Option<&'a Scope<'a>>, /// Stores only inlinable constant variables. - vars: AHashMap>, + vars: FxHashMap>, } impl<'a> Scope<'a> { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs index f88080abc402..a43ce38aa25f 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs @@ -2,10 +2,9 @@ use std::{borrow::Cow, sync::Arc}; use indexmap::IndexSet; use petgraph::{algo::tarjan_scc, Direction::Incoming}; -use rustc_hash::FxHashSet; +use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; use swc_atoms::{atom, JsWord}; use swc_common::{ - collections::{AHashMap, AHashSet, ARandomState}, pass::{CompilerPass, Repeated}, util::take::Take, Mark, SyntaxContext, DUMMY_SP, @@ -94,7 +93,7 @@ struct TreeShaker { data: Arc, - bindings: Arc>, + bindings: Arc>, } impl CompilerPass for TreeShaker { @@ -105,7 +104,7 @@ impl CompilerPass for TreeShaker { #[derive(Default)] struct Data { - used_names: AHashMap, + used_names: FxHashMap, /// Variable usage graph /// @@ -115,7 +114,7 @@ struct Data { /// Entrypoints. entries: FxHashSet, - graph_ix: IndexSet, + graph_ix: IndexSet, } impl Data { @@ -224,7 +223,7 @@ struct Scope<'a> { parent: Option<&'a Scope<'a>>, kind: ScopeKind, - bindings_affected_by_eval: AHashSet, + bindings_affected_by_eval: FxHashSet, found_direct_eval: bool, found_arguemnts: bool, diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/scope.rs b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/scope.rs index 515ad8bece83..ed1cbc8d495b 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/scope.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/scope.rs @@ -7,7 +7,7 @@ use std::{ }; use indexmap::map::{Entry, IndexMap}; -use swc_common::collections::{AHashMap, AHashSet, ARandomState}; +use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; use swc_ecma_ast::*; use swc_ecma_transforms_base::ext::ExprRefExt; use tracing::{span, Level}; @@ -242,11 +242,11 @@ pub(super) struct Scope<'a> { pub kind: ScopeKind, inline_barriers: RefCell>, - bindings: IndexMap, - unresolved_usages: AHashSet, + bindings: IndexMap, + unresolved_usages: FxHashSet, /// Simple optimization. We don't need complex scope analysis. - pub constants: AHashMap>, + pub constants: FxHashMap>, } impl<'a> Scope<'a> { diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs b/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs index cd75e04d5c4e..09d03c415bfd 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs @@ -1,8 +1,8 @@ use std::ops::Deref; +use rustc_hash::FxHashMap; use swc_atoms::JsWord; use swc_common::{ - collections::AHashMap, util::{move_map::MoveMap, take::Take}, BytePos, Spanned, DUMMY_SP, }; @@ -101,7 +101,7 @@ pub(super) fn remove_span(e: &mut Expr) { } } -type EnumMapType = AHashMap; +type EnumMapType = FxHashMap; pub(super) struct EnumMap<'a>(&'a EnumMapType); diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/legacy/mod.rs b/crates/swc_ecma_transforms_proposal/src/decorators/legacy/mod.rs index 80e54ea41398..b5e6737d6267 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/legacy/mod.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/legacy/mod.rs @@ -1,8 +1,9 @@ use std::{iter, mem}; use metadata::remove_span; +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, util::take::Take, BytePos, DUMMY_SP}; +use swc_common::{util::take::Take, BytePos, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::{private_ident, prop_name_to_expr_value, quote_ident, ExprFactory, StmtLike}; @@ -37,7 +38,7 @@ pub(super) fn new(metadata: bool) -> TscDecorator { pub(super) struct TscDecorator { metadata: bool, - enums: AHashMap, + enums: FxHashMap, /// Used for computed keys, and this variables are not initialized. vars: Vec, diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs index ec96c2f89fa2..05338bfff716 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs @@ -1,5 +1,6 @@ +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, comments::Comments, Span}; +use swc_common::{comments::Comments, Span}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; @@ -26,7 +27,7 @@ struct PureAnnotations where C: Comments, { - imports: AHashMap, + imports: FxHashMap, comments: Option, } diff --git a/crates/swc_ecma_transforms_react/src/refresh/mod.rs b/crates/swc_ecma_transforms_react/src/refresh/mod.rs index 600ebaa00da1..e1a7576ec981 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/mod.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/mod.rs @@ -1,6 +1,7 @@ +use rustc_hash::FxHashSet; use swc_common::{ - collections::AHashSet, comments::Comments, sync::Lrc, util::take::Take, BytePos, Mark, - SourceMap, SourceMapper, Span, Spanned, SyntaxContext, DUMMY_SP, + comments::Comments, sync::Lrc, util::take::Take, BytePos, Mark, SourceMap, SourceMapper, Span, + Spanned, SyntaxContext, DUMMY_SP, }; use swc_ecma_ast::*; use swc_ecma_utils::{private_ident, quote_ident, quote_str, ExprFactory}; @@ -76,7 +77,7 @@ impl Refresh { fn get_persistent_id_from_var_decl( &self, var_decl: &mut VarDecl, - used_in_jsx: &AHashSet, + used_in_jsx: &FxHashSet, hook_reg: &mut HookRegister, ) -> Persist { // We only handle the case when a single variable is declared diff --git a/crates/swc_ecma_transforms_react/src/refresh/util.rs b/crates/swc_ecma_transforms_react/src/refresh/util.rs index ebc93354d8de..c51f0af3be3f 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/util.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/util.rs @@ -1,4 +1,5 @@ -use swc_common::{collections::AHashSet, Spanned, SyntaxContext, DUMMY_SP}; +use rustc_hash::FxHashSet; +use swc_common::{Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::ExprFactory; use swc_ecma_visit::{noop_visit_type, Visit, VisitWith}; @@ -89,7 +90,7 @@ pub fn is_import_or_require(expr: &Expr) -> bool { } } -pub struct UsedInJsx(AHashSet); +pub struct UsedInJsx(FxHashSet); impl Visit for UsedInJsx { noop_visit_type!(); @@ -126,8 +127,8 @@ impl Visit for UsedInJsx { } } -pub fn collect_ident_in_jsx>(item: &V) -> AHashSet { - let mut visitor = UsedInJsx(AHashSet::default()); +pub fn collect_ident_in_jsx>(item: &V) -> FxHashSet { + let mut visitor = UsedInJsx(FxHashSet::default()); item.visit_with(&mut visitor); visitor.0 } diff --git a/crates/swc_ecma_transforms_typescript/Cargo.toml b/crates/swc_ecma_transforms_typescript/Cargo.toml index b949ea2a9a33..b901a65b07ec 100644 --- a/crates/swc_ecma_transforms_typescript/Cargo.toml +++ b/crates/swc_ecma_transforms_typescript/Cargo.toml @@ -16,9 +16,10 @@ bench = false concurrent = ["swc_common/concurrent"] [dependencies] -once_cell = { workspace = true } -ryu-js = { workspace = true } -serde = { workspace = true, features = ["derive"] } +once_cell = { workspace = true } +rustc-hash = { workspace = true } +ryu-js = { workspace = true } +serde = { workspace = true, features = ["derive"] } swc_atoms = { version = "3.0.4", path = "../swc_atoms" } swc_common = { version = "5.0.1", path = "../swc_common" } diff --git a/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs b/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs index ecb5362d5a6c..8912667ca27c 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs @@ -1,4 +1,4 @@ -use swc_common::collections::{AHashMap, AHashSet}; +use rustc_hash::{FxHashMap, FxHashSet}; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; use swc_ecma_visit::{noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith}; @@ -7,12 +7,12 @@ use crate::{strip_type::IsConcrete, ImportsNotUsedAsValues}; #[derive(Debug, Default)] pub(crate) struct UsageCollect { - id_usage: AHashSet, - import_chain: AHashMap, + id_usage: FxHashSet, + import_chain: FxHashMap, } -impl From> for UsageCollect { - fn from(id_usage: AHashSet) -> Self { +impl From> for UsageCollect { + fn from(id_usage: FxHashSet) -> Self { Self { id_usage, import_chain: Default::default(), @@ -117,7 +117,7 @@ impl UsageCollect { return; } - let mut new_usage = AHashSet::default(); + let mut new_usage = FxHashSet::default(); for id in &self.id_usage { let mut next = self.import_chain.remove(id); while let Some(id) = next { @@ -144,8 +144,8 @@ fn get_module_ident(ts_entity_name: &TsEntityName) -> &Ident { #[derive(Debug, Default)] pub(crate) struct DeclareCollect { - id_type: AHashSet, - id_value: AHashSet, + id_type: FxHashSet, + id_value: FxHashSet, } /// Only scan the top level of the module. diff --git a/crates/swc_ecma_transforms_typescript/src/transform.rs b/crates/swc_ecma_transforms_typescript/src/transform.rs index 6a13f5c1b796..481914cd203d 100644 --- a/crates/swc_ecma_transforms_typescript/src/transform.rs +++ b/crates/swc_ecma_transforms_typescript/src/transform.rs @@ -1,12 +1,10 @@ use std::{iter, mem}; +use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; use swc_common::{ - collections::{AHashMap, AHashSet}, - errors::HANDLER, - source_map::PURE_SP, - util::take::Take, - Mark, Span, Spanned, SyntaxContext, DUMMY_SP, + errors::HANDLER, source_map::PURE_SP, util::take::Take, Mark, Span, Spanned, SyntaxContext, + DUMMY_SP, }; use swc_ecma_ast::*; use swc_ecma_utils::{ @@ -62,12 +60,12 @@ pub(crate) struct Transform { ref_rewriter: Option>, - decl_id_record: AHashSet, + decl_id_record: FxHashSet, namespace_id: Option, - exported_binding: AHashMap>, + exported_binding: FxHashMap>, enum_record: TsEnumRecord, - const_enum: AHashSet, + const_enum: FxHashSet, var_list: Vec, export_var_list: Vec, @@ -1413,7 +1411,7 @@ impl Transform { } struct ExportQuery { - export_name: AHashMap>, + export_name: FxHashMap>, } impl QueryRef for ExportQuery { diff --git a/crates/swc_ecma_transforms_typescript/src/ts_enum.rs b/crates/swc_ecma_transforms_typescript/src/ts_enum.rs index 729e4729605f..9a0d19083b63 100644 --- a/crates/swc_ecma_transforms_typescript/src/ts_enum.rs +++ b/crates/swc_ecma_transforms_typescript/src/ts_enum.rs @@ -1,5 +1,6 @@ +use rustc_hash::FxHashMap; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, SyntaxContext, DUMMY_SP}; +use swc_common::{SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{ number::{JsNumber, ToJsString}, @@ -13,7 +14,7 @@ pub(crate) struct TsEnumRecordKey { pub member_name: JsWord, } -pub(crate) type TsEnumRecord = AHashMap; +pub(crate) type TsEnumRecord = FxHashMap; #[derive(Debug, Clone)] pub(crate) enum TsEnumRecordValue { diff --git a/crates/swc_ecma_transforms_typescript/src/typescript.rs b/crates/swc_ecma_transforms_typescript/src/typescript.rs index 2918d7befe7b..924840d43eb2 100644 --- a/crates/swc_ecma_transforms_typescript/src/typescript.rs +++ b/crates/swc_ecma_transforms_typescript/src/typescript.rs @@ -1,10 +1,8 @@ use std::mem; use once_cell::sync::Lazy; -use swc_common::{ - collections::AHashSet, comments::Comments, sync::Lrc, util::take::Take, Mark, SourceMap, Span, - Spanned, -}; +use rustc_hash::FxHashSet; +use swc_common::{comments::Comments, sync::Lrc, util::take::Take, Mark, SourceMap, Span, Spanned}; use swc_ecma_ast::*; use swc_ecma_transforms_react::{parse_expr_for_jsx, JsxDirectives}; use swc_ecma_visit::{visit_mut_pass, VisitMut, VisitMutWith}; @@ -47,7 +45,7 @@ pub(crate) struct TypeScript { pub unresolved_mark: Mark, pub top_level_mark: Mark, - id_usage: AHashSet, + id_usage: FxHashSet, } impl VisitMut for TypeScript { @@ -192,7 +190,7 @@ where { config: Config, tsx_config: TsxConfig, - id_usage: AHashSet, + id_usage: FxHashSet, comments: C, cm: Lrc, top_level_mark: Mark, diff --git a/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs b/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs index 8903cc417f21..71efbb6bb17b 100644 --- a/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs +++ b/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs @@ -1,4 +1,5 @@ -use swc_common::{collections::AHashMap, SyntaxContext}; +use rustc_hash::FxHashMap; +use swc_common::SyntaxContext; use swc_ecma_ast::*; use swc_ecma_utils::{ find_pat_ids, ident::IdentLike, ExprCtx, ExprExt, IsEmpty, StmtExt, Type, Value, @@ -40,7 +41,7 @@ where in_strict: false, remaining_depth: 3, }, - used_recursively: AHashMap::default(), + used_recursively: FxHashMap::default(), }; n.visit_with(&mut v); let top_scope = v.scope; @@ -74,7 +75,7 @@ where scope: S::ScopeData, ctx: Ctx, expr_ctx: ExprCtx, - used_recursively: AHashMap, + used_recursively: FxHashMap, } impl UsageAnalyzer diff --git a/crates/swc_ecma_utils/src/function/fn_env_hoister.rs b/crates/swc_ecma_utils/src/function/fn_env_hoister.rs index c24dce838342..a2ae0be6eeb6 100644 --- a/crates/swc_ecma_utils/src/function/fn_env_hoister.rs +++ b/crates/swc_ecma_utils/src/function/fn_env_hoister.rs @@ -1,10 +1,9 @@ use std::mem; use indexmap::IndexMap; +use rustc_hash::FxBuildHasher; use swc_atoms::JsWord; -use swc_common::{ - collections::ARandomState, util::take::Take, Span, Spanned, SyntaxContext, DUMMY_SP, -}; +use swc_common::{util::take::Take, Span, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; @@ -13,7 +12,7 @@ use crate::ExprFactory; #[derive(Default)] struct SuperField { computed: Option, - ident: IndexMap, + ident: IndexMap, } /// Don't use it against function, it will stop if come across any function diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs index 08f0b08a396c..35914d6177a4 100644 --- a/crates/swc_ecma_utils/src/lib.rs +++ b/crates/swc_ecma_utils/src/lib.rs @@ -15,11 +15,9 @@ pub extern crate swc_ecma_ast; use std::{borrow::Cow, hash::Hash, num::FpCategory, ops::Add}; use number::ToJsString; -use rustc_hash::FxHashMap; +use rustc_hash::{FxHashMap, FxHashSet}; use swc_atoms::JsWord; -use swc_common::{ - collections::AHashSet, util::take::Take, Mark, Span, Spanned, SyntaxContext, DUMMY_SP, -}; +use swc_common::{util::take::Take, Mark, Span, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_visit::{ noop_visit_mut_type, noop_visit_type, visit_mut_obj_and_computed, visit_obj_and_computed, @@ -1920,7 +1918,7 @@ where I: IdentLike + Eq + Hash + Send + Sync, { only: Option, - bindings: AHashSet, + bindings: FxHashSet, is_pat_decl: bool, } @@ -2043,7 +2041,7 @@ where } /// Collects binding identifiers. -pub fn collect_decls(n: &N) -> AHashSet +pub fn collect_decls(n: &N) -> FxHashSet where I: IdentLike + Eq + Hash + Send + Sync, N: VisitWith>, @@ -2059,7 +2057,7 @@ where /// Collects binding identifiers, but only if it has a context which is /// identical to `ctxt`. -pub fn collect_decls_with_ctxt(n: &N, ctxt: SyntaxContext) -> AHashSet +pub fn collect_decls_with_ctxt(n: &N, ctxt: SyntaxContext) -> FxHashSet where I: IdentLike + Eq + Hash + Send + Sync, N: VisitWith>, @@ -3454,7 +3452,7 @@ mod tests { fn run_collect_decls(text: &str, expected_names: &[&str]) { let module = parse_module(text); - let decls: AHashSet = collect_decls(&module); + let decls: FxHashSet = collect_decls(&module); let mut names = decls.iter().map(|d| d.0.to_string()).collect::>(); names.sort(); assert_eq!(names, expected_names); diff --git a/crates/swc_estree_compat/Cargo.toml b/crates/swc_estree_compat/Cargo.toml index 9e99ef4ae6df..386400cbbed7 100644 --- a/crates/swc_estree_compat/Cargo.toml +++ b/crates/swc_estree_compat/Cargo.toml @@ -18,9 +18,9 @@ bench = false [features] [dependencies] -ahash = { workspace = true, features = ["compile-time-rng"] } anyhow = { workspace = true } copyless = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } diff --git a/crates/swc_fast_graph/src/digraph.rs b/crates/swc_fast_graph/src/digraph.rs index 420f76d6b9b1..a9e5b36886e6 100644 --- a/crates/swc_fast_graph/src/digraph.rs +++ b/crates/swc_fast_graph/src/digraph.rs @@ -6,7 +6,7 @@ use std::{ cmp::Ordering, fmt, - hash::{self, BuildHasherDefault, Hash}, + hash::{self, Hash}, iter::Cloned, marker::PhantomData, ops::Deref, @@ -25,10 +25,7 @@ use petgraph::{ }, Directed, Direction, EdgeType, Incoming, IntoWeightedEdge, Outgoing, Undirected, }; -use rustc_hash::FxHasher; -use swc_common::collections::AHashSet; - -type FxBuildHasher = BuildHasherDefault; +use rustc_hash::{FxBuildHasher, FxHashSet}; /// A `GraphMap` with directed edges. /// @@ -865,10 +862,10 @@ where N: Copy + Ord + Hash, Ty: EdgeType, { - type Map = AHashSet; + type Map = FxHashSet; - fn visit_map(&self) -> AHashSet { - AHashSet::with_capacity_and_hasher(self.node_count(), Default::default()) + fn visit_map(&self) -> FxHashSet { + FxHashSet::with_capacity_and_hasher(self.node_count(), Default::default()) } fn reset_map(&self, map: &mut Self::Map) { diff --git a/crates/swc_graph_analyzer/Cargo.toml b/crates/swc_graph_analyzer/Cargo.toml index 77d71e622f07..221ae6ebbc3e 100644 --- a/crates/swc_graph_analyzer/Cargo.toml +++ b/crates/swc_graph_analyzer/Cargo.toml @@ -14,6 +14,7 @@ bench = false [dependencies] auto_impl = { workspace = true } petgraph = { workspace = true } +rustc-hash = { workspace = true } swc_common = { version = "5.0.1", path = "../swc_common/" } swc_fast_graph = { version = "6.0.0", path = "../swc_fast_graph/" } tracing = { workspace = true } diff --git a/crates/swc_graph_analyzer/src/lib.rs b/crates/swc_graph_analyzer/src/lib.rs index b04ead2cd490..8765d95f1c1e 100644 --- a/crates/swc_graph_analyzer/src/lib.rs +++ b/crates/swc_graph_analyzer/src/lib.rs @@ -1,7 +1,7 @@ use std::{fmt::Debug, hash::Hash, marker::PhantomData}; use auto_impl::auto_impl; -use swc_common::collections::AHashSet; +use rustc_hash::FxHashSet; use swc_fast_graph::digraph::FastDiGraphMap; #[auto_impl(&, Box, Rc, Arc)] @@ -17,7 +17,7 @@ where G: DepGraph, { /// `(src, dst)` - tracked: AHashSet<(G::ModuleId, G::ModuleId)>, + tracked: FxHashSet<(G::ModuleId, G::ModuleId)>, dep_graph: G, data: GraphResult, } diff --git a/crates/swc_html_minifier/Cargo.toml b/crates/swc_html_minifier/Cargo.toml index f3856aeef907..c1db666fc5ff 100644 --- a/crates/swc_html_minifier/Cargo.toml +++ b/crates/swc_html_minifier/Cargo.toml @@ -16,12 +16,18 @@ version = "9.0.0" bench = false [features] -default = ["default-css-minifier"] -default-css-minifier = ["swc_css_ast", "swc_css_codegen", "swc_css_minifier", "swc_css_parser"] custom-css-minifier = [] +default = ["default-css-minifier"] +default-css-minifier = [ + "swc_css_ast", + "swc_css_codegen", + "swc_css_minifier", + "swc_css_parser", +] [dependencies] once_cell = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index 587a464863aa..2911c6d55a35 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -3,12 +3,13 @@ use std::{borrow::Cow, cmp::Ordering, mem::take}; use once_cell::sync::Lazy; +use rustc_hash::FxHashMap; use serde_json::Value; use swc_atoms::{js_word, JsWord}; use swc_cached::regex::CachedRegex; use swc_common::{ - collections::AHashMap, comments::SingleThreadedComments, sync::Lrc, EqIgnoreSpan, FileName, - FilePathMapping, Mark, SourceMap, DUMMY_SP, + comments::SingleThreadedComments, sync::Lrc, EqIgnoreSpan, FileName, FilePathMapping, Mark, + SourceMap, DUMMY_SP, }; use swc_html_ast::*; use swc_html_parser::parser::ParserConfig; @@ -232,7 +233,7 @@ struct Minifier<'a, C: MinifyCss> { current_element: Option, latest_element: Option, descendant_of_pre: bool, - attribute_name_counter: Option>, + attribute_name_counter: Option>, css_minifier: &'a C, } @@ -2818,7 +2819,7 @@ impl VisitMut for Minifier<'_, C> { } struct AttributeNameCounter { - tree: AHashMap, + tree: FxHashMap, } impl VisitMut for AttributeNameCounter { diff --git a/crates/swc_html_parser/Cargo.toml b/crates/swc_html_parser/Cargo.toml index ca8ea041ee9c..7d38d7bdad8b 100644 --- a/crates/swc_html_parser/Cargo.toml +++ b/crates/swc_html_parser/Cargo.toml @@ -19,6 +19,8 @@ bench = false debug = [] [dependencies] +rustc-hash = { workspace = true } + swc_atoms = { version = "3.0.4", path = "../swc_atoms" } swc_common = { version = "5.0.1", path = "../swc_common" } swc_html_ast = { version = "5.0.0", path = "../swc_html_ast" } diff --git a/crates/swc_html_parser/src/lexer/mod.rs b/crates/swc_html_parser/src/lexer/mod.rs index b7379faecda0..67bb760d8374 100644 --- a/crates/swc_html_parser/src/lexer/mod.rs +++ b/crates/swc_html_parser/src/lexer/mod.rs @@ -1,7 +1,8 @@ use std::{cell::RefCell, char::REPLACEMENT_CHARACTER, collections::VecDeque, mem::take, rc::Rc}; +use rustc_hash::FxHashSet; use swc_atoms::{js_word, Atom, JsWord}; -use swc_common::{collections::AHashSet, input::Input, BytePos, Span}; +use swc_common::{input::Input, BytePos, Span}; use swc_html_ast::{AttributeToken, Raw, Token, TokenAndSpan}; use swc_html_utils::{Entity, HTML_ENTITIES}; @@ -113,7 +114,7 @@ where buf: Rc>, sub_buf: Rc>, current_token: Option, - attributes_validator: AHashSet, + attributes_validator: FxHashSet, attribute_start_position: Option, character_reference_code: Option)>>, temporary_buffer: String, diff --git a/crates/swc_html_parser/tests/html5lib_tests.rs b/crates/swc_html_parser/tests/html5lib_tests.rs index c4a04abe92a1..b4fd66ed40fb 100644 --- a/crates/swc_html_parser/tests/html5lib_tests.rs +++ b/crates/swc_html_parser/tests/html5lib_tests.rs @@ -4,10 +4,10 @@ use std::{fs, mem::take, path::PathBuf}; use common::{document_span_visualizer, DomVisualizer}; +use rustc_hash::FxHashSet; use serde_json::Value; use swc_atoms::JsWord; use swc_common::{ - collections::AHashSet, input::{SourceFileInput, StringInput}, BytePos, }; @@ -169,7 +169,7 @@ fn html5lib_test_tokenizer(input: PathBuf) { *raw_tag_name = None; let mut new_attributes = Vec::new(); - let mut already_seen: AHashSet = Default::default(); + let mut already_seen: FxHashSet = Default::default(); for mut attribute in take(attributes) { if already_seen.contains(&attribute.name) { diff --git a/crates/swc_html_utils/Cargo.toml b/crates/swc_html_utils/Cargo.toml index 50f70e9f92c5..442b04a20605 100644 --- a/crates/swc_html_utils/Cargo.toml +++ b/crates/swc_html_utils/Cargo.toml @@ -17,6 +17,7 @@ bench = false [dependencies] once_cell = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } diff --git a/crates/swc_html_utils/src/lib.rs b/crates/swc_html_utils/src/lib.rs index 92cfa1d1a804..fbebdf284591 100644 --- a/crates/swc_html_utils/src/lib.rs +++ b/crates/swc_html_utils/src/lib.rs @@ -1,15 +1,15 @@ use once_cell::sync::Lazy; +use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use swc_atoms::JsWord; -use swc_common::collections::AHashMap; #[derive(Serialize, Deserialize, Debug)] pub struct Entity { pub characters: String, } -pub static HTML_ENTITIES: Lazy> = Lazy::new(|| { - let entities: AHashMap = +pub static HTML_ENTITIES: Lazy> = Lazy::new(|| { + let entities: FxHashMap = serde_json::from_str(include_str!("../data/entities.json")) .expect("failed to parse entities.json for html entities"); @@ -33,19 +33,19 @@ pub struct AttributeInfo { pub struct Element { _extends: Option>, #[serde(flatten)] - pub other: AHashMap, + pub other: FxHashMap, } -pub static HTML_ELEMENTS_AND_ATTRIBUTES: Lazy> = Lazy::new(|| { - let default_attributes: AHashMap = +pub static HTML_ELEMENTS_AND_ATTRIBUTES: Lazy> = Lazy::new(|| { + let default_attributes: FxHashMap = serde_json::from_str(include_str!("../data/html_elements_and_attributes.json")) .expect("failed to parse html_elements_and_attributes.json for default attributes"); default_attributes }); -pub static SVG_ELEMENTS_AND_ATTRIBUTES: Lazy> = Lazy::new(|| { - let svg_elements_and_attributes: AHashMap = +pub static SVG_ELEMENTS_AND_ATTRIBUTES: Lazy> = Lazy::new(|| { + let svg_elements_and_attributes: FxHashMap = serde_json::from_str(include_str!("../data/svg_elements_and_attributes.json")) .expect("failed to parse svg_elements_and_attributes.json for default attributes"); diff --git a/crates/swc_node_bundler/Cargo.toml b/crates/swc_node_bundler/Cargo.toml index 2438f862dc78..0b23e04dd99a 100644 --- a/crates/swc_node_bundler/Cargo.toml +++ b/crates/swc_node_bundler/Cargo.toml @@ -24,6 +24,7 @@ dashmap = { workspace = true } is-macro = { workspace = true } once_cell = { workspace = true } regex = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"], optional = true } serde_json = { workspace = true } tracing = { workspace = true } diff --git a/crates/swc_node_bundler/src/loaders/swc.rs b/crates/swc_node_bundler/src/loaders/swc.rs index a53fd54c4ace..32d0ff1f0d4f 100644 --- a/crates/swc_node_bundler/src/loaders/swc.rs +++ b/crates/swc_node_bundler/src/loaders/swc.rs @@ -2,6 +2,7 @@ use std::{collections::HashMap, env, sync::Arc}; use anyhow::{bail, Context, Error}; use helpers::Helpers; +use rustc_hash::FxHashMap; use swc::{ config::{GlobalInliningPassEnvs, InputSourceMap, IsModule, JscConfig, TransformConfig}, try_with_handler, @@ -9,7 +10,6 @@ use swc::{ use swc_atoms::JsWord; use swc_bundler::{Load, ModuleData}; use swc_common::{ - collections::AHashMap, comments::{NoopComments, SingleThreadedComments}, errors::{Handler, HANDLER}, sync::Lrc, @@ -41,7 +41,7 @@ impl SwcLoader { SwcLoader { compiler, options } } - fn env_map(&self) -> Lrc> { + fn env_map(&self) -> Lrc> { let mut m = HashMap::default(); let envs = self @@ -55,7 +55,7 @@ impl SwcLoader { .map(|g| g.envs.clone()) .unwrap_or_default(); - let envs_map: AHashMap<_, _> = match envs { + let envs_map: FxHashMap<_, _> = match envs { GlobalInliningPassEnvs::Map(m) => m, GlobalInliningPassEnvs::List(envs) => envs .into_iter() diff --git a/crates/swc_node_bundler/src/v1/mod.rs b/crates/swc_node_bundler/src/v1/mod.rs index f30031686ff2..09013b0a7126 100644 --- a/crates/swc_node_bundler/src/v1/mod.rs +++ b/crates/swc_node_bundler/src/v1/mod.rs @@ -1,9 +1,10 @@ use std::{collections::HashMap, fmt, marker::PhantomData, path::PathBuf}; +use rustc_hash::FxHashMap; use serde::Deserialize; use string_enum::StringEnum; use swc_atoms::JsWord; -use swc_common::{collections::AHashMap, FileName}; +use swc_common::FileName; use swc_ecma_ast::EsVersion; use swc_ecma_loader::TargetEnv; @@ -52,7 +53,7 @@ pub struct Config { pub external_modules: Vec, #[serde(default)] - pub alias: AHashMap>, + pub alias: FxHashMap>, #[serde(default)] pub preserve_symlinks: bool, @@ -82,7 +83,7 @@ pub enum Mode { pub enum EntryConfig { File(String), Multiple(Vec), - Files(AHashMap), + Files(FxHashMap), } impl From for HashMap { diff --git a/crates/swc_node_comments/Cargo.toml b/crates/swc_node_comments/Cargo.toml index 19f1e5d5e67f..911229c41cd3 100644 --- a/crates/swc_node_comments/Cargo.toml +++ b/crates/swc_node_comments/Cargo.toml @@ -15,7 +15,8 @@ version = "5.0.0" bench = false [dependencies] -dashmap = { workspace = true } +dashmap = { workspace = true } +rustc-hash = { workspace = true } swc_atoms = { version = "3.0.4", path = "../swc_atoms" } swc_common = { version = "5.0.1", path = "../swc_common" } diff --git a/crates/swc_node_comments/src/lib.rs b/crates/swc_node_comments/src/lib.rs index 7059f0f96427..417f00bf161a 100644 --- a/crates/swc_node_comments/src/lib.rs +++ b/crates/swc_node_comments/src/lib.rs @@ -3,14 +3,14 @@ use std::sync::Arc; use dashmap::DashMap; +use rustc_hash::FxBuildHasher; use swc_atoms::atom; use swc_common::{ - collections::ARandomState, comments::{Comment, CommentKind, Comments}, BytePos, DUMMY_SP, }; -type CommentMap = Arc, ARandomState>>; +type CommentMap = Arc, FxBuildHasher>>; /// Multi-threaded implementation of [Comments] #[derive(Clone, Default)] diff --git a/crates/swc_plugin_proxy/Cargo.toml b/crates/swc_plugin_proxy/Cargo.toml index d4217e2f97cf..444bf1d3d745 100644 --- a/crates/swc_plugin_proxy/Cargo.toml +++ b/crates/swc_plugin_proxy/Cargo.toml @@ -21,11 +21,11 @@ plugin-mode = ["__plugin_mode", "swc_common/plugin-base", "rkyv-impl"] plugin-rt = ["__plugin_rt", "swc_common/plugin-base", "rkyv-impl"] [dependencies] - -bytecheck = { workspace = true, optional = true } -rancor = { workspace = true, optional = true } -rkyv = { workspace = true, optional = true } -tracing = { workspace = true } +bytecheck = { workspace = true, optional = true } +rancor = { workspace = true, optional = true } +rkyv = { workspace = true, optional = true } +rustc-hash = { workspace = true } +tracing = { workspace = true } better_scoped_tls = { version = "1.0.0", path = "../better_scoped_tls" } swc_common = { version = "5.0.1", path = "../swc_common" } diff --git a/crates/swc_plugin_proxy/src/metadata/transform_plugin_metadata.rs b/crates/swc_plugin_proxy/src/metadata/transform_plugin_metadata.rs index b0d48230ac0c..135c9890abca 100644 --- a/crates/swc_plugin_proxy/src/metadata/transform_plugin_metadata.rs +++ b/crates/swc_plugin_proxy/src/metadata/transform_plugin_metadata.rs @@ -98,9 +98,7 @@ impl TransformPluginProgramMetadata { /// Each time this is called, it'll require a call between host-plugin which /// involves serialization / deserialization. #[allow(unreachable_code)] - pub fn get_raw_experimental_context( - &self, - ) -> swc_common::collections::AHashMap { + pub fn get_raw_experimental_context(&self) -> rustc_hash::FxHashMap { // TODO: There is no clear usecase yet - enable when we have a correct usecase. unimplemented!("Not supported yet"); @@ -111,6 +109,6 @@ impl TransformPluginProgramMetadata { .expect("Raw experimental metadata should exists, even if it's empty map"); #[cfg(not(target_arch = "wasm32"))] - swc_common::collections::AHashMap::default() + rustc_hash::FxHashMap::default() } } diff --git a/crates/swc_plugin_runner/Cargo.toml b/crates/swc_plugin_runner/Cargo.toml index ffc49b773246..6d1ef0e15677 100644 --- a/crates/swc_plugin_runner/Cargo.toml +++ b/crates/swc_plugin_runner/Cargo.toml @@ -55,6 +55,7 @@ enumset = { workspace = true } futures = { workspace = true } once_cell = { workspace = true } parking_lot = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } tokio = { workspace = true, optional = true } diff --git a/crates/swc_plugin_runner/benches/ecma_invoke.rs b/crates/swc_plugin_runner/benches/ecma_invoke.rs index 7e968672326b..8608b583b04f 100644 --- a/crates/swc_plugin_runner/benches/ecma_invoke.rs +++ b/crates/swc_plugin_runner/benches/ecma_invoke.rs @@ -13,8 +13,8 @@ use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Benc #[cfg(feature = "__rkyv")] use swc_common::plugin::serialized::{PluginSerializedBytes, VersionedSerializable}; use swc_common::{ - collections::AHashMap, plugin::metadata::TransformPluginMetadataContext, FileName, - FilePathMapping, Globals, Mark, SourceMap, GLOBALS, + plugin::metadata::TransformPluginMetadataContext, FileName, FilePathMapping, Globals, Mark, + SourceMap, GLOBALS, }; use swc_ecma_ast::EsVersion; use swc_ecma_parser::parse_file_as_program; @@ -99,8 +99,8 @@ fn bench_transform(b: &mut Bencher, plugin_dir: &Path) { None, ); - let experimental_metadata: VersionedSerializable> = - VersionedSerializable::new(AHashMap::default()); + let experimental_metadata: VersionedSerializable> = + VersionedSerializable::new(FxHashMap::default()); let _experimental_metadata = PluginSerializedBytes::try_serialize(&experimental_metadata) .expect("Should be a hashmap"); diff --git a/crates/swc_plugin_runner/src/cache.rs b/crates/swc_plugin_runner/src/cache.rs index 0e750c30b71e..cc5ce7321128 100644 --- a/crates/swc_plugin_runner/src/cache.rs +++ b/crates/swc_plugin_runner/src/cache.rs @@ -9,10 +9,8 @@ use std::{ use anyhow::{Context, Error}; use enumset::EnumSet; use parking_lot::Mutex; -use swc_common::{ - collections::AHashMap, - sync::{Lazy, OnceCell}, -}; +use rustc_hash::FxHashMap; +use swc_common::sync::{Lazy, OnceCell}; #[cfg(not(target_arch = "wasm32"))] use wasmer::{sys::BaseTunables, CpuFeature, Engine, Target, Triple}; use wasmer::{Module, Store}; @@ -44,13 +42,13 @@ pub struct PluginModuleCacheInner { // FileSystemCache. This works since SWC does not revalidates plugin in single process // lifecycle. #[cfg(all(not(target_arch = "wasm32"), feature = "filesystem_cache"))] - fs_cache_hash_store: AHashMap, + fs_cache_hash_store: FxHashMap, // Generic in-memory cache to the raw bytes, either read by fs or supplied by bindgen. - memory_cache_store: AHashMap>, + memory_cache_store: FxHashMap>, // A naive hashmap to the compiled plugin modules. // Current it doesn't have any invalidation or expiration logics like lru, // having a lot of plugins may create some memory pressure. - compiled_module_bytes: AHashMap, + compiled_module_bytes: FxHashMap, } impl PluginModuleCacheInner { diff --git a/crates/swc_plugin_runner/tests/css_rkyv.rs b/crates/swc_plugin_runner/tests/css_rkyv.rs index 00b2436e2217..c4bbaa9adfd8 100644 --- a/crates/swc_plugin_runner/tests/css_rkyv.rs +++ b/crates/swc_plugin_runner/tests/css_rkyv.rs @@ -7,13 +7,11 @@ use std::{ }; use anyhow::{anyhow, Error}; +use rustc_hash::FxHashMap; use serde_json::json; #[cfg(feature = "__rkyv")] use swc_common::plugin::serialized::PluginSerializedBytes; -use swc_common::{ - collections::AHashMap, plugin::metadata::TransformPluginMetadataContext, sync::Lazy, FileName, - Mark, -}; +use swc_common::{plugin::metadata::TransformPluginMetadataContext, sync::Lazy, FileName, Mark}; use testing::CARGO_TARGET_DIR; use tracing::info; @@ -91,7 +89,7 @@ fn invoke(input: PathBuf) { &swc_common::plugin::serialized::VersionedSerializable::new(parsed.clone()), ) .expect("Should serializable"); - let experimental_metadata: AHashMap = [ + let experimental_metadata: FxHashMap = [ ( "TestExperimental".to_string(), "ExperimentalValue".to_string(), @@ -143,7 +141,7 @@ fn invoke(input: PathBuf) { ) .expect("Should serializable"); - let experimental_metadata: AHashMap = [ + let experimental_metadata: FxHashMap = [ ( "TestExperimental".to_string(), "ExperimentalValue".to_string(), diff --git a/crates/swc_plugin_runner/tests/ecma_integration.rs b/crates/swc_plugin_runner/tests/ecma_integration.rs index 0b0c01cfb275..f643e28cb5a7 100644 --- a/crates/swc_plugin_runner/tests/ecma_integration.rs +++ b/crates/swc_plugin_runner/tests/ecma_integration.rs @@ -8,12 +8,12 @@ use std::{ }; use anyhow::{anyhow, Error}; +use rustc_hash::FxHashMap; use serde_json::json; #[cfg(feature = "__rkyv")] use swc_common::plugin::serialized::PluginSerializedBytes; use swc_common::{ - collections::AHashMap, errors::HANDLER, plugin::metadata::TransformPluginMetadataContext, - sync::Lazy, FileName, Mark, + errors::HANDLER, plugin::metadata::TransformPluginMetadataContext, sync::Lazy, FileName, Mark, }; use swc_ecma_ast::{CallExpr, Callee, EsVersion, Expr, Lit, MemberExpr, Program, Str}; use swc_ecma_parser::{parse_file_as_program, Syntax}; @@ -121,7 +121,7 @@ fn internal() { let program = PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) .expect("Should serializable"); - let experimental_metadata: AHashMap = [ + let experimental_metadata: FxHashMap = [ ( "TestExperimental".to_string(), "ExperimentalValue".to_string(), @@ -189,7 +189,7 @@ fn internal() { let program = PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) .expect("Should serializable"); - let experimental_metadata: AHashMap = [ + let experimental_metadata: FxHashMap = [ ( "TestExperimental".to_string(), "ExperimentalValue".to_string(), diff --git a/crates/swc_plugin_runner/tests/ecma_rkyv.rs b/crates/swc_plugin_runner/tests/ecma_rkyv.rs index 235cd645bf82..96d6ee86eafb 100644 --- a/crates/swc_plugin_runner/tests/ecma_rkyv.rs +++ b/crates/swc_plugin_runner/tests/ecma_rkyv.rs @@ -7,13 +7,11 @@ use std::{ }; use anyhow::{anyhow, Error}; +use rustc_hash::FxHashMap; use serde_json::json; #[cfg(feature = "__rkyv")] use swc_common::plugin::serialized::PluginSerializedBytes; -use swc_common::{ - collections::AHashMap, plugin::metadata::TransformPluginMetadataContext, sync::Lazy, FileName, - Mark, -}; +use swc_common::{plugin::metadata::TransformPluginMetadataContext, sync::Lazy, FileName, Mark}; use swc_ecma_ast::{EsVersion, Program}; use swc_ecma_parser::{parse_file_as_program, Syntax, TsSyntax}; use testing::CARGO_TARGET_DIR; @@ -100,7 +98,7 @@ fn internal(input: PathBuf) { &swc_common::plugin::serialized::VersionedSerializable::new(parsed.clone()), ) .expect("Should serializable"); - let experimental_metadata: AHashMap = [ + let experimental_metadata: FxHashMap = [ ( "TestExperimental".to_string(), "ExperimentalValue".to_string(), @@ -158,7 +156,7 @@ fn internal(input: PathBuf) { ) .expect("Should serializable"); - let experimental_metadata: AHashMap = [ + let experimental_metadata: FxHashMap = [ ( "TestExperimental".to_string(), "ExperimentalValue".to_string(), diff --git a/crates/swc_plugin_runner/tests/issues.rs b/crates/swc_plugin_runner/tests/issues.rs index f65036392567..4bd154983c51 100644 --- a/crates/swc_plugin_runner/tests/issues.rs +++ b/crates/swc_plugin_runner/tests/issues.rs @@ -8,10 +8,11 @@ use std::{ }; use anyhow::{anyhow, Error}; +use rustc_hash::FxHashMap; use serde_json::json; #[cfg(feature = "__rkyv")] use swc_common::plugin::serialized::PluginSerializedBytes; -use swc_common::{collections::AHashMap, plugin::metadata::TransformPluginMetadataContext, Mark}; +use swc_common::{plugin::metadata::TransformPluginMetadataContext, Mark}; use swc_ecma_ast::{EsVersion, Program}; use swc_ecma_parser::{parse_file_as_program, Syntax}; use testing::CARGO_TARGET_DIR; @@ -81,7 +82,7 @@ fn issue_6404() -> Result<(), Error> { let program = PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) .expect("Should serializable"); - let experimental_metadata: AHashMap = [ + let experimental_metadata: FxHashMap = [ ( "TestExperimental".to_string(), "ExperimentalValue".to_string(), diff --git a/crates/swc_xml_parser/Cargo.toml b/crates/swc_xml_parser/Cargo.toml index 13e6474b7878..b962c27850a1 100644 --- a/crates/swc_xml_parser/Cargo.toml +++ b/crates/swc_xml_parser/Cargo.toml @@ -19,6 +19,8 @@ bench = false debug = [] [dependencies] +rustc-hash = { workspace = true } + swc_atoms = { version = "3.0.4", path = "../swc_atoms" } swc_common = { version = "5.0.1", path = "../swc_common" } swc_xml_ast = { version = "5.0.0", path = "../swc_xml_ast" } diff --git a/crates/swc_xml_parser/src/lexer/mod.rs b/crates/swc_xml_parser/src/lexer/mod.rs index e8aa7000580e..3186e9411097 100644 --- a/crates/swc_xml_parser/src/lexer/mod.rs +++ b/crates/swc_xml_parser/src/lexer/mod.rs @@ -1,7 +1,8 @@ use std::{collections::VecDeque, mem::take}; +use rustc_hash::FxHashSet; use swc_atoms::JsWord; -use swc_common::{collections::AHashSet, input::Input, BytePos, Span}; +use swc_common::{input::Input, BytePos, Span}; use swc_xml_ast::{AttributeToken, Token, TokenAndSpan}; use crate::{ @@ -804,7 +805,7 @@ where current_tag_token.kind = kind; } - let mut already_seen: AHashSet = Default::default(); + let mut already_seen: FxHashSet = Default::default(); let attributes = current_tag_token .attributes diff --git a/crates/testing/Cargo.toml b/crates/testing/Cargo.toml index f3e3a9dd416b..3d1e5f433dc1 100644 --- a/crates/testing/Cargo.toml +++ b/crates/testing/Cargo.toml @@ -18,6 +18,7 @@ difference = { workspace = true } once_cell = { workspace = true } pretty_assertions = { workspace = true } regex = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } tracing = { workspace = true } diff --git a/crates/testing/src/lib.rs b/crates/testing/src/lib.rs index 62870370adbe..db41e1dcc5be 100644 --- a/crates/testing/src/lib.rs +++ b/crates/testing/src/lib.rs @@ -14,8 +14,8 @@ use difference::Changeset; use once_cell::sync::Lazy; pub use pretty_assertions::{assert_eq, assert_ne}; use regex::Regex; +use rustc_hash::FxHashMap; use swc_common::{ - collections::AHashMap, errors::{Diagnostic, Handler, HANDLER}, sync::Lrc, FilePathMapping, SourceMap, @@ -52,7 +52,7 @@ pub fn init() -> tracing::subscriber::DefaultGuard { } pub fn find_executable(name: &str) -> Option { - static CACHE: Lazy>> = Lazy::new(Default::default); + static CACHE: Lazy>> = Lazy::new(Default::default); { let locked = CACHE.read().unwrap();