From 51bac3ce0e72195fa3ebf3ef4fb287bc5451b6f7 Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 3 Apr 2026 17:55:37 +0200 Subject: chore: fix debug feature Signed-off-by: Henry --- crates/types/src/archive.rs | 12 ++---------- crates/types/src/instructions.rs | 2 +- crates/types/src/lib.rs | 22 +++++++++++----------- crates/types/src/value.rs | 36 ++++++++++++++++++++++-------------- 4 files changed, 36 insertions(+), 36 deletions(-) (limited to 'crates/types') diff --git a/crates/types/src/archive.rs b/crates/types/src/archive.rs index 069addf..dc98e30 100644 --- a/crates/types/src/archive.rs +++ b/crates/types/src/archive.rs @@ -4,10 +4,10 @@ use alloc::vec::Vec; use crate::TinyWasmModule; -const TWASM_MAGIC_PREFIX: &[u8; 4] = b"TWAS"; -const TWASM_VERSION: &[u8; 2] = b"03"; #[rustfmt::skip] const TWASM_MAGIC: [u8; 16] = [ TWASM_MAGIC_PREFIX[0], TWASM_MAGIC_PREFIX[1], TWASM_MAGIC_PREFIX[2], TWASM_MAGIC_PREFIX[3], TWASM_VERSION[0], TWASM_VERSION[1], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; +const TWASM_MAGIC_PREFIX: &[u8; 4] = b"TWAS"; +const TWASM_VERSION: &[u8; 2] = b"03"; fn validate_magic(wasm: &[u8]) -> Result { if wasm.len() < TWASM_MAGIC.len() || &wasm[..TWASM_MAGIC_PREFIX.len()] != TWASM_MAGIC_PREFIX { @@ -65,14 +65,6 @@ impl TinyWasmModule { mod tests { use super::*; - #[test] - fn test_serialize() { - let wasm = TinyWasmModule::default(); - let twasm = wasm.serialize_twasm().expect("should serialize"); - let wasm2 = TinyWasmModule::from_twasm(&twasm).unwrap(); - assert_eq!(wasm, wasm2); - } - #[test] fn test_invalid_magic() { let wasm = TinyWasmModule::default(); diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index 1165c06..83d0da8 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -48,10 +48,10 @@ pub enum ConstInstruction { /// Wasm Bytecode can map to multiple of these instructions. /// /// See +#[rustfmt::skip] #[derive(Clone, Copy, PartialEq)] #[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] -#[rustfmt::skip] pub enum Instruction { LocalCopy32(LocalAddr, LocalAddr), LocalCopy64(LocalAddr, LocalAddr), LocalCopy128(LocalAddr, LocalAddr), LocalCopyRef(LocalAddr, LocalAddr), I32AddLocals(LocalAddr, LocalAddr), I64AddLocals(LocalAddr, LocalAddr), diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 78b83d0..8a815cb 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -2,9 +2,9 @@ no_crate_inject, attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_assignments, unused_variables)) ))] -#![warn(missing_debug_implementations, rust_2018_idioms, unreachable_pub)] +#![warn(rust_2018_idioms, unreachable_pub)] #![no_std] -#![forbid(unsafe_code)] +#![deny(unsafe_code)] //! Types used by [`tinywasm`](https://docs.rs/tinywasm) and [`tinywasm_parser`](https://docs.rs/tinywasm_parser). @@ -50,7 +50,7 @@ pub mod archive; #[cfg(not(feature = "archive"))] pub mod archive { - #[derive(Debug)] + #[cfg_attr(feature = "debug", derive(Debug))] pub enum TwasmError {} impl core::fmt::Display for TwasmError { fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -272,6 +272,12 @@ pub struct WasmFunction { // wrapper around Arc<[T]> to support serde serialization and deserialization pub struct ArcSlice(pub Arc<[T]>); +impl Debug for ArcSlice { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + self.0.as_ref().fmt(f) + } +} + impl From> for ArcSlice { fn from(vec: alloc::vec::Vec) -> Self { Self(Arc::from(vec)) @@ -292,21 +298,15 @@ impl Deref for ArcSlice { } } -impl Debug for ArcSlice { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - self.0.as_ref().fmt(f) - } -} - #[cfg(feature = "archive")] -impl serde::Serialize for ArcSlice { +impl serde::Serialize for ArcSlice { fn serialize(&self, serializer: S) -> Result { self.0.as_ref().serialize(serializer) } } #[cfg(feature = "archive")] -impl<'de, T: serde::Deserialize<'de> + Debug> serde::Deserialize<'de> for ArcSlice { +impl<'de, T: serde::Deserialize<'de>> serde::Deserialize<'de> for ArcSlice { fn deserialize>(deserializer: D) -> Result { let vec: alloc::vec::Vec = alloc::vec::Vec::deserialize(deserializer)?; Ok(Self(Arc::from(vec))) diff --git a/crates/types/src/value.rs b/crates/types/src/value.rs index afaa0d3..8cc7f1b 100644 --- a/crates/types/src/value.rs +++ b/crates/types/src/value.rs @@ -23,12 +23,33 @@ pub enum WasmValue { RefFunc(FuncRef), } +impl Debug for WasmValue { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::I32(i) => write!(f, "i32({i})"), + Self::I64(i) => write!(f, "i64({i})"), + Self::F32(i) => write!(f, "f32({i})"), + Self::F64(i) => write!(f, "f64({i})"), + Self::V128(i) => write!(f, "v128({i:?})"), + #[cfg(feature = "debug")] + Self::RefExtern(i) => write!(f, "ref({i:?})"), + #[cfg(feature = "debug")] + Self::RefFunc(i) => write!(f, "func({i:?})"), + #[cfg(not(feature = "debug"))] + Self::RefExtern(_) => write!(f, "ref()"), + #[cfg(not(feature = "debug"))] + Self::RefFunc(_) => write!(f, "func()"), + } + } +} + #[derive(Clone, Copy, PartialEq, Eq)] pub struct ExternRef(Option); #[derive(Clone, Copy, PartialEq, Eq)] pub struct FuncRef(Option); +#[cfg(feature = "debug")] impl Debug for ExternRef { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self.0 { @@ -38,6 +59,7 @@ impl Debug for ExternRef { } } +#[cfg(feature = "debug")] impl Debug for FuncRef { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self.0 { @@ -268,20 +290,6 @@ impl WasmValue { } } -impl Debug for WasmValue { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - Self::I32(i) => write!(f, "i32({i})"), - Self::I64(i) => write!(f, "i64({i})"), - Self::F32(i) => write!(f, "f32({i})"), - Self::F64(i) => write!(f, "f64({i})"), - Self::V128(i) => write!(f, "v128({i:?})"), - Self::RefExtern(i) => write!(f, "ref({i:?})"), - Self::RefFunc(i) => write!(f, "func({i:?})"), - } - } -} - impl WasmValue { /// Get the type of a [`WasmValue`] #[inline] -- cgit v1.3.1