Allow building without std (#1069)
Closes https://github.com/CraneStation/cranelift/issues/1067
This commit is contained in:
committed by
Benjamin Bouvier
parent
40f6d3b753
commit
a1f6457e8a
@@ -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 }
|
cranelift-bforest = { path = "../cranelift-bforest", version = "0.44.0", default-features = false }
|
||||||
failure = { version = "0.1.1", default-features = false, features = ["derive"] }
|
failure = { version = "0.1.1", default-features = false, features = ["derive"] }
|
||||||
failure_derive = { version = "0.1.1", default-features = false }
|
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"
|
target-lexicon = "0.8.1"
|
||||||
log = { version = "0.4.6", default-features = false }
|
log = { version = "0.4.6", default-features = false }
|
||||||
serde = { version = "1.0.94", features = ["derive"], optional = true }
|
serde = { version = "1.0.94", features = ["derive"], optional = true }
|
||||||
@@ -43,10 +43,10 @@ std = [
|
|||||||
"cranelift-codegen-meta/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.
|
# a HashMap implementation, and a workaround for Cargo #4866.
|
||||||
core = [
|
core = [
|
||||||
"hashmap_core",
|
"hashbrown",
|
||||||
"cranelift-codegen-meta/core"
|
"cranelift-codegen-meta/core"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ impl<'a> MemoryCodeSink<'a> {
|
|||||||
unsafe {
|
unsafe {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))]
|
#[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))]
|
||||||
write_unaligned(self.data.offset(self.offset) as *mut T, x);
|
write_unaligned(self.data.offset(self.offset) as *mut T, x);
|
||||||
self.offset += std::mem::size_of::<T>() as isize;
|
self.offset += core::mem::size_of::<T>() as isize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::isa::TargetIsa;
|
|||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
type Num = u32;
|
type Num = u32;
|
||||||
const NUM_BITS: usize = std::mem::size_of::<Num>() * 8;
|
const NUM_BITS: usize = core::mem::size_of::<Num>() * 8;
|
||||||
|
|
||||||
/// Wrapper class for longer bit vectors that cannot be represented by a single BitSet.
|
/// Wrapper class for longer bit vectors that cannot be represented by a single BitSet.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -20,7 +20,7 @@ impl Stackmap {
|
|||||||
isa: &dyn TargetIsa,
|
isa: &dyn TargetIsa,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let loc = &func.locations;
|
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.
|
// 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,
|
// 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.
|
// it could contain a stale reference value if the garbage collector relocated the value.
|
||||||
|
|||||||
@@ -1078,8 +1078,6 @@ mod tests {
|
|||||||
d -= 1;
|
d -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(n_tests_done, 50_148_000);
|
assert_eq!(n_tests_done, 50_148_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,9 @@
|
|||||||
//! - bucketing constants by size.
|
//! - bucketing constants by size.
|
||||||
|
|
||||||
use crate::ir::Constant;
|
use crate::ir::Constant;
|
||||||
|
use crate::HashMap;
|
||||||
use cranelift_entity::EntityRef;
|
use cranelift_entity::EntityRef;
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::BTreeMap;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
/// This type describes the actual constant data.
|
/// This type describes the actual constant data.
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ use crate::ir::{
|
|||||||
use crate::isa::TargetIsa;
|
use crate::isa::TargetIsa;
|
||||||
use crate::packed_option::ReservedValue;
|
use crate::packed_option::ReservedValue;
|
||||||
use crate::write::write_operands;
|
use crate::write::write_operands;
|
||||||
|
use crate::HashMap;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::iter;
|
use core::iter;
|
||||||
use core::mem;
|
use core::mem;
|
||||||
use core::ops::{Index, IndexMut};
|
use core::ops::{Index, IndexMut};
|
||||||
use core::u16;
|
use core::u16;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
/// A data flow graph defines all instructions and extended basic blocks in a function as well as
|
/// A data flow graph defines all instructions and extended basic blocks in a function as well as
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ extern crate alloc as std;
|
|||||||
extern crate std;
|
extern crate std;
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use hashmap_core::{map as hash_map, HashMap, HashSet};
|
use hashbrown::{hash_map, HashMap, HashSet};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::collections::{hash_map, HashMap, HashSet};
|
use std::collections::{hash_map, HashMap, HashSet};
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ use crate::fx::FxHashMap;
|
|||||||
use core::hash::Hash;
|
use core::hash::Hash;
|
||||||
use core::mem;
|
use core::mem;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use crate::fx::FxHasher;
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
type Hasher = core::hash::BuildHasherDefault<FxHasher>;
|
||||||
|
|
||||||
struct Val<K, V> {
|
struct Val<K, V> {
|
||||||
value: V,
|
value: V,
|
||||||
next_key: Option<K>,
|
next_key: Option<K>,
|
||||||
@@ -16,7 +21,10 @@ struct Val<K, V> {
|
|||||||
|
|
||||||
/// A view into an occupied entry in a `ScopedHashMap`. It is part of the `Entry` enum.
|
/// A view into an occupied entry in a `ScopedHashMap`. It is part of the `Entry` enum.
|
||||||
pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
|
pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
|
||||||
|
#[cfg(feature = "std")]
|
||||||
entry: super::hash_map::OccupiedEntry<'a, K, Val<K, V>>,
|
entry: super::hash_map::OccupiedEntry<'a, K, Val<K, V>>,
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
entry: super::hash_map::OccupiedEntry<'a, K, Val<K, V>, Hasher>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, K, V> OccupiedEntry<'a, K, V> {
|
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.
|
/// A view into a vacant entry in a `ScopedHashMap`. It is part of the `Entry` enum.
|
||||||
pub struct VacantEntry<'a, K: 'a, V: 'a> {
|
pub struct VacantEntry<'a, K: 'a, V: 'a> {
|
||||||
|
#[cfg(feature = "std")]
|
||||||
entry: super::hash_map::VacantEntry<'a, K, Val<K, V>>,
|
entry: super::hash_map::VacantEntry<'a, K, Val<K, V>>,
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
entry: super::hash_map::VacantEntry<'a, K, Val<K, V>, Hasher>,
|
||||||
next_key: Option<K>,
|
next_key: Option<K>,
|
||||||
depth: usize,
|
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.
|
/// Sets the value of the entry with the `VacantEntry`'s key.
|
||||||
pub fn insert(self, value: V) {
|
pub fn insert(self, value: V) {
|
||||||
self.entry.insert(Val {
|
self.entry.insert(Val {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
use crate::ir::{Function, SourceLoc, Value, ValueLabel, ValueLabelAssignments, ValueLoc};
|
use crate::ir::{Function, SourceLoc, Value, ValueLabel, ValueLabelAssignments, ValueLoc};
|
||||||
use crate::isa::TargetIsa;
|
use crate::isa::TargetIsa;
|
||||||
use crate::regalloc::{Context, RegDiversions};
|
use crate::regalloc::{Context, RegDiversions};
|
||||||
use std::cmp::Ordering;
|
use crate::HashMap;
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use core::cmp::Ordering;
|
||||||
use std::iter::Iterator;
|
use core::iter::Iterator;
|
||||||
use std::ops::Bound::*;
|
use core::ops::Bound::*;
|
||||||
use std::ops::Deref;
|
use core::ops::Deref;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
#[cfg(feature = "enable-serde")]
|
#[cfg(feature = "enable-serde")]
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ use crate::ir::{
|
|||||||
use crate::isa::{RegInfo, TargetIsa};
|
use crate::isa::{RegInfo, TargetIsa};
|
||||||
use crate::packed_option::ReservedValue;
|
use crate::packed_option::ReservedValue;
|
||||||
use crate::value_label::ValueLabelsRanges;
|
use crate::value_label::ValueLabelsRanges;
|
||||||
|
use crate::HashSet;
|
||||||
use core::fmt::{self, Write};
|
use core::fmt::{self, Write};
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
use crate::iter::{Iter, IterMut};
|
use crate::iter::{Iter, IterMut};
|
||||||
use crate::keys::Keys;
|
use crate::keys::Keys;
|
||||||
use crate::EntityRef;
|
use crate::EntityRef;
|
||||||
|
use core::cmp::min;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use core::ops::{Index, IndexMut};
|
use core::ops::{Index, IndexMut};
|
||||||
use core::slice;
|
use core::slice;
|
||||||
@@ -12,7 +13,6 @@ use serde::{
|
|||||||
ser::{SerializeSeq, Serializer},
|
ser::{SerializeSeq, Serializer},
|
||||||
Deserialize, Serialize,
|
Deserialize, Serialize,
|
||||||
};
|
};
|
||||||
use std::cmp::min;
|
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
/// A mapping `K -> V` for densely indexed entity references.
|
/// A mapping `K -> V` for densely indexed entity references.
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ edition = "2018"
|
|||||||
cranelift-codegen = { path = "../cranelift-codegen", version = "0.44.0", default-features = false }
|
cranelift-codegen = { path = "../cranelift-codegen", version = "0.44.0", default-features = false }
|
||||||
target-lexicon = "0.8.1"
|
target-lexicon = "0.8.1"
|
||||||
log = { version = "0.4.6", default-features = false }
|
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" }
|
smallvec = { version = "0.6.10" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = ["cranelift-codegen/std"]
|
std = ["cranelift-codegen/std"]
|
||||||
core = ["hashmap_core", "cranelift-codegen/core"]
|
core = ["hashbrown", "cranelift-codegen/core"]
|
||||||
|
|
||||||
# Temporary feature that enforces basic block semantics.
|
# Temporary feature that enforces basic block semantics.
|
||||||
basic-blocks = ["cranelift-codegen/basic-blocks"]
|
basic-blocks = ["cranelift-codegen/basic-blocks"]
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ impl<'a> FunctionBuilder<'a> {
|
|||||||
/// This will not do anything unless `func.dfg.collect_debug_info` is called first.
|
/// 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) {
|
pub fn set_val_label(&mut self, val: Value, label: ValueLabel) {
|
||||||
if let Some(values_labels) = self.func.dfg.values_labels.as_mut() {
|
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 {
|
let start = ValueLabelStart {
|
||||||
from: self.srcloc,
|
from: self.srcloc,
|
||||||
|
|||||||
@@ -191,9 +191,9 @@ extern crate alloc as std;
|
|||||||
extern crate std;
|
extern crate std;
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use hashmap_core::HashMap;
|
use hashbrown::{hash_map, HashMap};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::collections::HashMap;
|
use std::collections::{hash_map, HashMap};
|
||||||
|
|
||||||
pub use crate::frontend::{FunctionBuilder, FunctionBuilderContext};
|
pub use crate::frontend::{FunctionBuilder, FunctionBuilderContext};
|
||||||
pub use crate::switch::Switch;
|
pub use crate::switch::Switch;
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cranelift-codegen = { path = "../cranelift-codegen", version = "0.44.0", 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-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 }
|
failure = { version = "0.1.1", default-features = false }
|
||||||
log = { version = "0.4.6", default-features = false }
|
log = { version = "0.4.6", default-features = false }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = ["cranelift-codegen/std", "cranelift-entity/std"]
|
std = ["cranelift-codegen/std", "cranelift-entity/std"]
|
||||||
core = ["hashmap_core", "cranelift-codegen/core"]
|
core = ["hashbrown", "cranelift-codegen/core"]
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
maintenance = { status = "experimental" }
|
maintenance = { status = "experimental" }
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ extern crate alloc as std;
|
|||||||
extern crate std;
|
extern crate std;
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use hashmap_core::{map as hash_map, HashMap};
|
use hashbrown::{hash_map, HashMap};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::collections::{hash_map, HashMap};
|
use std::collections::{hash_map, HashMap};
|
||||||
|
|
||||||
|
|||||||
@@ -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-codegen = { path = "../cranelift-codegen", version = "0.44.0", default-features = false }
|
||||||
cranelift-entity = { path = "../cranelift-entity", 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 }
|
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 = { version = "0.1.1", default-features = false, features = ["derive"] }
|
||||||
failure_derive = { version = "0.1.1", default-features = false }
|
failure_derive = { version = "0.1.1", default-features = false }
|
||||||
log = { version = "0.4.6", default-features = false }
|
log = { version = "0.4.6", default-features = false }
|
||||||
@@ -28,7 +28,7 @@ target-lexicon = "0.8.1"
|
|||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = ["cranelift-codegen/std", "cranelift-frontend/std", "wasmparser/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"]
|
enable-serde = ["serde"]
|
||||||
|
|
||||||
# Temporary feature that enforces basic block semantics.
|
# Temporary feature that enforces basic block semantics.
|
||||||
|
|||||||
@@ -37,9 +37,10 @@ extern crate alloc as std;
|
|||||||
extern crate std;
|
extern crate std;
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use hashmap_core::{
|
use hashbrown::{
|
||||||
|
hash_map,
|
||||||
hash_map::Entry::{Occupied, Vacant},
|
hash_map::Entry::{Occupied, Vacant},
|
||||||
map as hash_map, HashMap,
|
HashMap,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::collections::{
|
use std::collections::{
|
||||||
|
|||||||
Reference in New Issue
Block a user