Skip to content

Commit

Permalink
Merge with upstream (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhil authored Aug 23, 2024
2 parents d66ad85 + 38946ad commit 1f86598
Show file tree
Hide file tree
Showing 129 changed files with 2,198 additions and 2,377 deletions.
171 changes: 122 additions & 49 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,15 @@ wit-bindgen = { git = "https://github.com/wasmfx/wit-bindgenfx", tag = "v0.30.0"
wit-bindgen-rust-macro = { git = "https://github.com/wasmfx/wit-bindgenfx", tag = "v0.30.0", default-features = false }

# wasm-tools family:
wasmparser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0", default-features = false }
wat = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
wast = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
wasmprinter = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
wasm-encoder = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
wasm-smith = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
wasm-mutate = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
wit-parser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
wit-component = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
wasmparser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.216.0", default-features = false }
wat = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.216.0" }
wast = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.216.0" }
wasmprinter = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.216.0" }
wasm-encoder = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.216.0" }
wasm-smith = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.216.0" }
wasm-mutate = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.216.0" }
wit-parser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.216.0" }
wit-component = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.216.0" }

# Non-Bytecode Alliance maintained dependencies:
# --------------------------
Expand Down
2 changes: 2 additions & 0 deletions cranelift/bitset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ rust-version.workspace = true
workspace = true

[dependencies]
arbitrary = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }

[features]
enable-serde = ["dep:serde", "dep:serde_derive"]
arbitrary = ["dep:arbitrary"]
95 changes: 73 additions & 22 deletions cranelift/bitset/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,33 @@ where
self.0 = T::from(0);
}

/// Remove and return the smallest value in the bitset.
///
/// # Example
///
/// ```
/// use cranelift_bitset::ScalarBitSet;
///
/// let mut bitset = ScalarBitSet::<u64>::new();
///
/// bitset.insert(0);
/// bitset.insert(24);
/// bitset.insert(13);
/// bitset.insert(36);
///
/// assert_eq!(bitset.pop_min(), Some(0));
/// assert_eq!(bitset.pop_min(), Some(13));
/// assert_eq!(bitset.pop_min(), Some(24));
/// assert_eq!(bitset.pop_min(), Some(36));
/// assert_eq!(bitset.pop_min(), None);
/// ```
#[inline]
pub fn pop_min(&mut self) -> Option<u8> {
let min = self.min()?;
self.remove(min);
Some(min)
}

/// Remove and return the largest value in the bitset.
///
/// # Example
Expand All @@ -364,14 +391,14 @@ where
/// bitset.insert(13);
/// bitset.insert(36);
///
/// assert_eq!(bitset.pop(), Some(36));
/// assert_eq!(bitset.pop(), Some(24));
/// assert_eq!(bitset.pop(), Some(13));
/// assert_eq!(bitset.pop(), Some(0));
/// assert_eq!(bitset.pop(), None);
/// assert_eq!(bitset.pop_max(), Some(36));
/// assert_eq!(bitset.pop_max(), Some(24));
/// assert_eq!(bitset.pop_max(), Some(13));
/// assert_eq!(bitset.pop_max(), Some(0));
/// assert_eq!(bitset.pop_max(), None);
/// ```
#[inline]
pub fn pop(&mut self) -> Option<u8> {
pub fn pop_max(&mut self) -> Option<u8> {
let max = self.max()?;
self.remove(max);
Some(max)
Expand Down Expand Up @@ -458,11 +485,8 @@ where
/// );
/// ```
#[inline]
pub fn iter(&self) -> Iter<T> {
Iter {
value: self.0,
index: 0,
}
pub fn iter(self) -> Iter<T> {
Iter { bitset: self }
}
}

Expand Down Expand Up @@ -494,6 +518,12 @@ where
}
}

impl<T: ScalarBitSetStorage> From<T> for ScalarBitSet<T> {
fn from(bits: T) -> Self {
Self(bits)
}
}

/// A trait implemented by all integers that can be used as the backing storage
/// for a [`ScalarBitSet`].
///
Expand Down Expand Up @@ -550,8 +580,7 @@ impl_storage!(usize);

/// An iterator over the elements in a [`ScalarBitSet`].
pub struct Iter<T> {
value: T,
index: u8,
bitset: ScalarBitSet<T>,
}

impl<T> Iterator for Iter<T>
Expand All @@ -562,14 +591,36 @@ where

#[inline]
fn next(&mut self) -> Option<u8> {
if self.value == T::from(0) {
None
} else {
let trailing_zeros = self.value.trailing_zeros();
let elem = self.index + trailing_zeros;
self.index += trailing_zeros + 1;
self.value = self.value >> (trailing_zeros + 1);
Some(elem)
}
self.bitset.pop_min()
}
}

impl<T> DoubleEndedIterator for Iter<T>
where
T: ScalarBitSetStorage,
{
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
self.bitset.pop_max()
}
}

