Skip to content

Commit b5272a5

Browse files
authored
Don't use fully-qualified paths for wasmtime_environ::error::* (#12221)
* Don't use fully-qualified paths for `wasmtime_environ::error::*` Use the types via the `wasmtime_environ::prelude` instead. Follow up to #12204 * Fix unwinder build without cranelift feature
1 parent bbd12e9 commit b5272a5

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

crates/cranelift/src/compiler.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use wasmtime_environ::{
3838
DefinedFuncIndex, FlagValue, FrameInstPos, FrameStackShape, FrameStateSlotBuilder,
3939
FrameTableBuilder, FuncKey, FunctionBodyData, FunctionLoc, HostCall, InliningCompiler,
4040
ModuleTranslation, ModuleTypesBuilder, PtrSize, StackMapSection, StaticModuleIndex,
41-
TrapEncodingBuilder, TrapSentinel, TripleExt, Tunables, WasmFuncType, WasmValType,
41+
TrapEncodingBuilder, TrapSentinel, TripleExt, Tunables, WasmFuncType, WasmValType, prelude::*,
4242
};
4343
use wasmtime_unwinder::ExceptionTableBuilder;
4444

@@ -815,11 +815,7 @@ impl wasmtime_environ::Compiler for Compiler {
815815
}
816816

