Address most of the comments

This commit is contained in:
Syrus Akbary
2023-02-25 11:23:03 -08:00
parent 5bdf3d4e2b
commit 93def03796
19 changed files with 45 additions and 84 deletions

View File

@@ -100,6 +100,7 @@ core = ["hashbrown"]
sys = [ sys = [
"wasmer-compiler/translator", "wasmer-compiler/translator",
"wasmer-compiler/compiler", "wasmer-compiler/compiler",
"std",
] ]
sys-default = ["sys", "wat", "cranelift"] sys-default = ["sys", "wat", "cranelift"]
# - Compilers. # - Compilers.

View File

@@ -42,12 +42,6 @@ impl Default for Engine {
} }
} }
// impl Into<Engine> for engine_imp::Engine {
// fn into(self) -> Engine {
// Engine(self)
// }
// }
impl From<engine_imp::Engine> for Engine { impl From<engine_imp::Engine> for Engine {
fn from(inner: engine_imp::Engine) -> Self { fn from(inner: engine_imp::Engine) -> Self {
Self(inner) Self(inner)

View File

@@ -4,43 +4,6 @@ use thiserror::Error;
#[cfg(feature = "sys")] #[cfg(feature = "sys")]
pub use wasmer_compiler::{LinkError, RuntimeError}; pub use wasmer_compiler::{LinkError, RuntimeError};
// /// An error while instantiating a module.
// ///
// /// This is not a common WebAssembly error, however
// /// we need to differentiate from a `LinkError` (an error
// /// that happens while linking, on instantiation), a
// /// Trap that occurs when calling the WebAssembly module
// /// start function, and an error when initializing the user's
// /// host environments.
// #[derive(Debug)]
// #[cfg_attr(feature = "std", derive(Error))]
// pub enum InstantiationError {
// /// A linking ocurred during instantiation.
// #[cfg_attr(feature = "std", error(transparent))]
// Link(LinkError),
// /// A runtime error occured while invoking the start function
// #[cfg_attr(feature = "std", error(transparent))]
// Start(RuntimeError),
// /// The module was compiled with a CPU feature that is not available on
// /// the current host.
// #[cfg_attr(feature = "std", error("missing required CPU features: {0:?}"))]
// CpuFeature(String),
// /// Import from a different [`Store`].
// /// This error occurs when an import from a different store is used.
// #[cfg_attr(feature = "std", error("cannot mix imports from different stores"))]
// DifferentStores,
// }
// #[cfg(feature = "core")]
// impl std::fmt::Display for InstantiationError {
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// write!(f, "InstantiationError")
// }
// }
/// An error while instantiating a module. /// An error while instantiating a module.
/// ///
/// This is not a common WebAssembly error, however /// This is not a common WebAssembly error, however
@@ -49,28 +12,36 @@ pub use wasmer_compiler::{LinkError, RuntimeError};
/// Trap that occurs when calling the WebAssembly module /// Trap that occurs when calling the WebAssembly module
/// start function, and an error when initializing the user's /// start function, and an error when initializing the user's
/// host environments. /// host environments.
#[derive(Error, Debug)] #[derive(Debug)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum InstantiationError { pub enum InstantiationError {
/// A linking ocurred during instantiation. /// A linking ocurred during instantiation.
#[error(transparent)] #[cfg_attr(feature = "std", error(transparent))]
Link(LinkError), Link(LinkError),
/// A runtime error occured while invoking the start function /// A runtime error occured while invoking the start function
#[error(transparent)] #[cfg_attr(feature = "std", error(transparent))]
Start(RuntimeError), Start(RuntimeError),
/// The module was compiled with a CPU feature that is not available on /// The module was compiled with a CPU feature that is not available on
/// the current host. /// the current host.
#[error("missing required CPU features: {0:?}")] #[cfg_attr(feature = "std", error("missing required CPU features: {0:?}"))]
CpuFeature(String), CpuFeature(String),
/// Import from a different Store. /// Import from a different [`Store`].
/// This error occurs when an import from a different store is used. /// This error occurs when an import from a different store is used.
#[error("cannot mix imports from different stores")] #[cfg_attr(feature = "std", error("cannot mix imports from different stores"))]
DifferentStores, DifferentStores,
/// Import from a different Store. /// Import from a different Store.
/// This error occurs when an import from a different store is used. /// This error occurs when an import from a different store is used.
#[error("incorrect OS or architecture")] #[cfg_attr(feature = "std", error("incorrect OS or architecture"))]
DifferentArchOS, DifferentArchOS,
} }
#[cfg(feature = "core")]
impl std::fmt::Display for InstantiationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "InstantiationError")
}
}

