refactor(semantic, transformer): simplify FxIndexMap type aliases (#7524)

Pure refactor. Simplify `FxIndexMap` type aliases by using `rustc_hash`'s `FxBuildHasher`, instead of longhand `BuildHasherDefault<FxHasher>`.
This commit is contained in:
overlookmotel 2024-11-28 12:01:17 +00:00
parent 55f3636ecf
commit d21448bf65
4 changed files with 10 additions and 14 deletions

View file

@ -1,7 +1,7 @@
use std::{hash::BuildHasherDefault, mem}; use std::mem;
use indexmap::IndexMap; use indexmap::IndexMap;
use rustc_hash::{FxHashMap, FxHasher}; use rustc_hash::{FxBuildHasher, FxHashMap};
use oxc_index::IndexVec; use oxc_index::IndexVec;
use oxc_span::CompactStr; use oxc_span::CompactStr;
@ -10,7 +10,7 @@ pub use oxc_syntax::scope::{ScopeFlags, ScopeId};
use crate::{symbol::SymbolId, NodeId}; use crate::{symbol::SymbolId, NodeId};
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>; type FxIndexMap<K, V> = IndexMap<K, V, FxBuildHasher>;
pub(crate) type Bindings = FxIndexMap<CompactStr, SymbolId>; pub(crate) type Bindings = FxIndexMap<CompactStr, SymbolId>;
pub type UnresolvedReferences = FxHashMap<CompactStr, Vec<ReferenceId>>; pub type UnresolvedReferences = FxHashMap<CompactStr, Vec<ReferenceId>>;

View file

@ -87,11 +87,9 @@
//! The Implementation based on //! The Implementation based on
//! <https://github.com/babel/babel/blob/d20b314c14533ab86351ecf6ca6b7296b66a57b3/packages/babel-traverse/src/path/conversion.ts#L170-L247> //! <https://github.com/babel/babel/blob/d20b314c14533ab86351ecf6ca6b7296b66a57b3/packages/babel-traverse/src/path/conversion.ts#L170-L247>
use std::hash::BuildHasherDefault;
use compact_str::CompactString; use compact_str::CompactString;
use indexmap::IndexMap; use indexmap::IndexMap;
use rustc_hash::{FxHashSet, FxHasher}; use rustc_hash::{FxBuildHasher, FxHashSet};
use oxc_allocator::{Box as ArenaBox, Vec as ArenaVec}; use oxc_allocator::{Box as ArenaBox, Vec as ArenaVec};
use oxc_ast::{ast::*, NONE}; use oxc_ast::{ast::*, NONE};
@ -106,7 +104,7 @@ use oxc_traverse::{Ancestor, BoundIdentifier, Traverse, TraverseCtx};
use crate::EnvOptions; use crate::EnvOptions;
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>; type FxIndexMap<K, V> = IndexMap<K, V, FxBuildHasher>;
/// Mode for arrow function conversion /// Mode for arrow function conversion
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]

View file

@ -139,10 +139,8 @@
//! * <https://github.com/babel/babel/blob/v7.26.2/packages/babel-helper-create-class-features-plugin/src/fields.ts> //! * <https://github.com/babel/babel/blob/v7.26.2/packages/babel-helper-create-class-features-plugin/src/fields.ts>
//! * Class properties TC39 proposal: <https://github.com/tc39/proposal-class-fields> //! * Class properties TC39 proposal: <https://github.com/tc39/proposal-class-fields>
use std::hash::BuildHasherDefault;
use indexmap::IndexMap; use indexmap::IndexMap;
use rustc_hash::FxHasher; use rustc_hash::FxBuildHasher;
use serde::Deserialize; use serde::Deserialize;
use oxc_allocator::{Address, GetAddress}; use oxc_allocator::{Address, GetAddress};
@ -158,7 +156,7 @@ mod private;
mod static_prop; mod static_prop;
mod utils; mod utils;
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>; type FxIndexMap<K, V> = IndexMap<K, V, FxBuildHasher>;
#[derive(Debug, Default, Clone, Copy, Deserialize)] #[derive(Debug, Default, Clone, Copy, Deserialize)]
#[serde(default, rename_all = "camelCase")] #[serde(default, rename_all = "camelCase")]

View file

@ -88,11 +88,11 @@
use std::{ use std::{
cell::Cell, cell::Cell,
fmt::{Debug, Display}, fmt::{Debug, Display},
hash::{BuildHasherDefault, Hash}, hash::Hash,
}; };
use indexmap::IndexMap; use indexmap::IndexMap;
use rustc_hash::FxHasher; use rustc_hash::FxBuildHasher;
use oxc_allocator::{Allocator, CloneIn}; use oxc_allocator::{Allocator, CloneIn};
use oxc_ast::{ast::*, visit::walk, Visit}; use oxc_ast::{ast::*, visit::walk, Visit};
@ -105,7 +105,7 @@ use oxc_syntax::{
symbol::SymbolId, symbol::SymbolId,
}; };
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>; type FxIndexMap<K, V> = IndexMap<K, V, FxBuildHasher>;
/// Check `ScopeTree` and `SymbolTable` are correct after transform /// Check `ScopeTree` and `SymbolTable` are correct after transform
pub fn check_semantic_after_transform( pub fn check_semantic_after_transform(