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 = [
"wasmer-compiler/translator",
"wasmer-compiler/compiler",
"std",
]
sys-default = ["sys", "wat", "cranelift"]
# - 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 {
fn from(inner: engine_imp::Engine) -> Self {
Self(inner)

View File

@@ -4,43 +4,6 @@ use thiserror::Error;
#[cfg(feature = "sys")]
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.
///
/// 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
/// start function, and an error when initializing the user's
/// host environments.
#[derive(Error, Debug)]
#[derive(Debug)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum InstantiationError {
/// A linking ocurred during instantiation.
#[error(transparent)]
#[cfg_attr(feature = "std", error(transparent))]
Link(LinkError),
/// A runtime error occured while invoking the start function
#[error(transparent)]
#[cfg_attr(feature = "std", error(transparent))]
Start(RuntimeError),
/// The module was compiled with a CPU feature that is not available on
/// the current host.
#[error("missing required CPU features: {0:?}")]
#[cfg_attr(feature = "std", error("missing required CPU features: {0:?}"))]
CpuFeature(String),
/// Import from a different Store.
/// Import from a different [`Store`].
/// 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,
/// Import from a different Store.
/// 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,
}
#[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
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>
where
T: Any + Send + Sync + 'static + Sized,
{
unimplemented!();
unimplemented!("ExternRef is not yet supported in Javascript");
}
pub(crate) fn vm_externref(&self) -> VMExternRef {
unimplemented!();
unimplemented!("ExternRef is not yet supported in Javascript");
}
pub(crate) unsafe fn from_vm_externref(
store: &mut impl AsStoreMut,
vm_externref: VMExternRef,
) -> Self {
unimplemented!();
unimplemented!("ExternRef is not yet supported in Javascript");
}
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {

View File

@@ -237,7 +237,8 @@ impl Module {
bytes: impl IntoBytes,
) -> Result<Self, DeserializeError> {
#[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"))]
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
pub type VMSharedMemory = VMMemory;
/// The VM Global type
#[derive(Clone, Debug, PartialEq)]
pub struct VMGlobal {
pub(crate) global: JsGlobal,
@@ -125,6 +126,7 @@ impl VMGlobal {
unsafe impl Send for VMGlobal {}
unsafe impl Sync for VMGlobal {}
/// The VM Table type
#[derive(Clone, Debug, PartialEq)]
pub struct VMTable {
pub(crate) table: JsTable,
@@ -138,11 +140,14 @@ impl VMTable {
pub(crate) fn new(table: JsTable, ty: TableType) -> Self {
Self { table, ty }
}
/// Get the table size at runtime
pub fn get_runtime_size(&self) -> u32 {
self.table.length()
}
}
/// The VM Function type
#[derive(Clone)]
pub struct VMFunction {
pub(crate) function: JsFunction,

View File

@@ -13,7 +13,7 @@ use wasmer_vm::init_traps;
pub use wasmer_vm::TrapHandlerFn;
#[cfg(feature = "sys")]
use crate::sys::WasmerCompilerEngine;
use crate::sys::NativeEngineExt;
#[cfg(feature = "sys")]
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
/// engine.
pub trait WasmerCompilerEngine {
pub trait NativeEngineExt {
/// Create a new `Engine` with the given config
#[cfg(feature = "compiler")]
fn new(compiler_config: Box<dyn CompilerConfig>, target: Target, features: Features) -> Self;
@@ -95,7 +95,7 @@ pub trait WasmerCompilerEngine {
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 {
crate::engine::Engine(Engine::new(compiler_config, target, features))
}

View File

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

View File

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

View File

@@ -6,7 +6,7 @@ pub(crate) mod module;
mod tunables;
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 target_lexicon::{Architecture, CallingConvention, OperatingSystem, Triple, HOST};
#[cfg(feature = "compiler")]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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