Skip to content

Commit

Permalink
improve: use rustc-hash instead of fxhash for more active support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ggiggle committed Jan 25, 2024
1 parent 346905f commit 2ecdfda
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 173 deletions.
260 changes: 123 additions & 137 deletions Cargo.lock

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions pilota-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@ maintenance = { status = "actively-developed" }

[dependencies]
pilota-thrift-parser = { path = "../pilota-thrift-parser", version = "0.10" }
pilota = { path = "../pilota", version = "0.10" }

toml = "0.8"
anyhow = "1"
dashmap = "5"
heck = "0.4"
syn = "2"
itertools = "0.12"
lazy_static = "1"
normpath = "1"
serde = { version = "1", features = ["derive"] }
serde_yaml = "0.9"
fxhash = "0.2"
paste = "1"
petgraph = "0.6"
phf = { version = "0.11", features = ["macros"] }
proc-macro2 = "1"
salsa = { version = "0.17.0-pre.2" }
scoped-tls = "1"
quote = "1"
rayon = "1"
lazy_static = "1"
rustc-hash = "1"
salsa = { version = "0.17.0-pre.2" }
scoped-tls = "1"
serde = { version = "1", features = ["derive"] }
serde_yaml = "0.9"
syn = "2"
toml = "0.8"
tracing = "0.1"
dashmap = "5"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
phf = { version = "0.11", features = ["macros"] }
itertools = "0.12"
paste = "1"
petgraph = "0.6"
anyhow = "1"

