From ffb1e095fc1d6a2d54cc7637797c625dee6ebe6a Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Wed, 29 May 2024 01:39:21 +0200 Subject: chore: update deps, cleanup Signed-off-by: Henry Gressmann --- crates/parser/src/lib.rs | 6 +++--- crates/parser/src/module.rs | 11 +++++------ crates/tinywasm/src/runtime/stack/block_stack.rs | 15 +++++++-------- crates/tinywasm/src/runtime/stack/call_stack.rs | 2 +- crates/tinywasm/src/runtime/stack/mod.rs | 2 +- crates/tinywasm/src/runtime/stack/value_stack.rs | 1 - crates/types/src/lib.rs | 2 +- 7 files changed, 18 insertions(+), 21 deletions(-) (limited to 'crates') diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 4ee9bb5..51743c7 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -92,7 +92,7 @@ impl Parser { return Err(ParseError::EndNotReached); } - reader.to_module() + reader.into_module() } #[cfg(feature = "std")] @@ -132,7 +132,7 @@ impl Parser { reader.process_payload(payload, &mut validator)?; buffer.drain(..consumed); if eof || reader.end_reached { - return reader.to_module(); + return reader.into_module(); } } }; @@ -144,6 +144,6 @@ impl TryFrom for TinyWasmModule { type Error = ParseError; fn try_from(reader: ModuleReader) -> Result { - reader.to_module() + reader.into_module() } } diff --git a/crates/parser/src/module.rs b/crates/parser/src/module.rs index a4bdba4..294782c 100644 --- a/crates/parser/src/module.rs +++ b/crates/parser/src/module.rs @@ -179,14 +179,12 @@ impl ModuleReader { } #[inline] - pub(crate) fn to_module(self) -> Result { + pub(crate) fn into_module(self) -> Result { if !self.end_reached { return Err(ParseError::EndNotReached); } - let local_function_count = self.code.len(); - - if self.code_type_addrs.len() != local_function_count { + if self.code_type_addrs.len() != self.code.len() { return Err(ParseError::Other("Code and code type address count mismatch".to_string())); } @@ -199,13 +197,14 @@ impl ModuleReader { locals, ty: self.func_types.get(ty_idx as usize).expect("No func type for func, this is a bug").clone(), }) - .collect::>(); + .collect::>() + .into_boxed_slice(); let globals = self.globals; let table_types = self.table_types; Ok(TinyWasmModule { - funcs: funcs.into_boxed_slice(), + funcs, func_types: self.func_types.into_boxed_slice(), globals: globals.into_boxed_slice(), table_types: table_types.into_boxed_slice(), diff --git a/crates/tinywasm/src/runtime/stack/block_stack.rs b/crates/tinywasm/src/runtime/stack/block_stack.rs index 31cabfa..c01c9fb 100644 --- a/crates/tinywasm/src/runtime/stack/block_stack.rs +++ b/crates/tinywasm/src/runtime/stack/block_stack.rs @@ -1,14 +1,16 @@ use crate::{cold, unlikely, Error, Result}; use alloc::vec::Vec; -#[derive(Debug, Clone)] +#[derive(Debug)] pub(crate) struct BlockStack(Vec); -impl BlockStack { - pub(crate) fn new() -> Self { +impl Default for BlockStack { + fn default() -> Self { Self(Vec::with_capacity(128)) } +} +impl BlockStack { #[inline(always)] pub(crate) fn len(&self) -> usize { self.0.len() @@ -50,7 +52,7 @@ impl BlockStack { } } -#[derive(Debug, Clone, Copy)] +#[derive(Debug)] pub(crate) struct BlockFrame { pub(crate) instr_ptr: usize, // position of the instruction pointer when the block was entered pub(crate) end_instr_offset: u32, // position of the end instruction of the block @@ -69,10 +71,7 @@ pub(crate) struct BlockFrame { pub(crate) ty: BlockType, } -impl BlockFrame {} - -#[derive(Debug, Copy, Clone)] -#[allow(dead_code)] +#[derive(Debug)] pub(crate) enum BlockType { Loop, If, diff --git a/crates/tinywasm/src/runtime/stack/call_stack.rs b/crates/tinywasm/src/runtime/stack/call_stack.rs index 08b80c1..14077a8 100644 --- a/crates/tinywasm/src/runtime/stack/call_stack.rs +++ b/crates/tinywasm/src/runtime/stack/call_stack.rs @@ -37,7 +37,7 @@ impl CallStack { } } -#[derive(Debug, Clone)] +#[derive(Debug)] pub(crate) struct CallFrame { pub(crate) instr_ptr: usize, pub(crate) block_ptr: u32, diff --git a/crates/tinywasm/src/runtime/stack/mod.rs b/crates/tinywasm/src/runtime/stack/mod.rs index c9cc048..06510ab 100644 --- a/crates/tinywasm/src/runtime/stack/mod.rs +++ b/crates/tinywasm/src/runtime/stack/mod.rs @@ -16,6 +16,6 @@ pub(crate) struct Stack { impl Stack { pub(crate) fn new(call_frame: CallFrame) -> Self { - Self { values: ValueStack::default(), blocks: BlockStack::new(), call_stack: CallStack::new(call_frame) } + Self { values: ValueStack::default(), blocks: BlockStack::default(), call_stack: CallStack::new(call_frame) } } } diff --git a/crates/tinywasm/src/runtime/stack/value_stack.rs b/crates/tinywasm/src/runtime/stack/value_stack.rs index 3668670..db05364 100644 --- a/crates/tinywasm/src/runtime/stack/value_stack.rs +++ b/crates/tinywasm/src/runtime/stack/value_stack.rs @@ -68,7 +68,6 @@ impl ValueStack { self.stack.end >= 2 && self.stack.end <= self.stack.data.len(), "invalid stack state (should be impossible)" ); - self.stack.data[self.stack.end - 2] = func(self.stack.data[self.stack.end - 2], self.stack.data[self.stack.end - 1]); diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 5e38bfc..d447efb 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -307,7 +307,7 @@ pub enum ElementKind { Declared, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] pub enum ElementItem { Func(FuncAddr), -- cgit v1.3.1