Skip to content

Commit

Permalink
Rename UniversalEngine to Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
epilys committed Jul 20, 2022
1 parent e463f92 commit 9147f76
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 90 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ path = "examples/early_exit.rs"
required-features = ["cranelift"]

[[example]]
name = "engine-universal"
path = "examples/engine_universal.rs"
name = "engine"
path = "examples/engine.rs"
required-features = ["cranelift"]

[[example]]
Expand Down
13 changes: 6 additions & 7 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,17 @@ example.

### Engines

1. [**Universal engine**][engine-universal], explains what an engine is, what the
Universal engine is, and how to set it up. The example completes itself
with the compilation of the Wasm module, its instantiation, and
finally, by calling an exported function.
1. [**Engine**][engine], explains what an engine is and how to set it up. The
example completes itself with the compilation of the Wasm module, its
instantiation, and finally, by calling an exported function.

_Keywords_: Universal, engine, in-memory, executable code.
_Keywords_: engine, in-memory, executable code.

<details>
<summary><em>Execute the example</em></summary>

```shell
$ cargo run --example engine-universal --release --features "cranelift"
$ cargo run --example engine --release --features "cranelift"
```

</details>
Expand Down Expand Up @@ -358,7 +357,7 @@ example.
</details>
[hello-world]: ./hello_world.rs
[engine-universal]: ./engine_universal.rs
[engine]: ./engine.rs
[engine-headless]: ./engine_headless.rs
[compiler-singlepass]: ./compiler_singlepass.rs
[compiler-cranelift]: ./compiler_cranelift.rs
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/deterministic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
use wasm_smith::{Config, ConfiguredModule};
use wasmer::{CompilerConfig, Module, Store, UniversalEngine};
use wasmer::{CompilerConfig, Engine, Module, Store};
use wasmer_compiler::Universal;
use wasmer_compiler_cranelift::Cranelift;
use wasmer_compiler_llvm::LLVM;
Expand All @@ -23,7 +23,7 @@ impl Config for NoImportsConfig {
}
}

