Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the stack-machine wasmi engine backend #818

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 1 addition & 38 deletions crates/cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use anyhow::{bail, Context, Error, Result};
use anyhow::{Context, Error, Result};
use clap::Parser;
use std::{
ffi::OsStr,
net::SocketAddr,
path::{Path, PathBuf},
str::FromStr,
};
use wasmi::EngineBackend;
use wasmi_wasi::{ambient_authority, Dir, TcpListener, WasiCtx, WasiCtxBuilder};

/// A CLI flag value key-value argument.
Expand Down Expand Up @@ -37,23 +36,6 @@ impl FromStr for KeyValue {
}
}

/// A `wasmi` [`EngineBackend`].
#[derive(Debug, Clone)]
pub struct ExecutionEngine(EngineBackend);

impl FromStr for ExecutionEngine {
type Err = Error;

fn from_str(argument: &str) -> Result<Self, Self::Err> {
let engine = match argument {
"stack-machine" => ExecutionEngine(EngineBackend::StackMachine),
"register-machine" => ExecutionEngine(EngineBackend::RegisterMachine),
_ => bail!("invalid execution engine: {argument}"),
};
Ok(engine)
}
}

/// The `wasmi` CLI application arguments.
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None, trailing_var_arg = true)]
Expand Down Expand Up @@ -106,20 +88,6 @@ pub struct Args {
#[clap(long = "fuel", value_name = "N")]
fuel: Option<u64>,

/// Tells `wasmi` which execution engine to use. (EXPERIMENTAL / UNSTABLE)
///
/// Valid Arguments:
///
/// - stack-machine (default)
///
/// - register-machine
#[clap(
long = "engine",
value_name = "ENGINE",
value_parser(ExecutionEngine::from_str)
)]
engine: Option<ExecutionEngine>,

/// Arguments given to the Wasm module or the invoked function.
#[clap(value_name = "ARGS")]
func_args: Vec<String>,
Expand All @@ -146,11 +114,6 @@ impl Args {
self.fuel
}

/// Returns the execution engine given to the CLI app if any.
pub fn engine(&self) -> Option<EngineBackend> {
self.engine.as_ref().map(|engine| engine.0)
}

/// Pre-opens all directories given in `--dir` and returns them for use by the [`WasiCtx`].
///
/// # Errors
Expand Down
10 changes: 2 additions & 8 deletions crates/cli/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils;
use anyhow::{anyhow, Error};
use std::path::Path;
use wasmi::{Config, EngineBackend, ExternType, Func, FuncType, Instance, Module, Store};
use wasmi::{Config, ExternType, Func, FuncType, Instance, Module, Store};
use wasmi_wasi::WasiCtx;

/// The [`Context`] for the `wasmi` CLI application.
Expand All @@ -23,14 +23,8 @@ impl Context {
///
/// - If parsing, validating, compiling or instantiating the Wasm module failed.
/// - If adding WASI defintions to the linker failed.
pub fn new(
wasm_file: &Path,
wasi_ctx: WasiCtx,
fuel: Option<u64>,
engine: EngineBackend,
) -> Result<Self, Error> {
pub fn new(wasm_file: &Path, wasi_ctx: WasiCtx, fuel: Option<u64>) -> Result<Self, Error> {
let mut config = Config::default();
config.set_engine_backend(engine);
if fuel.is_some() {
config.consume_fuel(true);
}
Expand Down
3 changes: 1 addition & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ fn main() -> Result<()> {
let args = Args::parse();
let wasm_file = args.wasm_file();
let wasi_ctx = args.wasi_context()?;
let engine = args.engine().unwrap_or_default();
let mut ctx = Context::new(wasm_file, wasi_ctx, args.fuel(), engine)?;
let mut ctx = Context::new(wasm_file, wasi_ctx, args.fuel())?;
let (func_name, func) = get_invoked_func(&args, &ctx)?;
let ty = func.ty(ctx.store());
let func_args = utils::decode_func_args(&ty, args.func_args())?;
Expand Down
3 changes: 1 addition & 2 deletions crates/wasmi/benches/bench/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{fs::File, io::Read as _};
use wasmi::{Config, EngineBackend, StackLimits};
use wasmi::{Config, StackLimits};

/// Returns the Wasm binary at the given `file_name` as `Vec<u8>`.
///
Expand All @@ -25,7 +25,6 @@ pub fn bench_config() -> Config {
let mut config = Config::default();
config.wasm_tail_call(true);
config.set_stack_limits(StackLimits::new(1024, 1024 * 1024, 64 * 1024).unwrap());
config.set_engine_backend(EngineBackend::RegisterMachine);
config
}

Expand Down
Loading
Loading