View File

@@ -13,25 +13,25 @@ impl ExternRef {
where where
T: Any + Send + Sync + 'static + Sized, T: Any + Send + Sync + 'static + Sized,
{ {
unimplemented!(); unimplemented!("ExternRef is not yet supported in Javascript");
} }
pub fn downcast<'a, T>(&self, store: &'a impl AsStoreRef) -> Option<&'a T> pub fn downcast<'a, T>(&self, store: &'a impl AsStoreRef) -> Option<&'a T>
where where
T: Any + Send + Sync + 'static + Sized, T: Any + Send + Sync + 'static + Sized,
{ {
unimplemented!(); unimplemented!("ExternRef is not yet supported in Javascript");
} }
pub(crate) fn vm_externref(&self) -> VMExternRef { pub(crate) fn vm_externref(&self) -> VMExternRef {
unimplemented!(); unimplemented!("ExternRef is not yet supported in Javascript");
} }
pub(crate) unsafe fn from_vm_externref( pub(crate) unsafe fn from_vm_externref(
store: &mut impl AsStoreMut, store: &mut impl AsStoreMut,
vm_externref: VMExternRef, vm_externref: VMExternRef,
) -> Self { ) -> Self {
unimplemented!(); unimplemented!("ExternRef is not yet supported in Javascript");
} }
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool { pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {

View File

@@ -237,7 +237,8 @@ impl Module {
bytes: impl IntoBytes, bytes: impl IntoBytes,
) -> Result<Self, DeserializeError> { ) -> Result<Self, DeserializeError> {
#[cfg(feature = "js-serializable-module")] #[cfg(feature = "js-serializable-module")]
return Self::new(_engine, bytes.into_bytes()).map_err(|e| DeserializeError::Compiler(e)); return Self::from_binary(_engine, &bytes.into_bytes())
.map_err(|e| DeserializeError::Compiler(e));
#[cfg(not(feature = "js-serializable-module"))] #[cfg(not(feature = "js-serializable-module"))]
return Err(DeserializeError::Generic("You need to enable the `js-serializable-module` feature flag to deserialize a `Module`".to_string())); return Err(DeserializeError::Generic("You need to enable the `js-serializable-module` feature flag to deserialize a `Module`".to_string()));

View File

@@ -110,6 +110,7 @@ impl VMMemory {
/// The shared memory is the same as the normal memory /// The shared memory is the same as the normal memory
pub type VMSharedMemory = VMMemory; pub type VMSharedMemory = VMMemory;
/// The VM Global type
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct VMGlobal { pub struct VMGlobal {
pub(crate) global: JsGlobal, pub(crate) global: JsGlobal,
@@ -125,6 +126,7 @@ impl VMGlobal {
unsafe impl Send for VMGlobal {} unsafe impl Send for VMGlobal {}
unsafe impl Sync for VMGlobal {} unsafe impl Sync for VMGlobal {}
/// The VM Table type
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct VMTable { pub struct VMTable {
pub(crate) table: JsTable, pub(crate) table: JsTable,
@@ -138,11 +140,14 @@ impl VMTable {
pub(crate) fn new(table: JsTable, ty: TableType) -> Self { pub(crate) fn new(table: JsTable, ty: TableType) -> Self {
Self { table, ty } Self { table, ty }
} }
/// Get the table size at runtime
pub fn get_runtime_size(&self) -> u32 { pub fn get_runtime_size(&self) -> u32 {
self.table.length() self.table.length()
} }
} }
/// The VM Function type
#[derive(Clone)] #[derive(Clone)]
pub struct VMFunction { pub struct VMFunction {
pub(crate) function: JsFunction, pub(crate) function: JsFunction,

View File

@@ -13,7 +13,7 @@ use wasmer_vm::init_traps;
pub use wasmer_vm::TrapHandlerFn; pub use wasmer_vm::TrapHandlerFn;
#[cfg(feature = "sys")] #[cfg(feature = "sys")]
use crate::sys::WasmerCompilerEngine; use crate::sys::NativeEngineExt;
#[cfg(feature = "sys")] #[cfg(feature = "sys")]
pub use wasmer_vm::{StoreHandle, StoreObjects}; pub use wasmer_vm::{StoreHandle, StoreObjects};

View File

@@ -65,7 +65,7 @@ impl From<EngineBuilder> for crate::engine::Engine {
/// The custom trait to access to all the `sys` function in the common /// The custom trait to access to all the `sys` function in the common
/// engine. /// engine.
pub trait WasmerCompilerEngine { pub trait NativeEngineExt {
/// Create a new `Engine` with the given config /// Create a new `Engine` with the given config
#[cfg(feature = "compiler")] #[cfg(feature = "compiler")]
fn new(compiler_config: Box<dyn CompilerConfig>, target: Target, features: Features) -> Self; fn new(compiler_config: Box<dyn CompilerConfig>, target: Target, features: Features) -> Self;
@@ -95,7 +95,7 @@ pub trait WasmerCompilerEngine {
fn tunables(&self) -> &dyn Tunables; fn tunables(&self) -> &dyn Tunables;
} }
impl WasmerCompilerEngine for crate::engine::Engine { impl NativeEngineExt for crate::engine::Engine {
fn new(compiler_config: Box<dyn CompilerConfig>, target: Target, features: Features) -> Self { fn new(compiler_config: Box<dyn CompilerConfig>, target: Target, features: Features) -> Self {
crate::engine::Engine(Engine::new(compiler_config, target, features)) crate::engine::Engine(Engine::new(compiler_config, target, features))
} }

View File

@@ -1,6 +1,6 @@
use super::memory_view::MemoryView; use super::memory_view::MemoryView;
use crate::store::{AsStoreMut, AsStoreRef}; use crate::store::{AsStoreMut, AsStoreRef};
use crate::sys::WasmerCompilerEngine; use crate::sys::NativeEngineExt;
use crate::vm::VMExternMemory; use crate::vm::VMExternMemory;
use crate::MemoryAccessError; use crate::MemoryAccessError;
use crate::MemoryType; use crate::MemoryType;

View File

@@ -1,5 +1,5 @@
use crate::store::{AsStoreMut, AsStoreRef}; use crate::store::{AsStoreMut, AsStoreRef};
use crate::sys::WasmerCompilerEngine; use crate::sys::NativeEngineExt;
use crate::TableType; use crate::TableType;
use crate::Value; use crate::Value;
use crate::{vm::VMExternTable, ExternRef, Function, RuntimeError}; use crate::{vm::VMExternTable, ExternRef, Function, RuntimeError};

View File

@@ -6,7 +6,7 @@ pub(crate) mod module;
mod tunables; mod tunables;
pub(crate) mod typed_function; pub(crate) mod typed_function;
pub use crate::sys::engine::WasmerCompilerEngine; pub use crate::sys::engine::NativeEngineExt;
pub use crate::sys::tunables::BaseTunables; pub use crate::sys::tunables::BaseTunables;
pub use target_lexicon::{Architecture, CallingConvention, OperatingSystem, Triple, HOST}; pub use target_lexicon::{Architecture, CallingConvention, OperatingSystem, Triple, HOST};
#[cfg(feature = "compiler")] #[cfg(feature = "compiler")]

View File

@@ -1,5 +1,5 @@
use crate::engine::AsEngineRef; use crate::engine::AsEngineRef;
use crate::sys::engine::WasmerCompilerEngine; use crate::sys::engine::NativeEngineExt;
use bytes::Bytes; use bytes::Bytes;
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;

View File

@@ -6,7 +6,7 @@ pub use wasmer_compiler::BaseTunables;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::sys::WasmerCompilerEngine; use crate::sys::NativeEngineExt;
use crate::TableType; use crate::TableType;
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
use std::ptr::NonNull; use std::ptr::NonNull;

View File

@@ -3,8 +3,7 @@
#[cfg(feature = "js")] #[cfg(feature = "js")]
pub(crate) use crate::js::vm::{ pub(crate) use crate::js::vm::{
VMExtern, VMExternFunction, VMExternGlobal, VMExternMemory, VMExternRef, VMExternTable, VMExtern, VMExternFunction, VMExternGlobal, VMExternMemory, VMExternRef, VMExternTable,
VMFuncRef, VMFunction, VMFunctionBody, VMFunctionEnvironment, VMGlobal, VMInstance, VMMemory, VMFuncRef, VMFunctionBody, VMFunctionEnvironment, VMInstance, VMTrampoline,
VMSharedMemory, VMTable, VMTrampoline,
}; };
#[cfg(feature = "sys")] #[cfg(feature = "sys")]
@@ -13,17 +12,18 @@ pub(crate) use crate::sys::vm::{
VMFuncRef, VMFunctionBody, VMFunctionEnvironment, VMInstance, VMTrampoline, VMFuncRef, VMFunctionBody, VMFunctionEnvironment, VMInstance, VMTrampoline,
}; };
#[cfg(feature = "js")]
pub use crate::js::vm::{VMFunction, VMGlobal, VMMemory, VMSharedMemory, VMTable};
#[cfg(feature = "sys")]
pub use wasmer_vm::{VMFunction, VMGlobal, VMMemory, VMSharedMemory, VMTable};
// Needed for tunables customization (those are public types now) // Needed for tunables customization (those are public types now)
#[cfg(feature = "sys")] #[cfg(feature = "sys")]
pub use wasmer_vm::{ pub use wasmer_vm::{
// An extra one for VMMemory implementors // An extra one for VMMemory implementors
LinearMemory, LinearMemory,
VMFunction,
VMGlobal,
VMMemory,
VMMemoryDefinition, VMMemoryDefinition,
VMSharedMemory,
VMTable,
VMTableDefinition, VMTableDefinition,
}; };

View File

@@ -12,7 +12,7 @@ use futures::Future;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tracing::*; use tracing::*;
#[cfg(feature = "sys")] #[cfg(feature = "sys")]
use wasmer::WasmerCompilerEngine; use wasmer::NativeEngineExt;
use wasmer::{FunctionEnvMut, Instance, Memory, Module, Store}; use wasmer::{FunctionEnvMut, Instance, Memory, Module, Store};
use wasmer_wasi_types::wasi::{Errno, ExitCode}; use wasmer_wasi_types::wasi::{Errno, ExitCode};

View File

@@ -6,13 +6,8 @@ use std::{pin::Pin, time::Duration};
use ::tokio::runtime::Handle; use ::tokio::runtime::Handle;
use futures::Future; use futures::Future;
use wasmer::MemoryType;
#[cfg(feature = "js")]
use wasmer::VMMemory;
#[cfg(not(target_family = "wasm"))]
use wasmer::vm::VMMemory; use wasmer::vm::VMMemory;
use wasmer::MemoryType;
#[cfg(feature = "sys")] #[cfg(feature = "sys")]
use wasmer_types::MemoryStyle; use wasmer_types::MemoryStyle;

View File

@@ -4,7 +4,7 @@ use derivative::Derivative;
use rand::Rng; use rand::Rng;
use tracing::{trace, warn}; use tracing::{trace, warn};
#[cfg(feature = "sys")] #[cfg(feature = "sys")]
use wasmer::WasmerCompilerEngine; use wasmer::NativeEngineExt;
use wasmer::{ use wasmer::{
AsStoreMut, AsStoreRef, FunctionEnvMut, Global, Instance, Memory, MemoryView, Module, AsStoreMut, AsStoreRef, FunctionEnvMut, Global, Instance, Memory, MemoryView, Module,
TypedFunction, TypedFunction,

View File

@@ -1,10 +1,7 @@
use super::*; use super::*;
use crate::syscalls::*; use crate::syscalls::*;
#[cfg(feature = "sys")]
use wasmer::vm::VMMemory; use wasmer::vm::VMMemory;
#[cfg(feature = "js")]
use wasmer::VMMemory;
/// ### `proc_fork()` /// ### `proc_fork()`
/// Forks the current process into a new subprocess. If the function /// Forks the current process into a new subprocess. If the function

View File

@@ -1,10 +1,7 @@
use super::*; use super::*;
use crate::syscalls::*; use crate::syscalls::*;
#[cfg(feature = "sys")]
use wasmer::vm::VMMemory; use wasmer::vm::VMMemory;
#[cfg(feature = "js")]
use wasmer::VMMemory;
/// ### `thread_spawn()` /// ### `thread_spawn()`
/// Creates a new thread by spawning that shares the same /// Creates a new thread by spawning that shares the same