fn compile_and_compare(name: &str, engine: UniversalEngine, wasm: &[u8]) {
fn compile_and_compare(name: &str, engine: Engine, wasm: &[u8]) {
let store = Store::new_with_engine(&engine);

// compile for first time
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub use wasmer_compiler_cranelift::{Cranelift, CraneliftOptLevel};
pub use wasmer_compiler_llvm::{LLVMOptLevel, LLVM};

#[cfg(feature = "universal")]
pub use wasmer_compiler::{Universal, UniversalArtifact, UniversalEngine};
pub use wasmer_compiler::{Engine, Universal, UniversalArtifact};

/// Version number of this crate.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down
18 changes: 9 additions & 9 deletions lib/api/src/sys/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::sys::tunables::BaseTunables;
use std::fmt;
use std::sync::{Arc, RwLock};
use wasmer_compiler::CompilerConfig;
use wasmer_compiler::{Tunables, Universal, UniversalEngine};
use wasmer_compiler::{Engine, Tunables, Universal};
use wasmer_vm::{init_traps, TrapHandler, TrapHandlerFn};

use wasmer_vm::StoreObjects;
Expand All @@ -12,7 +12,7 @@ use wasmer_vm::StoreObjects;
/// wrap the actual context in a box.
pub(crate) struct StoreInner {
pub(crate) objects: StoreObjects,
pub(crate) engine: Arc<UniversalEngine>,
pub(crate) engine: Arc<Engine>,
pub(crate) tunables: Box<dyn Tunables + Send + Sync>,
pub(crate) trap_handler: Option<Box<TrapHandlerFn<'static>>>,
}
Expand All @@ -29,7 +29,7 @@ pub(crate) struct StoreInner {
/// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#store>
pub struct Store {
pub(crate) inner: Box<StoreInner>,
engine: Arc<UniversalEngine>,
engine: Arc<Engine>,
trap_handler: Arc<RwLock<Option<Box<TrapHandlerFn<'static>>>>>,
}

Expand All @@ -41,7 +41,7 @@ impl Store {
}

/// Creates a new `Store` with a specific [`Engine`].
pub fn new_with_engine(engine: &UniversalEngine) -> Self {
pub fn new_with_engine(engine: &Engine) -> Self {
Self::new_with_tunables(engine, BaseTunables::for_target(engine.target()))
}

Expand All @@ -52,7 +52,7 @@ impl Store {

/// Creates a new `Store` with a specific [`Engine`] and [`Tunables`].
pub fn new_with_tunables(
engine: &UniversalEngine,
engine: &Engine,
tunables: impl Tunables + Send + Sync + 'static,
) -> Self {
// Make sure the signal handlers are installed.
Expand All @@ -77,7 +77,7 @@ impl Store {
}

/// Returns the [`Engine`].
pub fn engine(&self) -> &Arc<UniversalEngine> {
pub fn engine(&self) -> &Arc<Engine> {
&self.engine
}

Expand Down Expand Up @@ -139,7 +139,7 @@ impl Default for Store {
}

#[allow(unreachable_code, unused_mut)]
fn get_engine(mut config: impl CompilerConfig + 'static) -> UniversalEngine {
fn get_engine(mut config: impl CompilerConfig + 'static) -> Engine {
cfg_if::cfg_if! {
if #[cfg(feature = "default-universal")] {
wasmer_compiler::Universal::new(config)
Expand Down Expand Up @@ -195,7 +195,7 @@ impl<'a> StoreRef<'a> {
}

/// Returns the [`Engine`].
pub fn engine(&self) -> &Arc<UniversalEngine> {
pub fn engine(&self) -> &Arc<Engine> {
&self.inner.engine
}

Expand Down Expand Up @@ -228,7 +228,7 @@ impl<'a> StoreMut<'a> {
}

/// Returns the [`Engine`].
pub fn engine(&self) -> &Arc<UniversalEngine> {
pub fn engine(&self) -> &Arc<Engine> {
&self.inner.engine
}

Expand Down
12 changes: 6 additions & 6 deletions lib/c-api/src/wasm_c_api/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::error::update_last_error;
use cfg_if::cfg_if;
use std::sync::Arc;
#[cfg(feature = "universal")]
use wasmer_compiler::{Universal, UniversalEngine};
use wasmer_compiler::{Engine, Universal};

/// Kind of compilers that can be used by the engines.
///
Expand Down Expand Up @@ -262,7 +262,7 @@ pub extern "C" fn wasm_config_set_engine(config: &mut wasm_config_t, engine: was
/// cbindgen:ignore
#[repr(C)]
pub struct wasm_engine_t {
pub(crate) inner: Arc<UniversalEngine>,
pub(crate) inner: Arc<Engine>,
}

#[cfg(feature = "compiler")]
Expand Down Expand Up @@ -295,7 +295,7 @@ cfg_if! {
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
let compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
let engine: Arc<UniversalEngine> = Arc::new(Universal::new(compiler_config).engine());
let engine: Arc<Engine> = Arc::new(Universal::new(compiler_config).engine());
Box::new(wasm_engine_t { inner: engine })
}
} else if #[cfg(feature = "universal")] {
Expand All @@ -308,7 +308,7 @@ cfg_if! {
/// cbindgen:ignore
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
let engine: Arc<UniversalEngine> = Arc::new(Universal::headless().engine());
let engine: Arc<Engine> = Arc::new(Universal::headless().engine());
Box::new(wasm_engine_t { inner: engine })
}
} else {
Expand Down Expand Up @@ -421,7 +421,7 @@ pub extern "C" fn wasm_engine_new_with_config(
#[cfg(not(feature = "universal"))]
return return_with_error("Wasmer has not been compiled with the `universal` feature.");
#[cfg(feature = "universal")]
let inner: Arc<UniversalEngine> =
let inner: Arc<Engine> =
{
let mut builder = Universal::new(compiler_config);

Expand All @@ -437,7 +437,7 @@ pub extern "C" fn wasm_engine_new_with_config(
};
Some(Box::new(wasm_engine_t { inner }))
} else {
let inner: Arc<UniversalEngine> =
let inner: Arc<Engine> =
cfg_if! {
if #[cfg(feature = "universal")] {
let mut builder = Universal::headless();
Expand Down
16 changes: 6 additions & 10 deletions lib/cli-compiler/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::string::ToString;
#[allow(unused_imports)]
use std::sync::Arc;
use structopt::StructOpt;
use wasmer_compiler::UniversalEngineBuilder;
use wasmer_compiler::EngineBuilder;
use wasmer_compiler::{CompilerConfig, Features};
use wasmer_types::{MemoryStyle, MemoryType, Pages, PointerWidth, TableStyle, TableType, Target};

Expand Down Expand Up @@ -172,10 +172,9 @@ impl CompilerOptions {
&self,
target: Target,
compiler_config: Box<dyn CompilerConfig>,
) -> Result<UniversalEngineBuilder> {
) -> Result<EngineBuilder> {
let features = self.get_features(compiler_config.default_features_for_target(&target))?;
let engine: UniversalEngineBuilder =
UniversalEngineBuilder::new(Some(compiler_config.compiler()), features);
let engine: EngineBuilder = EngineBuilder::new(Some(compiler_config.compiler()), features);

Ok(engine)
}
Expand Down Expand Up @@ -358,11 +357,8 @@ impl ToString for CompilerType {
}

impl StoreOptions {
/// Get a UniversalEngineBulder for the Target
pub fn get_engine_for_target(
&self,
target: Target,
) -> Result<(UniversalEngineBuilder, CompilerType)> {
/// Get a EngineBulder for the Target
pub fn get_engine_for_target(&self, target: Target) -> Result<(EngineBuilder, CompilerType)> {
let (compiler_config, compiler_type) = self.compiler.get_compiler_config()?;
let engine = self.get_engine_with_compiler(target, compiler_config)?;
Ok((engine, compiler_type))
Expand All @@ -372,7 +368,7 @@ impl StoreOptions {
&self,
target: Target,
compiler_config: Box<dyn CompilerConfig>,
) -> Result<UniversalEngineBuilder> {
) -> Result<EngineBuilder> {
self.compiler.get_engine_by_type(target, compiler_config)
}

Expand Down
11 changes: 5 additions & 6 deletions lib/cli/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ impl CompilerOptions {
&self,
target: Target,
compiler_config: Box<dyn CompilerConfig>,
) -> Result<Box<UniversalEngine>> {
) -> Result<Box<Engine>> {
let features = self.get_features(compiler_config.default_features_for_target(&target))?;
let engine: Box<UniversalEngine> = Box::new(
let engine: Box<Engine> = Box::new(
wasmer_compiler::Universal::new(compiler_config)
.features(features)
.target(target)
Expand Down Expand Up @@ -321,7 +321,7 @@ impl StoreOptions {
&self,
target: Target,
compiler_config: Box<dyn CompilerConfig>,
) -> Result<Box<UniversalEngine>> {
) -> Result<Box<Engine>> {
let engine = self.compiler.get_engine(target, compiler_config)?;

Ok(engine)
Expand All @@ -331,9 +331,8 @@ impl StoreOptions {
// If we don't have a compiler, but we have an engine
#[cfg(not(feature = "compiler"))]
impl StoreOptions {
fn get_engine_headless(&self) -> Result<Arc<UniversalEngine>> {
let engine: Arc<UniversalEngine> =
Arc::new(wasmer_compiler::Universal::headless().engine());
fn get_engine_headless(&self) -> Result<Arc<Engine>> {
let engine: Arc<Engine> = Arc::new(wasmer_compiler::Universal::headless().engine());
Ok(engine)
}

Expand Down
13 changes: 5 additions & 8 deletions lib/compiler/src/engine/universal/artifact.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Define `UniversalArtifact`, based on `UniversalArtifactBuild`
//! to allow compiling and instantiating to be done as separate steps.
use super::engine::{UniversalEngine, UniversalEngineInner};
use super::engine::{Engine, EngineInner};
use crate::engine::universal::link::link_module;
use crate::ArtifactCreate;
use crate::Features;
Expand Down Expand Up @@ -39,7 +39,7 @@ impl UniversalArtifact {
/// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated.
#[cfg(feature = "universal_engine")]
pub fn new(
engine: &UniversalEngine,
engine: &Engine,
data: &[u8],
tunables: &dyn Tunables,
) -> Result<Self, CompileError> {
Expand Down Expand Up @@ -71,7 +71,7 @@ impl UniversalArtifact {

/// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated.
#[cfg(not(feature = "universal_engine"))]
pub fn new(_engine: &UniversalEngine, _data: &[u8]) -> Result<Self, CompileError> {
pub fn new(_engine: &Engine, _data: &[u8]) -> Result<Self, CompileError> {
Err(CompileError::Codegen(
"Compilation is not enabled in the engine".to_string(),
))
Expand All @@ -82,10 +82,7 @@ impl UniversalArtifact {
/// # Safety
/// This function is unsafe because rkyv reads directly without validating
/// the data.
pub unsafe fn deserialize(
engine: &UniversalEngine,
bytes: &[u8],
) -> Result<Self, DeserializeError> {
pub unsafe fn deserialize(engine: &Engine, bytes: &[u8]) -> Result<Self, DeserializeError> {
if !UniversalArtifactBuild::is_deserializable(bytes) {
return Err(DeserializeError::Incompatible(
"The provided bytes are not wasmer-universal".to_string(),
Expand All @@ -102,7 +99,7 @@ impl UniversalArtifact {

/// Construct a `UniversalArtifactBuild` from component parts.
pub fn from_parts(
engine_inner: &mut UniversalEngineInner,
engine_inner: &mut EngineInner,
artifact: UniversalArtifactBuild,
) -> Result<Self, CompileError> {
let module_info = artifact.create_module_info();
Expand Down
16 changes: 8 additions & 8 deletions lib/compiler/src/engine/universal/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::UniversalEngine;
use super::Engine;
use crate::{CompilerConfig, Features};
use wasmer_types::Target;

Expand Down Expand Up @@ -44,24 +44,24 @@ impl Universal {
self
}

/// Build the `UniversalEngine` for this configuration
/// Build the `Engine` for this configuration
#[cfg(feature = "universal_engine")]
pub fn engine(self) -> UniversalEngine {
pub fn engine(self) -> Engine {
let target = self.target.unwrap_or_default();
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();
UniversalEngine::new(compiler, target, features)
Engine::new(compiler, target, features)
} else {
UniversalEngine::headless()
Engine::headless()
}
}

/// Build the `UniversalEngine` for this configuration
/// Build the `Engine` for this configuration
#[cfg(not(feature = "universal_engine"))]
pub fn engine(self) -> UniversalEngine {
UniversalEngine::headless()
pub fn engine(self) -> Engine {
Engine::headless()
}
}
Loading

0 comments on commit 9147f76

Please sign in to comment.