Skip to content

Commit 065dc60

Browse files
chore: put debug impl behind feature flag, cleanup
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent a8d0579 commit 065dc60

File tree

23 files changed

+136
-110
lines changed

23 files changed

+136
-110
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Safety wise, TinyWasm doesn't use any unsafe code and is designed to be complete
4646
| [**Custom Page Sizes**](https://github.com/WebAssembly/custom-page-sizes/blob/main/proposals/custom-page-sizes/Overview.md) | 🟢 | `next` |
4747
| [**Tail Call**](https://github.com/WebAssembly/tail-call/blob/main/proposals/tail-call/Overview.md) | 🟢 | `next` |
4848
| [**Memory64**](https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md) | 🟢 | `next` |
49-
| [**Fixed-Width SIMD**](https://github.com/webassembly/simd) | 🚧 | N/A |
49+
| [**Fixed-Width SIMD**](https://github.com/webassembly/simd) | 🟢 | `next` |
5050

5151
## Usage
5252

crates/tinywasm/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ serde_json.workspace=true
3434
serde.workspace=true
3535

3636
[features]
37-
default=["std", "parser", "log", "archive", "canonicalize_nans"]
37+
default=["std", "parser", "log", "archive", "canonicalize_nans", "debug"]
3838

3939
log=["dep:log", "tinywasm-parser?/log", "tinywasm-types/log"]
4040
std=["tinywasm-parser?/std", "tinywasm-types/std"]
@@ -48,6 +48,9 @@ archive=["tinywasm-types/archive"]
4848
# canonicalize all NaN values to a single representation
4949
canonicalize_nans=[]
5050

51+
# derive Debug for runtime/types structs
52+
debug=["tinywasm-types/debug"]
53+
5154
[[test]]
5255
name="test-wasm-1"
5356
harness=false

crates/tinywasm/src/engine.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ pub(crate) struct EngineInner {
4040
}
4141

4242
/// Fuel accounting policy for budgeted execution.
43-
#[derive(Debug, Clone, Copy)]
4443
#[non_exhaustive]
45-
#[derive(Default)]
44+
#[derive(Default, Clone, Copy)]
45+
#[cfg_attr(feature = "debug", derive(Debug))]
4646
pub enum FuelPolicy {
4747
/// Charge one fuel unit per retired instruction.
4848
#[default]
@@ -67,7 +67,8 @@ pub const DEFAULT_VALUE_STACK_REF_SIZE: usize = 4 * 1024; // 4k slots
6767
pub const DEFAULT_CALL_STACK_SIZE: usize = 2048; // 1024 frames
6868

6969
/// Configuration for the WebAssembly interpreter
70-
#[derive(Debug, Clone)]
70+
#[derive(Clone)]
71+
#[cfg_attr(feature = "debug", derive(Debug))]
7172
#[non_exhaustive]
7273
pub struct Config {
7374
/// Initial size of the 32-bit value stack (i32, f32 values).

crates/tinywasm/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tinywasm_types::archive::TwasmError;
88
pub use tinywasm_parser::ParseError;
99

1010
/// Errors that can occur for `TinyWasm` operations
11-
#[derive(Debug)]
11+
#[cfg_attr(feature = "debug", derive(Debug))]
1212
#[non_exhaustive]
1313
pub enum Error {
1414
/// A WebAssembly trap occurred

crates/tinywasm/src/func.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub enum ExecProgress<T> {
1313
Suspended,
1414
}
1515

16-
#[derive(Debug, Clone, Copy)]
16+
#[derive(Clone, Copy)]
17+
#[cfg_attr(feature = "debug", derive(Debug))]
1718
pub(crate) struct ExecutionState {
1819
pub(crate) callframe: CallFrame,
1920
}
@@ -33,7 +34,7 @@ pub struct FuncExecution<'store> {
3334
state: FuncExecutionState,
3435
}
3536

36-
#[derive(Debug)]
37+
#[cfg_attr(feature = "debug", derive(Debug))]
3738
enum FuncExecutionState {
3839
Running { exec_state: ExecutionState, root_func_addr: u32 },
3940
Completed { result: Option<Vec<WasmValue>> },

crates/tinywasm/src/imports.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use crate::{LinkingError, MemoryRef, MemoryRefMut, Result, log};
1010
use tinywasm_types::*;
1111

1212
/// The internal representation of a function
13-
#[derive(Debug, Clone)]
13+
#[derive(Clone)]
14+
#[cfg_attr(feature = "debug", derive(Debug))]
1415
pub enum Function {
1516
/// A host function
1617
Host(Rc<HostFunction>),
@@ -49,7 +50,7 @@ impl HostFunction {
4950
pub(crate) type HostFuncInner = Box<dyn Fn(FuncContext<'_>, &[WasmValue]) -> Result<Vec<WasmValue>>>;
5051

5152
/// The context of a host-function call
52-
#[derive(Debug)]
53+
#[cfg_attr(feature = "debug", derive(Debug))]
5354
pub struct FuncContext<'a> {
5455
pub(crate) store: &'a mut crate::Store,
5556
pub(crate) module_addr: ModuleInstanceAddr,

crates/tinywasm/src/instance.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ use crate::{Error, FuncHandle, FuncHandleTyped, Imports, MemoryRef, MemoryRefMut
1010
/// Backed by an Rc, so cloning is cheap
1111
///
1212
/// See <https://webassembly.github.io/spec/core/exec/runtime.html#module-instances>
13-
#[derive(Debug, Clone)]
13+
#[derive(Clone)]
14+
#[cfg_attr(feature = "debug", derive(Debug))]
1415
pub struct ModuleInstance(pub(crate) Rc<ModuleInstanceInner>);
1516

1617
#[expect(dead_code)]
17-
#[derive(Debug)]
18+
#[cfg_attr(feature = "debug", derive(Debug))]
1819
pub(crate) struct ModuleInstanceInner {
1920
pub(crate) failed_to_instantiate: bool,
2021

crates/tinywasm/src/interpreter/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::{Result, Store, interpreter::stack::CallFrame};
1111
pub(crate) use value128::*;
1212
pub(crate) use values::*;
1313

14-
#[derive(Debug, Clone, Copy)]
14+
#[derive(Clone, Copy)]
15+
#[cfg_attr(feature = "debug", derive(Debug))]
1516
pub(crate) enum ExecState {
1617
Completed,
1718
Suspended(CallFrame),
@@ -20,7 +21,8 @@ pub(crate) enum ExecState {
2021
/// The main `TinyWasm` runtime.
2122
///
2223
/// This is the default runtime used by `TinyWasm`.
23-
#[derive(Debug, Default)]
24+
#[derive(Default)]
25+
#[cfg_attr(feature = "debug", derive(Debug))]
2426
pub(crate) struct InterpreterRuntime;
2527

2628
impl InterpreterRuntime {

crates/tinywasm/src/interpreter/stack/call_stack.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{Result, Trap, unlikely};
33
use alloc::vec::Vec;
44
use tinywasm_types::{FuncAddr, ModuleInstanceAddr, ValueCountsSmall};
55

6-
#[derive(Debug)]
6+
#[cfg_attr(feature = "debug", derive(Debug))]
77
pub(crate) struct CallStack {
88
stack: Vec<CallFrame>,
99
}
@@ -32,7 +32,8 @@ impl CallStack {
3232
}
3333
}
3434

35-
#[derive(Debug, Clone, Copy, Default)]
35+
#[derive(Clone, Copy, Default)]
36+
#[cfg_attr(feature = "debug", derive(Debug))]
3637
pub(crate) struct CallFrame {
3738
pub(crate) instr_ptr: u32,
3839
pub(crate) module_addr: ModuleInstanceAddr,
@@ -41,7 +42,8 @@ pub(crate) struct CallFrame {
4142
pub(crate) stack_offset: ValueCountsSmall,
4243
}
4344

44-
#[derive(Debug, Clone, Copy, Default)]
45+
#[derive(Clone, Copy, Default)]
46+
#[cfg_attr(feature = "debug", derive(Debug))]
4547
pub(crate) struct StackBase {
4648
pub(crate) s32: u32,
4749
pub(crate) s64: u32,

crates/tinywasm/src/interpreter/stack/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) use value_stack::ValueStack;
77
use crate::engine::Config;
88

99
/// A WebAssembly Stack
10-
#[derive(Debug)]
10+
#[cfg_attr(feature = "debug", derive(Debug))]
1111
pub(crate) struct Stack {
1212
pub(crate) values: ValueStack,
1313
pub(crate) call_stack: CallStack,

0 commit comments

Comments
 (0)