# The official rust-protobuf parser currently has some bug.
# We will switch to the official one when https://github.com/stepancheg/rust-protobuf/pull/646 is fixed.
Expand Down
8 changes: 4 additions & 4 deletions pilota-build/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::{

use dashmap::DashMap;
use faststr::FastStr;
use fxhash::FxHashMap;
use itertools::Itertools;
use normpath::PathExt;
use pilota::AHashMap;
use pkg_tree::PkgNode;
use quote::quote;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
Expand Down Expand Up @@ -136,7 +136,7 @@ where
&self,
stream: &mut String,
item: CodegenItem,
dup: &mut FxHashMap<FastStr, Vec<DefId>>,
dup: &mut AHashMap<FastStr, Vec<DefId>>,
) {
CUR_ITEM.set(&item.def_id, || match item.kind {
CodegenKind::Direct => {
Expand Down Expand Up @@ -191,7 +191,7 @@ where
})
}

fn duplicate(&self, dup: &mut FxHashMap<FastStr, Vec<DefId>>, def_id: DefId) -> bool {
fn duplicate(&self, dup: &mut AHashMap<FastStr, Vec<DefId>>, def_id: DefId) -> bool {
let name = self.rust_name(def_id);
if !self.dedups.contains(&name.0) {
return false;
Expand Down Expand Up @@ -483,7 +483,7 @@ where
let span = tracing::span!(tracing::Level::TRACE, "write_mod", path = ?p);

let _enter = span.enter();
let mut dup = FxHashMap::default();
let mut dup = AHashMap::default();
for def_id in def_ids.iter() {
this.write_item(&mut stream, *def_id, &mut dup)
}
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/codegen/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::{borrow::Cow, path::PathBuf, process::Command, sync::Arc};

use anyhow::bail;
use faststr::FastStr;
use fxhash::FxHashMap;
use itertools::Itertools;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use rustc_hash::FxHashMap;

use super::CodegenItem;
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt, path::PathBuf, sync::Arc};

use fxhash::{FxHashMap, FxHashSet};
use rustc_hash::{FxHashMap, FxHashSet};

use crate::{
middle::{
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/dedup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use fxhash::FxHashMap;
use rustc_hash::FxHashMap;

use crate::{
rir::{Arg, EnumVariant, Field, Item, Method, Node},
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/middle/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::{collections::HashMap, ops::Deref, path::PathBuf, sync::Arc};
use anyhow::Context as _;
use dashmap::DashMap;
use faststr::FastStr;
use fxhash::{FxHashMap, FxHashSet};
use heck::ToShoutySnakeCase;
use itertools::Itertools;
use normpath::PathExt;
use quote::format_ident;
use rustc_hash::{FxHashMap, FxHashSet};
use salsa::ParallelDatabase;

use self::tls::with_cur_item;
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/middle/type_graph.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use fxhash::FxHashMap;
use petgraph::{algo::has_path_connecting, graph::NodeIndex, Graph};
use rustc_hash::FxHashMap;

use super::{
rir::Item,
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/middle/workspace_graph.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use fxhash::FxHashMap;
use petgraph::{graph::NodeIndex, Graph};
use rustc_hash::FxHashMap;

use super::{
rir::Item,
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{ir::File, symbol::FileId};
pub(crate) mod protobuf;
pub(crate) mod thrift;

use fxhash::FxHashMap;
use rustc_hash::FxHashMap;
pub use thrift::ThriftParser;

pub use self::protobuf::ProtobufParser;
Expand Down
9 changes: 5 additions & 4 deletions pilota-build/src/parser/protobuf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::{collections::HashMap, path::PathBuf, sync::Arc};

use faststr::FastStr;
use fxhash::{FxHashMap, FxHashSet};
use itertools::Itertools;
use normpath::PathExt;
use pilota::AHashMap;
use protobuf::descriptor::{
field_descriptor_proto::{Label, Type},
DescriptorProto, EnumDescriptorProto, ServiceDescriptorProto,
};
use rustc_hash::{FxHashMap, FxHashSet};

use super::Parser;
use crate::{
Expand Down Expand Up @@ -62,7 +63,7 @@ impl Lower {
&self,
type_: Option<protobuf::EnumOrUnknown<protobuf::descriptor::field_descriptor_proto::Type>>,
type_name: Option<&str>,
nested_messages: &FxHashMap<String, &DescriptorProto>,
nested_messages: &AHashMap<FastStr, &DescriptorProto>,
message_name: Option<&str>,
) -> ir::Ty {
if let Some(name) = type_name {
Expand Down Expand Up @@ -193,8 +194,8 @@ impl Lower {
let nested_messages = message
.nested_type
.iter()
.map(|m| (format!("{}.{}", fq_message_name, m.name()), m))
.collect::<FxHashMap<_, _>>();
.map(|m| (format!("{}.{}", fq_message_name, m.name()).into(), m))
.collect::<AHashMap<FastStr, _>>();

let mut fields = Vec::default();
let mut oneof_fields = FxHashMap::default();
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/parser/thrift/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{path::PathBuf, str::FromStr, sync::Arc};

use faststr::FastStr;
use fxhash::FxHashMap;
use heck::ToUpperCamelCase;
use itertools::Itertools;
use normpath::PathExt;
use pilota_thrift_parser as thrift_parser;
use pilota_thrift_parser::parser::Parser as _;
use rustc_hash::FxHashMap;
use salsa::ParallelDatabase;
use thrift_parser::Annotations;

Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/plugin/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{collections::HashSet, ops::DerefMut, sync::Arc};

use faststr::FastStr;
use fxhash::FxHashMap;
use itertools::Itertools;
use quote::quote;
use rustc_hash::FxHashMap;

use crate::{
db::RirDatabase,
Expand Down
9 changes: 5 additions & 4 deletions pilota-build/src/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::{ptr::NonNull, sync::Arc};

use fxhash::{FxHashMap, FxHashSet};
use itertools::Itertools;
use pilota::AHashMap;
use rustc_hash::{FxHashMap, FxHashSet};

use crate::{
errors,
Expand Down Expand Up @@ -178,9 +179,9 @@ impl ir::visit::Visitor for CollectDef<'_> {

#[derive(Default, Debug)]
pub struct SymbolTable {
pub(crate) value: FxHashMap<Symbol, DefId>,
pub(crate) ty: FxHashMap<Symbol, DefId>,
pub(crate) mods: FxHashMap<Symbol, DefId>,
pub(crate) value: AHashMap<Symbol, DefId>,
pub(crate) ty: AHashMap<Symbol, DefId>,
pub(crate) mods: AHashMap<Symbol, DefId>,
}

pub struct Resolver {
Expand Down
2 changes: 1 addition & 1 deletion pilota-thrift-parser/src/parser/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use nom::{
IResult,
};

use super::super::{
use crate::{
descriptor::{Annotation, Annotations, Literal},
parser::*,
};
Expand Down

0 comments on commit 2ecdfda

Please sign in to comment.