A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Don't use fully-qualified paths for `wasmtime_environ::error::*` (#12221)
Nick Fitzgeraldb5272a5f1030
diff --git a/crates/cranelift/src/compiler.rs b/crates/cranelift/src/compiler.rsindex 246591755c..3b75e2821d 100644--- a/crates/cranelift/src/compiler.rs+++ b/crates/cranelift/src/compiler.rs@@ -38,7 +38,7 @@ use wasmtime_environ::{DefinedFuncIndex, FlagValue, FrameInstPos, FrameStackShape, FrameStateSlotBuilder,FrameTableBuilder, FuncKey, FunctionBodyData, FunctionLoc, HostCall, InliningCompiler,ModuleTranslation, ModuleTypesBuilder, PtrSize, StackMapSection, StaticModuleIndex,- TrapEncodingBuilder, TrapSentinel, TripleExt, Tunables, WasmFuncType, WasmValType,+ TrapEncodingBuilder, TrapSentinel, TripleExt, Tunables, WasmFuncType, WasmValType, prelude::*,};use wasmtime_unwinder::ExceptionTableBuilder;@@ -815,11 +815,7 @@ impl wasmtime_environ::Compiler for Compiler {}impl InliningCompiler for Compiler {- fn calls(- &self,- func_body: &CompiledFunctionBody,- calls: &mut wasmtime_environ::prelude::IndexSet<FuncKey>,- ) -> Result<()> {+ fn calls(&self, func_body: &CompiledFunctionBody, calls: &mut IndexSet<FuncKey>) -> Result<()> {debug_assert!(!func_body.code.is::<CompiledFunction>());debug_assert!(func_body.code.is::<Option<CompilerContext>>());let cx = func_body@@ -1579,7 +1575,7 @@ fn clif_to_env_exception_tables<'a>(builder: &mut ExceptionTableBuilder,range: Range<u64>,call_sites: impl Iterator<Item = FinalizedMachCallSite<'a>>,-) -> wasmtime_environ::error::Result<()> {+) -> Result<()> {builder.add_func(CodeOffset::try_from(range.start).unwrap(), call_sites)}@@ -1591,7 +1587,7 @@ fn clif_to_env_frame_tables<'a>(tag_sites: impl Iterator<Item = MachBufferDebugTagList<'a>>,frame_layout: &MachBufferFrameLayout,frame_descriptors: &HashMap<FuncKey, Vec<u8>>,-) -> wasmtime_environ::error::Result<()> {+) -> Result<()> {let mut frame_descriptor_indices = HashMap::new();for tag_site in tag_sites {// Split into frames; each has three debug tags.@@ -1647,7 +1643,7 @@ fn clif_to_env_breakpoints(range: Range<u64>,breakpoint_patches: impl Iterator<Item = (u32, Range<u32>)>,patch_table: &mut Vec<(u32, Range<u32>)>,-) -> wasmtime_environ::error::Result<()> {+) -> Result<()> {patch_table.extend(breakpoint_patches.map(|(wasm_pc, offset_range)| {let start = offset_range.start + u32::try_from(range.start).unwrap();let end = offset_range.end + u32::try_from(range.start).unwrap();diff --git a/crates/cranelift/src/debug/transform/mod.rs b/crates/cranelift/src/debug/transform/mod.rsindex ecd3205555..1f73eb7648 100644--- a/crates/cranelift/src/debug/transform/mod.rs+++ b/crates/cranelift/src/debug/transform/mod.rs@@ -11,7 +11,7 @@ use synthetic::ModuleSyntheticUnit;use thiserror::Error;use wasmtime_environ::error::Error;use wasmtime_environ::{- DefinedFuncIndex, ModuleTranslation, PrimaryMap, StaticModuleIndex, Tunables,+ DefinedFuncIndex, ModuleTranslation, PrimaryMap, StaticModuleIndex, Tunables, prelude::*,};pub use address_transform::AddressTransform;@@ -54,11 +54,11 @@ pub(crate) struct DebugInputContext<'a> {fn load_dwp<'data>(translation: ModuleTranslation<'data>,buffer: &'data [u8],-) -> wasmtime_environ::error::Result<DwarfPackage<gimli::EndianSlice<'data, gimli::LittleEndian>>> {+) -> Result<DwarfPackage<gimli::EndianSlice<'data, gimli::LittleEndian>>> {let endian_slice = gimli::EndianSlice::new(buffer, LittleEndian);let dwarf_package = DwarfPackage::load(- |id| -> wasmtime_environ::error::Result<_> {+ |id| -> Result<_> {let slice = match id {gimli::SectionId::DebugAbbrev => {translation.debuginfo.dwarf.debug_abbrev.reader().slice()diff --git a/crates/cranelift/src/debug/write_debuginfo.rs b/crates/cranelift/src/debug/write_debuginfo.rsindex 62fa5c5a8d..2123f5c159 100644--- a/crates/cranelift/src/debug/write_debuginfo.rs+++ b/crates/cranelift/src/debug/write_debuginfo.rs@@ -5,8 +5,11 @@ use cranelift_codegen::isa::{TargetIsa,unwind::{CfaUnwindInfo, UnwindInfo},};-use gimli::write::{Address, Dwarf, EndianVec, FrameTable, Result, Sections, Writer};+use gimli::write::{+ Address, Dwarf, EndianVec, FrameTable, Result as WriteResult, Sections, Writer,+};use gimli::{RunTimeEndian, SectionId};+use wasmtime_environ::error::Result as EnvResult;pub struct DwarfSection {pub name: &'static str,@@ -32,7 +35,7 @@ fn emit_dwarf_sections(isa: &dyn TargetIsa,mut dwarf: Dwarf,frames: Option<FrameTable>,-) -> wasmtime_environ::error::Result<Vec<DwarfSection>> {+) -> EnvResult<Vec<DwarfSection>> {let endian = match isa.endianness() {Endianness::Little => RunTimeEndian::Little,Endianness::Big => RunTimeEndian::Big,@@ -48,7 +51,7 @@ fn emit_dwarf_sections(}let mut result = Vec::new();- sections.for_each_mut(|id, s| -> wasmtime_environ::error::Result<()> {+ sections.for_each_mut(|id, s| -> EnvResult<()> {let name = id.name();let body = s.writer.take();if body.is_empty() {@@ -80,15 +83,15 @@ impl Writer for WriterRelocate {self.writer.len()}- fn write(&mut self, bytes: &[u8]) -> Result<()> {+ fn write(&mut self, bytes: &[u8]) -> WriteResult<()> {self.writer.write(bytes)}- fn write_at(&mut self, offset: usize, bytes: &[u8]) -> Result<()> {+ fn write_at(&mut self, offset: usize, bytes: &[u8]) -> WriteResult<()> {self.writer.write_at(offset, bytes)}- fn write_address(&mut self, address: Address, size: u8) -> Result<()> {+ fn write_address(&mut self, address: Address, size: u8) -> WriteResult<()> {match address {Address::Constant(val) => self.write_udata(val, size),Address::Symbol { symbol, addend } => {@@ -104,7 +107,7 @@ impl Writer for WriterRelocate {}}- fn write_offset(&mut self, val: usize, section: SectionId, size: u8) -> Result<()> {+ fn write_offset(&mut self, val: usize, section: SectionId, size: u8) -> WriteResult<()> {let offset = self.len() as u32;let target = DwarfSectionRelocTarget::Section(section.name());self.relocs.push(DwarfSectionReloc {@@ -122,7 +125,7 @@ impl Writer for WriterRelocate {val: usize,section: SectionId,size: u8,- ) -> Result<()> {+ ) -> WriteResult<()> {let target = DwarfSectionRelocTarget::Section(section.name());self.relocs.push(DwarfSectionReloc {target,@@ -165,7 +168,7 @@ fn create_frame_table(pub fn emit_dwarf(isa: &dyn TargetIsa,compilation: &mut Compilation<'_>,-) -> wasmtime_environ::error::Result<Vec<DwarfSection>> {+) -> EnvResult<Vec<DwarfSection>> {let dwarf = transform_dwarf(isa, compilation)?;let frame_table = create_frame_table(isa, compilation);let sections = emit_dwarf_sections(isa, dwarf, frame_table)?;diff --git a/crates/fiber/src/nostd.rs b/crates/fiber/src/nostd.rsindex 3e824a2d73..f7ff0ee491 100644--- a/crates/fiber/src/nostd.rs+++ b/crates/fiber/src/nostd.rs@@ -31,10 +31,11 @@ use alloc::boxed::Box;use alloc::{vec, vec::Vec};use core::cell::Cell;use core::ops::Range;+use wasmtime_environ::prelude::*;// The no_std implementation is infallible in practice, but we use// `wasmtime_environ::error::Error` here absent any better alternative.-pub type Error = wasmtime_environ::error::Error;+pub use wasmtime_environ::error::Error;pub struct FiberStack {base: BasePtr,@@ -133,7 +134,7 @@ impl Fiber {// On unsupported platforms `wasmtime_fiber_init` is a panicking shim so// return an error saying the host architecture isn't supported instead.if !SUPPORTED_ARCH {- wasmtime_environ::error::bail!("fibers unsupported on this host architecture");+ bail!("fibers unsupported on this host architecture");}unsafe {let data = Box::into_raw(Box::new(func)).cast();diff --git a/crates/unwinder/src/exception_table.rs b/crates/unwinder/src/exception_table.rsindex e74c70680c..5fcc2c0561 100644--- a/crates/unwinder/src/exception_table.rs+++ b/crates/unwinder/src/exception_table.rs@@ -19,6 +19,7 @@ use alloc::vec::Vec;use cranelift_codegen::{ExceptionContextLoc, FinalizedMachCallSite, FinalizedMachExceptionHandler, binemit::CodeOffset,};+use wasmtime_environ::prelude::*;/// Collector struct for exception handlers per call site.///@@ -127,7 +128,7 @@ impl ExceptionTableBuilder {&mut self,start_offset: CodeOffset,call_sites: impl Iterator<Item = FinalizedMachCallSite<'a>>,- ) -> wasmtime_environ::error::Result<()> {+ ) -> Result<()> {// Ensure that we see functions in offset order.assert!(start_offset >= self.last_start_offset);self.last_start_offset = start_offset;@@ -252,37 +253,36 @@ pub struct ExceptionHandler {impl<'a> ExceptionTable<'a> {/// Parse exception tables from a byte-slice as produced by/// [`ExceptionTableBuilder::serialize`].- pub fn parse(data: &'a [u8]) -> wasmtime_environ::error::Result<ExceptionTable<'a>> {+ pub fn parse(data: &'a [u8]) -> Result<ExceptionTable<'a>> {let mut data = Bytes(data);- let callsite_count = data.read::<U32Bytes<LittleEndian>>().map_err(|_| {- wasmtime_environ::error::anyhow!("Unable to read callsite count prefix")- })?;+ let callsite_count = data+ .read::<U32Bytes<LittleEndian>>()+ .map_err(|_| anyhow!("Unable to read callsite count prefix"))?;let callsite_count = usize::try_from(callsite_count.get(LittleEndian))?;let handler_count = data.read::<U32Bytes<LittleEndian>>()- .map_err(|_| wasmtime_environ::error::anyhow!("Unable to read handler count prefix"))?;+ .map_err(|_| anyhow!("Unable to read handler count prefix"))?;let handler_count = usize::try_from(handler_count.get(LittleEndian))?;let (callsites, data) =object::slice_from_bytes::<U32Bytes<LittleEndian>>(data.0, callsite_count)- .map_err(|_| wasmtime_environ::error::anyhow!("Unable to read callsites slice"))?;+ .map_err(|_| anyhow!("Unable to read callsites slice"))?;let (frame_offsets, data) =- object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, callsite_count).map_err(- |_| wasmtime_environ::error::anyhow!("Unable to read frame_offsets slice"),- )?;+ object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, callsite_count)+ .map_err(|_| anyhow!("Unable to read frame_offsets slice"))?;let (ranges, data) =object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, callsite_count)- .map_err(|_| wasmtime_environ::error::anyhow!("Unable to read ranges slice"))?;+ .map_err(|_| anyhow!("Unable to read ranges slice"))?;let (tags, data) = object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, handler_count)- .map_err(|_| wasmtime_environ::error::anyhow!("Unable to read tags slice"))?;+ .map_err(|_| anyhow!("Unable to read tags slice"))?;let (contexts, data) =object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, handler_count)- .map_err(|_| wasmtime_environ::error::anyhow!("Unable to read contexts slice"))?;+ .map_err(|_| anyhow!("Unable to read contexts slice"))?;let (handlers, data) =object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, handler_count)- .map_err(|_| wasmtime_environ::error::anyhow!("Unable to read handlers slice"))?;+ .map_err(|_| anyhow!("Unable to read handlers slice"))?;if !data.is_empty() {- wasmtime_environ::error::bail!("Unexpected data at end of serialized exception table");+ bail!("Unexpected data at end of serialized exception table");}Ok(ExceptionTable {