From bc3d00e879396cea7171d24b44e64bf197e8a2ca Mon Sep 17 00:00:00 2001 From: fanninpm <27117322+fanninpm@users.noreply.github.com> Date: Mon, 25 May 2026 00:53:54 -0400 Subject: [PATCH] Replace `ahash` with `rapidhash` (#7954) * Add `rapidhash` to list of dependencies * Use `rapidhash::quality::RandomState` in `codegen` crate * Use `rapidhash::quality::RandomState` in `stdlib` crate * Use `rapidhash::quality::RandomState` in `vm` crate * Remove `ahash` from lists of dependencies --- .github/dependabot.yml | 1 - Cargo.lock | 28 ++++++++++++---------------- Cargo.toml | 2 +- crates/codegen/Cargo.toml | 2 +- crates/codegen/src/lib.rs | 4 ++-- crates/stdlib/Cargo.toml | 2 +- crates/stdlib/src/contextvars.rs | 2 +- crates/vm/Cargo.toml | 2 +- crates/vm/src/builtins/type.rs | 3 ++- crates/vm/src/intern.rs | 2 +- crates/vm/src/vm/interpreter.rs | 7 +++++-- crates/vm/src/vm/mod.rs | 2 +- 12 files changed, 28 insertions(+), 29 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e3f9ba3b7..7533ce368 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -85,7 +85,6 @@ updates: - "quote-use*" random: patterns: - - "ahash" - "getrandom" - "mt19937" - "rand*" diff --git a/Cargo.lock b/Cargo.lock index eab7707b5..0d191fc99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,19 +25,6 @@ dependencies = [ "cpufeatures", ] -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "getrandom 0.3.4", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.4" @@ -2928,6 +2915,15 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "rapidhash" +version = "4.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e48930979c155e2f33aa36ab3119b5ee81332beb6482199a8ecd6029b80b59" +dependencies = [ + "rustversion", +] + [[package]] name = "rayon" version = "1.12.0" @@ -3241,7 +3237,6 @@ dependencies = [ name = "rustpython-codegen" version = "0.5.0" dependencies = [ - "ahash", "bitflags 2.11.1", "indexmap", "itertools 0.14.0", @@ -3250,6 +3245,7 @@ dependencies = [ "memchr", "num-complex", "num-traits", + "rapidhash", "rustpython-compiler-core", "rustpython-literal", "rustpython-ruff_python_ast", @@ -3498,7 +3494,6 @@ name = "rustpython-stdlib" version = "0.5.0" dependencies = [ "adler32", - "ahash", "ascii", "aws-lc-rs", "base64", @@ -3549,6 +3544,7 @@ dependencies = [ "pkcs8", "pymath", "rand_core 0.9.5", + "rapidhash", "rustls", "rustls-native-certs", "rustls-pemfile", @@ -3588,7 +3584,6 @@ version = "0.5.0" name = "rustpython-vm" version = "0.5.0" dependencies = [ - "ahash", "ascii", "bitflags 2.11.1", "bstr", @@ -3619,6 +3614,7 @@ dependencies = [ "parking_lot", "paste", "psm", + "rapidhash", "result-like", "rustpython-codegen", "rustpython-common", diff --git a/Cargo.toml b/Cargo.toml index 567e68a91..9fbdd9d71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -176,7 +176,6 @@ ruff_source_file = { package = "rustpython-ruff_source_file", version = "0.15.8" der = { version = "0.8", features = ["alloc", "oid", "pem", "zeroize"] } phf = { version = "0.13.1", default-features = false, features = ["macros"]} adler32 = "1.2.0" -ahash = "0.8.12" approx = "0.5.1" ascii = "1.1" aws-lc-rs = "1.16.3" @@ -260,6 +259,7 @@ quote = "1.0.45" radium = "1.1.1" rand = "0.9" rand_core = { version = "0.9", features = ["os_rng"] } +rapidhash = "4.4.1" result-like = "0.5.0" rustix = { version = "1.1", features = ["event", "param", "system"] } rustls = { version = "0.23.39", default-features = false } diff --git a/crates/codegen/Cargo.toml b/crates/codegen/Cargo.toml index 4f32fcc3c..031f3b965 100644 --- a/crates/codegen/Cargo.toml +++ b/crates/codegen/Cargo.toml @@ -19,7 +19,6 @@ rustpython-wtf8 = { workspace = true } ruff_python_ast = { workspace = true } ruff_text_size = { workspace = true } -ahash = { workspace = true } bitflags = { workspace = true } indexmap = { workspace = true } itertools = { workspace = true } @@ -29,6 +28,7 @@ num-traits = { workspace = true } thiserror = { workspace = true } malachite-bigint = { workspace = true } memchr = { workspace = true } +rapidhash = { workspace = true } unicode_names2 = { workspace = true } [dev-dependencies] diff --git a/crates/codegen/src/lib.rs b/crates/codegen/src/lib.rs index 8d6ad9843..b598ab7e9 100644 --- a/crates/codegen/src/lib.rs +++ b/crates/codegen/src/lib.rs @@ -8,8 +8,8 @@ extern crate log; extern crate alloc; -type IndexMap = indexmap::IndexMap; -type IndexSet = indexmap::IndexSet; +type IndexMap = indexmap::IndexMap; +type IndexSet = indexmap::IndexSet; pub mod compile; pub mod error; diff --git a/crates/stdlib/Cargo.toml b/crates/stdlib/Cargo.toml index f77d467d6..88afc2432 100644 --- a/crates/stdlib/Cargo.toml +++ b/crates/stdlib/Cargo.toml @@ -37,7 +37,6 @@ ruff_python_ast = { workspace = true } ruff_text_size = { workspace = true } ruff_source_file = { workspace = true } -ahash = { workspace = true } ascii = { workspace = true } crossbeam-utils = { workspace = true } flame = { workspace = true, optional = true } @@ -51,6 +50,7 @@ num-traits = { workspace = true } num_enum = { workspace = true } parking_lot = { workspace = true } phf = { workspace = true, default-features = true, features = ["macros"] } +rapidhash = { workspace = true } memchr = { workspace = true } base64 = { workspace = true } diff --git a/crates/stdlib/src/contextvars.rs b/crates/stdlib/src/contextvars.rs index ee5942755..0a6e0f123 100644 --- a/crates/stdlib/src/contextvars.rs +++ b/crates/stdlib/src/contextvars.rs @@ -28,7 +28,7 @@ mod _contextvars { use indexmap::IndexMap; // TODO: Real hamt implementation - type Hamt = IndexMap, PyObjectRef, ahash::RandomState>; + type Hamt = IndexMap, PyObjectRef, rapidhash::quality::RandomState>; #[pyclass(no_attr, name = "Hamt", module = "contextvars")] #[derive(Debug, PyPayload)] diff --git a/crates/vm/Cargo.toml b/crates/vm/Cargo.toml index 8ff078b81..83e41fa1f 100644 --- a/crates/vm/Cargo.toml +++ b/crates/vm/Cargo.toml @@ -44,7 +44,6 @@ rustpython-literal = { workspace = true } rustpython-sre_engine = { workspace = true } ascii = { workspace = true } -ahash = { workspace = true } bitflags = { workspace = true } bstr = { workspace = true } crossbeam-utils = { workspace = true } @@ -64,6 +63,7 @@ num-traits = { workspace = true } num_enum = { workspace = true } parking_lot = { workspace = true } paste = { workspace = true } +rapidhash = { workspace = true } scopeguard = { workspace = true } serde = { workspace = true, optional = true } static_assertions = { workspace = true } diff --git a/crates/vm/src/builtins/type.rs b/crates/vm/src/builtins/type.rs index 8b920c2fe..fa673d420 100644 --- a/crates/vm/src/builtins/type.rs +++ b/crates/vm/src/builtins/type.rs @@ -408,7 +408,8 @@ cfg_select! { /// For attributes we do not use a dict, but an IndexMap, which is an Hash Table /// that maintains order and is compatible with the standard HashMap This is probably /// faster and only supports strings as keys. -pub(crate) type PyAttributes = IndexMap<&'static PyStrInterned, PyObjectRef, ahash::RandomState>; +pub(crate) type PyAttributes = + IndexMap<&'static PyStrInterned, PyObjectRef, rapidhash::quality::RandomState>; unsafe impl Traverse for PyAttributes { fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { diff --git a/crates/vm/src/intern.rs b/crates/vm/src/intern.rs index da1d63f87..981732f2d 100644 --- a/crates/vm/src/intern.rs +++ b/crates/vm/src/intern.rs @@ -11,7 +11,7 @@ use core::{borrow::Borrow, ops::Deref}; #[derive(Debug)] pub(crate) struct StringPool { - inner: PyRwLock>, + inner: PyRwLock>, } impl Default for StringPool { diff --git a/crates/vm/src/vm/interpreter.rs b/crates/vm/src/vm/interpreter.rs index 505986aca..bb0b80bb6 100644 --- a/crates/vm/src/vm/interpreter.rs +++ b/crates/vm/src/vm/interpreter.rs @@ -95,8 +95,11 @@ where } as usize); // Initialize frozen modules (core + user-provided) - let mut frozen: std::collections::HashMap<&'static str, FrozenModule, ahash::RandomState> = - core_frozen_inits().collect(); + let mut frozen: std::collections::HashMap< + &'static str, + FrozenModule, + rapidhash::quality::RandomState, + > = core_frozen_inits().collect(); frozen.extend(frozen_modules); // Create PyGlobalState diff --git a/crates/vm/src/vm/mod.rs b/crates/vm/src/vm/mod.rs index a99012cd1..ca89e9185 100644 --- a/crates/vm/src/vm/mod.rs +++ b/crates/vm/src/vm/mod.rs @@ -589,7 +589,7 @@ pub(crate) struct CallableCache { pub struct PyGlobalState { pub config: PyConfig, pub module_defs: BTreeMap<&'static str, &'static builtins::PyModuleDef>, - pub frozen: HashMap<&'static str, FrozenModule, ahash::RandomState>, + pub frozen: HashMap<&'static str, FrozenModule, rapidhash::quality::RandomState>, pub stacksize: AtomicCell, pub thread_count: AtomicCell, pub hash_secret: HashSecret,