From 8e45a5aad13cf8e49959da2762af113d588af3b1 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Tue, 13 Aug 2024 12:41:26 -0400 Subject: [PATCH] Use hashbrown::HashSet instead of ahash::HashSet (#12951) In the `target_transpiler/mod.rs` module we were using ahash::HashSet for a hash set implementation, but the rest of Qiskit has standardized on using hashbrown for the `HashSet` and `HashMap` types. Hashbrown uses ahash for it's hashing algorithm but it also provides other advantages. To ensure that hash sets are compatible across the library we should be using the same library for everything. To support this goal, this commit also adds a clippy rule that raises a warning if the std library hashmap or hashset is used, or the versions from ahash. This means with our current dependency set the only allowed hashset types are `hashbrown::HashMap`/`HashSet` and `indexmap::IndexMap`/`IndexSet` (for where we need to maintain insertion order). Ideally we'd have a rule that forces the use of ahash with `IndexMap` and `IndexSet` (see #12935) but I don't think clippy exposes an option to enable something like that. --- .clippy.toml | 6 ++++++ crates/accelerate/src/target_transpiler/mod.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .clippy.toml diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 00000000000..3487b230a9c --- /dev/null +++ b/.clippy.toml @@ -0,0 +1,6 @@ +disallowed-types = [ + "std::collections::HashSet", + "std::collections::HashMap", + "ahash::HashSet", + "ahash::HashMap", +] diff --git a/crates/accelerate/src/target_transpiler/mod.rs b/crates/accelerate/src/target_transpiler/mod.rs index 0954e8e347f..6d6e105b265 100644 --- a/crates/accelerate/src/target_transpiler/mod.rs +++ b/crates/accelerate/src/target_transpiler/mod.rs @@ -20,7 +20,7 @@ use std::ops::Index; use ahash::RandomState; -use ahash::HashSet; +use hashbrown::HashSet; use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; use nullable_index_map::NullableIndexMap;