Remove some custom error types in Wasmtime (#5347)

* Remove some custom error types in Wasmtime

These types are mostly cumbersome to work with nowadays that `anyhow` is
used everywhere else. This commit removes `InstantiationError` and
`SetupError` in favor of using `anyhow::Error` throughout. This can
eventually culminate in creation of specific errors for embedders to
downcast to but for now this should be general enough.

* Fix Windows build
This commit is contained in:
Alex Crichton
2022-12-01 14:47:10 -06:00
committed by GitHub
parent 4510a4a805
commit e0b9663e44
13 changed files with 129 additions and 266 deletions

View File

@@ -5,13 +5,13 @@ use crate::{
AsContextMut, Engine, Export, Extern, Func, Global, Memory, Module, SharedMemory,
StoreContextMut, Table, TypedFunc,
};
use anyhow::{anyhow, bail, Context, Error, Result};
use anyhow::{anyhow, bail, Context, Result};
use std::mem;
use std::sync::Arc;
use wasmtime_environ::{EntityType, FuncIndex, GlobalIndex, MemoryIndex, PrimaryMap, TableIndex};
use wasmtime_runtime::{
Imports, InstanceAllocationRequest, InstantiationError, StorePtr, VMContext, VMFunctionBody,
VMFunctionImport, VMGlobalImport, VMMemoryImport, VMOpaqueContext, VMTableImport,
Imports, InstanceAllocationRequest, StorePtr, VMContext, VMFunctionBody, VMFunctionImport,
VMGlobalImport, VMMemoryImport, VMOpaqueContext, VMTableImport,
};
/// An instantiated WebAssembly module.
@@ -317,20 +317,11 @@ impl Instance {
// items from this instance into other instances should be ok when
// those items are loaded and run we'll have all the metadata to
// look at them.
store
.engine()
.allocator()
.initialize(
&mut instance_handle,
compiled_module.module(),
store.engine().config().features.bulk_memory,
)
.map_err(|e| -> Error {
match e {
InstantiationError::Trap(trap) => trap.into(),
other => other.into(),
}
})?;
store.engine().allocator().initialize(
&mut instance_handle,
compiled_module.module(),
store.engine().config().features.bulk_memory,
)?;
Ok((instance, compiled_module.module().start_func))
}

View File

@@ -8,8 +8,8 @@ use std::sync::Arc;
use wasmtime_environ::{EntityIndex, MemoryPlan, MemoryStyle, Module, WASM_PAGE_SIZE};
use wasmtime_runtime::{
allocate_single_memory_instance, DefaultMemoryCreator, Imports, InstanceAllocationRequest,
InstantiationError, Memory, MemoryImage, RuntimeLinearMemory, RuntimeMemoryCreator,
SharedMemory, StorePtr, VMMemoryDefinition,
Memory, MemoryImage, RuntimeLinearMemory, RuntimeMemoryCreator, SharedMemory, StorePtr,
VMMemoryDefinition,
};
/// Create a "frankenstein" instance with a single memory.
@@ -48,8 +48,7 @@ pub fn create_memory(
.as_mut()
.expect("the store pointer cannot be null here")
};
Memory::new_dynamic(&plan, creator, store, None)
.map_err(|err| InstantiationError::Resource(err.into()))?
Memory::new_dynamic(&plan, creator, store, None)?
}
};