diff options
| author | Henry <mail@henrygressmann.de> | 2026-04-03 17:24:38 +0200 |
|---|---|---|
| committer | Henry <mail@henrygressmann.de> | 2026-04-03 17:24:38 +0200 |
| commit | 065dc608ab25030d1719fef4dd55271c95245884 (patch) | |
| tree | 4712f22e1756fef5b06bfaea839a1e42da75305f /crates/types | |
| parent | a8d057903cca3b7dd0a010b5649a9bd8173acc1b (diff) | |
chore: put debug impl behind feature flag, cleanup
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/types')
| -rw-r--r-- | crates/types/Cargo.toml | 3 | ||||
| -rw-r--r-- | crates/types/src/instructions.rs | 9 | ||||
| -rw-r--r-- | crates/types/src/lib.rs | 63 | ||||
| -rw-r--r-- | crates/types/src/value.rs | 3 |
4 files changed, 52 insertions, 26 deletions
diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index 5efcb8b..94832c1 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -16,8 +16,9 @@ postcard={version="1.1", optional=true, default-features=false, features=["alloc serde={version="1.0", optional=true, default-features=false, features=["alloc"]} [features] -default=["std", "log", "archive"] +default=["std", "log", "archive", "debug"] std=["serde?/std"] archive=["dep:postcard", "dep:serde"] log=["dep:log"] +debug=[] diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index 29c9cab..1165c06 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -2,7 +2,8 @@ use super::{FuncAddr, GlobalAddr, LocalAddr, TableAddr, TypeAddr, ValType, Value use crate::{ConstIdx, DataAddr, ElemAddr, ExternAddr, MemAddr}; /// Represents a memory immediate in a WebAssembly memory instruction. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] #[repr(Rust, packed)] pub struct MemoryArg { @@ -27,7 +28,8 @@ impl MemoryArg { } } -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum ConstInstruction { I32Const(i32), @@ -46,7 +48,8 @@ pub enum ConstInstruction { /// Wasm Bytecode can map to multiple of these instructions. /// /// See <https://webassembly.github.io/spec/core/binary/instructions.html> -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] #[rustfmt::skip] pub enum Instruction { diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 7112834..78b83d0 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -65,7 +65,8 @@ pub mod archive { /// This is the internal representation of a WebAssembly module in `TinyWasm`. /// `TinyWasmModules` are validated before being created, so they are guaranteed to be valid (as long as they were created by `TinyWasm`). /// This means you should not trust a `TinyWasmModule` created by a third party to be valid. -#[derive(Debug, Clone, Default, PartialEq)] +#[derive(Clone, Default, PartialEq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct TinyWasmModule { /// Optional address of the start function @@ -122,7 +123,8 @@ pub struct TinyWasmModule { /// A WebAssembly External Kind. /// /// See <https://webassembly.github.io/spec/core/syntax/types.html#external-types> -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum ExternalKind { /// A WebAssembly Function. @@ -160,7 +162,8 @@ pub type ModuleInstanceAddr = Addr; /// A WebAssembly External Value. /// /// See <https://webassembly.github.io/spec/core/exec/runtime.html#external-values> -#[derive(Debug, Clone)] +#[derive(Clone)] +#[cfg_attr(feature = "debug", derive(Debug))] pub enum ExternVal { Func(FuncAddr), Table(TableAddr), @@ -193,14 +196,16 @@ impl ExternVal { /// The type of a WebAssembly Function. /// /// See <https://webassembly.github.io/spec/core/syntax/types.html#function-types> -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Clone, PartialEq, Eq, Default)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct FuncType { pub params: Box<[ValType]>, pub results: Box<[ValType]>, } -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] +#[derive(Default, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct ValueCounts { pub c32: u32, @@ -209,7 +214,8 @@ pub struct ValueCounts { pub cref: u32, } -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] +#[derive(Default, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct ValueCountsSmall { pub c32: u16, @@ -250,7 +256,8 @@ impl<'a, T: IntoIterator<Item = &'a ValType>> From<T> for ValueCountsSmall { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Clone, PartialEq, Default)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct WasmFunction { pub instructions: ArcSlice<Instruction>, @@ -306,14 +313,16 @@ impl<'de, T: serde::Deserialize<'de> + Debug> serde::Deserialize<'de> for ArcSli } } -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Clone, PartialEq, Eq, Default)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct WasmFunctionData { pub v128_constants: Box<[i128]>, } /// A WebAssembly Module Export -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct Export { /// The name of the export. @@ -324,21 +333,24 @@ pub struct Export { pub index: u32, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Clone, PartialEq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct Global { pub ty: GlobalType, pub init: ConstInstruction, } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct GlobalType { pub mutable: bool, pub ty: ValType, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct TableType { pub element_type: ValType, @@ -357,7 +369,8 @@ impl TableType { } /// Represents a memory's type. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct MemoryType { arch: MemoryArch, @@ -407,14 +420,16 @@ impl MemoryType { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum MemoryArch { I32, I64, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct Import { pub module: Box<str>, @@ -422,7 +437,8 @@ pub struct Import { pub kind: ImportKind, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum ImportKind { Function(TypeAddr), @@ -442,7 +458,8 @@ impl From<&ImportKind> for ExternalKind { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Clone, PartialEq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct Data { pub data: Box<[u8]>, @@ -450,14 +467,16 @@ pub struct Data { pub kind: DataKind, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Clone, PartialEq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum DataKind { Active { mem: MemAddr, offset: ConstInstruction }, Passive, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Clone, PartialEq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct Element { pub kind: ElementKind, @@ -466,7 +485,8 @@ pub struct Element { pub ty: ValType, } -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum ElementKind { Passive, @@ -474,7 +494,8 @@ pub enum ElementKind { Declared, } -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum ElementItem { Func(FuncAddr), diff --git a/crates/types/src/value.rs b/crates/types/src/value.rs index 7b58948..afaa0d3 100644 --- a/crates/types/src/value.rs +++ b/crates/types/src/value.rs @@ -299,7 +299,8 @@ impl WasmValue { } /// Type of a WebAssembly value. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub enum ValType { /// A 32-bit integer. |
