diff --git a/cranelift/codegen/Cargo.toml b/cranelift/codegen/Cargo.toml index eb6a1094c8..e38f06d608 100644 --- a/cranelift/codegen/Cargo.toml +++ b/cranelift/codegen/Cargo.toml @@ -18,7 +18,7 @@ cranelift-entity = { path = "../cranelift-entity", version = "0.44.0", default-f cranelift-bforest = { path = "../cranelift-bforest", version = "0.44.0", default-features = false } failure = { version = "0.1.1", default-features = false, features = ["derive"] } failure_derive = { version = "0.1.1", default-features = false } -hashmap_core = { version = "0.1.9", optional = true } +hashbrown = { version = "0.6", optional = true } target-lexicon = "0.8.1" log = { version = "0.4.6", default-features = false } serde = { version = "1.0.94", features = ["derive"], optional = true } @@ -43,10 +43,10 @@ std = [ "cranelift-codegen-meta/std" ] -# The "core" features enables use of "hashmap_core" since core doesn't have +# The "core" features enables use of "hashbrown" since core doesn't have # a HashMap implementation, and a workaround for Cargo #4866. core = [ - "hashmap_core", + "hashbrown", "cranelift-codegen-meta/core" ] diff --git a/cranelift/codegen/src/binemit/memorysink.rs b/cranelift/codegen/src/binemit/memorysink.rs index ffb8b44b49..ac3e82bea2 100644 --- a/cranelift/codegen/src/binemit/memorysink.rs +++ b/cranelift/codegen/src/binemit/memorysink.rs @@ -99,7 +99,7 @@ impl<'a> MemoryCodeSink<'a> { unsafe { #[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))] write_unaligned(self.data.offset(self.offset) as *mut T, x); - self.offset += std::mem::size_of::() as isize; + self.offset += core::mem::size_of::() as isize; } } } diff --git a/cranelift/codegen/src/binemit/stackmap.rs b/cranelift/codegen/src/binemit/stackmap.rs index 4051b47e19..5d6844dcf3 100644 --- a/cranelift/codegen/src/binemit/stackmap.rs +++ b/cranelift/codegen/src/binemit/stackmap.rs @@ -4,7 +4,7 @@ use crate::isa::TargetIsa; use std::vec::Vec; type Num = u32; -const NUM_BITS: usize = std::mem::size_of::() * 8; +const NUM_BITS: usize = core::mem::size_of::() * 8; /// Wrapper class for longer bit vectors that cannot be represented by a single BitSet. #[derive(Clone, Debug)] @@ -20,7 +20,7 @@ impl Stackmap { isa: &dyn TargetIsa, ) -> Self { let loc = &func.locations; - let mut live_ref_in_stack_slot = std::collections::HashSet::new(); + let mut live_ref_in_stack_slot = crate::HashSet::new(); // References can be in registers, and live registers values are pushed onto the stack before calls and traps. // TODO: Implement register maps. If a register containing a reference is spilled and reused after a safepoint, // it could contain a stale reference value if the garbage collector relocated the value. diff --git a/cranelift/codegen/src/divconst_magic_numbers.rs b/cranelift/codegen/src/divconst_magic_numbers.rs index b155496ab9..7b302e9b1a 100644 --- a/cranelift/codegen/src/divconst_magic_numbers.rs +++ b/cranelift/codegen/src/divconst_magic_numbers.rs @@ -1078,8 +1078,6 @@ mod tests { d -= 1; } } - assert_eq!(n_tests_done, 50_148_000); } - } diff --git a/cranelift/codegen/src/ir/constant.rs b/cranelift/codegen/src/ir/constant.rs index c22380db55..9f21209c4c 100644 --- a/cranelift/codegen/src/ir/constant.rs +++ b/cranelift/codegen/src/ir/constant.rs @@ -9,8 +9,9 @@ //! - bucketing constants by size. use crate::ir::Constant; +use crate::HashMap; use cranelift_entity::EntityRef; -use std::collections::{BTreeMap, HashMap}; +use std::collections::BTreeMap; use std::vec::Vec; /// This type describes the actual constant data. diff --git a/cranelift/codegen/src/ir/dfg.rs b/cranelift/codegen/src/ir/dfg.rs index 5b3054b59d..e4ec9c6be8 100644 --- a/cranelift/codegen/src/ir/dfg.rs +++ b/cranelift/codegen/src/ir/dfg.rs @@ -13,12 +13,12 @@ use crate::ir::{ use crate::isa::TargetIsa; use crate::packed_option::ReservedValue; use crate::write::write_operands; +use crate::HashMap; use core::fmt; use core::iter; use core::mem; use core::ops::{Index, IndexMut}; use core::u16; -use std::collections::HashMap; use std::vec::Vec; /// A data flow graph defines all instructions and extended basic blocks in a function as well as diff --git a/cranelift/codegen/src/lib.rs b/cranelift/codegen/src/lib.rs index 73f2114561..0e61171d14 100644 --- a/cranelift/codegen/src/lib.rs +++ b/cranelift/codegen/src/lib.rs @@ -50,7 +50,7 @@ extern crate alloc as std; extern crate std; #[cfg(not(feature = "std"))] -use hashmap_core::{map as hash_map, HashMap, HashSet}; +use hashbrown::{hash_map, HashMap, HashSet}; #[cfg(feature = "std")] use std::collections::{hash_map, HashMap, HashSet}; diff --git a/cranelift/codegen/src/scoped_hash_map.rs b/cranelift/codegen/src/scoped_hash_map.rs index fe22e26ce3..809d22132a 100644 --- a/cranelift/codegen/src/scoped_hash_map.rs +++ b/cranelift/codegen/src/scoped_hash_map.rs @@ -8,6 +8,11 @@ use crate::fx::FxHashMap; use core::hash::Hash; use core::mem; +#[cfg(not(feature = "std"))] +use crate::fx::FxHasher; +#[cfg(not(feature = "std"))] +type Hasher = core::hash::BuildHasherDefault; + struct Val { value: V, next_key: Option, @@ -16,7 +21,10 @@ struct Val { /// A view into an occupied entry in a `ScopedHashMap`. It is part of the `Entry` enum. pub struct OccupiedEntry<'a, K: 'a, V: 'a> { + #[cfg(feature = "std")] entry: super::hash_map::OccupiedEntry<'a, K, Val>, + #[cfg(not(feature = "std"))] + entry: super::hash_map::OccupiedEntry<'a, K, Val, Hasher>, } impl<'a, K, V> OccupiedEntry<'a, K, V> { @@ -28,12 +36,15 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { /// A view into a vacant entry in a `ScopedHashMap`. It is part of the `Entry` enum. pub struct VacantEntry<'a, K: 'a, V: 'a> { + #[cfg(feature = "std")] entry: super::hash_map::VacantEntry<'a, K, Val>, + #[cfg(not(feature = "std"))] + entry: super::hash_map::VacantEntry<'a, K, Val, Hasher>, next_key: Option, depth: usize, } -impl<'a, K, V> VacantEntry<'a, K, V> { +impl<'a, K: Hash, V> VacantEntry<'a, K, V> { /// Sets the value of the entry with the `VacantEntry`'s key. pub fn insert(self, value: V) { self.entry.insert(Val { diff --git a/cranelift/codegen/src/value_label.rs b/cranelift/codegen/src/value_label.rs index d3d1e0672c..b6ad71faf8 100644 --- a/cranelift/codegen/src/value_label.rs +++ b/cranelift/codegen/src/value_label.rs @@ -1,11 +1,12 @@ use crate::ir::{Function, SourceLoc, Value, ValueLabel, ValueLabelAssignments, ValueLoc}; use crate::isa::TargetIsa; use crate::regalloc::{Context, RegDiversions}; -use std::cmp::Ordering; -use std::collections::{BTreeMap, HashMap}; -use std::iter::Iterator; -use std::ops::Bound::*; -use std::ops::Deref; +use crate::HashMap; +use core::cmp::Ordering; +use core::iter::Iterator; +use core::ops::Bound::*; +use core::ops::Deref; +use std::collections::BTreeMap; use std::vec::Vec; #[cfg(feature = "enable-serde")] diff --git a/cranelift/codegen/src/write.rs b/cranelift/codegen/src/write.rs index 8d974c1ec5..8f5f81d23e 100644 --- a/cranelift/codegen/src/write.rs +++ b/cranelift/codegen/src/write.rs @@ -13,8 +13,8 @@ use crate::ir::{ use crate::isa::{RegInfo, TargetIsa}; use crate::packed_option::ReservedValue; use crate::value_label::ValueLabelsRanges; +use crate::HashSet; use core::fmt::{self, Write}; -use std::collections::HashSet; use std::string::String; use std::vec::Vec; diff --git a/cranelift/entity/src/map.rs b/cranelift/entity/src/map.rs index 77fe38ce92..884f812fb2 100644 --- a/cranelift/entity/src/map.rs +++ b/cranelift/entity/src/map.rs @@ -3,6 +3,7 @@ use crate::iter::{Iter, IterMut}; use crate::keys::Keys; use crate::EntityRef; +use core::cmp::min; use core::marker::PhantomData; use core::ops::{Index, IndexMut}; use core::slice; @@ -12,7 +13,6 @@ use serde::{ ser::{SerializeSeq, Serializer}, Deserialize, Serialize, }; -use std::cmp::min; use std::vec::Vec; /// A mapping `K -> V` for densely indexed entity references. diff --git a/cranelift/frontend/Cargo.toml b/cranelift/frontend/Cargo.toml index e30bde657e..0f8aefe91d 100644 --- a/cranelift/frontend/Cargo.toml +++ b/cranelift/frontend/Cargo.toml @@ -14,13 +14,13 @@ edition = "2018" cranelift-codegen = { path = "../cranelift-codegen", version = "0.44.0", default-features = false } target-lexicon = "0.8.1" log = { version = "0.4.6", default-features = false } -hashmap_core = { version = "0.1.9", optional = true } +hashbrown = { version = "0.6", optional = true } smallvec = { version = "0.6.10" } [features] default = ["std"] std = ["cranelift-codegen/std"] -core = ["hashmap_core", "cranelift-codegen/core"] +core = ["hashbrown", "cranelift-codegen/core"] # Temporary feature that enforces basic block semantics. basic-blocks = ["cranelift-codegen/basic-blocks"] diff --git a/cranelift/frontend/src/frontend.rs b/cranelift/frontend/src/frontend.rs index fbd2428e1c..6204071618 100644 --- a/cranelift/frontend/src/frontend.rs +++ b/cranelift/frontend/src/frontend.rs @@ -341,7 +341,7 @@ impl<'a> FunctionBuilder<'a> { /// This will not do anything unless `func.dfg.collect_debug_info` is called first. pub fn set_val_label(&mut self, val: Value, label: ValueLabel) { if let Some(values_labels) = self.func.dfg.values_labels.as_mut() { - use std::collections::hash_map::Entry; + use crate::hash_map::Entry; let start = ValueLabelStart { from: self.srcloc, diff --git a/cranelift/frontend/src/lib.rs b/cranelift/frontend/src/lib.rs index eff5c655fd..5e53944901 100644 --- a/cranelift/frontend/src/lib.rs +++ b/cranelift/frontend/src/lib.rs @@ -191,9 +191,9 @@ extern crate alloc as std; extern crate std; #[cfg(not(feature = "std"))] -use hashmap_core::HashMap; +use hashbrown::{hash_map, HashMap}; #[cfg(feature = "std")] -use std::collections::HashMap; +use std::collections::{hash_map, HashMap}; pub use crate::frontend::{FunctionBuilder, FunctionBuilderContext}; pub use crate::switch::Switch; diff --git a/cranelift/module/Cargo.toml b/cranelift/module/Cargo.toml index 890c1a5778..2ce44cc32c 100644 --- a/cranelift/module/Cargo.toml +++ b/cranelift/module/Cargo.toml @@ -13,14 +13,14 @@ edition = "2018" [dependencies] cranelift-codegen = { path = "../cranelift-codegen", version = "0.44.0", default-features = false } cranelift-entity = { path = "../cranelift-entity", version = "0.44.0", default-features = false } -hashmap_core = { version = "0.1.9", optional = true } +hashbrown = { version = "0.6", optional = true } failure = { version = "0.1.1", default-features = false } log = { version = "0.4.6", default-features = false } [features] default = ["std"] std = ["cranelift-codegen/std", "cranelift-entity/std"] -core = ["hashmap_core", "cranelift-codegen/core"] +core = ["hashbrown", "cranelift-codegen/core"] [badges] maintenance = { status = "experimental" } diff --git a/cranelift/module/src/lib.rs b/cranelift/module/src/lib.rs index 7cb9c10f22..0122171e9a 100644 --- a/cranelift/module/src/lib.rs +++ b/cranelift/module/src/lib.rs @@ -28,7 +28,7 @@ extern crate alloc as std; extern crate std; #[cfg(not(feature = "std"))] -use hashmap_core::{map as hash_map, HashMap}; +use hashbrown::{hash_map, HashMap}; #[cfg(feature = "std")] use std::collections::{hash_map, HashMap}; diff --git a/cranelift/wasm/Cargo.toml b/cranelift/wasm/Cargo.toml index fd7f51608d..5e2a9e1cbe 100644 --- a/cranelift/wasm/Cargo.toml +++ b/cranelift/wasm/Cargo.toml @@ -15,7 +15,7 @@ wasmparser = { version = "0.39.1", default-features = false } cranelift-codegen = { path = "../cranelift-codegen", version = "0.44.0", default-features = false } cranelift-entity = { path = "../cranelift-entity", version = "0.44.0", default-features = false } cranelift-frontend = { path = "../cranelift-frontend", version = "0.44.0", default-features = false } -hashmap_core = { version = "0.1.9", optional = true } +hashbrown = { version = "0.6", optional = true } failure = { version = "0.1.1", default-features = false, features = ["derive"] } failure_derive = { version = "0.1.1", default-features = false } log = { version = "0.4.6", default-features = false } @@ -28,7 +28,7 @@ target-lexicon = "0.8.1" [features] default = ["std"] std = ["cranelift-codegen/std", "cranelift-frontend/std", "wasmparser/std"] -core = ["hashmap_core", "cranelift-codegen/core", "cranelift-frontend/core", "wasmparser/core"] +core = ["hashbrown", "cranelift-codegen/core", "cranelift-frontend/core", "wasmparser/core"] enable-serde = ["serde"] # Temporary feature that enforces basic block semantics. diff --git a/cranelift/wasm/src/lib.rs b/cranelift/wasm/src/lib.rs index d47feb631d..297c9df5f0 100644 --- a/cranelift/wasm/src/lib.rs +++ b/cranelift/wasm/src/lib.rs @@ -37,9 +37,10 @@ extern crate alloc as std; extern crate std; #[cfg(not(feature = "std"))] -use hashmap_core::{ +use hashbrown::{ + hash_map, hash_map::Entry::{Occupied, Vacant}, - map as hash_map, HashMap, + HashMap, }; #[cfg(feature = "std")] use std::collections::{