From d9cdd0b53c870bf7d9d69b854b8da2692d152871 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Wed, 15 May 2024 13:38:13 +0200 Subject: feat: v0.7.0 (#13) * Remove all unsafe code * Refactor interpreter loop * Optimize Call-frames * Remove unnecessary reference counter data from store --------- Signed-off-by: Henry Gressmann --- crates/types/src/archive.rs | 22 ---------------------- crates/types/src/instructions.rs | 1 + crates/types/src/lib.rs | 5 ++--- 3 files changed, 3 insertions(+), 25 deletions(-) (limited to 'crates/types/src') diff --git a/crates/types/src/archive.rs b/crates/types/src/archive.rs index 9bf095b..52146e7 100644 --- a/crates/types/src/archive.rs +++ b/crates/types/src/archive.rs @@ -65,18 +65,6 @@ impl TinyWasmModule { Ok(root.deserialize(&mut rkyv::Infallible).unwrap()) } - #[cfg(feature = "unsafe")] - #[allow(unsafe_code)] - /// Creates a TinyWasmModule from a slice of bytes. - /// - /// # Safety - /// This function is only safe to call if the bytes have been created by - /// a trusted source. Otherwise, it may cause undefined behavior. - pub unsafe fn from_twasm_unchecked(wasm: &[u8]) -> Self { - let len = validate_magic(wasm).unwrap(); - rkyv::archived_root::(&wasm[len..]).deserialize(&mut rkyv::Infallible).unwrap() - } - /// Serializes the TinyWasmModule into a vector of bytes. /// AlignedVec can be deferenced as a slice of bytes and /// implements io::Write when the `std` feature is enabled. @@ -101,14 +89,4 @@ mod tests { let wasm2 = TinyWasmModule::from_twasm(&twasm).unwrap(); assert_eq!(wasm, wasm2); } - - #[cfg(feature = "unsafe")] - #[test] - fn test_serialize_unchecked() { - let wasm = TinyWasmModule::default(); - let twasm = wasm.serialize_twasm(); - #[allow(unsafe_code)] - let wasm2 = unsafe { TinyWasmModule::from_twasm_unchecked(&twasm) }; - assert_eq!(wasm, wasm2); - } } diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index ee624bd..6290bb4 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -85,6 +85,7 @@ pub enum ConstInstruction { #[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] // should be kept as small as possible (16 bytes max) #[rustfmt::skip] +#[non_exhaustive] pub enum Instruction { // > Custom Instructions BrLabel(LabelAddr), diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index c5c8071..5e38bfc 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -4,8 +4,7 @@ ))] #![warn(missing_debug_implementations, rust_2018_idioms, unreachable_pub)] #![no_std] -#![cfg_attr(not(feature = "unsafe"), forbid(unsafe_code))] -#![cfg_attr(feature = "unsafe", deny(unused_unsafe))] +#![forbid(unsafe_code)] //! Types used by [`tinywasm`](https://docs.rs/tinywasm) and [`tinywasm_parser`](https://docs.rs/tinywasm_parser). @@ -95,7 +94,7 @@ pub struct TinyWasmModule { /// A WebAssembly External Kind. /// /// See -#[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 ExternalKind { /// A WebAssembly Function. -- cgit v1.3.1