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
14 changes: 5 additions & 9 deletions crates/cranelift/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions crates/cranelift/src/debug/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
21 changes: 12 additions & 9 deletions crates/cranelift/src/debug/write_debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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 } => {
Expand All @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down
5 changes: 3 additions & 2 deletions crates/fiber/src/nostd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
30 changes: 15 additions & 15 deletions crates/unwinder/src/exception_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down