From c87e8c54022562cdf39ca0e5a4d0be7a390fec03 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sun, 20 Apr 2025 14:26:33 +0200 Subject: [PATCH 1/3] necessary parts to make the wit-bindgen test pass --- Cargo.lock | 33 ++++++----------- Cargo.toml | 20 +++++------ crates/cli-flags/src/lib.rs | 4 +++ crates/environ/src/component/types.rs | 17 +++++++++ crates/environ/src/component/types_builder.rs | 29 +++++++++++++++ crates/environ/src/fact/trampoline.rs | 35 ++++++++++++++++--- crates/wasmtime/src/config.rs | 10 ++++++ crates/wasmtime/src/engine/serialization.rs | 9 +++++ .../src/runtime/component/func/typed.rs | 1 + .../wasmtime/src/runtime/component/types.rs | 2 ++ .../wasmtime/src/runtime/component/values.rs | 4 +++ crates/wit-bindgen/src/lib.rs | 2 ++ crates/wit-bindgen/src/rust.rs | 2 ++ crates/wit-bindgen/src/types.rs | 1 + 14 files changed, 132 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7fe74840252d..746d8f0916bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3983,8 +3983,7 @@ dependencies = [ [[package]] name = "wasm-encoder" version = "0.229.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38ba1d491ecacb085a2552025c10a675a6fddcbd03b1fc9b36c536010ce265d2" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "leb128fmt", "wasmparser 0.229.0", @@ -4012,8 +4011,7 @@ dependencies = [ [[package]] name = "wasm-metadata" version = "0.229.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78fdb7d29a79191ab363dc90c1ddd3a1e880ffd5348d92d48482393a9e6c5f4d" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "anyhow", "indexmap 2.7.0", @@ -4024,8 +4022,7 @@ dependencies = [ [[package]] name = "wasm-mutate" version = "0.229.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b8030bb9e10d1e050d1d8796af5e454e6082a5302ce68948f41debd0ea2a8e" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "egg", "log", @@ -4038,8 +4035,7 @@ dependencies = [ [[package]] name = "wasm-smith" version = "0.229.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0227a2ef527946ab58f9eefcb232576d89126db8c96b266c04e4a934cf24c92" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "anyhow", "arbitrary", @@ -4061,8 +4057,7 @@ dependencies = [ [[package]] name = "wasm-wave" version = "0.229.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd33c30a68c41ff354d7b3741f5d2d3dfbf8eb52033176bb01364cbdf016c17c" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "indexmap 2.7.0", "logos", @@ -4129,8 +4124,7 @@ dependencies = [ [[package]] name = "wasmparser" version = "0.229.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc3b1f053f5d41aa55640a1fa9b6d1b8a9e4418d118ce308d20e24ff3575a8c" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "bitflags 2.6.0", "hashbrown 0.15.2", @@ -4142,8 +4136,7 @@ dependencies = [ [[package]] name = "wasmprinter" version = "0.229.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d25dac01892684a99b8fbfaf670eb6b56edea8a096438c75392daeb83156ae2e" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "anyhow", "termcolor", @@ -4820,8 +4813,7 @@ dependencies = [ [[package]] name = "wast" version = "229.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63fcaff613c12225696bb163f79ca38ffb40e9300eff0ff4b8aa8b2f7eadf0d9" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "bumpalo", "leb128fmt", @@ -4833,8 +4825,7 @@ dependencies = [ [[package]] name = "wat" version = "1.229.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4189bad08b70455a9e9e67dc126d2dcf91fac143a80f1046747a5dde6d4c33e0" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "wast 229.0.0", ] @@ -5223,8 +5214,7 @@ dependencies = [ [[package]] name = "wit-component" version = "0.229.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f550067740e223bfe6c4878998e81cdbe2529dd9a793dc49248dd6613394e8b" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "anyhow", "bitflags 2.6.0", @@ -5260,8 +5250,7 @@ dependencies = [ [[package]] name = "wit-parser" version = "0.229.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "459c6ba62bf511d6b5f2a845a2a736822e38059c1cfa0b644b467bbbfae4efa6" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#aa5618f4cd2258e7ae70b3aca929cb24f31534c6" dependencies = [ "anyhow", "id-arena", diff --git a/Cargo.toml b/Cargo.toml index d2f29417bdf7..d0ee984300b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -307,16 +307,16 @@ wit-bindgen = { version = "0.41.0", default-features = false } wit-bindgen-rust-macro = { version = "0.41.0", default-features = false } # wasm-tools family: -wasmparser = { version = "0.229.0", default-features = false, features = ['simd'] } -wat = "1.229.0" -wast = "229.0.0" -wasmprinter = "0.229.0" -wasm-encoder = "0.229.0" -wasm-smith = "0.229.0" -wasm-mutate = "0.229.0" -wit-parser = "0.229.0" -wit-component = "0.229.0" -wasm-wave = "0.229.0" +wasmparser = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } +wat = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } +wast = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } +wasmprinter = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } +wasm-encoder = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } +wasm-smith = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } +wasm-mutate = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } +wit-parser = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } +wit-component = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } +wasm-wave = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } # Non-Bytecode Alliance maintained dependencies: # -------------------------- diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs index 5897bd862a7e..bd92e73de794 100644 --- a/crates/cli-flags/src/lib.rs +++ b/crates/cli-flags/src/lib.rs @@ -386,6 +386,9 @@ wasmtime_option_group! { pub exceptions: Option, /// DEPRECATED: Configure support for the legacy exceptions proposal. pub legacy_exceptions: Option, + /// Component model support for fixed size lists: this corresponds + /// to the 🔧 emoji in the component model specification + pub component_model_fixed_size_list: Option, } enum Wasm { @@ -1015,6 +1018,7 @@ impl CommonOptions { ("component-model-async", component_model_async, wasm_component_model_async) ("component-model-async", component_model_async_builtins, wasm_component_model_async_builtins) ("component-model-async", component_model_async_stackful, wasm_component_model_async_stackful) + ("component-model", component_model_fixed_size_list, wasm_component_model_fixed_size_lists) ("threads", threads, wasm_threads) ("gc", gc, wasm_gc) ("gc", reference_types, wasm_reference_types) diff --git a/crates/environ/src/component/types.rs b/crates/environ/src/component/types.rs index 078b5227c688..1c0f44397db6 100644 --- a/crates/environ/src/component/types.rs +++ b/crates/environ/src/component/types.rs @@ -89,6 +89,8 @@ indices! { pub struct TypeResultIndex(u32); /// Index pointing to a list type in the component model. pub struct TypeListIndex(u32); + /// Index pointing to a fixed size list type in the component model. + pub struct TypeFixedSizeListIndex(u32); /// Index pointing to a future type in the component model. pub struct TypeFutureIndex(u32); @@ -285,6 +287,7 @@ pub struct ComponentTypes { pub(super) stream_tables: PrimaryMap, pub(super) error_context_tables: PrimaryMap, + pub(super) fixed_size_lists: PrimaryMap, } impl TypeTrace for ComponentTypes { @@ -358,6 +361,7 @@ impl ComponentTypes { InterfaceType::Enum(i) => &self[*i].abi, InterfaceType::Option(i) => &self[*i].abi, InterfaceType::Result(i) => &self[*i].abi, + InterfaceType::FixedSizeList(i) => &self[*i].abi, } } @@ -407,6 +411,7 @@ impl_index! { impl Index for ComponentTypes { TypeFutureTable => future_tables } impl Index for ComponentTypes { TypeStreamTable => stream_tables } impl Index for ComponentTypes { TypeErrorContextTable => error_context_tables } + impl Index for ComponentTypes { TypeFixedSizeList => fixed_size_lists } } // Additionally forward anything that can index `ModuleTypes` to `ModuleTypes` @@ -582,6 +587,7 @@ pub enum InterfaceType { Future(TypeFutureTableIndex), Stream(TypeStreamTableIndex), ErrorContext(TypeComponentLocalErrorContextTableIndex), + FixedSizeList(TypeFixedSizeListIndex), } /// Bye information about a type in the canonical ABI, with metadata for both @@ -1129,6 +1135,17 @@ pub struct TypeList { pub element: InterfaceType, } +/// Shape of a "fixed size list" interface type. +#[derive(Serialize, Deserialize, Clone, Hash, Eq, PartialEq, Debug)] +pub struct TypeFixedSizeList { + /// The element type of the list. + pub element: InterfaceType, + /// The fixed length of the list. + pub size: u32, + /// Byte information about this type in the canonical ABI. + pub abi: CanonicalAbiInfo, +} + /// Maximum number of flat types, for either params or results. pub const MAX_FLAT_TYPES: usize = if MAX_FLAT_PARAMS > MAX_FLAT_RESULTS { MAX_FLAT_PARAMS diff --git a/crates/environ/src/component/types_builder.rs b/crates/environ/src/component/types_builder.rs index b66849efa076..1bfa48c4e0cc 100644 --- a/crates/environ/src/component/types_builder.rs +++ b/crates/environ/src/component/types_builder.rs @@ -50,6 +50,7 @@ pub struct ComponentTypesBuilder { future_tables: HashMap, stream_tables: HashMap, error_context_tables: HashMap, + fixed_size_lists: HashMap, component_types: ComponentTypes, module_types: ModuleTypesBuilder, @@ -111,6 +112,7 @@ impl ComponentTypesBuilder { component_types: ComponentTypes::default(), type_info: TypeInformationCache::default(), resources: ResourcesBuilder::default(), + fixed_size_lists: HashMap::default(), } } @@ -418,6 +420,9 @@ impl ComponentTypesBuilder { ComponentDefinedType::Stream(ty) => { InterfaceType::Stream(self.stream_table_type(types, ty)?) } + ComponentDefinedType::FixedSizeList(ty, size) => { + InterfaceType::FixedSizeList(self.fixed_size_list_type(types, ty, *size)?) + } }; let info = self.type_information(&ret); if info.depth > MAX_TYPE_DEPTH { @@ -531,6 +536,19 @@ impl ComponentTypesBuilder { self.add_tuple_type(TypeTuple { types, abi }) } + fn fixed_size_list_type(&mut self, types: TypesRef<'_>, ty: &ComponentValType, size: u32) -> Result { + assert_eq!(types.id(), self.module_types.validator_id()); + let element = self.valtype(types, ty)?; + Ok(self.new_fixed_size_list_type(element, size)) + } + + pub(crate) fn new_fixed_size_list_type(&mut self, element: InterfaceType, size: u32) -> TypeFixedSizeListIndex { + let element_abi = self.component_types.canonical_abi(&element); + let abi = CanonicalAbiInfo::record( + (0..size).into_iter().map(|_| element_abi)); + self.add_fixed_size_list_type(TypeFixedSizeList { element, size, abi }) + } + fn flags_type(&mut self, flags: &IndexSet) -> TypeFlagsIndex { let flags = TypeFlags { names: flags.iter().map(|s| s.to_string()).collect(), @@ -647,6 +665,11 @@ impl ComponentTypesBuilder { intern_and_fill_flat_types!(self, tuples, ty) } + /// Interns a new tuple type within this type information. + pub fn add_fixed_size_list_type(&mut self, ty: TypeFixedSizeList) -> TypeFixedSizeListIndex { + intern_and_fill_flat_types!(self, fixed_size_lists, ty) + } + /// Interns a new variant type within this type information. pub fn add_variant_type(&mut self, ty: TypeVariant) -> TypeVariantIndex { intern_and_fill_flat_types!(self, variants, ty) @@ -782,6 +805,7 @@ impl ComponentTypesBuilder { InterfaceType::Enum(i) => &self.type_info.enums[*i], InterfaceType::Option(i) => &self.type_info.options[*i], InterfaceType::Result(i) => &self.type_info.results[*i], + InterfaceType::FixedSizeList(i) => &self.type_info.fixed_size_lists[*i], } } } @@ -891,6 +915,7 @@ struct TypeInformationCache { options: PrimaryMap, results: PrimaryMap, lists: PrimaryMap, + fixed_size_lists: PrimaryMap, } struct TypeInformation { @@ -1040,6 +1065,10 @@ impl TypeInformation { self.build_record(ty.types.iter().map(|t| types.type_information(t))); } + fn fixed_size_lists(&mut self, types: &ComponentTypesBuilder, ty: &TypeFixedSizeList) { + self.build_record((0..ty.size).into_iter().map(|_| types.type_information(&ty.element))); + } + fn enums(&mut self, _types: &ComponentTypesBuilder, _ty: &TypeEnum) { self.depth = 1; self.flat.push(FlatType::I32, FlatType::I32); diff --git a/crates/environ/src/fact/trampoline.rs b/crates/environ/src/fact/trampoline.rs index 0263d77363cb..a682a1adb111 100644 --- a/crates/environ/src/fact/trampoline.rs +++ b/crates/environ/src/fact/trampoline.rs @@ -16,11 +16,7 @@ //! can be somewhat arbitrary, an intentional decision. use crate::component::{ - CanonicalAbiInfo, ComponentTypesBuilder, FixedEncoding as FE, FlatType, InterfaceType, - StringEncoding, Transcode, TypeComponentLocalErrorContextTableIndex, TypeEnumIndex, - TypeFlagsIndex, TypeFutureTableIndex, TypeListIndex, TypeOptionIndex, TypeRecordIndex, - TypeResourceTableIndex, TypeResultIndex, TypeStreamTableIndex, TypeTupleIndex, - TypeVariantIndex, VariantInfo, FLAG_MAY_ENTER, FLAG_MAY_LEAVE, MAX_FLAT_PARAMS, + CanonicalAbiInfo, ComponentTypesBuilder, FixedEncoding as FE, FlatType, InterfaceType, StringEncoding, Transcode, TypeComponentLocalErrorContextTableIndex, TypeEnumIndex, TypeFixedSizeListIndex, TypeFlagsIndex, TypeFutureTableIndex, TypeListIndex, TypeOptionIndex, TypeRecordIndex, TypeResourceTableIndex, TypeResultIndex, TypeStreamTableIndex, TypeTupleIndex, TypeVariantIndex, VariantInfo, FLAG_MAY_ENTER, FLAG_MAY_LEAVE, MAX_FLAT_PARAMS }; use crate::fact::signature::Signature; use crate::fact::transcode::Transcoder; @@ -1044,6 +1040,7 @@ impl<'a, 'b> Compiler<'a, 'b> { | InterfaceType::Future(_) | InterfaceType::Stream(_) | InterfaceType::ErrorContext(_) => 1, + InterfaceType::FixedSizeList(i) => self.types[*i].size as usize, }; match self.fuel.checked_sub(cost) { @@ -1083,6 +1080,9 @@ impl<'a, 'b> Compiler<'a, 'b> { InterfaceType::ErrorContext(t) => { self.translate_error_context(*t, src, dst_ty, dst) } + InterfaceType::FixedSizeList(t) => { + self.translate_fixed_size_list(*t, src, dst_ty, dst); + } } } @@ -2628,6 +2628,31 @@ impl<'a, 'b> Compiler<'a, 'b> { } } + fn translate_fixed_size_list( + &mut self, + src_ty: TypeFixedSizeListIndex, + src: &Source<'_>, + dst_ty: &InterfaceType, + dst: &Destination, + ) { + let src_ty = &self.types[src_ty]; + let dst_ty = match dst_ty { + InterfaceType::FixedSizeList(t) => &self.types[*t], + _ => panic!("expected a fixed size list"), + }; + + // TODO: subtyping + assert_eq!(src_ty.size, dst_ty.size); + + let srcs = src + .record_field_srcs(self.types, (0..src_ty.size).into_iter().map(|_| src_ty.element)); + let dsts = dst + .record_field_dsts(self.types, (0..dst_ty.size).into_iter().map(|_| dst_ty.element)); + for (src, dst) in srcs.zip(dsts) { + self.translate(&src_ty.element, &src, &dst_ty.element, &dst); + } + } + fn translate_variant( &mut self, src_ty: TypeVariantIndex, diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rs index e410708e2d61..a945fb425cc4 100644 --- a/crates/wasmtime/src/config.rs +++ b/crates/wasmtime/src/config.rs @@ -1159,6 +1159,16 @@ impl Config { self } + /// This corresponds to the 🔧 emoji in the component model specification. + /// + /// Please note that Wasmtime's support for this feature is _very_ + /// incomplete. + #[cfg(feature = "component-model")] + pub fn wasm_component_model_fixed_size_lists(&mut self, enable: bool) -> &mut Self { + self.wasm_feature(WasmFeatures::CM_FIXED_SIZE_LIST, enable); + self + } + #[doc(hidden)] // FIXME(#3427) - if/when implemented then un-hide this pub fn wasm_exceptions(&mut self, enable: bool) -> &mut Self { self.wasm_feature(WasmFeatures::EXCEPTIONS, enable); diff --git a/crates/wasmtime/src/engine/serialization.rs b/crates/wasmtime/src/engine/serialization.rs index 229490c7ee95..70539ef2cc50 100644 --- a/crates/wasmtime/src/engine/serialization.rs +++ b/crates/wasmtime/src/engine/serialization.rs @@ -209,6 +209,7 @@ struct WasmFeatures { gc_types: bool, wide_arithmetic: bool, stack_switching: bool, + component_model_fixed_size_list: bool, } impl Metadata<'_> { @@ -242,6 +243,7 @@ impl Metadata<'_> { gc_types, stack_switching, wide_arithmetic, + cm_fixed_size_list, // Always on; we don't currently have knobs for these. mutable_global: _, @@ -287,6 +289,7 @@ impl Metadata<'_> { component_model_async_builtins: cm_async_builtins, component_model_async_stackful: cm_async_stackful, component_model_error_context: cm_error_context, + component_model_fixed_size_list: cm_fixed_size_list, }, } } @@ -499,6 +502,7 @@ impl Metadata<'_> { component_model_async_builtins, component_model_async_stackful, component_model_error_context, + component_model_fixed_size_list, gc_types, wide_arithmetic, stack_switching, @@ -606,6 +610,11 @@ impl Metadata<'_> { other.contains(F::CM_ERROR_CONTEXT), "WebAssembly component model support for error-context", )?; + Self::check_bool( + component_model_fixed_size_list, + other.contains(F::CM_FIXED_SIZE_LIST), + "WebAssembly component model support for fixed size lists", + )?; Self::check_cfg_bool( cfg!(feature = "gc"), "gc", diff --git a/crates/wasmtime/src/runtime/component/func/typed.rs b/crates/wasmtime/src/runtime/component/func/typed.rs index bd978dbc51c0..8bc60d40e4a8 100644 --- a/crates/wasmtime/src/runtime/component/func/typed.rs +++ b/crates/wasmtime/src/runtime/component/func/typed.rs @@ -2581,6 +2581,7 @@ pub fn desc(ty: &InterfaceType) -> &'static str { InterfaceType::Future(_) => "future", InterfaceType::Stream(_) => "stream", InterfaceType::ErrorContext(_) => "error-context", + InterfaceType::FixedSizeList(_) => "list<_, N>", } } diff --git a/crates/wasmtime/src/runtime/component/types.rs b/crates/wasmtime/src/runtime/component/types.rs index 9998a99d03b4..3ad72fbb4295 100644 --- a/crates/wasmtime/src/runtime/component/types.rs +++ b/crates/wasmtime/src/runtime/component/types.rs @@ -148,6 +148,7 @@ impl TypeChecker<'_> { (InterfaceType::Future(_), _) | (InterfaceType::Stream(_), _) | (InterfaceType::ErrorContext(_), _) => todo!(), + (InterfaceType::FixedSizeList(_), _) => todo!(), } } @@ -666,6 +667,7 @@ impl Type { InterfaceType::Future(_) | InterfaceType::Stream(_) | InterfaceType::ErrorContext(_) => todo!(), + InterfaceType::FixedSizeList(_) => todo!(), } } diff --git a/crates/wasmtime/src/runtime/component/values.rs b/crates/wasmtime/src/runtime/component/values.rs index a20378c1b7bf..f955ec1442ef 100644 --- a/crates/wasmtime/src/runtime/component/values.rs +++ b/crates/wasmtime/src/runtime/component/values.rs @@ -201,6 +201,7 @@ impl Val { InterfaceType::Future(_) | InterfaceType::Stream(_) | InterfaceType::ErrorContext(_) => todo!(), + InterfaceType::FixedSizeList(_) => todo!(), }) } @@ -325,6 +326,7 @@ impl Val { InterfaceType::Future(_) | InterfaceType::Stream(_) | InterfaceType::ErrorContext(_) => todo!(), + InterfaceType::FixedSizeList(_) => todo!(), }) } @@ -438,6 +440,7 @@ impl Val { (InterfaceType::Future(_), _) | (InterfaceType::Stream(_), _) | (InterfaceType::ErrorContext(_), _) => todo!(), + (InterfaceType::FixedSizeList(_), _) => todo!(), } } @@ -576,6 +579,7 @@ impl Val { (InterfaceType::Future(_), _) | (InterfaceType::Stream(_), _) | (InterfaceType::ErrorContext(_), _) => todo!(), + (InterfaceType::FixedSizeList(_), _) => todo!(), } } diff --git a/crates/wit-bindgen/src/lib.rs b/crates/wit-bindgen/src/lib.rs index 5ff283f9871d..d0a2186b1ba3 100644 --- a/crates/wit-bindgen/src/lib.rs +++ b/crates/wit-bindgen/src/lib.rs @@ -1843,6 +1843,7 @@ impl<'a> InterfaceGenerator<'a> { TypeDefKind::Handle(handle) => self.type_handle(id, name, handle, &ty.docs), TypeDefKind::Resource => self.type_resource(id, name, ty, &ty.docs), TypeDefKind::Unknown => unreachable!(), + TypeDefKind::FixedSizeList(_, _) => todo!(), } } @@ -3625,6 +3626,7 @@ fn type_contains_lists(ty: Type, resolve: &Resolve) -> bool { .any(|case| option_type_contains_lists(case.ty, resolve)), TypeDefKind::Type(ty) => type_contains_lists(*ty, resolve), TypeDefKind::List(_) => true, + TypeDefKind::FixedSizeList(_, _) => todo!(), }, // Technically strings are lists too, but we ignore that here because diff --git a/crates/wit-bindgen/src/rust.rs b/crates/wit-bindgen/src/rust.rs index f87f808a6a4d..ce26120f3118 100644 --- a/crates/wit-bindgen/src/rust.rs +++ b/crates/wit-bindgen/src/rust.rs @@ -132,6 +132,7 @@ pub trait RustGenerator<'a> { TypeDefKind::Type(Type::String) => true, TypeDefKind::Type(_) => false, TypeDefKind::Unknown => unreachable!(), + TypeDefKind::FixedSizeList(_, _) => todo!(), } } } @@ -187,6 +188,7 @@ pub trait RustGenerator<'a> { TypeDefKind::Type(t) => self.ty(t, mode), TypeDefKind::Unknown => unreachable!(), + TypeDefKind::FixedSizeList(_, _) => todo!(), } } diff --git a/crates/wit-bindgen/src/types.rs b/crates/wit-bindgen/src/types.rs index 8b36ce05dac7..28079e53a033 100644 --- a/crates/wit-bindgen/src/types.rs +++ b/crates/wit-bindgen/src/types.rs @@ -157,6 +157,7 @@ impl Types { TypeDefKind::Handle(_) => info.has_handle = true, TypeDefKind::Resource => {} TypeDefKind::Unknown => unreachable!(), + TypeDefKind::FixedSizeList(_, _) => todo!(), } self.type_info.insert(ty, info); info From b663725f8ec53844e51955e8ea8a3c3f8e0e0a00 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sat, 12 Jul 2025 17:15:45 +0200 Subject: [PATCH 2/3] fixed size list support is in wasm-tools master --- Cargo.lock | 99 ++++++++++++++++++++++++++++++------------------------ Cargo.toml | 21 ++++++------ 2 files changed, 67 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44df37a5a618..0f243840061b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,7 +211,7 @@ dependencies = [ "bitflags 2.6.0", "cexpr", "clang-sys", - "itertools 0.12.1", + "itertools 0.13.0", "log", "prettyplease", "proc-macro2", @@ -2107,15 +2107,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.13.0" @@ -4047,7 +4038,7 @@ name = "verify-component-adapter" version = "36.0.0" dependencies = [ "anyhow", - "wasmparser 0.229.0", + "wasmparser 0.235.0", "wat", ] @@ -4238,14 +4229,13 @@ dependencies = [ ] [[package]] -name = "wasm-metadata" -version = "0.229.0" -source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#9669555dd2656a5a12710682812de12c3e82da04" +name = "wasm-encoder" +version = "0.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3bc393c395cb621367ff02d854179882b9a351b4e0c93d1397e6090b53a5c2a" dependencies = [ - "anyhow", - "indexmap 2.7.0", - "wasm-encoder 0.229.0", - "wasmparser 0.229.0", + "leb128fmt", + "wasmparser 0.235.0", ] [[package]] @@ -4262,8 +4252,9 @@ dependencies = [ [[package]] name = "wasm-mutate" -version = "0.229.0" -source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#9669555dd2656a5a12710682812de12c3e82da04" +version = "0.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8917477e93c5c48b6d0dc9f94ea5d6fe9a0ccc3576cbb618f049011cc7e9261" dependencies = [ "egg", "log", @@ -4275,8 +4266,9 @@ dependencies = [ [[package]] name = "wasm-smith" -version = "0.229.0" -source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#9669555dd2656a5a12710682812de12c3e82da04" +version = "0.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3be2ca016817c0732fdb615d41183ecd6fee1a0052c838b3cdffaa66e141883" dependencies = [ "anyhow", "arbitrary", @@ -4297,8 +4289,9 @@ dependencies = [ [[package]] name = "wasm-wave" -version = "0.229.0" -source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#9669555dd2656a5a12710682812de12c3e82da04" +version = "0.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "034bc908dc5c1257ffc63b42c7ac7039092bd369e858c5e78e3242b662a8b7d1" dependencies = [ "indexmap 2.7.0", "logos", @@ -4375,12 +4368,13 @@ dependencies = [ [[package]] name = "wasmprinter" -version = "0.229.0" -source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#9669555dd2656a5a12710682812de12c3e82da04" +version = "0.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75aa8e9076de6b9544e6dab4badada518cca0bf4966d35b131bbd057aed8fa0a" dependencies = [ "anyhow", "termcolor", - "wasmparser 0.229.0", + "wasmparser 0.235.0", ] [[package]] @@ -4428,7 +4422,7 @@ dependencies = [ "wasi-common", "wasm-encoder", "wasm-wave", - "wasmparser 0.229.0", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-asm-macros", "wasmtime-internal-cache", @@ -4557,7 +4551,7 @@ dependencies = [ "wasmtime-wasi-threads", "wasmtime-wasi-tls", "wasmtime-wast", - "wast 229.0.0", + "wast 235.0.0", "wat", "windows-sys 0.60.2", "wit-component", @@ -4613,7 +4607,7 @@ dependencies = [ "arbitrary", "env_logger 0.11.5", "libfuzzer-sys", - "wasmparser 0.229.0", + "wasmparser 0.235.0", "wasmprinter", "wasmtime-environ", "wasmtime-test-util", @@ -4643,7 +4637,7 @@ dependencies = [ "rand", "smallvec", "target-lexicon", - "wasmparser 0.229.0", + "wasmparser 0.235.0", "wasmtime", "wasmtime-fuzzing", "wasmtime-test-util", @@ -4671,7 +4665,7 @@ dependencies = [ "wasm-smith", "wasm-spec-interpreter", "wasmi", - "wasmparser 0.229.0", + "wasmparser 0.235.0", "wasmprinter", "wasmtime", "wasmtime-cli-flags", @@ -4759,7 +4753,7 @@ dependencies = [ "smallvec", "target-lexicon", "thiserror 2.0.12", - "wasmparser 0.229.0", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-math", "wasmtime-internal-versioned-export-macros", @@ -4855,7 +4849,7 @@ dependencies = [ "gimli 0.32.0", "object 0.37.1", "target-lexicon", - "wasmparser 0.229.0", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-cranelift", "winch-codegen", @@ -5070,7 +5064,7 @@ dependencies = [ "log", "tokio", "wasmtime", - "wast 229.0.0", + "wast 235.0.0", ] [[package]] @@ -5084,8 +5078,9 @@ dependencies = [ [[package]] name = "wast" -version = "229.0.0" -source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#9669555dd2656a5a12710682812de12c3e82da04" +version = "235.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1eda4293f626c99021bb3a6fbe4fbbe90c0e31a5ace89b5f620af8925de72e13" dependencies = [ "bumpalo", "gimli 0.31.1", @@ -5097,10 +5092,11 @@ dependencies = [ [[package]] name = "wat" -version = "1.229.0" -source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#9669555dd2656a5a12710682812de12c3e82da04" +version = "1.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e777e0327115793cb96ab220b98f85327ec3d11f34ec9e8d723264522ef206aa" dependencies = [ - "wast 229.0.0", + "wast 235.0.0", ] [[package]] @@ -5230,7 +5226,7 @@ dependencies = [ "smallvec", "target-lexicon", "thiserror 2.0.12", - "wasmparser 0.229.0", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-cranelift", "wasmtime-internal-math", @@ -5547,10 +5543,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64a57a11109cc553396f89f3a38a158a97d0b1adaec113bd73e0f64d30fb601f" dependencies = [ "anyhow", - "id-arena", + "bitflags 2.6.0", "indexmap 2.7.0", "log", - "semver", "serde", "serde_derive", "serde_json", @@ -5560,6 +5555,24 @@ dependencies = [ "wit-parser", ] +[[package]] +name = "wit-parser" +version = "0.235.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a1f95a87d03a33e259af286b857a95911eb46236a0f726cbaec1227b3dfc67a" +dependencies = [ + "anyhow", + "id-arena", + "indexmap 2.7.0", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser 0.235.0", +] + [[package]] name = "witx" version = "0.9.1" diff --git a/Cargo.toml b/Cargo.toml index 0f7bbf69abee..79afe3f578ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -330,16 +330,17 @@ wit-bindgen-rt = { version = "0.43.0", default-features = false } wit-bindgen-rust-macro = { version = "0.43.0", default-features = false } # wasm-tools family: -wasmparser = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list", default-features = false, features = ['simd'] } -wat = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } -wast = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } -wasmprinter = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } -wasm-encoder = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } -wasm-smith = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } -wasm-mutate = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } -wit-parser = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } -wit-component = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } -wasm-wave = { git = "https://github.com/cpetig/wasm-tools", branch = "fixed-length-list" } +wasmparser = { version = "0.235.0", default-features = false, features = ['simd'] } +wat = "1.235.0" +wast = "235.0.0" +wasmprinter = "0.235.0" +wasm-encoder = "0.235.0" +wasm-smith = "0.235.0" +wasm-mutate = "0.235.0" +wit-parser = "0.235.0" +wit-component = "0.235.0" +wasm-wave = "0.235.0" +wasm-compose = "0.235.0" # Non-Bytecode Alliance maintained dependencies: # -------------------------- From 1cf1e1010c5e1076e5094aa0848b71927404f7fb Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sat, 12 Jul 2025 17:34:00 +0200 Subject: [PATCH 3/3] post-merge fixes --- crates/environ/src/component/types_builder.rs | 22 ++++++++++---- crates/environ/src/fact/trampoline.rs | 18 ++++++----- crates/wasmtime/src/config.rs | 3 +- crates/wasmtime/src/engine/serialization.rs | 30 +++++++++++++++++++ 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/crates/environ/src/component/types_builder.rs b/crates/environ/src/component/types_builder.rs index 16b3bbecd076..6aa3b051cb9c 100644 --- a/crates/environ/src/component/types_builder.rs +++ b/crates/environ/src/component/types_builder.rs @@ -536,16 +536,24 @@ impl ComponentTypesBuilder { self.add_tuple_type(TypeTuple { types, abi }) } - fn fixed_size_list_type(&mut self, types: TypesRef<'_>, ty: &ComponentValType, size: u32) -> Result { + fn fixed_size_list_type( + &mut self, + types: TypesRef<'_>, + ty: &ComponentValType, + size: u32, + ) -> Result { assert_eq!(types.id(), self.module_types.validator_id()); let element = self.valtype(types, ty)?; Ok(self.new_fixed_size_list_type(element, size)) } - pub(crate) fn new_fixed_size_list_type(&mut self, element: InterfaceType, size: u32) -> TypeFixedSizeListIndex { + pub(crate) fn new_fixed_size_list_type( + &mut self, + element: InterfaceType, + size: u32, + ) -> TypeFixedSizeListIndex { let element_abi = self.component_types.canonical_abi(&element); - let abi = CanonicalAbiInfo::record( - (0..size).into_iter().map(|_| element_abi)); + let abi = CanonicalAbiInfo::record((0..size).into_iter().map(|_| element_abi)); self.add_fixed_size_list_type(TypeFixedSizeList { element, size, abi }) } @@ -1066,7 +1074,11 @@ impl TypeInformation { } fn fixed_size_lists(&mut self, types: &ComponentTypesBuilder, ty: &TypeFixedSizeList) { - self.build_record((0..ty.size).into_iter().map(|_| types.type_information(&ty.element))); + self.build_record( + (0..ty.size) + .into_iter() + .map(|_| types.type_information(&ty.element)), + ); } fn enums(&mut self, _types: &ComponentTypesBuilder, _ty: &TypeEnum) { diff --git a/crates/environ/src/fact/trampoline.rs b/crates/environ/src/fact/trampoline.rs index d7e43ba73cc8..0b1de64488be 100644 --- a/crates/environ/src/fact/trampoline.rs +++ b/crates/environ/src/fact/trampoline.rs @@ -19,9 +19,9 @@ use crate::component::{ CanonicalAbiInfo, ComponentTypesBuilder, FLAG_MAY_ENTER, FLAG_MAY_LEAVE, FixedEncoding as FE, FlatType, InterfaceType, MAX_FLAT_ASYNC_PARAMS, MAX_FLAT_PARAMS, PREPARE_ASYNC_NO_RESULT, PREPARE_ASYNC_WITH_RESULT, StringEncoding, Transcode, TypeComponentLocalErrorContextTableIndex, - TypeEnumIndex, TypeFlagsIndex, TypeFutureTableIndex, TypeListIndex, TypeOptionIndex, - TypeRecordIndex, TypeResourceTableIndex, TypeResultIndex, TypeStreamTableIndex, TypeTupleIndex, - TypeVariantIndex, VariantInfo, + TypeEnumIndex, TypeFixedSizeListIndex, TypeFlagsIndex, TypeFutureTableIndex, TypeListIndex, + TypeOptionIndex, TypeRecordIndex, TypeResourceTableIndex, TypeResultIndex, + TypeStreamTableIndex, TypeTupleIndex, TypeVariantIndex, VariantInfo, }; use crate::fact::signature::Signature; use crate::fact::transcode::Transcoder; @@ -2850,10 +2850,14 @@ impl<'a, 'b> Compiler<'a, 'b> { // TODO: subtyping assert_eq!(src_ty.size, dst_ty.size); - let srcs = src - .record_field_srcs(self.types, (0..src_ty.size).into_iter().map(|_| src_ty.element)); - let dsts = dst - .record_field_dsts(self.types, (0..dst_ty.size).into_iter().map(|_| dst_ty.element)); + let srcs = src.record_field_srcs( + self.types, + (0..src_ty.size).into_iter().map(|_| src_ty.element), + ); + let dsts = dst.record_field_dsts( + self.types, + (0..dst_ty.size).into_iter().map(|_| dst_ty.element), + ); for (src, dst) in srcs.zip(dsts) { self.translate(&src_ty.element, &src, &dst_ty.element, &dst); } diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rs index c5daac4008d9..2bc6043ce47c 100644 --- a/crates/wasmtime/src/config.rs +++ b/crates/wasmtime/src/config.rs @@ -1166,8 +1166,9 @@ impl Config { #[cfg(feature = "component-model")] pub fn wasm_component_model_fixed_size_lists(&mut self, enable: bool) -> &mut Self { self.wasm_feature(WasmFeatures::CM_FIXED_SIZE_LIST, enable); + self } - + /// This corresponds to the 📝 emoji in the component model specification. /// /// Please note that Wasmtime's support for this feature is _very_ diff --git a/crates/wasmtime/src/engine/serialization.rs b/crates/wasmtime/src/engine/serialization.rs index bdec95720d6a..86dc67e13936 100644 --- a/crates/wasmtime/src/engine/serialization.rs +++ b/crates/wasmtime/src/engine/serialization.rs @@ -208,7 +208,37 @@ impl Metadata<'_> { let engine_target = engine.target(); let module_target = target_lexicon::Triple::from_str(&self.target).map_err(|e| anyhow!(e))?; + + if module_target.architecture != engine_target.architecture { + bail!( + "Module was compiled for architecture '{}'", + module_target.architecture + ); + } + + if module_target.operating_system != engine_target.operating_system { + bail!( + "Module was compiled for operating system '{}'", + module_target.operating_system + ); + } + + Ok(()) + } + + fn check_shared_flags(&mut self, engine: &Engine) -> Result<()> { + for (name, val) in self.shared_flags.iter() { + engine + .check_compatible_with_shared_flag(name, val) + .map_err(|s| anyhow::Error::msg(s)) + .context("compilation settings of module incompatible with native host")?; + } + Ok(()) + } + + fn check_isa_flags(&mut self, engine: &Engine) -> Result<()> { for (name, val) in self.isa_flags.iter() { + engine .check_compatible_with_isa_flag(name, val) .map_err(|s| anyhow::Error::msg(s)) .context("compilation settings of module incompatible with native host")?;