Bump the wasm-tools crates (#3139)
* Bump the wasm-tools crates Pulls in some updates here and there, mostly for updating crates to the latest version to prepare for later memory64 work. * Update lightbeam
This commit is contained in:
@@ -2150,7 +2150,7 @@ fn translate_unreachable_operator<FE: FuncEnvironment + ?Sized>(
|
||||
fn get_heap_addr(
|
||||
heap: ir::Heap,
|
||||
addr32: ir::Value,
|
||||
offset: u32,
|
||||
offset: u64,
|
||||
width: u32,
|
||||
addr_ty: Type,
|
||||
builder: &mut FunctionBuilder,
|
||||
@@ -2160,6 +2160,9 @@ fn get_heap_addr(
|
||||
|
||||
let offset_guard_size: u64 = builder.func.heaps[heap].offset_guard_size.into();
|
||||
|
||||
// Currently this function only supports 32-bit memories.
|
||||
let offset = u32::try_from(offset).unwrap();
|
||||
|
||||
// How exactly the bounds check is performed here and what it's performed
|
||||
// on is a bit tricky. Generally we want to rely on access violations (e.g.
|
||||
// segfaults) to generate traps since that means we don't have to bounds
|
||||
@@ -2239,12 +2242,12 @@ fn prepare_load<FE: FuncEnvironment + ?Sized>(
|
||||
state: &mut FuncTranslationState,
|
||||
environ: &mut FE,
|
||||
) -> WasmResult<(MemFlags, Value, Offset32)> {
|
||||
let addr32 = state.pop1();
|
||||
let addr = state.pop1();
|
||||
|
||||
let heap = state.get_heap(builder.func, memarg.memory, environ)?;
|
||||
let (base, offset) = get_heap_addr(
|
||||
heap,
|
||||
addr32,
|
||||
addr,
|
||||
memarg.offset,
|
||||
loaded_bytes,
|
||||
environ.pointer_type(),
|
||||
@@ -2335,11 +2338,14 @@ fn fold_atomic_mem_addr(
|
||||
) -> Value {
|
||||
let access_ty_bytes = access_ty.bytes();
|
||||
let final_lma = if memarg.offset > 0 {
|
||||
// Note that 32-bit memories are only supported here at this time, the
|
||||
// logic here (e.g. the `iadd_imm` will need to check for overflow and
|
||||
// other bits and pieces for 64-bit memories.
|
||||
assert!(builder.func.dfg.value_type(linear_mem_addr) == I32);
|
||||
let linear_mem_addr = builder.ins().uextend(I64, linear_mem_addr);
|
||||
let a = builder
|
||||
.ins()
|
||||
.iadd_imm(linear_mem_addr, i64::from(memarg.offset));
|
||||
.iadd_imm(linear_mem_addr, i64::try_from(memarg.offset).unwrap());
|
||||
let cflags = builder.ins().ifcmp_imm(a, 0x1_0000_0000i64);
|
||||
builder.ins().trapif(
|
||||
IntCC::UnsignedGreaterThanOrEqual,
|
||||
@@ -2374,10 +2380,14 @@ fn finalise_atomic_mem_addr<FE: FuncEnvironment + ?Sized>(
|
||||
environ: &mut FE,
|
||||
) -> WasmResult<Value> {
|
||||
// Check the alignment of `linear_mem_addr`.
|
||||
//
|
||||
// Note that the `iadd_imm` here and the `try_from` only works for 32-bit
|
||||
// memories.
|
||||
let access_ty_bytes = access_ty.bytes();
|
||||
assert!(builder.func.dfg.value_type(linear_mem_addr) == I32);
|
||||
let final_lma = builder
|
||||
.ins()
|
||||
.iadd_imm(linear_mem_addr, i64::from(memarg.offset));
|
||||
.iadd_imm(linear_mem_addr, i64::try_from(memarg.offset).unwrap());
|
||||
if access_ty_bytes != 1 {
|
||||
assert!(access_ty_bytes == 2 || access_ty_bytes == 4 || access_ty_bytes == 8);
|
||||
let final_lma_misalignment = builder
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
use crate::state::FuncTranslationState;
|
||||
use crate::translation_utils::{
|
||||
DataIndex, ElemIndex, EntityIndex, EntityType, Event, EventIndex, FuncIndex, Global,
|
||||
GlobalIndex, InstanceIndex, InstanceTypeIndex, Memory, MemoryIndex, ModuleIndex,
|
||||
ModuleTypeIndex, SignatureIndex, Table, TableIndex, TypeIndex,
|
||||
DataIndex, ElemIndex, EntityIndex, EntityType, FuncIndex, Global, GlobalIndex, InstanceIndex,
|
||||
InstanceTypeIndex, Memory, MemoryIndex, ModuleIndex, ModuleTypeIndex, SignatureIndex, Table,
|
||||
TableIndex, Tag, TagIndex, TypeIndex,
|
||||
};
|
||||
use core::convert::From;
|
||||
use core::convert::TryFrom;
|
||||
@@ -771,15 +771,15 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
|
||||
field: Option<&'data str>,
|
||||
) -> WasmResult<()>;
|
||||
|
||||
/// Declares an event import to the environment.
|
||||
fn declare_event_import(
|
||||
/// Declares an tag import to the environment.
|
||||
fn declare_tag_import(
|
||||
&mut self,
|
||||
event: Event,
|
||||
tag: Tag,
|
||||
module: &'data str,
|
||||
field: Option<&'data str>,
|
||||
) -> WasmResult<()> {
|
||||
drop((event, module, field));
|
||||
Err(WasmError::Unsupported("wasm events".to_string()))
|
||||
drop((tag, module, field));
|
||||
Err(WasmError::Unsupported("wasm tags".to_string()))
|
||||
}
|
||||
|
||||
/// Declares a global import to the environment.
|
||||
@@ -844,16 +844,16 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
|
||||
/// Declares a memory to the environment
|
||||
fn declare_memory(&mut self, memory: Memory) -> WasmResult<()>;
|
||||
|
||||
/// Provides the number of defined events up front. By default this does nothing, but
|
||||
/// Provides the number of defined tags up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_events(&mut self, _num: u32) -> WasmResult<()> {
|
||||
fn reserve_tags(&mut self, _num: u32) -> WasmResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Declares an event to the environment
|
||||
fn declare_event(&mut self, event: Event) -> WasmResult<()> {
|
||||
drop(event);
|
||||
Err(WasmError::Unsupported("wasm events".to_string()))
|
||||
/// Declares an tag to the environment
|
||||
fn declare_tag(&mut self, tag: Tag) -> WasmResult<()> {
|
||||
drop(tag);
|
||||
Err(WasmError::Unsupported("wasm tags".to_string()))
|
||||
}
|
||||
|
||||
/// Provides the number of defined globals up front. By default this does nothing, but
|
||||
@@ -885,14 +885,10 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
|
||||
name: &'data str,
|
||||
) -> WasmResult<()>;
|
||||
|
||||
/// Declares an event export to the environment.
|
||||
fn declare_event_export(
|
||||
&mut self,
|
||||
event_index: EventIndex,
|
||||
name: &'data str,
|
||||
) -> WasmResult<()> {
|
||||
drop((event_index, name));
|
||||
Err(WasmError::Unsupported("wasm events".to_string()))
|
||||
/// Declares an tag export to the environment.
|
||||
fn declare_tag_export(&mut self, tag_index: TagIndex, name: &'data str) -> WasmResult<()> {
|
||||
drop((tag_index, name));
|
||||
Err(WasmError::Unsupported("wasm tags".to_string()))
|
||||
}
|
||||
|
||||
/// Declares a global export to the environment.
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
//! to deal with each part of it.
|
||||
use crate::environ::{ModuleEnvironment, WasmResult};
|
||||
use crate::sections_translator::{
|
||||
parse_alias_section, parse_data_section, parse_element_section, parse_event_section,
|
||||
parse_export_section, parse_function_section, parse_global_section, parse_import_section,
|
||||
parse_instance_section, parse_memory_section, parse_name_section, parse_start_section,
|
||||
parse_table_section, parse_type_section,
|
||||
parse_alias_section, parse_data_section, parse_element_section, parse_export_section,
|
||||
parse_function_section, parse_global_section, parse_import_section, parse_instance_section,
|
||||
parse_memory_section, parse_name_section, parse_start_section, parse_table_section,
|
||||
parse_tag_section, parse_type_section,
|
||||
};
|
||||
use crate::state::ModuleTranslationState;
|
||||
use cranelift_codegen::timing;
|
||||
@@ -59,9 +59,9 @@ pub fn translate_module<'data>(
|
||||
parse_memory_section(memories, environ)?;
|
||||
}
|
||||
|
||||
Payload::EventSection(events) => {
|
||||
validator.event_section(&events)?;
|
||||
parse_event_section(events, environ)?;
|
||||
Payload::TagSection(tags) => {
|
||||
validator.tag_section(&tags)?;
|
||||
parse_tag_section(tags, environ)?;
|
||||
}
|
||||
|
||||
Payload::GlobalSection(globals) => {
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
use crate::environ::{Alias, ModuleEnvironment, WasmError, WasmResult};
|
||||
use crate::state::ModuleTranslationState;
|
||||
use crate::translation_utils::{
|
||||
tabletype_to_type, type_to_type, DataIndex, ElemIndex, EntityIndex, EntityType, Event,
|
||||
EventIndex, FuncIndex, Global, GlobalIndex, GlobalInit, InstanceIndex, Memory, MemoryIndex,
|
||||
ModuleIndex, Table, TableElementType, TableIndex, TypeIndex,
|
||||
tabletype_to_type, type_to_type, DataIndex, ElemIndex, EntityIndex, EntityType, FuncIndex,
|
||||
Global, GlobalIndex, GlobalInit, InstanceIndex, Memory, MemoryIndex, ModuleIndex, Table,
|
||||
TableElementType, TableIndex, Tag, TagIndex, TypeIndex,
|
||||
};
|
||||
use crate::wasm_unsupported;
|
||||
use core::convert::TryFrom;
|
||||
@@ -24,10 +24,10 @@ use std::boxed::Box;
|
||||
use std::vec::Vec;
|
||||
use wasmparser::{
|
||||
self, Data, DataKind, DataSectionReader, Element, ElementItem, ElementItems, ElementKind,
|
||||
ElementSectionReader, EventSectionReader, EventType, Export, ExportSectionReader, ExternalKind,
|
||||
FunctionSectionReader, GlobalSectionReader, GlobalType, ImportSectionEntryType,
|
||||
ImportSectionReader, MemorySectionReader, MemoryType, NameSectionReader, Naming, Operator,
|
||||
TableSectionReader, TableType, TypeDef, TypeSectionReader,
|
||||
ElementSectionReader, Export, ExportSectionReader, ExternalKind, FunctionSectionReader,
|
||||
GlobalSectionReader, GlobalType, ImportSectionEntryType, ImportSectionReader,
|
||||
MemorySectionReader, MemoryType, NameSectionReader, Naming, Operator, TableSectionReader,
|
||||
TableType, TagSectionReader, TagType, TypeDef, TypeSectionReader,
|
||||
};
|
||||
|
||||
fn entity_type(
|
||||
@@ -45,7 +45,7 @@ fn entity_type(
|
||||
EntityType::Instance(environ.type_to_instance_type(TypeIndex::from_u32(sig))?)
|
||||
}
|
||||
ImportSectionEntryType::Memory(ty) => EntityType::Memory(memory(ty)),
|
||||
ImportSectionEntryType::Event(evt) => EntityType::Event(event(evt)),
|
||||
ImportSectionEntryType::Tag(t) => EntityType::Tag(tag(t)),
|
||||
ImportSectionEntryType::Global(ty) => {
|
||||
EntityType::Global(global(ty, environ, GlobalInit::Import)?)
|
||||
}
|
||||
@@ -54,19 +54,16 @@ fn entity_type(
|
||||
}
|
||||
|
||||
fn memory(ty: MemoryType) -> Memory {
|
||||
match ty {
|
||||
MemoryType::M32 { limits, shared } => Memory {
|
||||
minimum: limits.initial,
|
||||
maximum: limits.maximum,
|
||||
shared: shared,
|
||||
},
|
||||
// FIXME(#2361)
|
||||
MemoryType::M64 { .. } => unimplemented!(),
|
||||
assert!(!ty.memory64);
|
||||
Memory {
|
||||
minimum: ty.initial.try_into().unwrap(),
|
||||
maximum: ty.maximum.map(|i| i.try_into().unwrap()),
|
||||
shared: ty.shared,
|
||||
}
|
||||
}
|
||||
|
||||
fn event(e: EventType) -> Event {
|
||||
Event {
|
||||
fn tag(e: TagType) -> Tag {
|
||||
Tag {
|
||||
ty: TypeIndex::from_u32(e.type_index),
|
||||
}
|
||||
}
|
||||
@@ -78,8 +75,8 @@ fn table(ty: TableType, environ: &mut dyn ModuleEnvironment<'_>) -> WasmResult<T
|
||||
Some(t) => TableElementType::Val(t),
|
||||
None => TableElementType::Func,
|
||||
},
|
||||
minimum: ty.limits.initial,
|
||||
maximum: ty.limits.maximum,
|
||||
minimum: ty.initial,
|
||||
maximum: ty.maximum,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -174,8 +171,8 @@ pub fn parse_import_section<'data>(
|
||||
ImportSectionEntryType::Memory(ty) => {
|
||||
environ.declare_memory_import(memory(ty), import.module, import.field)?;
|
||||
}
|
||||
ImportSectionEntryType::Event(e) => {
|
||||
environ.declare_event_import(event(e), import.module, import.field)?;
|
||||
ImportSectionEntryType::Tag(e) => {
|
||||
environ.declare_tag_import(tag(e), import.module, import.field)?;
|
||||
}
|
||||
ImportSectionEntryType::Global(ty) => {
|
||||
let ty = global(ty, environ, GlobalInit::Import)?;
|
||||
@@ -243,16 +240,16 @@ pub fn parse_memory_section(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Parses the Event section of the wasm module.
|
||||
pub fn parse_event_section(
|
||||
events: EventSectionReader,
|
||||
/// Parses the Tag section of the wasm module.
|
||||
pub fn parse_tag_section(
|
||||
tags: TagSectionReader,
|
||||
environ: &mut dyn ModuleEnvironment,
|
||||
) -> WasmResult<()> {
|
||||
environ.reserve_events(events.get_count())?;
|
||||
environ.reserve_tags(tags.get_count())?;
|
||||
|
||||
for entry in events {
|
||||
let event = event(entry?);
|
||||
environ.declare_event(event)?;
|
||||
for entry in tags {
|
||||
let tag = tag(entry?);
|
||||
environ.declare_tag(tag)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -321,7 +318,7 @@ pub fn parse_export_section<'data>(
|
||||
ExternalKind::Memory => {
|
||||
environ.declare_memory_export(MemoryIndex::new(index), field)?
|
||||
}
|
||||
ExternalKind::Event => environ.declare_event_export(EventIndex::new(index), field)?,
|
||||
ExternalKind::Tag => environ.declare_tag_export(TagIndex::new(index), field)?,
|
||||
ExternalKind::Global => {
|
||||
environ.declare_global_export(GlobalIndex::new(index), field)?
|
||||
}
|
||||
@@ -473,20 +470,31 @@ pub fn parse_name_section<'data>(
|
||||
environ.declare_module_name(name);
|
||||
}
|
||||
wasmparser::Name::Local(l) => {
|
||||
let mut reader = l.get_function_local_reader()?;
|
||||
for _ in 0..reader.get_count() {
|
||||
let mut reader = l.get_indirect_map()?;
|
||||
for _ in 0..reader.get_indirect_count() {
|
||||
let f = reader.read()?;
|
||||
if f.func_index == u32::max_value() {
|
||||
if f.indirect_index == u32::max_value() {
|
||||
continue;
|
||||
}
|
||||
let mut map = f.get_map()?;
|
||||
for _ in 0..map.get_count() {
|
||||
let Naming { index, name } = map.read()?;
|
||||
environ.declare_local_name(FuncIndex::from_u32(f.func_index), index, name)
|
||||
environ.declare_local_name(
|
||||
FuncIndex::from_u32(f.indirect_index),
|
||||
index,
|
||||
name,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
wasmparser::Name::Unknown { .. } => {}
|
||||
wasmparser::Name::Label(_)
|
||||
| wasmparser::Name::Type(_)
|
||||
| wasmparser::Name::Table(_)
|
||||
| wasmparser::Name::Global(_)
|
||||
| wasmparser::Name::Memory(_)
|
||||
| wasmparser::Name::Element(_)
|
||||
| wasmparser::Name::Data(_)
|
||||
| wasmparser::Name::Unknown { .. } => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -516,7 +524,7 @@ pub fn parse_instance_section<'data>(
|
||||
ExternalKind::Instance => {
|
||||
EntityIndex::Instance(InstanceIndex::from_u32(arg.index))
|
||||
}
|
||||
ExternalKind::Event => unimplemented!(),
|
||||
ExternalKind::Tag => unimplemented!(),
|
||||
|
||||
// this won't pass validation
|
||||
ExternalKind::Type => unreachable!(),
|
||||
|
||||
@@ -95,8 +95,8 @@ entity_impl!(InstanceIndex);
|
||||
/// Index type of an event inside the WebAssembly module.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
pub struct EventIndex(u32);
|
||||
entity_impl!(EventIndex);
|
||||
pub struct TagIndex(u32);
|
||||
entity_impl!(TagIndex);
|
||||
|
||||
/// Specialized index for just module types.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
|
||||
@@ -139,7 +139,7 @@ pub enum EntityType {
|
||||
/// A linear memory with the specified limits
|
||||
Memory(Memory),
|
||||
/// An event definition.
|
||||
Event(Event),
|
||||
Tag(Tag),
|
||||
/// A table with the specified element type and limits
|
||||
Table(Table),
|
||||
/// A function type where the index points to the type section and records a
|
||||
@@ -236,7 +236,7 @@ pub struct Memory {
|
||||
/// WebAssembly event.
|
||||
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
pub struct Event {
|
||||
pub struct Tag {
|
||||
/// The event signature type.
|
||||
pub ty: TypeIndex,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user