Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: use rustc-hash #538

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/biome_analyze/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ The first step is to setup a struct to represent the rule configuration.
```rust,ignore
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReactExtensiveDependenciesOptions {
hooks_config: HashMap<String, ReactHookConfiguration>,
stable_config: HashSet<StableReactHookConfiguration>,
hooks_config: FxHashMap<String, ReactHookConfiguration>,
stable_config: FxHashSet<StableReactHookConfiguration>,
}

impl Rule for UseExhaustiveDependencies {
Expand Down
5 changes: 3 additions & 2 deletions crates/biome_analyze/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rustc_hash::FxHashMap;

use crate::{Rule, RuleKey};
use std::any::{Any, TypeId};
use std::collections::HashMap;
use std::fmt::Debug;
use std::path::PathBuf;

Expand Down Expand Up @@ -28,7 +29,7 @@ impl RuleOptions {

/// A convenient new type data structure to insert and get rules
#[derive(Debug, Default)]
pub struct AnalyzerRules(HashMap<RuleKey, RuleOptions>);
pub struct AnalyzerRules(FxHashMap<RuleKey, RuleOptions>);

impl AnalyzerRules {
/// It tracks the options of a specific rule
Expand Down
8 changes: 3 additions & 5 deletions crates/biome_analyze/src/services.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::{RuleKey, TextRange};
use biome_diagnostics::{Diagnostic, LineIndexBuf, Resource, Result, SourceCode};
use std::{
any::{Any, TypeId},
collections::HashMap,
};
use rustc_hash::FxHashMap;
use std::any::{Any, TypeId};

#[derive(Debug, Diagnostic)]
#[diagnostic(category = "internalError/io", tags(INTERNAL))]
Expand Down Expand Up @@ -43,7 +41,7 @@ pub trait FromServices: Sized {

#[derive(Debug, Default)]
pub struct ServiceBag {
services: HashMap<TypeId, Box<dyn Any>>,
services: FxHashMap<TypeId, Box<dyn Any>>,
}

impl ServiceBag {
Expand Down
1 change: 1 addition & 0 deletions crates/biome_aria/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ version = "0.1.0"

[dependencies]
biome_aria_metadata = { workspace = true }
rustc-hash = { workspace = true }
18 changes: 9 additions & 9 deletions crates/biome_aria/src/roles.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{define_role, is_aria_property_valid};
use biome_aria_metadata::AriaPropertiesEnum;
use std::collections::HashMap;
use rustc_hash::FxHashMap;
use std::fmt::Debug;
use std::slice::Iter;
use std::str::FromStr;
Expand Down Expand Up @@ -892,7 +892,7 @@ impl<'a> AriaRoles {
&self,
element: &str,
// To generate `attributes`, you can use `biome_js_analyze::aria_services::AriaServices::extract_defined_attributes`
attributes: &HashMap<String, Vec<String>>,
attributes: &FxHashMap<String, Vec<String>>,
) -> Option<&'static dyn AriaRoleDefinition> {
let result = match element {
"article" => &ArticleRole as &dyn AriaRoleDefinition,
Expand Down Expand Up @@ -1023,7 +1023,7 @@ impl<'a> AriaRoles {
pub fn is_not_interactive_element(
&self,
element_name: &str,
attributes: Option<HashMap<String, Vec<String>>>,
attributes: Option<FxHashMap<String, Vec<String>>>,
) -> bool {
// <header> elements do not technically have semantics, unless the
// element is a direct descendant of <body>, and this crate cannot
Expand Down Expand Up @@ -1125,7 +1125,7 @@ pub struct AriaRoles;

#[cfg(test)]
mod test {
use std::collections::HashMap;
use rustc_hash::FxHashMap;

use crate::AriaRoles;

Expand All @@ -1134,7 +1134,7 @@ mod test {
let aria_roles = AriaRoles {};
assert!(!aria_roles.is_not_interactive_element("header", None));
assert!(!aria_roles.is_not_interactive_element("input", {
let mut attributes = HashMap::new();
let mut attributes = FxHashMap::default();
attributes.insert("type".to_string(), vec!["search".to_string()]);
Some(attributes)
}));
Expand All @@ -1151,7 +1151,7 @@ mod test {
assert!(aria_roles.is_not_interactive_element("h6", None));
assert!(aria_roles.is_not_interactive_element("body", None));
assert!(aria_roles.is_not_interactive_element("input", {
let mut attributes = HashMap::new();
let mut attributes = FxHashMap::default();
attributes.insert("type".to_string(), vec!["hidden".to_string()]);
Some(attributes)
}));
Expand All @@ -1163,12 +1163,12 @@ mod test {

// No attributes
let implicit_role = aria_roles
.get_implicit_role("button", &HashMap::new())
.get_implicit_role("button", &FxHashMap::default())
.unwrap();
assert_eq!(implicit_role.type_name(), "biome_aria::roles::ButtonRole");

// <input type="search">
let mut attributes = HashMap::new();
let mut attributes = FxHashMap::default();
attributes.insert("type".to_string(), vec!["search".to_string()]);
let implicit_role = aria_roles.get_implicit_role("input", &attributes).unwrap();
assert_eq!(
Expand All @@ -1177,7 +1177,7 @@ mod test {
);

// <select name="animals" multiple size="4">
let mut attributes = HashMap::new();
let mut attributes = FxHashMap::default();
attributes.insert("name".to_string(), vec!["animals".to_string()]);
attributes.insert("multiple".to_string(), vec![String::new()]);
attributes.insert("size".to_string(), vec!["4".to_string()]);
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ hdrhistogram = { version = "7.5.0", default-features = false }
indexmap = { workspace = true }
lazy_static = { workspace = true }
rayon = "1.5.1"
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["io-std", "io-util", "net", "time", "rt", "sync", "rt-multi-thread", "macros"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crossbeam::{
channel::{unbounded, Receiver, Sender},
select,
};
use std::collections::HashSet;
use rustc_hash::FxHashSet;
use std::{
ffi::OsString,
io,
Expand Down Expand Up @@ -297,7 +297,7 @@ fn process_messages(options: ProcessMessagesOptions) {
warnings,
} = options;

let mut paths: HashSet<String> = HashSet::new();
let mut paths: FxHashSet<String> = FxHashSet::default();
let mut printed_diagnostics: u16 = 0;
let mut not_printed_diagnostics = 0;
let mut total_skipped_suggested_fixes = 0;
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::{
borrow::Cow,
collections::HashMap,
hash::Hash,
ops::Sub,
ptr,
time::{Duration, Instant},
};

use hdrhistogram::Histogram;
use rustc_hash::FxHashMap;
use std::sync::{Mutex, RwLock};
use tracing::{span, subscriber::Interest, Level, Metadata, Subscriber};
use tracing_subscriber::{
Expand All @@ -22,7 +22,7 @@ struct MetricsLayer;

lazy_static::lazy_static! {
/// Global storage for metrics data
static ref METRICS: RwLock<HashMap<CallsiteKey, Mutex<CallsiteEntry>>> = RwLock::default();
static ref METRICS: RwLock<FxHashMap<CallsiteKey, Mutex<CallsiteEntry>>> = RwLock::default();
}

/// Static pointer to the metadata of a callsite, used as a unique identifier
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/src/reports/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_hash::FxHashMap;
use serde::Serialize;
use std::collections::HashMap;

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -8,7 +8,7 @@ pub struct FormatterReport {
summary: Option<FormatterReportSummary>,

/// The key is the path of the file
files: HashMap<String, FormatterReportFileDetail>,
files: FxHashMap<String, FormatterReportFileDetail>,
}

impl FormatterReport {
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/src/reports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::reports::formatter::{FormatterReportFileDetail, FormatterReportSummar
use biome_diagnostics::{Category, Severity};
use biome_service::WorkspaceError;
use formatter::FormatterReport;
use rustc_hash::FxHashMap;
use serde::Serialize;
use std::collections::HashMap;

#[derive(Debug, Default, Serialize)]
pub struct Report {
Expand All @@ -15,7 +15,7 @@ pub struct Report {
/// Diagnostics tracked during a generic traversal
///
/// The key is the path of the file where the diagnostics occurred
diagnostics: HashMap<String, ReportErrorKind>,
diagnostics: FxHashMap<String, ReportErrorKind>,
}

#[derive(Debug, Serialize)]
Expand Down
1 change: 1 addition & 0 deletions crates/biome_control_flow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ version = "0.1.0"

[dependencies]
biome_rowan = { workspace = true }
rustc-hash = { workspace = true }
8 changes: 3 additions & 5 deletions crates/biome_control_flow/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#![deny(rustdoc::broken_intra_doc_links)]

use std::{
collections::HashMap,
fmt::{self, Display, Formatter},
};
use std::fmt::{self, Display, Formatter};

use biome_rowan::{Language, SyntaxElement, SyntaxNode};
use rustc_hash::FxHashMap;

pub mod builder;

Expand Down Expand Up @@ -180,7 +178,7 @@ impl<L: Language> Display for ControlFlowGraph<L> {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
writeln!(fmt, "flowchart TB")?;

let mut links = HashMap::new();
let mut links = FxHashMap::default();
for (id, block) in self.blocks.iter().enumerate() {
if fmt.alternate() {
writeln!(fmt, " subgraph block_{id}")?;
Expand Down
3 changes: 1 addition & 2 deletions crates/biome_formatter/src/format_element/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
};
use biome_rowan::TextSize;
use rustc_hash::FxHashMap;
use std::collections::HashMap;
use std::ops::Deref;

/// A formatted document.
Expand Down Expand Up @@ -133,7 +132,7 @@ impl std::fmt::Display for Document {
#[derive(Clone, Default, Debug)]
struct IrFormatContext {
/// The interned elements that have been printed to this point
printed_interned_elements: HashMap<Interned, usize>,
printed_interned_elements: FxHashMap<Interned, usize>,
}

impl FormatContext for IrFormatContext {
Expand Down
1 change: 1 addition & 0 deletions crates/biome_fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ crossbeam = "0.8.2"
indexmap = { workspace = true }
parking_lot = { version = "0.12.0", features = ["arc_lock"] }
rayon = "1.7.0"
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true }
tracing = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions crates/biome_fs/src/fs/memory.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::hash_map::Entry;
use std::collections::{hash_map::IntoIter, HashMap};
use rustc_hash::FxHashMap;
use std::collections::hash_map::{Entry, IntoIter};
use std::io;
use std::panic::AssertUnwindSafe;
use std::path::{Path, PathBuf};
Expand All @@ -16,8 +16,8 @@ use super::{BoxedTraversal, ErrorKind, File, FileSystemDiagnostic};

/// Fully in-memory file system, stores the content of all known files in a hashmap
pub struct MemoryFileSystem {
files: AssertUnwindSafe<RwLock<HashMap<PathBuf, FileEntry>>>,
errors: HashMap<PathBuf, ErrorEntry>,
files: AssertUnwindSafe<RwLock<FxHashMap<PathBuf, FileEntry>>>,
errors: FxHashMap<PathBuf, ErrorEntry>,
allow_write: bool,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use biome_diagnostics::Applicability;
use biome_js_factory::make;
use biome_js_syntax::JsStringLiteralExpression;
use biome_rowan::{AstNode, BatchMutationExt, TextRange};
use std::{collections::HashSet, ops::Range};
use rustc_hash::FxHashSet;
use std::ops::Range;

declare_rule! {
/// Disallow `\8` and `\9` escape sequences in string literals.
Expand Down Expand Up @@ -166,7 +167,7 @@ impl Rule for NoNonoctalDecimalEscape {
}
}

let mut seen = HashSet::new();
let mut seen = FxHashSet::default();
signals.retain(|rule_state| seen.insert(rule_state.diagnostics_text_range));
signals
}
Expand Down
Loading
Loading