Moved tunables into Store

This commit is contained in:
Syrus
2020-06-18 12:56:38 -07:00
parent 83203a849b
commit 5273fa0cae
18 changed files with 118 additions and 167 deletions

View File

@@ -1,8 +1,7 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use test_utils::get_compiler_config_from_str;
use wasmer::*;
use wasmer_engine_jit::JITEngine;
use wasmer_engine_jit::JIT;
static BASIC_WAT: &str = r#"(module
(func $multiply (import "env" "multiply") (param i32 i32) (result i32))
@@ -151,19 +150,19 @@ pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Cr
fn run_static_benchmarks(c: &mut Criterion) {
#[cfg(feature = "llvm")]
{
let store = test_utils::get_default_llvm_store();
let store = Store::new(&JIT::new(&wasmer_compiler_llvm::LLVM::new()).engine());
run_basic_static_function(&store, "llvm", c);
}
#[cfg(feature = "cranelift")]
{
let store = test_utils::get_default_cranelift_store();
let store = Store::new(&JIT::new(&wasmer_compiler_cranelift::Cranelift::new()).engine());
run_basic_static_function(&store, "cranelift", c);
}
#[cfg(feature = "singlepass")]
{
let store = test_utils::get_default_singlepass_store();
let store = Store::new(&JIT::new(&wasmer_compiler_singlepass::Singlepass::new()).engine());
run_basic_static_function(&store, "singlepass", c);
}
}
@@ -171,19 +170,19 @@ fn run_static_benchmarks(c: &mut Criterion) {
fn run_dynamic_benchmarks(c: &mut Criterion) {
#[cfg(feature = "llvm")]
{
let store = test_utils::get_default_llvm_store();
let store = Store::new(&JIT::new(&wasmer_compiler_llvm::LLVM::new()).engine());
run_basic_dynamic_function(&store, "llvm", c);
}
#[cfg(feature = "cranelift")]
{
let store = test_utils::get_default_cranelift_store();
let store = Store::new(&JIT::new(&wasmer_compiler_cranelift::Cranelift::new()).engine());
run_basic_dynamic_function(&store, "cranelift", c);
}
#[cfg(feature = "singlepass")]
{
let store = test_utils::get_default_singlepass_store();
let store = Store::new(&JIT::new(&wasmer_compiler_singlepass::Singlepass::new()).engine());
run_basic_dynamic_function(&store, "singlepass", c);
}
}

View File

@@ -19,7 +19,7 @@ pub struct Memory {
impl Memory {
pub fn new(store: &Store, ty: MemoryType) -> Result<Memory, MemoryError> {
let tunables = store.engine().tunables();
let tunables = store.tunables();
let memory_plan = tunables.memory_plan(ty);
let memory = tunables.create_memory(memory_plan)?;

View File

@@ -33,7 +33,7 @@ impl Table {
/// All the elements in the table will be set to the `init` value.
pub fn new(store: &Store, ty: TableType, init: Val) -> Result<Table, RuntimeError> {
let item = init.into_checked_anyfunc(store)?;
let tunables = store.engine().tunables();
let tunables = store.tunables();
let table_plan = tunables.table_plan(ty);
let table = tunables
.create_table(table_plan)

View File

@@ -8,7 +8,7 @@ use thiserror::Error;
use wasmer_compiler::CompileError;
#[cfg(feature = "wat")]
use wasmer_compiler::WasmError;
use wasmer_engine::{Artifact, DeserializeError, Resolver, SerializeError};
use wasmer_engine::{Artifact, DeserializeError, Resolver, SerializeError, Tunables as _};
use wasmer_runtime::{ExportsIterator, ImportsIterator, InstanceHandle, ModuleInfo};
#[derive(Error, Debug)]
@@ -156,7 +156,7 @@ impl Module {
}
fn compile(store: &Store, binary: &[u8]) -> Result<Self, CompileError> {
let artifact = store.engine().compile(binary)?;
let artifact = store.engine().compile(binary, store.tunables())?;
Ok(Self::from_artifact(store, artifact))
}
@@ -261,11 +261,9 @@ impl Module {
resolver: &dyn Resolver,
) -> Result<InstanceHandle, InstantiationError> {
unsafe {
let instance_handle = self.artifact.instantiate(
self.store.engine().tunables(),
resolver,
Box::new(()),
)?;
let instance_handle =
self.artifact
.instantiate(self.store.tunables(), resolver, Box::new(()))?;
// After the instance handle is created, we need to initialize
// the data, call the start function and so. However, if any

View File

@@ -1,7 +1,7 @@
#[cfg(all(feature = "compiler", feature = "engine"))]
use crate::tunables::Tunables;
#[cfg(all(feature = "compiler", feature = "engine"))]
use wasmer_compiler::CompilerConfig;
use wasmer_engine::Tunables as BaseTunables;
use std::sync::Arc;
use wasmer_engine::Engine;
@@ -9,6 +9,7 @@ use wasmer_engine::Engine;
#[derive(Clone)]
pub struct Store {
engine: Arc<dyn Engine + Send + Sync>,
tunables: Arc<dyn BaseTunables + Send + Sync>,
}
impl Store {
@@ -18,9 +19,27 @@ impl Store {
{
Store {
engine: engine.cloned(),
tunables: Arc::new(Tunables::for_target(engine.target())),
}
}
pub fn new_with_tunables<E>(
engine: &E,
tunables: impl BaseTunables + Send + Sync + 'static,
) -> Store
where
E: Engine + ?Sized,
{
Store {
engine: engine.cloned(),
tunables: Arc::new(tunables),
}
}
pub fn tunables(&self) -> &dyn BaseTunables {
self.tunables.as_ref()
}
pub fn engine(&self) -> &Arc<dyn Engine + Send + Sync> {
&self.engine
}
@@ -63,11 +82,9 @@ impl Default for Store {
cfg_if::cfg_if! {
if #[cfg(feature = "default-jit")] {
wasmer_engine_jit::JIT::new(&config)
.tunables(Tunables::for_target)
.engine()
} else if #[cfg(feature = "default-native")] {
wasmer_engine_native::Native::new(&config)
.tunables(Tunables::for_target)
.engine()
} else {
compile_error!("No default engine chosen")
@@ -77,8 +94,10 @@ impl Default for Store {
let config = get_config();
let engine = get_engine(config);
let tunables = Tunables::for_target(engine.target());
Store {
engine: Arc::new(engine),
tunables: Arc::new(tunables),
}
}
}

View File

@@ -18,6 +18,7 @@ use wasmer_compiler::{CompileError, Features, Triple};
use wasmer_compiler::{CompileModuleInfo, ModuleEnvironment};
use wasmer_engine::{
register_frame_info, Artifact, DeserializeError, GlobalFrameInfoRegistration, SerializeError,
Tunables,
};
#[cfg(feature = "compiler")]
use wasmer_engine::{Engine, SerializableFunctionFrameInfo};
@@ -43,10 +44,13 @@ impl JITArtifact {
/// Compile a data buffer into a `JITArtifact`, which may then be instantiated.
#[cfg(feature = "compiler")]
pub fn new(jit: &JITEngine, data: &[u8]) -> Result<Self, CompileError> {
pub fn new(
jit: &JITEngine,
data: &[u8],
tunables: &dyn Tunables,
) -> Result<Self, CompileError> {
let environ = ModuleEnvironment::new();
let mut inner_jit = jit.inner_mut();
let tunables = jit.tunables();
let features = inner_jit.features();
let translation = environ.translate(data).map_err(CompileError::Wasm)?;
@@ -75,7 +79,7 @@ impl JITArtifact {
// Compile the Module
let compilation = compiler.compile_module(
&inner_jit.target(),
&jit.target(),
&compile_info,
translation.module_translation.as_ref().unwrap(),
translation.function_body_inputs,

View File

@@ -1,12 +1,10 @@
use crate::JITEngine;
use std::sync::Arc;
use wasmer_compiler::{Compiler, CompilerConfig, Features, Target};
use wasmer_engine::Tunables;
/// The JIT builder
pub struct JIT<'a> {
compiler_config: Option<&'a dyn CompilerConfig>,
tunables_fn: Option<Box<Fn(&Target) -> Box<dyn Tunables + Send + Sync>>>,
target: Option<Target>,
features: Option<Features>,
}
@@ -17,7 +15,6 @@ impl<'a> JIT<'a> {
Self {
compiler_config: Some(compiler_config),
target: None,
tunables_fn: None,
features: None,
}
}
@@ -27,7 +24,6 @@ impl<'a> JIT<'a> {
Self {
compiler_config: None,
target: None,
tunables_fn: None,
features: None,
}
}
@@ -38,20 +34,6 @@ impl<'a> JIT<'a> {
self
}
/// Set the tunables constructor function.
///
/// It should receive a [`Target`] and return a
pub fn tunables<F, T>(mut self, tunables_fn: F) -> Self
where
F: Fn(&Target) -> T + 'static,
T: Tunables + Send + Sync + 'static
{
self.tunables_fn = Some(Box::new(move |target: &Target| {
Box::new(tunables_fn(target))
}));
self
}
/// Set the features
pub fn features(mut self, features: Features) -> Self {
self.features = Some(features);
@@ -61,18 +43,14 @@ impl<'a> JIT<'a> {
/// Build the `JITEngine` for this configuration
pub fn engine(self) -> JITEngine {
let target = self.target.unwrap_or_default();
let tunables_fn = self
.tunables_fn
.expect("You need to specify tunables for the JIT");
let tunables: Arc<dyn Tunables + Send + Sync> = tunables_fn(&target).into();
if let Some(compiler_config) = self.compiler_config {
let features = self
.features
.unwrap_or_else(|| compiler_config.default_features_for_target(&target));
let compiler = compiler_config.compiler();
JITEngine::new(compiler, target, tunables, features)
JITEngine::new(compiler, target, features)
} else {
JITEngine::headless(tunables)
JITEngine::headless()
}
}
}

View File

@@ -21,19 +21,15 @@ use wasmer_runtime::{
#[derive(Clone)]
pub struct JITEngine {
inner: Arc<Mutex<JITEngineInner>>,
tunables: Arc<dyn Tunables + Send + Sync>,
/// The target for the compiler
target: Arc<Target>,
engine_id: EngineId,
}
impl JITEngine {
/// Create a new `JITEngine` with the given config
#[cfg(feature = "compiler")]
pub fn new(
compiler: Box<dyn Compiler + Send>,
target: Target,
tunables: Arc<dyn Tunables + 'static + Send + Sync>,
features: Features,
) -> Self {
pub fn new(compiler: Box<dyn Compiler + Send>, target: Target, features: Features) -> Self {
Self {
inner: Arc::new(Mutex::new(JITEngineInner {
compiler: Some(compiler),
@@ -41,9 +37,8 @@ impl JITEngine {
code_memory: CodeMemory::new(),
signatures: SignatureRegistry::new(),
features,
target: Some(target),
})),
tunables: tunables,
target: Arc::new(target),
engine_id: EngineId::default(),
}
}
@@ -61,7 +56,7 @@ impl JITEngine {
///
/// Headless engines can't compile or validate any modules,
/// they just take already processed Modules (via `Module::serialize`).
pub fn headless(tunables: Arc<dyn Tunables + 'static + Send + Sync>) -> Self {
pub fn headless() -> Self {
Self {
inner: Arc::new(Mutex::new(JITEngineInner {
#[cfg(feature = "compiler")]
@@ -70,9 +65,8 @@ impl JITEngine {
code_memory: CodeMemory::new(),
signatures: SignatureRegistry::new(),
features: Features::default(),
target: None,
})),
tunables,
target: Arc::new(Target::default()),
engine_id: EngineId::default(),
}
}
@@ -87,9 +81,9 @@ impl JITEngine {
}
impl Engine for JITEngine {
/// Get the tunables
fn tunables(&self) -> &dyn Tunables {
&*self.tunables
/// The target
fn target(&self) -> &Target {
&self.target
}
/// Register a signature
@@ -115,8 +109,12 @@ impl Engine for JITEngine {
}
/// Compile a WebAssembly binary
fn compile(&self, binary: &[u8]) -> Result<Arc<dyn Artifact>, CompileError> {
Ok(Arc::new(JITArtifact::new(&self, binary)?))
fn compile(
&self,
binary: &[u8],
tunables: &dyn Tunables,
) -> Result<Arc<dyn Artifact>, CompileError> {
Ok(Arc::new(JITArtifact::new(&self, binary, tunables)?))
}
/// Deserializes a WebAssembly module
@@ -142,8 +140,6 @@ pub struct JITEngineInner {
function_call_trampolines: HashMap<VMSharedSignatureIndex, VMTrampoline>,
/// The features to compile the Wasm module with
features: Features,
/// The target for the compiler
target: Option<Target>,
/// The code memory is responsible of publishing the compiled
/// functions to memory.
code_memory: CodeMemory,
@@ -177,11 +173,6 @@ impl JITEngineInner {
))
}
/// The target
pub fn target(&self) -> &Target {
&self.target.as_ref().unwrap()
}
/// The Wasm features
pub fn features(&self) -> &Features {
&self.features

View File

@@ -33,6 +33,7 @@ use wasmer_compiler::{CompileError, CompileModuleInfo, Features};
use wasmer_engine::Engine;
use wasmer_engine::{
Artifact, DeserializeError, InstantiationError, LinkError, RuntimeError, SerializeError,
Tunables,
};
use wasmer_runtime::{MemoryPlan, TablePlan};
use wasmer_runtime::{ModuleInfo, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline};
@@ -95,10 +96,13 @@ impl NativeArtifact {
/// Compile a data buffer into a `NativeArtifact`, which may then be instantiated.
#[cfg(feature = "compiler")]
pub fn new(engine: &NativeEngine, data: &[u8]) -> Result<Self, CompileError> {
pub fn new(
engine: &NativeEngine,
data: &[u8],
tunables: &dyn Tunables,
) -> Result<Self, CompileError> {
let environ = ModuleEnvironment::new();
let mut engine_inner = engine.inner_mut();
let tunables = engine.tunables();
let translation = environ.translate(data).map_err(CompileError::Wasm)?;
let features = engine_inner.features();
@@ -123,7 +127,7 @@ impl NativeArtifact {
};
let compiler = engine_inner.compiler()?;
let target = engine_inner.target();
let target = engine.target();
// Compile the Module
let compilation = compiler.compile_module(

View File

@@ -6,7 +6,6 @@ use wasmer_engine::Tunables;
/// The Native builder
pub struct Native<'a> {
compiler_config: Option<&'a CompilerConfig>,
tunables_fn: Option<Box<Fn(&Target) -> Box<dyn Tunables + Send + Sync>>>,
target: Option<Target>,
features: Option<Features>,
}
@@ -18,7 +17,6 @@ impl<'a> Native<'a> {
Self {
compiler_config: Some(compiler_config),
target: None,
tunables_fn: None,
features: None,
}
}
@@ -28,7 +26,6 @@ impl<'a> Native<'a> {
Self {
compiler_config: None,
target: None,
tunables_fn: None,
features: None,
}
}
@@ -39,20 +36,6 @@ impl<'a> Native<'a> {
self
}
/// Set the tunables constructor function.
///
/// It should receive a [`Target`] and return a
pub fn tunables<F, T>(mut self, tunables_fn: F) -> Self
where
F: Fn(&Target) -> T + 'static,
T: Tunables + Send + Sync + 'static
{
self.tunables_fn = Some(Box::new(move |target: &Target| {
Box::new(tunables_fn(target))
}));
self
}
/// Set the features
pub fn features(mut self, features: Features) -> Self {
self.features = Some(features);
@@ -62,18 +45,14 @@ impl<'a> Native<'a> {
/// Build the `NativeEngine` for this configuration
pub fn engine(self) -> NativeEngine {
let target = self.target.unwrap_or_default();
let tunables_fn = self
.tunables_fn
.expect("You need to specify tunables for the JIT");
let tunables: Arc<dyn Tunables + Send + Sync> = tunables_fn(&target).into();
if let Some(compiler_config) = self.compiler_config {
let features = self
.features
.unwrap_or_else(|| compiler_config.default_features_for_target(&target));
let compiler = compiler_config.compiler();
NativeEngine::new(compiler, target, tunables, features)
NativeEngine::new(compiler, target, features)
} else {
NativeEngine::headless(tunables)
NativeEngine::headless()
}
}
}

View File

@@ -16,29 +16,24 @@ use wasmer_runtime::{SignatureRegistry, VMSharedSignatureIndex, VMTrampoline};
#[derive(Clone)]
pub struct NativeEngine {
inner: Arc<Mutex<NativeEngineInner>>,
tunables: Arc<dyn Tunables + Send + Sync>,
/// The target for the compiler
target: Arc<Target>,
engine_id: EngineId,
}
impl NativeEngine {
/// Create a new `NativeEngine` with the given config
#[cfg(feature = "compiler")]
pub fn new(
compiler: Box<dyn Compiler + Send>,
target: Target,
tunables: Arc<dyn Tunables + 'static + Send + Sync>,
features: Features,
) -> Self {
pub fn new(compiler: Box<dyn Compiler + Send>, target: Target, features: Features) -> Self {
Self {
inner: Arc::new(Mutex::new(NativeEngineInner {
compiler: Some(compiler),
trampolines: HashMap::new(),
signatures: SignatureRegistry::new(),
prefixer: None,
target: Some(target),
features,
})),
tunables,
target: Arc::new(target),
engine_id: EngineId::default(),
}
}
@@ -56,7 +51,7 @@ impl NativeEngine {
///
/// Headless engines can't compile or validate any modules,
/// they just take already processed Modules (via `Module::serialize`).
pub fn headless(tunables: Arc<dyn Tunables + 'static + Send + Sync>) -> Self {
pub fn headless() -> Self {
Self {
inner: Arc::new(Mutex::new(NativeEngineInner {
#[cfg(feature = "compiler")]
@@ -64,10 +59,9 @@ impl NativeEngine {
trampolines: HashMap::new(),
signatures: SignatureRegistry::new(),
prefixer: None,
target: None,
features: Features::default(),
})),
tunables,
target: Arc::new(Target::default()),
engine_id: EngineId::default(),
}
}
@@ -100,9 +94,9 @@ impl NativeEngine {
}
impl Engine for NativeEngine {
/// Get the tunables
fn tunables(&self) -> &dyn Tunables {
&*self.tunables
/// The target
fn target(&self) -> &Target {
&self.target
}
/// Register a signature
@@ -128,8 +122,12 @@ impl Engine for NativeEngine {
}
/// Compile a WebAssembly binary
fn compile(&self, binary: &[u8]) -> Result<Arc<dyn Artifact>, CompileError> {
Ok(Arc::new(NativeArtifact::new(&self, binary)?))
fn compile(
&self,
binary: &[u8],
tunables: &dyn Tunables,
) -> Result<Arc<dyn Artifact>, CompileError> {
Ok(Arc::new(NativeArtifact::new(&self, binary, tunables)?))
}
/// Deserializes a WebAssembly module (binary content of a Shared Object file)
@@ -173,8 +171,6 @@ pub struct NativeEngineInner {
/// the functions in the shared object generated by the `NativeEngine`,
/// so we can assure no collisions.
prefixer: Option<Box<dyn Fn(&[u8]) -> String + Send>>,
/// The target for the compiler
target: Option<Target>,
}
impl NativeEngineInner {
@@ -202,11 +198,6 @@ impl NativeEngineInner {
&self.features
}
/// The target
pub fn target(&self) -> &Target {
&self.target.as_ref().unwrap()
}
/// Validate the module
#[cfg(feature = "compiler")]
pub fn validate<'data>(&self, data: &'data [u8]) -> Result<(), CompileError> {

View File

@@ -6,7 +6,7 @@ use std::path::Path;
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use std::sync::Arc;
use wasm_common::FunctionType;
use wasmer_compiler::CompileError;
use wasmer_compiler::{CompileError, Target};
use wasmer_runtime::{VMSharedSignatureIndex, VMTrampoline};
/// A unimplemented Wasmer `Engine`.
@@ -16,8 +16,8 @@ use wasmer_runtime::{VMSharedSignatureIndex, VMTrampoline};
///
/// The product that an `Engine` produces and consumes is the [`Artifact`].
pub trait Engine {
/// Get the tunables
fn tunables(&self) -> &dyn Tunables;
/// Gets the target
fn target(&self) -> &Target;
/// Register a signature
fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex;
@@ -32,7 +32,11 @@ pub trait Engine {
fn validate(&self, binary: &[u8]) -> Result<(), CompileError>;
/// Compile a WebAssembly binary
fn compile(&self, binary: &[u8]) -> Result<Arc<dyn Artifact>, CompileError>;
fn compile(
&self,
binary: &[u8],
tunables: &dyn Tunables,
) -> Result<Arc<dyn Artifact>, CompileError>;
/// Deserializes a WebAssembly module
///

View File

@@ -173,9 +173,7 @@ impl Run {
#[cfg(feature = "native")]
{
if wasmer_engine_native::NativeArtifact::is_deserializable(&contents) {
let engine = wasmer_engine_native::Native::headless()
.tunables(Tunables::for_target)
.engine();
let engine = wasmer_engine_native::Native::headless().engine();
let store = Store::new(&engine);
let module = unsafe { Module::deserialize_from_file(&store, &self.path)? };
return Ok(module);
@@ -184,9 +182,7 @@ impl Run {
#[cfg(feature = "jit")]
{
if wasmer_engine_jit::JITArtifact::is_deserializable(&contents) {
let engine = wasmer_engine_jit::JIT::headless()
.tunables(Tunables::for_target)
.engine();
let engine = wasmer_engine_jit::JIT::headless().engine();
let store = Store::new(&engine);
let module = unsafe { Module::deserialize_from_file(&store, &self.path)? };
return Ok(module);

View File

@@ -314,7 +314,6 @@ impl StoreOptions {
#[cfg(feature = "jit")]
EngineType::JIT => Box::new(
wasmer_engine_jit::JIT::new(&*compiler_config)
.tunables(Tunables::for_target)
.features(features)
.target(target)
.engine(),
@@ -322,7 +321,6 @@ impl StoreOptions {
#[cfg(feature = "native")]
EngineType::Native => Box::new(
wasmer_engine_native::Native::new(&mut *compiler_config)
.tunables(Tunables::for_target)
.target(target)
.features(features)
.engine(),
@@ -364,17 +362,9 @@ impl StoreOptions {
let engine_type = self.get_engine()?;
let engine: Arc<dyn Engine + Send + Sync> = match engine_type {
#[cfg(feature = "jit")]
EngineType::JIT => Arc::new(
wasmer_engine_jit::JIT::headless()
.tunables(Tunables::for_target)
.engine(),
),
EngineType::JIT => Arc::new(wasmer_engine_jit::JIT::headless().engine()),
#[cfg(feature = "native")]
EngineType::Native => Arc::new(
wasmer_engine_native::Native::headless()
.tunables(Tunables::for_target)
.engine(),
),
EngineType::Native => Arc::new(wasmer_engine_native::Native::headless().engine()),
#[cfg(not(all(feature = "jit", feature = "native",)))]
engine => bail!(
"The `{}` engine is not included in this binary.",

View File

@@ -30,9 +30,7 @@ pub fn get_compiler(canonicalize_nans: bool) -> impl CompilerConfig {
pub fn get_engine() -> impl Engine {
let compiler_config = get_compiler(false);
JIT::new(&compiler_config)
.tunables(Tunables::for_target)
.engine()
JIT::new(&compiler_config).engine()
}
pub fn get_store() -> Store {
@@ -46,12 +44,10 @@ pub fn get_store_with_middlewares<I: Iterator<Item = Arc<dyn FunctionMiddlewareG
for x in middlewares {
compiler_config.push_middleware(x);
}
let engine = JIT::new(&compiler_config)
.tunables(Tunables::for_target)
.engine();
let engine = JIT::new(&compiler_config).engine();
Store::new(&engine)
}
pub fn get_headless_store() -> Store {
Store::new(&JIT::headless().tunables(Tunables::for_target).engine())
Store::new(&JIT::headless().engine())
}

View File

@@ -42,12 +42,7 @@ pub fn run_wast(wast_path: &str, compiler: &str) -> anyhow::Result<()> {
#[cfg(feature = "test-singlepass")]
features.multi_value(false);
let compiler_config = get_compiler(true);
let store = Store::new(
&JIT::new(&compiler_config)
.tunables(Tunables::for_target)
.features(features)
.engine(),
);
let store = Store::new(&JIT::new(&compiler_config).features(features).engine());
// let mut native = NativeEngine::new(compiler_config, tunables);
// native.set_deterministic_prefixer(native_prefixer);
// let store = Store::new(&native);

View File

@@ -13,7 +13,7 @@ use wasm_common::{
use wasmer_compiler::CompileError;
#[cfg(feature = "compiler")]
use wasmer_compiler::ModuleEnvironment;
use wasmer_engine::{Artifact, DeserializeError, Engine as _, SerializeError};
use wasmer_engine::{Artifact, DeserializeError, Engine as _, SerializeError, Tunables};
use wasmer_runtime::{
MemoryPlan, ModuleInfo, TablePlan, VMContext, VMFunctionBody, VMSharedSignatureIndex,
};
@@ -55,9 +55,12 @@ impl DummyArtifact {
#[cfg(feature = "compiler")]
/// Compile a data buffer into a `DummyArtifact`, which may then be instantiated.
pub fn new(engine: &DummyEngine, data: &[u8]) -> Result<Self, CompileError> {
pub fn new(
engine: &DummyEngine,
data: &[u8],
tunables: &dyn Tunables,
) -> Result<Self, CompileError> {
let environ = ModuleEnvironment::new();
let tunables = engine.tunables();
let translation = environ.translate(data).map_err(CompileError::Wasm)?;

View File

@@ -3,7 +3,7 @@
use crate::DummyArtifact;
use std::sync::Arc;
use wasm_common::FunctionType;
use wasmer_compiler::{CompileError, Features};
use wasmer_compiler::{CompileError, Features, Target};
use wasmer_engine::{Artifact, DeserializeError, Engine, EngineId, Tunables};
use wasmer_runtime::{
SignatureRegistry, VMContext, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline,
@@ -22,17 +22,17 @@ extern "C" fn dummy_trampoline(
pub struct DummyEngine {
signatures: Arc<SignatureRegistry>,
features: Arc<Features>,
tunables: Arc<dyn Tunables + Send + Sync>,
target: Arc<Target>,
engine_id: EngineId,
}
impl DummyEngine {
#[cfg(feature = "compiler")]
pub fn new(tunables: impl Tunables + 'static + Send + Sync) -> Self {
pub fn new() -> Self {
Self {
signatures: Arc::new(SignatureRegistry::new()),
tunables: Arc::new(tunables),
features: Arc::new(Default::default()),
target: Arc::new(Default::default()),
engine_id: EngineId::default(),
}
}
@@ -44,8 +44,8 @@ impl DummyEngine {
impl Engine for DummyEngine {
/// Get the tunables
fn tunables(&self) -> &dyn Tunables {
&*self.tunables
fn target(&self) -> &Target {
&self.target
}
/// Register a signature
@@ -92,8 +92,12 @@ impl Engine for DummyEngine {
}
/// Compile a WebAssembly binary
fn compile(&self, binary: &[u8]) -> Result<Arc<dyn Artifact>, CompileError> {
Ok(Arc::new(DummyArtifact::new(&self, &binary)?))
fn compile(
&self,
binary: &[u8],
tunables: &dyn Tunables,
) -> Result<Arc<dyn Artifact>, CompileError> {
Ok(Arc::new(DummyArtifact::new(&self, binary, tunables)?))
}
/// Deserializes a WebAssembly module (binary content of a Shared Object file)