impl<T> ExactSizeIterator for Iter<T>
where
T: ScalarBitSetStorage,
{
#[inline]
fn len(&self) -> usize {
usize::from(self.bitset.len())
}
}

#[cfg(feature = "arbitrary")]
impl<'a, T> arbitrary::Arbitrary<'a> for ScalarBitSet<T>
where
T: ScalarBitSetStorage + arbitrary::Arbitrary<'a>,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
T::arbitrary(u).map(Self)
}
}
92 changes: 0 additions & 92 deletions cranelift/codegen/meta/src/cdsl/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ static RUST_NAME_PREFIX: &str = "ir::types::";
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) enum ValueType {
Lane(LaneType),
Reference(ReferenceType),
Vector(VectorType),
DynamicVector(DynamicVectorType),
}
Expand All @@ -28,15 +27,10 @@ impl ValueType {
LaneTypeIterator::new()
}

pub fn all_reference_types() -> ReferenceTypeIterator {
ReferenceTypeIterator::new()
}

/// Return a string containing the documentation comment for this type.
pub fn doc(&self) -> String {
match *self {
ValueType::Lane(l) => l.doc(),
ValueType::Reference(r) => r.doc(),
ValueType::Vector(ref v) => v.doc(),
ValueType::DynamicVector(ref v) => v.doc(),
}
Expand All @@ -46,7 +40,6 @@ impl ValueType {
pub fn lane_bits(&self) -> u64 {
match *self {
ValueType::Lane(l) => l.lane_bits(),
ValueType::Reference(r) => r.lane_bits(),
ValueType::Vector(ref v) => v.lane_bits(),
ValueType::DynamicVector(ref v) => v.lane_bits(),
}
Expand All @@ -69,7 +62,6 @@ impl ValueType {
pub fn number(&self) -> u16 {
match *self {
ValueType::Lane(l) => l.number(),
ValueType::Reference(r) => r.number(),
ValueType::Vector(ref v) => v.number(),
ValueType::DynamicVector(ref v) => v.number(),
}
Expand All @@ -90,7 +82,6 @@ impl fmt::Display for ValueType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ValueType::Lane(l) => l.fmt(f),
ValueType::Reference(r) => r.fmt(f),
ValueType::Vector(ref v) => v.fmt(f),
ValueType::DynamicVector(ref v) => v.fmt(f),
}
Expand All @@ -104,13 +95,6 @@ impl From<LaneType> for ValueType {
}
}

/// Create a ValueType from a given reference type.
impl From<ReferenceType> for ValueType {
fn from(reference: ReferenceType) -> Self {
ValueType::Reference(reference)
}
}

/// Create a ValueType from a given vector type.
impl From<VectorType> for ValueType {
fn from(vector: VectorType) -> Self {
Expand Down Expand Up @@ -434,79 +418,3 @@ impl fmt::Debug for DynamicVectorType {
)
}
}

/// Reference type is scalar type, but not lane type.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct ReferenceType(pub shared_types::Reference);

impl ReferenceType {
/// Return a string containing the documentation comment for this reference type.
pub fn doc(self) -> String {
format!("An opaque reference type with {} bits.", self.lane_bits())
}

/// Return the number of bits in a lane.
pub fn lane_bits(self) -> u64 {
match self.0 {
shared_types::Reference::R32 => 32,
shared_types::Reference::R64 => 64,
}
}

/// Find the unique number associated with this reference type.
pub fn number(self) -> u16 {
constants::REFERENCE_BASE
+ match self {
ReferenceType(shared_types::Reference::R32) => 0,
ReferenceType(shared_types::Reference::R64) => 1,
}
}

pub fn ref_from_bits(num_bits: u16) -> ReferenceType {
ReferenceType(match num_bits {
32 => shared_types::Reference::R32,
64 => shared_types::Reference::R64,
_ => unreachable!("unexpected number of bits for a reference type"),
})
}
}

impl fmt::Display for ReferenceType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "r{}", self.lane_bits())
}
}

impl fmt::Debug for ReferenceType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ReferenceType(bits={})", self.lane_bits())
}
}

/// Create a ReferenceType from a given reference variant.
impl From<shared_types::Reference> for ReferenceType {
fn from(r: shared_types::Reference) -> Self {
ReferenceType(r)
}
}

/// An iterator for different reference types.
pub(crate) struct ReferenceTypeIterator {
reference_iter: shared_types::ReferenceIterator,
}

impl ReferenceTypeIterator {
/// Create a new reference type iterator.
fn new() -> Self {
Self {
reference_iter: shared_types::ReferenceIterator::new(),
}
}
}

impl Iterator for ReferenceTypeIterator {
type Item = ReferenceType;
fn next(&mut self) -> Option<Self::Item> {
self.reference_iter.next().map(ReferenceType::from)
}
}
Loading

0 comments on commit 1f86598

Please sign in to comment.