diff --git a/Cargo.lock b/Cargo.lock index 46384b2d6a..f1d0c04bfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -586,7 +586,7 @@ dependencies = [ "smallvec", "target-lexicon", "thiserror", - "wasmparser 0.67.0", + "wasmparser 0.68.0", "wat", ] @@ -1150,7 +1150,7 @@ dependencies = [ "smallvec", "thiserror", "typemap", - "wasmparser 0.67.0", + "wasmparser 0.68.0", "wat", ] @@ -2321,24 +2321,18 @@ checksum = "32fddd575d477c6e9702484139cf9f23dcd554b06d185ed0f56c857dd3a47aa6" [[package]] name = "wasmparser" -version = "0.66.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c97fc0456d6d09ca7b64bc33c34f4e8f29d5ccfa8e5595ef7a8957818339e6f6" - -[[package]] -name = "wasmparser" -version = "0.67.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f091cf3849e5fe76a60255bff169277459f2201435bc583b6656880553f0ad0" +checksum = "29a00e14eed9c2ecbbdbdd4fb284f49d21b6808965de24769a6379a13ec47d4c" [[package]] name = "wasmprinter" -version = "0.2.13" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b580bee9eb1f029fac6014620b31f82ea2afa22d0701b9bd7f879747e3f5242" +checksum = "f39a73b5f09cfcb1b568b61968d39b19e4ddec9b49040cfc091adf3b0788bca6" dependencies = [ "anyhow", - "wasmparser 0.66.0", + "wasmparser 0.68.0", ] [[package]] @@ -2357,7 +2351,7 @@ dependencies = [ "smallvec", "target-lexicon", "tempfile", - "wasmparser 0.67.0", + "wasmparser 0.68.0", "wasmtime-cache", "wasmtime-environ", "wasmtime-jit", @@ -2435,7 +2429,7 @@ dependencies = [ "test-programs", "tracing-subscriber", "wasi-common", - "wasmparser 0.67.0", + "wasmparser 0.68.0", "wasmtime", "wasmtime-cache", "wasmtime-debug", @@ -2471,7 +2465,7 @@ dependencies = [ "object", "target-lexicon", "thiserror", - "wasmparser 0.67.0", + "wasmparser 0.68.0", "wasmtime-environ", ] @@ -2490,7 +2484,7 @@ dependencies = [ "more-asserts", "serde", "thiserror", - "wasmparser 0.67.0", + "wasmparser 0.68.0", ] [[package]] @@ -2518,7 +2512,7 @@ dependencies = [ "log", "rayon", "wasm-smith", - "wasmparser 0.67.0", + "wasmparser 0.68.0", "wasmprinter", "wasmtime", "wasmtime-wast", @@ -2545,7 +2539,7 @@ dependencies = [ "serde", "target-lexicon", "thiserror", - "wasmparser 0.67.0", + "wasmparser 0.68.0", "wasmtime-cranelift", "wasmtime-debug", "wasmtime-environ", @@ -2562,7 +2556,7 @@ version = "0.21.0" dependencies = [ "cranelift-codegen", "lightbeam", - "wasmparser 0.67.0", + "wasmparser 0.68.0", "wasmtime-environ", ] diff --git a/Cargo.toml b/Cargo.toml index f1a538d8c7..796d74dbdf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ libc = "0.2.60" log = "0.4.8" rayon = "1.2.1" humantime = "2.0.0" -wasmparser = "0.67" +wasmparser = "0.68" [dev-dependencies] env_logger = "0.8.1" diff --git a/cranelift/wasm/Cargo.toml b/cranelift/wasm/Cargo.toml index 57df14aaa4..95a3626983 100644 --- a/cranelift/wasm/Cargo.toml +++ b/cranelift/wasm/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["webassembly", "wasm"] edition = "2018" [dependencies] -wasmparser = { version = "0.67.0", default-features = false } +wasmparser = { version = "0.68.0", default-features = false } cranelift-codegen = { path = "../codegen", version = "0.68.0", default-features = false } cranelift-entity = { path = "../entity", version = "0.68.0" } cranelift-frontend = { path = "../frontend", version = "0.68.0", default-features = false } diff --git a/cranelift/wasm/src/code_translator.rs b/cranelift/wasm/src/code_translator.rs index 4e31edd77c..16d68b69b9 100644 --- a/cranelift/wasm/src/code_translator.rs +++ b/cranelift/wasm/src/code_translator.rs @@ -534,6 +534,17 @@ pub fn translate_operator( state.popn(return_count); state.reachable = false; } + /********************************** Exception handing **********************************/ + Operator::Try { .. } + | Operator::Catch + | Operator::BrOnExn { .. } + | Operator::Throw { .. } + | Operator::Rethrow => { + return Err(wasm_unsupported!( + "proposed exception handling operator {:?}", + op + )); + } /************************************ Calls **************************************** * The call instructions pop off their arguments from the stack and append their * return values to it. `call_indirect` needs environment support because there is an diff --git a/cranelift/wasm/src/environ/spec.rs b/cranelift/wasm/src/environ/spec.rs index 149e55d6dc..2ac50fe4e3 100644 --- a/cranelift/wasm/src/environ/spec.rs +++ b/cranelift/wasm/src/environ/spec.rs @@ -8,8 +8,8 @@ use crate::state::FuncTranslationState; use crate::translation_utils::{ - DataIndex, ElemIndex, EntityType, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, Table, - TableIndex, TypeIndex, + DataIndex, ElemIndex, EntityType, Event, EventIndex, FuncIndex, Global, GlobalIndex, Memory, + MemoryIndex, Table, TableIndex, TypeIndex, }; use core::convert::From; use core::convert::TryFrom; @@ -44,6 +44,8 @@ pub enum WasmType { FuncRef, /// ExternRef type ExternRef, + /// ExnRef type + ExnRef, } impl TryFrom for WasmType { @@ -58,6 +60,7 @@ impl TryFrom for WasmType { V128 => Ok(WasmType::V128), FuncRef => Ok(WasmType::FuncRef), ExternRef => Ok(WasmType::ExternRef), + ExnRef => Ok(WasmType::ExnRef), EmptyBlockType | Func => Err(WasmError::InvalidWebAssembly { message: "unexpected value type".to_string(), offset: 0, @@ -76,6 +79,7 @@ impl From for wasmparser::Type { WasmType::V128 => wasmparser::Type::V128, WasmType::FuncRef => wasmparser::Type::FuncRef, WasmType::ExternRef => wasmparser::Type::ExternRef, + WasmType::ExnRef => wasmparser::Type::ExnRef, } } } @@ -689,6 +693,17 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment { field: &'data str, ) -> WasmResult<()>; + /// Declares an event import to the environment. + fn declare_event_import( + &mut self, + event: Event, + module: &'data str, + field: &'data str, + ) -> WasmResult<()> { + drop((event, module, field)); + Err(WasmError::Unsupported("wasm events".to_string())) + } + /// Declares a global import to the environment. fn declare_global_import( &mut self, @@ -751,6 +766,18 @@ 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 + /// implementations can use this to preallocate memory if desired. + fn reserve_events(&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())) + } + /// Provides the number of defined globals up front. By default this does nothing, but /// implementations can use this to preallocate memory if desired. fn reserve_globals(&mut self, _num: u32) -> WasmResult<()> { @@ -780,6 +807,16 @@ 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 a global export to the environment. fn declare_global_export( &mut self, diff --git a/cranelift/wasm/src/module_translator.rs b/cranelift/wasm/src/module_translator.rs index 0b1794158f..631dedeaf3 100644 --- a/cranelift/wasm/src/module_translator.rs +++ b/cranelift/wasm/src/module_translator.rs @@ -2,9 +2,9 @@ //! to deal with each part of it. use crate::environ::{ModuleEnvironment, WasmResult}; use crate::sections_translator::{ - parse_data_section, parse_element_section, parse_export_section, parse_function_section, - parse_global_section, parse_import_section, parse_memory_section, parse_name_section, - parse_start_section, parse_table_section, parse_type_section, + parse_data_section, parse_element_section, parse_event_section, parse_export_section, + parse_function_section, parse_global_section, parse_import_section, parse_memory_section, + parse_name_section, parse_start_section, parse_table_section, parse_type_section, }; use crate::state::ModuleTranslationState; use cranelift_codegen::timing; @@ -65,6 +65,11 @@ pub fn translate_module<'data>( parse_memory_section(memories, environ)?; } + Payload::EventSection(events) => { + validator.event_section(&events)?; + parse_event_section(events, environ)?; + } + Payload::GlobalSection(globals) => { validator.global_section(&globals)?; parse_global_section(globals, environ)?; diff --git a/cranelift/wasm/src/sections_translator.rs b/cranelift/wasm/src/sections_translator.rs index 842839979d..4fee9bd087 100644 --- a/cranelift/wasm/src/sections_translator.rs +++ b/cranelift/wasm/src/sections_translator.rs @@ -10,8 +10,9 @@ use crate::environ::{ModuleEnvironment, WasmError, WasmResult}; use crate::state::ModuleTranslationState; use crate::translation_utils::{ - tabletype_to_type, type_to_type, DataIndex, ElemIndex, EntityType, FuncIndex, Global, - GlobalIndex, GlobalInit, Memory, MemoryIndex, Table, TableElementType, TableIndex, TypeIndex, + tabletype_to_type, type_to_type, DataIndex, ElemIndex, EntityType, Event, EventIndex, + FuncIndex, Global, GlobalIndex, GlobalInit, Memory, MemoryIndex, Table, TableElementType, + TableIndex, TypeIndex, }; use crate::wasm_unsupported; use core::convert::TryFrom; @@ -24,10 +25,10 @@ use std::boxed::Box; use std::vec::Vec; use wasmparser::{ self, Data, DataKind, DataSectionReader, Element, ElementItem, ElementItems, ElementKind, - ElementSectionReader, Export, ExportSectionReader, ExternalKind, FunctionSectionReader, - GlobalSectionReader, GlobalType, ImportSectionEntryType, ImportSectionReader, - MemorySectionReader, MemoryType, NameSectionReader, Naming, Operator, TableSectionReader, - TableType, TypeDef, TypeSectionReader, + ElementSectionReader, EventSectionReader, EventType, Export, ExportSectionReader, ExternalKind, + FunctionSectionReader, GlobalSectionReader, GlobalType, ImportSectionEntryType, + ImportSectionReader, MemorySectionReader, MemoryType, NameSectionReader, Naming, Operator, + TableSectionReader, TableType, TypeDef, TypeSectionReader, }; fn entity_type( @@ -39,6 +40,7 @@ fn entity_type( ImportSectionEntryType::Module(sig) => EntityType::Module(TypeIndex::from_u32(sig)), ImportSectionEntryType::Instance(sig) => EntityType::Instance(TypeIndex::from_u32(sig)), ImportSectionEntryType::Memory(ty) => EntityType::Memory(memory(ty)), + ImportSectionEntryType::Event(evt) => EntityType::Event(event(evt)), ImportSectionEntryType::Global(ty) => { EntityType::Global(global(ty, environ, GlobalInit::Import)?) } @@ -58,6 +60,12 @@ fn memory(ty: MemoryType) -> Memory { } } +fn event(e: EventType) -> Event { + Event { + ty: TypeIndex::from_u32(e.type_index), + } +} + fn table(ty: TableType, environ: &mut dyn ModuleEnvironment<'_>) -> WasmResult { Ok(Table { wasm_ty: ty.element_type.try_into()?, @@ -163,6 +171,7 @@ pub fn parse_import_section<'data>( EntityType::Memory(ty) => { environ.declare_memory_import(ty, module_name, field_name)?; } + EntityType::Event(e) => environ.declare_event_import(e, module_name, field_name)?, EntityType::Global(ty) => { environ.declare_global_import(ty, module_name, field_name)?; } @@ -227,6 +236,21 @@ pub fn parse_memory_section( Ok(()) } +/// Parses the Event section of the wasm module. +pub fn parse_event_section( + events: EventSectionReader, + environ: &mut dyn ModuleEnvironment, +) -> WasmResult<()> { + environ.reserve_events(events.get_count())?; + + for entry in events { + let event = event(entry?); + environ.declare_event(event)?; + } + + Ok(()) +} + /// Parses the Global section of the wasm module. pub fn parse_global_section( globals: GlobalSectionReader, @@ -290,6 +314,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::Global => { environ.declare_global_export(GlobalIndex::new(index), field)? } diff --git a/cranelift/wasm/src/translation_utils.rs b/cranelift/wasm/src/translation_utils.rs index 15ad15756e..613e50ac73 100644 --- a/cranelift/wasm/src/translation_utils.rs +++ b/cranelift/wasm/src/translation_utils.rs @@ -91,6 +91,12 @@ entity_impl!(ModuleIndex); pub struct InstanceIndex(u32); 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); + /// An index of an entity. #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] @@ -119,6 +125,8 @@ pub enum EntityType { Global(Global), /// A linear memory with the specified limits Memory(Memory), + /// An event definition. + Event(Event), /// 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 @@ -212,6 +220,14 @@ pub struct Memory { pub shared: bool, } +/// WebAssembly event. +#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] +#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] +pub struct Event { + /// The event signature type. + pub ty: TypeIndex, +} + /// Helper function translating wasmparser types to Cranelift types when possible. pub fn type_to_type( ty: wasmparser::Type, diff --git a/crates/debug/Cargo.toml b/crates/debug/Cargo.toml index 54414f9dc9..31caf0777c 100644 --- a/crates/debug/Cargo.toml +++ b/crates/debug/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] gimli = "0.23.0" -wasmparser = "0.67.0" +wasmparser = "0.68.0" object = { version = "0.22.0", default-features = false, features = ["read", "write"] } wasmtime-environ = { path = "../environ", version = "0.21.0" } target-lexicon = { version = "0.11.0", default-features = false } diff --git a/crates/environ/Cargo.toml b/crates/environ/Cargo.toml index ae10c53f33..847b749c71 100644 --- a/crates/environ/Cargo.toml +++ b/crates/environ/Cargo.toml @@ -16,7 +16,7 @@ anyhow = "1.0" cranelift-codegen = { path = "../../cranelift/codegen", version = "0.68.0", features = ["enable-serde"] } cranelift-entity = { path = "../../cranelift/entity", version = "0.68.0", features = ["enable-serde"] } cranelift-wasm = { path = "../../cranelift/wasm", version = "0.68.0", features = ["enable-serde"] } -wasmparser = "0.67.0" +wasmparser = "0.68.0" indexmap = { version = "1.0.2", features = ["serde-1"] } thiserror = "1.0.4" serde = { version = "1.0.94", features = ["derive"] } diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml index e620f5b08c..c5625d293b 100644 --- a/crates/fuzzing/Cargo.toml +++ b/crates/fuzzing/Cargo.toml @@ -12,8 +12,8 @@ arbitrary = { version = "0.4.1", features = ["derive"] } env_logger = "0.8.1" log = "0.4.8" rayon = "1.2.1" -wasmparser = "0.67.0" -wasmprinter = "0.2.13" +wasmparser = "0.68.0" +wasmprinter = "0.2.15" wasmtime = { path = "../wasmtime" } wasmtime-wast = { path = "../wast" } wasm-smith = "0.1.10" diff --git a/crates/jit/Cargo.toml b/crates/jit/Cargo.toml index a449ebc1b9..5af2425c2d 100644 --- a/crates/jit/Cargo.toml +++ b/crates/jit/Cargo.toml @@ -28,7 +28,7 @@ rayon = { version = "1.0", optional = true } region = "2.1.0" thiserror = "1.0.4" target-lexicon = { version = "0.11.0", default-features = false } -wasmparser = "0.67.0" +wasmparser = "0.68.0" more-asserts = "0.2.1" anyhow = "1.0" cfg-if = "1.0" diff --git a/crates/lightbeam/Cargo.toml b/crates/lightbeam/Cargo.toml index e2f3eedde4..9308b8918a 100644 --- a/crates/lightbeam/Cargo.toml +++ b/crates/lightbeam/Cargo.toml @@ -24,7 +24,7 @@ more-asserts = "0.2.1" smallvec = "1.0.0" thiserror = "1.0.9" typemap = "0.3" -wasmparser = "0.67.0" +wasmparser = "0.68.0" [dev-dependencies] lazy_static = "1.2" diff --git a/crates/lightbeam/wasmtime/Cargo.toml b/crates/lightbeam/wasmtime/Cargo.toml index e760e3cc15..f636577df0 100644 --- a/crates/lightbeam/wasmtime/Cargo.toml +++ b/crates/lightbeam/wasmtime/Cargo.toml @@ -13,6 +13,6 @@ edition = "2018" [dependencies] lightbeam = { path = "..", version = "0.21.0" } -wasmparser = "0.67" +wasmparser = "0.68" cranelift-codegen = { path = "../../../cranelift/codegen", version = "0.68.0" } wasmtime-environ = { path = "../../environ", version = "0.21.0" } diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.toml index 69123f2fe4..e0c0d3302c 100644 --- a/crates/wasmtime/Cargo.toml +++ b/crates/wasmtime/Cargo.toml @@ -16,7 +16,7 @@ wasmtime-jit = { path = "../jit", version = "0.21.0" } wasmtime-cache = { path = "../cache", version = "0.21.0", optional = true } wasmtime-profiling = { path = "../profiling", version = "0.21.0" } target-lexicon = { version = "0.11.0", default-features = false } -wasmparser = "0.67.0" +wasmparser = "0.68.0" anyhow = "1.0.19" region = "2.2.0" libc = "0.2" diff --git a/crates/wasmtime/src/types.rs b/crates/wasmtime/src/types.rs index 7c2a4a244e..ab576a668b 100644 --- a/crates/wasmtime/src/types.rs +++ b/crates/wasmtime/src/types.rs @@ -133,6 +133,7 @@ impl ValType { wasm::WasmType::V128 => Self::V128, wasm::WasmType::FuncRef => Self::FuncRef, wasm::WasmType::ExternRef => Self::ExternRef, + wasm::WasmType::ExnRef => unimplemented!(), } } } @@ -222,6 +223,7 @@ impl ExternType { }; InstanceType::from_wasmtime(module, exports).into() } + EntityType::Event(_) => unimplemented!("wasm event support"), } } }