Skip to content
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
2 changes: 1 addition & 1 deletion crates/wasmtime/src/compile/code_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'a> CodeBuilder<'a> {
let wasm = self
.wasm
.as_deref()
.ok_or_else(|| anyhow!("no wasm bytes have been configured"))?;
.ok_or_else(|| format_err!("no wasm bytes have been configured"))?;

#[cfg(not(feature = "compile-time-builtins"))]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ impl<'a> CodeBuilder<'a> {
main_wasm: &'b [u8],
) -> Result<crate::hash_set::HashSet<&'b str>, Error> {
let intrinsics_import = self.unsafe_intrinsics_import.as_deref().ok_or_else(|| {
anyhow!("must configure the unsafe-intrinsics import when using compile-time builtins")
format_err!(
"must configure the unsafe-intrinsics import when using compile-time builtins"
)
})?;

let mut instance_imports = crate::hash_set::HashSet::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ impl Engine {

pub(crate) fn try_compiler(&self) -> Result<&dyn wasmtime_environ::Compiler> {
self.compiler()
.ok_or_else(|| anyhow!("Engine was not configured with a compiler"))
.ok_or_else(|| format_err!("Engine was not configured with a compiler"))
}

/// Ahead-of-time (AOT) compiles a WebAssembly module.
Expand Down
8 changes: 4 additions & 4 deletions crates/wasmtime/src/engine/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ pub fn check_compatible(engine: &Engine, mmap: &[u8], expected: ObjectKind) -> R

let data = obj
.section_by_name(obj::ELF_WASM_ENGINE)
.ok_or_else(|| anyhow!("failed to find section `{}`", obj::ELF_WASM_ENGINE))?
.ok_or_else(|| format_err!("failed to find section `{}`", obj::ELF_WASM_ENGINE))?
.data()
.map_err(obj::ObjectCrateErrorWrapper)?;
let (first, data) = data
.split_first()
.ok_or_else(|| anyhow!("invalid engine section"))?;
.ok_or_else(|| format_err!("invalid engine section"))?;
if *first != VERSION {
bail!("mismatched version in engine section");
}
let (len, data) = data
.split_first()
.ok_or_else(|| anyhow!("invalid engine section"))?;
.ok_or_else(|| format_err!("invalid engine section"))?;
let len = usize::from(*len);
let (version, data) = if data.len() < len + 1 {
bail!("engine section too small")
Expand Down Expand Up @@ -202,7 +202,7 @@ impl Metadata<'_> {
fn check_triple(&self, engine: &Engine) -> Result<()> {
let engine_target = engine.target();
let module_target =
target_lexicon::Triple::from_str(&self.target).map_err(|e| anyhow!(e))?;
target_lexicon::Triple::from_str(&self.target).map_err(|e| format_err!(e))?;

if module_target.architecture != engine_target.architecture {
bail!(
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ extern crate std;
extern crate alloc;

pub(crate) mod prelude {
pub use crate::error::{Context, Error, Result, anyhow, bail, ensure, format_err};
pub use crate::error::{Context, Error, Result, bail, ensure, format_err};
pub use wasmtime_environ::prelude::*;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/code_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl CodeMemory {
published: false,
registered: false,
enable_branch_protection: enable_branch_protection
.ok_or_else(|| anyhow!("missing `{}` section", obj::ELF_WASM_BTI))?,
.ok_or_else(|| format_err!("missing `{}` section", obj::ELF_WASM_BTI))?,
needs_executable,
#[cfg(feature = "debug-builtins")]
has_native_debug_info,
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/component/func/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ where
// Exiting the component is disallowed, for example, when the `realloc`
// function calls a canonical import.
if unsafe { !flags.may_leave() } {
return Err(anyhow!(crate::Trap::CannotLeaveComponent));
return Err(format_err!(crate::Trap::CannotLeaveComponent));
}

if opts.async_ {
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/component/func/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ fn lower_string<T>(cx: &mut LowerContext<'_, T>, string: &str) -> Result<(usize,
let worst_case = bytes
.len()
.checked_mul(2)
.ok_or_else(|| anyhow!("byte length overflow"))?;
.ok_or_else(|| format_err!("byte length overflow"))?;
if worst_case > MAX_STRING_BYTE_LENGTH {
bail!("byte length too large");
}
Expand Down Expand Up @@ -1853,7 +1853,7 @@ where
let size = list
.len()
.checked_mul(elem_size)
.ok_or_else(|| anyhow!("size overflow copying a list"))?;
.ok_or_else(|| format_err!("size overflow copying a list"))?;
let ptr = cx.realloc(0, 0, T::ALIGN32, size)?;
T::linear_store_list_to_memory(cx, ty, ptr, list)?;
Ok((ptr, list.len()))
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/component/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl Instance {
{
let f = self
.get_func(store.as_context_mut(), name)
.ok_or_else(|| anyhow!("failed to find function export"))?;
.ok_or_else(|| format_err!("failed to find function export"))?;
Ok(f.typed::<Params, Results>(store)
.with_context(|| format!("failed to convert function to given type"))?)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/component/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl TypeChecker<'_> {
let idx = actual
.exports
.get(name)
.ok_or_else(|| anyhow!("module export `{name}` not defined"))?;
.ok_or_else(|| format_err!("module export `{name}` not defined"))?;
let actual = actual.type_of(*idx);
matching::entity_ty(self.engine, expected, &actual)
.with_context(|| format!("module export `{name}` has the wrong type"))?;
Expand All @@ -136,7 +136,7 @@ impl TypeChecker<'_> {
let expected = expected
.imports
.get(&(module.to_string(), name.to_string()))
.ok_or_else(|| anyhow!("module import `{module}::{name}` not defined"))?;
.ok_or_else(|| format_err!("module import `{module}::{name}` not defined"))?;
matching::entity_ty(self.engine, &actual, expected)
.with_context(|| format!("module import `{module}::{name}` has the wrong type"))?;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/component/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ fn load_variant(
}
};
let case_ty = types.nth(discriminant as usize).ok_or_else(|| {
anyhow!(
format_err!(
"discriminant {} out of range [0..{})",
discriminant,
types.len()
Expand Down Expand Up @@ -989,7 +989,7 @@ fn lift_variant(
let discriminant = next(src).get_u32();
let ty = types
.nth(discriminant as usize)
.ok_or_else(|| anyhow!("discriminant {discriminant} out of range [0..{len})"))?;
.ok_or_else(|| format_err!("discriminant {discriminant} out of range [0..{len})"))?;
let (value, value_flat) = match ty {
Some(ty) => (
Some(Box::new(Val::lift(cx, ty, src)?)),
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/gc/enabled/rooting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mod sealed {
/// objects that have been unrooted.
fn try_gc_ref<'a>(&self, store: &'a StoreOpaque) -> Result<&'a VMGcRef> {
self.get_gc_ref(store).ok_or_else(|| {
anyhow!("attempted to use a garbage-collected object that has been unrooted")
format_err!("attempted to use a garbage-collected object that has been unrooted")
})
}

Expand Down Expand Up @@ -314,7 +314,7 @@ impl GcRootIndex {
/// Panics if `self` is not associated with the given store.
pub(crate) fn try_gc_ref<'a>(&self, store: &'a StoreOpaque) -> Result<&'a VMGcRef> {
self.get_gc_ref(store).ok_or_else(|| {
anyhow!("attempted to use a garbage-collected object that has been unrooted")
format_err!("attempted to use a garbage-collected object that has been unrooted")
})
}

Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ impl Instance {
let f = self
.get_export(store.as_context_mut(), name)
.and_then(|f| f.into_func())
.ok_or_else(|| anyhow!("failed to find function export `{name}`"))?;
.ok_or_else(|| format_err!("failed to find function export `{name}`"))?;
Ok(f.typed::<Params, Results>(store)
.with_context(|| format!("failed to convert function `{name}` to given type"))?)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl<T> Linker<T> {
if let Err(import_err) = self._get_by_import(&import) {
let default_extern =
import_err.ty().default_value(&mut store).with_context(|| {
anyhow!(
format_err!(
"no default value exists for `{}::{}` with type `{:?}`",
import.module(),
import.name(),
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/native_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn relocate_dwarf_sections(bytes: &mut [u8], code_region: (*const u8, usize)) ->
.try_into()
.ok()
.and_then(|offset| object::from_bytes_mut::<U64Bytes<NE>>(&mut bytes[offset..]).ok())
.ok_or_else(|| anyhow!("invalid dwarf relocations"))?;
.ok_or_else(|| format_err!("invalid dwarf relocations"))?;
loc.set(NE, value);
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/store/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl StoreOpaque {
heap.memory
.grow(delta_pages_for_alloc, limiter)
.await?
.ok_or_else(|| anyhow!("failed to grow GC heap"))?;
.ok_or_else(|| format_err!("failed to grow GC heap"))?;
}
heap.store.vm_store_context.gc_heap = heap.memory.vmmemory();

Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/trampoline/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl RuntimeMemoryCreator for MemoryCreatorProxy {
usize::try_from(tunables.memory_guard_size).unwrap(),
)
.map(|mem| Box::new(LinearMemoryProxy { mem }) as Box<dyn RuntimeLinearMemory>)
.map_err(|e| anyhow!(e))
.map_err(|e| format_err!(e))
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,7 @@ impl FuncType {
.results()
.map(|ty| ty.default_value())
.collect::<Option<Vec<_>>>()
.ok_or_else(|| anyhow!("function results do not have a default value"))?;
.ok_or_else(|| format_err!("function results do not have a default value"))?;
Ok(Func::new(&mut store, self.clone(), move |_, _, results| {
for (slot, dummy) in results.iter_mut().zip(dummy_results.iter()) {
*slot = *dummy;
Expand Down Expand Up @@ -3000,7 +3000,7 @@ impl GlobalType {
let val = self
.content()
.default_value()
.ok_or_else(|| anyhow!("global type has no default value"))?;
.ok_or_else(|| format_err!("global type has no default value"))?;
RuntimeGlobal::new(store, self.clone(), val)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/types/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn entity_ty(engine: &Engine, expected: &EntityType, actual: &EntityType) ->
}

fn concrete_type_mismatch(msg: &str, expected: &WasmSubType, actual: &WasmSubType) -> crate::Error {
anyhow!("{msg}: expected type `{expected}`, found type `{actual}`")
format_err!("{msg}: expected type `{expected}`, found type `{actual}`")
}

fn global_ty(engine: &Engine, expected: &Global, actual: &Global) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions crates/wasmtime/src/runtime/vm/component/libcalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ unsafe fn utf8_to_utf8(
let dst = unsafe { slice::from_raw_parts_mut(dst, len) };
assert_no_overlap(src, dst);
log::trace!("utf8-to-utf8 {len}");
let src = core::str::from_utf8(src).map_err(|_| anyhow!("invalid utf8 encoding"))?;
let src = core::str::from_utf8(src).map_err(|_| format_err!("invalid utf8 encoding"))?;
dst.copy_from_slice(src.as_bytes());
Ok(())
}
Expand Down Expand Up @@ -222,7 +222,7 @@ unsafe fn utf16_to_utf16(
fn run_utf16_to_utf16(src: &[u16], mut dst: &mut [u16]) -> Result<bool> {
let mut all_latin1 = true;
for ch in core::char::decode_utf16(src.iter().map(|i| u16::from_le(*i))) {
let ch = ch.map_err(|_| anyhow!("invalid utf16 encoding"))?;
let ch = ch.map_err(|_| format_err!("invalid utf16 encoding"))?;
all_latin1 = all_latin1 && u8::try_from(u32::from(ch)).is_ok();
let result = ch.encode_utf16(dst);
let size = result.len();
Expand Down Expand Up @@ -305,7 +305,7 @@ unsafe fn utf8_to_utf16(
}

fn run_utf8_to_utf16(src: &[u8], dst: &mut [u16]) -> Result<usize> {
let src = core::str::from_utf8(src).map_err(|_| anyhow!("invalid utf8 encoding"))?;
let src = core::str::from_utf8(src).map_err(|_| format_err!("invalid utf8 encoding"))?;
let mut amt = 0;
for (i, dst) in src.encode_utf16().zip(dst) {
*dst = i.to_le();
Expand Down Expand Up @@ -358,7 +358,7 @@ unsafe fn utf16_to_utf8(
let mut dst_written = 0;

for ch in core::char::decode_utf16(src_iter) {
let ch = ch.map_err(|_| anyhow!("invalid utf16 encoding"))?;
let ch = ch.map_err(|_| format_err!("invalid utf16 encoding"))?;

// If the destination doesn't have enough space for this character
// then the loop is ended and this function will be called later with a
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/vm/const_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl ConstExprEvaluator {

fn pop(&mut self) -> Result<Val> {
self.stack.pop().ok_or_else(|| {
anyhow!(
format_err!(
"const expr evaluation error: attempted to pop from an empty \
evaluation stack"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl PoolingInstanceAllocator {
pagemap: match config.pagemap_scan {
Enabled::Auto => PageMap::new(),
Enabled::Yes => Some(PageMap::new().ok_or_else(|| {
anyhow!(
format_err!(
"required to enable PAGEMAP_SCAN but this system \
does not support it"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl GcHeapPool {
.alloc()
.map(|slot| GcHeapAllocationIndex(slot.0))
.ok_or_else(|| {
anyhow!(
format_err!(
"maximum concurrent GC heap limit of {} reached",
self.max_gc_heaps
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl TablePool {
let table_size = HostAlignedByteCount::new_rounded_up(
crate::runtime::vm::table::NOMINAL_MAX_TABLE_ELEM_SIZE
.checked_mul(config.limits.table_elements)
.ok_or_else(|| anyhow!("table size exceeds addressable memory"))?,
.ok_or_else(|| format_err!("table size exceeds addressable memory"))?,
)?;

let max_total_tables = usize::try_from(config.limits.total_tables).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Mmap {
.metadata()
.context("failed to get file metadata")?
.len();
let len = usize::try_from(len).map_err(|_| anyhow!("file too large to map"))?;
let len = usize::try_from(len).map_err(|_| format_err!("file too large to map"))?;

// Create a file mapping that allows PAGE_EXECUTE_WRITECOPY.
// This enables up-to these permissions but we won't leave all
Expand Down