817817
impl InliningCompiler for Compiler {
818-
fn calls(
819-
&self,
820-
func_body: &CompiledFunctionBody,
821-
calls: &mut wasmtime_environ::prelude::IndexSet<FuncKey>,
822-
) -> Result<()> {
818+
fn calls(&self, func_body: &CompiledFunctionBody, calls: &mut IndexSet<FuncKey>) -> Result<()> {
823819
debug_assert!(!func_body.code.is::<CompiledFunction>());
824820
debug_assert!(func_body.code.is::<Option<CompilerContext>>());
825821
let cx = func_body
@@ -1579,7 +1575,7 @@ fn clif_to_env_exception_tables<'a>(
15791575
builder: &mut ExceptionTableBuilder,
15801576
range: Range<u64>,
15811577
call_sites: impl Iterator<Item = FinalizedMachCallSite<'a>>,
1582-
) -> wasmtime_environ::error::Result<()> {
1578+
) -> Result<()> {
15831579
builder.add_func(CodeOffset::try_from(range.start).unwrap(), call_sites)
15841580
}
15851581

@@ -1591,7 +1587,7 @@ fn clif_to_env_frame_tables<'a>(
15911587
tag_sites: impl Iterator<Item = MachBufferDebugTagList<'a>>,
15921588
frame_layout: &MachBufferFrameLayout,
15931589
frame_descriptors: &HashMap<FuncKey, Vec<u8>>,
1594-
) -> wasmtime_environ::error::Result<()> {
1590+
) -> Result<()> {
15951591
let mut frame_descriptor_indices = HashMap::new();
15961592
for tag_site in tag_sites {
15971593
// Split into frames; each has three debug tags.
@@ -1647,7 +1643,7 @@ fn clif_to_env_breakpoints(
16471643
range: Range<u64>,
16481644
breakpoint_patches: impl Iterator<Item = (u32, Range<u32>)>,
16491645
patch_table: &mut Vec<(u32, Range<u32>)>,
1650-
) -> wasmtime_environ::error::Result<()> {
1646+
) -> Result<()> {
16511647
patch_table.extend(breakpoint_patches.map(|(wasm_pc, offset_range)| {
16521648
let start = offset_range.start + u32::try_from(range.start).unwrap();
16531649
let end = offset_range.end + u32::try_from(range.start).unwrap();

crates/cranelift/src/debug/transform/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use synthetic::ModuleSyntheticUnit;
1111
use thiserror::Error;
1212
use wasmtime_environ::error::Error;
1313
use wasmtime_environ::{
14-
DefinedFuncIndex, ModuleTranslation, PrimaryMap, StaticModuleIndex, Tunables,
14+
DefinedFuncIndex, ModuleTranslation, PrimaryMap, StaticModuleIndex, Tunables, prelude::*,
1515
};
1616

1717
pub use address_transform::AddressTransform;
@@ -54,11 +54,11 @@ pub(crate) struct DebugInputContext<'a> {
5454
fn load_dwp<'data>(
5555
translation: ModuleTranslation<'data>,
5656
buffer: &'data [u8],
57-
) -> wasmtime_environ::error::Result<DwarfPackage<gimli::EndianSlice<'data, gimli::LittleEndian>>> {
57+
) -> Result<DwarfPackage<gimli::EndianSlice<'data, gimli::LittleEndian>>> {
5858
let endian_slice = gimli::EndianSlice::new(buffer, LittleEndian);
5959

6060
let dwarf_package = DwarfPackage::load(
61-
|id| -> wasmtime_environ::error::Result<_> {
61+
|id| -> Result<_> {
6262
let slice = match id {
6363
gimli::SectionId::DebugAbbrev => {
6464
translation.debuginfo.dwarf.debug_abbrev.reader().slice()

crates/cranelift/src/debug/write_debuginfo.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ use cranelift_codegen::isa::{
55
TargetIsa,
66
unwind::{CfaUnwindInfo, UnwindInfo},
77
};
8-
use gimli::write::{Address, Dwarf, EndianVec, FrameTable, Result, Sections, Writer};
8+
use gimli::write::{
9+
Address, Dwarf, EndianVec, FrameTable, Result as WriteResult, Sections, Writer,
10+
};
911
use gimli::{RunTimeEndian, SectionId};
12+
use wasmtime_environ::error::Result as EnvResult;
1013

1114
pub struct DwarfSection {
1215
pub name: &'static str,
@@ -32,7 +35,7 @@ fn emit_dwarf_sections(
3235
isa: &dyn TargetIsa,
3336
mut dwarf: Dwarf,
3437
frames: Option<FrameTable>,
35-
) -> wasmtime_environ::error::Result<Vec<DwarfSection>> {
38+
) -> EnvResult<Vec<DwarfSection>> {
3639
let endian = match isa.endianness() {
3740
Endianness::Little => RunTimeEndian::Little,
3841
Endianness::Big => RunTimeEndian::Big,
@@ -48,7 +51,7 @@ fn emit_dwarf_sections(
4851
}
4952

5053
let mut result = Vec::new();
51-
sections.for_each_mut(|id, s| -> wasmtime_environ::error::Result<()> {
54+
sections.for_each_mut(|id, s| -> EnvResult<()> {
5255
let name = id.name();
5356
let body = s.writer.take();
5457
if body.is_empty() {
@@ -80,15 +83,15 @@ impl Writer for WriterRelocate {
8083
self.writer.len()
8184
}
8285

83-
fn write(&mut self, bytes: &[u8]) -> Result<()> {
86+
fn write(&mut self, bytes: &[u8]) -> WriteResult<()> {
8487
self.writer.write(bytes)
8588
}
8689

87-
fn write_at(&mut self, offset: usize, bytes: &[u8]) -> Result<()> {
90+
fn write_at(&mut self, offset: usize, bytes: &[u8]) -> WriteResult<()> {
8891
self.writer.write_at(offset, bytes)
8992
}
9093

91-
fn write_address(&mut self, address: Address, size: u8) -> Result<()> {
94+
fn write_address(&mut self, address: Address, size: u8) -> WriteResult<()> {
9295
match address {
9396
Address::Constant(val) => self.write_udata(val, size),
9497
Address::Symbol { symbol, addend } => {
@@ -104,7 +107,7 @@ impl Writer for WriterRelocate {
104107
}
105108
}
106109

107-
fn write_offset(&mut self, val: usize, section: SectionId, size: u8) -> Result<()> {
110+
fn write_offset(&mut self, val: usize, section: SectionId, size: u8) -> WriteResult<()> {
108111
let offset = self.len() as u32;
109112
let target = DwarfSectionRelocTarget::Section(section.name());
110113
self.relocs.push(DwarfSectionReloc {
@@ -122,7 +125,7 @@ impl Writer for WriterRelocate {
122125
val: usize,
123126
section: SectionId,
124127
size: u8,
125-
) -> Result<()> {
128+
) -> WriteResult<()> {
126129
let target = DwarfSectionRelocTarget::Section(section.name());
127130
self.relocs.push(DwarfSectionReloc {
128131
target,
@@ -165,7 +168,7 @@ fn create_frame_table(
165168
pub fn emit_dwarf(
166169
isa: &dyn TargetIsa,
167170
compilation: &mut Compilation<'_>,
168-
) -> wasmtime_environ::error::Result<Vec<DwarfSection>> {
171+
) -> EnvResult<Vec<DwarfSection>> {
169172
let dwarf = transform_dwarf(isa, compilation)?;
170173
let frame_table = create_frame_table(isa, compilation);
171174
let sections = emit_dwarf_sections(isa, dwarf, frame_table)?;

crates/fiber/src/nostd.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ use alloc::boxed::Box;
3131
use alloc::{vec, vec::Vec};
3232
use core::cell::Cell;
3333
use core::ops::Range;
34+
use wasmtime_environ::prelude::*;
3435

3536
// The no_std implementation is infallible in practice, but we use
3637
// `wasmtime_environ::error::Error` here absent any better alternative.
37-
pub type Error = wasmtime_environ::error::Error;
38+
pub use wasmtime_environ::error::Error;
3839

3940
pub struct FiberStack {
4041
base: BasePtr,
@@ -133,7 +134,7 @@ impl Fiber {
133134
// On unsupported platforms `wasmtime_fiber_init` is a panicking shim so
134135
// return an error saying the host architecture isn't supported instead.
135136
if !SUPPORTED_ARCH {
136-
wasmtime_environ::error::bail!("fibers unsupported on this host architecture");
137+
bail!("fibers unsupported on this host architecture");
137138
}
138139
unsafe {
139140
let data = Box::into_raw(Box::new(func)).cast();

crates/unwinder/src/exception_table.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use alloc::vec::Vec;
1919
use cranelift_codegen::{
2020
ExceptionContextLoc, FinalizedMachCallSite, FinalizedMachExceptionHandler, binemit::CodeOffset,
2121
};
22+
use wasmtime_environ::prelude::*;
2223

2324
/// Collector struct for exception handlers per call site.
2425
///
@@ -127,7 +128,7 @@ impl ExceptionTableBuilder {
127128
&mut self,
128129
start_offset: CodeOffset,
129130
call_sites: impl Iterator<Item = FinalizedMachCallSite<'a>>,
130-
) -> wasmtime_environ::error::Result<()> {
131+
) -> Result<()> {
131132
// Ensure that we see functions in offset order.
132133
assert!(start_offset >= self.last_start_offset);
133134
self.last_start_offset = start_offset;
@@ -252,37 +253,36 @@ pub struct ExceptionHandler {
252253
impl<'a> ExceptionTable<'a> {
253254
/// Parse exception tables from a byte-slice as produced by
254255
/// [`ExceptionTableBuilder::serialize`].
255-
pub fn parse(data: &'a [u8]) -> wasmtime_environ::error::Result<ExceptionTable<'a>> {
256+
pub fn parse(data: &'a [u8]) -> Result<ExceptionTable<'a>> {
256257
let mut data = Bytes(data);
257-
let callsite_count = data.read::<U32Bytes<LittleEndian>>().map_err(|_| {
258-
wasmtime_environ::error::anyhow!("Unable to read callsite count prefix")
259-
})?;
258+
let callsite_count = data
259+
.read::<U32Bytes<LittleEndian>>()
260+
.map_err(|_| anyhow!("Unable to read callsite count prefix"))?;
260261
let callsite_count = usize::try_from(callsite_count.get(LittleEndian))?;
261262
let handler_count = data
262263
.read::<U32Bytes<LittleEndian>>()
263-
.map_err(|_| wasmtime_environ::error::anyhow!("Unable to read handler count prefix"))?;
264+
.map_err(|_| anyhow!("Unable to read handler count prefix"))?;
264265
let handler_count = usize::try_from(handler_count.get(LittleEndian))?;
265266
let (callsites, data) =
266267
object::slice_from_bytes::<U32Bytes<LittleEndian>>(data.0, callsite_count)
267-
.map_err(|_| wasmtime_environ::error::anyhow!("Unable to read callsites slice"))?;
268+
.map_err(|_| anyhow!("Unable to read callsites slice"))?;
268269
let (frame_offsets, data) =
269-
object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, callsite_count).map_err(
270-
|_| wasmtime_environ::error::anyhow!("Unable to read frame_offsets slice"),
271-
)?;
270+
object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, callsite_count)
271+
.map_err(|_| anyhow!("Unable to read frame_offsets slice"))?;
272272
let (ranges, data) =
273273
object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, callsite_count)
274-
.map_err(|_| wasmtime_environ::error::anyhow!("Unable to read ranges slice"))?;
274+
.map_err(|_| anyhow!("Unable to read ranges slice"))?;
275275
let (tags, data) = object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, handler_count)
276-
.map_err(|_| wasmtime_environ::error::anyhow!("Unable to read tags slice"))?;
276+
.map_err(|_| anyhow!("Unable to read tags slice"))?;
277277
let (contexts, data) =
278278
object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, handler_count)
279-
.map_err(|_| wasmtime_environ::error::anyhow!("Unable to read contexts slice"))?;
279+
.map_err(|_| anyhow!("Unable to read contexts slice"))?;
280280
let (handlers, data) =
281281
object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, handler_count)
282-
.map_err(|_| wasmtime_environ::error::anyhow!("Unable to read handlers slice"))?;
282+
.map_err(|_| anyhow!("Unable to read handlers slice"))?;
283283

284284
if !data.is_empty() {
285-
wasmtime_environ::error::bail!("Unexpected data at end of serialized exception table");
285+
bail!("Unexpected data at end of serialized exception table");
286286
}
287287

288288
Ok(ExceptionTable {

0 commit comments

Comments
 (0)