diff --git a/crates/wit-component/src/encoding.rs b/crates/wit-component/src/encoding.rs index bd8a6a6d0..937233342 100644 --- a/crates/wit-component/src/encoding.rs +++ b/crates/wit-component/src/encoding.rs @@ -5,6 +5,7 @@ use crate::{ use anyhow::{anyhow, bail, Context, Result}; use indexmap::{map::Entry, IndexMap, IndexSet}; use std::hash::{Hash, Hasher}; +use std::mem; use wasm_encoder::*; use wasmparser::{Validator, WasmFeatures}; use wit_parser::{ @@ -455,13 +456,15 @@ struct TypeEncoder<'a> { } impl<'a> TypeEncoder<'a> { - fn finish(&self, component: &mut Component) { + fn finish(&self, component: &mut ComponentEncoding) { if !self.types.is_empty() { - component.section(&self.types); + component.flush(); + component.component.section(&self.types); } if !self.exports.is_empty() { - component.section(&self.exports); + component.flush(); + component.component.section(&self.exports); } } @@ -1075,9 +1078,7 @@ impl TypeContents { #[derive(Default)] struct EncodingState { /// The component being encoded. - component: Component, - /// The various index spaces used in the encoding. - indexes: Indexes, + component: ComponentEncoding, /// The index into the core module index space for the inner core module. /// /// If `None`, the core module has not been encoded. @@ -1106,14 +1107,10 @@ struct EncodingState { impl EncodingState { fn encode_core_module(&mut self, module: &[u8]) -> u32 { - *self.module_index.get_or_insert_with(|| { - self.component.section(&wasm_encoder::RawSection { - id: ComponentSectionId::CoreModule.into(), - data: module, - }); - - self.indexes.alloc_core_module() - }) + assert!(self.module_index.is_none()); + let ret = self.component.core_module_raw(module); + self.module_index = Some(ret); + ret } fn encode_core_instantiation( @@ -1131,19 +1128,15 @@ impl EncodingState { // Encode a shim instantiation if needed self.encode_shim_instantiation(imports); - let mut instances = InstanceSection::new(); let args: Vec<_> = imports .map .iter() .enumerate() .map(|(instance_index, (name, import))| { let mut exports = Vec::with_capacity(import.direct.len() + import.indirect.len()); - let mut aliases = ComponentAliasSection::new(); - let mut functions = CanonicalFunctionSection::new(); for lowering in &import.indirect { - let index = self.alias_core_item( - &mut aliases, + let index = self.component.alias_core_item( self.shim_instance_index .expect("shim should be instantiated"), ExportKind::Func, @@ -1153,36 +1146,25 @@ impl EncodingState { } for lowering in &import.direct { - let func_index = - self.alias_func(&mut aliases, instance_index as u32, lowering.name); - let core_func_index = self.lower_func(&mut functions, func_index, []); + let func_index = self + .component + .alias_func(instance_index as u32, lowering.name); + let core_func_index = self.component.lower_func(func_index, []); exports.push((lowering.name, ExportKind::Func, core_func_index)); } - self.component.section(&aliases); - self.component.section(&functions); - - let index = self.instantiate_core_exports(&mut instances, exports); + let index = self.component.instantiate_core_exports(exports); (*name, ModuleArg::Instance(index)) }) .collect(); - self.component.section(&instances); - self.instantiate_core_module(args, has_memory, has_realloc); self.encode_indirect_lowerings(encoding, imports) } fn encode_imports(&mut self, imports: &ImportEncoder) { - let mut section = ComponentImportSection::default(); - for (name, import) in &imports.map { - section.import(name, import.ty); - self.indexes.alloc_instance(); - } - - if !section.is_empty() { - self.component.section(§ion); + self.component.import(name, import.ty); } } @@ -1194,20 +1176,14 @@ impl EncodingState { ) -> Result<()> { let core_instance_index = self.instance_index.expect("must be instantiated"); - let mut section = ComponentExportSection::default(); - let mut instances = ComponentInstanceSection::new(); - for (export, is_default) in exports { // Alias the exports from the core module - let mut aliases = ComponentAliasSection::new(); - let mut functions = CanonicalFunctionSection::new(); let mut interface_exports = Vec::new(); for func in &export.functions { let name = expected_export_name((!is_default).then(|| export.name.as_str()), &func.name); - let core_func_index = self.alias_core_item( - &mut aliases, + let core_func_index = self.component.alias_core_item( core_instance_index, ExportKind::Func, name.as_ref(), @@ -1226,19 +1202,19 @@ impl EncodingState { .into_iter(encoding, self.memory_index, self.realloc_index)? .collect::>(); if export.guest_export_needs_post_return(func) { - let post_return = self.alias_core_item( - &mut aliases, + let post_return = self.component.alias_core_item( core_instance_index, ExportKind::Func, &format!("cabi_post_{name}"), ); options.push(CanonicalOption::PostReturn(post_return)); } - let func_index = self.lift_func(&mut functions, core_func_index, ty, options); + let func_index = self.component.lift_func(core_func_index, ty, options); if is_default { // Directly export the lifted function - section.export(&func.name, ComponentExportKind::Func, func_index); + self.component + .export(&func.name, ComponentExportKind::Func, func_index); } else { // Otherwise, add it to the list for later instantiation interface_exports.push(( @@ -1249,27 +1225,17 @@ impl EncodingState { } } - self.component.section(&aliases); - self.component.section(&functions); - if !interface_exports.is_empty() { if export.name.is_empty() { bail!("cannot export an unnamed interface"); } - let instance_index = self.instantiate_exports(&mut instances, interface_exports); - section.export(&export.name, ComponentExportKind::Instance, instance_index); + let instance_index = self.component.instantiate_exports(interface_exports); + self.component + .export(&export.name, ComponentExportKind::Instance, instance_index); } } - if !instances.is_empty() { - self.component.section(&instances); - } - - if !section.is_empty() { - self.component.section(§ion); - } - Ok(()) } @@ -1357,15 +1323,9 @@ impl EncodingState { fixups.section(&imports_section); fixups.section(&elements); - let shim_module_index = self.indexes.alloc_core_module(); - self.component.section(&ModuleSection(&shim)); - - self.fixups_module_index = Some(self.indexes.alloc_core_module()); - self.component.section(&ModuleSection(&fixups)); - - let mut instances = InstanceSection::default(); - self.shim_instance_index = Some(self.instantiate(&mut instances, shim_module_index, [])); - self.component.section(&instances); + let shim_module_index = self.component.core_module(&shim); + self.fixups_module_index = Some(self.component.core_module(&fixups)); + self.shim_instance_index = Some(self.component.instantiate(shim_module_index, [])); } fn encode_shim_function( @@ -1400,9 +1360,7 @@ impl EncodingState { .shim_instance_index .expect("must have an instantiated shim"); - let mut aliases = ComponentAliasSection::new(); - let table_index = self.alias_core_item( - &mut aliases, + let table_index = self.component.alias_core_item( shim_instance_index, ExportKind::Table, INDIRECT_TABLE_NAME, @@ -1411,14 +1369,13 @@ impl EncodingState { let mut exports = Vec::with_capacity(imports.indirect_count as usize); exports.push((INDIRECT_TABLE_NAME, ExportKind::Table, table_index)); - let mut functions = CanonicalFunctionSection::new(); for (instance_index, import) in imports.map.values().enumerate() { for lowering in &import.indirect { - let func_index = - self.alias_func(&mut aliases, instance_index as u32, lowering.name); + let func_index = self + .component + .alias_func(instance_index as u32, lowering.name); - let core_func_index = self.lower_func( - &mut functions, + let core_func_index = self.component.lower_func( func_index, lowering .options @@ -1433,17 +1390,11 @@ impl EncodingState { } } - self.component.section(&aliases); - self.component.section(&functions); - - let mut instances = InstanceSection::new(); - let instance_index = self.instantiate_core_exports(&mut instances, exports); - self.instantiate( - &mut instances, + let instance_index = self.component.instantiate_core_exports(exports); + self.component.instantiate( self.fixups_module_index.expect("must have fixup module"), [("", ModuleArg::Instance(instance_index))], ); - self.component.section(&instances); Ok(()) } @@ -1454,18 +1405,12 @@ impl EncodingState { { assert!(self.instance_index.is_none()); - let mut instances = InstanceSection::new(); - let mut aliases = ComponentAliasSection::new(); - - let instance_index = self.instantiate( - &mut instances, - self.module_index.expect("core module encoded"), - args, - ); + let instance_index = self + .component + .instantiate(self.module_index.expect("core module encoded"), args); if has_memory { - self.memory_index = Some(self.alias_core_item( - &mut aliases, + self.memory_index = Some(self.component.alias_core_item( instance_index, ExportKind::Memory, "memory", @@ -1473,134 +1418,206 @@ impl EncodingState { } if has_realloc { - self.realloc_index = Some(self.alias_core_item( - &mut aliases, + self.realloc_index = Some(self.component.alias_core_item( instance_index, ExportKind::Func, "cabi_realloc", )); } - self.component.section(&instances); - self.component.section(&aliases); - self.instance_index = Some(instance_index); } +} - fn instantiate<'a, A>( - &mut self, - instances: &mut InstanceSection, - module_index: u32, - args: A, - ) -> u32 +#[derive(Debug)] +struct DirectLowering<'a> { + name: &'a str, +} + +#[derive(Debug)] +struct IndirectLowering<'a> { + name: &'a str, + sig: WasmSignature, + options: RequiredOptions, + export_name: String, +} + +#[derive(Debug)] +struct ImportedInterface<'a> { + ty: ComponentTypeRef, + direct: Vec>, + indirect: Vec>, +} + +#[derive(Default)] +struct ComponentEncoding { + component: Component, + /// The last section which was appended to during encoding. + last_section: LastSection, + // Core index spaces + core_modules: u32, + core_funcs: u32, + core_memories: u32, + core_tables: u32, + core_instances: u32, + + // Component index spaces + funcs: u32, + instances: u32, +} + +impl ComponentEncoding { + fn finish(mut self) -> Vec { + self.flush(); + self.component.finish() + } + + fn instantiate<'a, A>(&mut self, module_index: u32, args: A) -> u32 where A: IntoIterator, A::IntoIter: ExactSizeIterator, { - instances.instantiate(module_index, args); - self.indexes.alloc_core_instance() - } - - fn alias_core_item( - &mut self, - aliases: &mut ComponentAliasSection, - instance: u32, - kind: ExportKind, - name: &str, - ) -> u32 { - aliases.core_instance_export(instance, kind, name); - match kind { - ExportKind::Func => self.indexes.alloc_core_func(), - ExportKind::Table => self.indexes.alloc_core_table(), - ExportKind::Memory => self.indexes.alloc_core_memory(), - ExportKind::Global | ExportKind::Tag => unreachable!(), - } + self.instances().instantiate(module_index, args); + inc(&mut self.core_instances) } - fn alias_func( - &mut self, - aliases: &mut ComponentAliasSection, - instance: u32, - name: &str, - ) -> u32 { - aliases.instance_export(instance, ComponentExportKind::Func, name); - self.indexes.alloc_func() + fn alias_func(&mut self, instance: u32, name: &str) -> u32 { + self.aliases() + .instance_export(instance, ComponentExportKind::Func, name); + inc(&mut self.funcs) } - fn lower_func( - &mut self, - functions: &mut CanonicalFunctionSection, - func_index: u32, - options: O, - ) -> u32 + fn lower_func(&mut self, func_index: u32, options: O) -> u32 where O: IntoIterator, O::IntoIter: ExactSizeIterator, { - functions.lower(func_index, options); - self.indexes.alloc_core_func() + self.canonical_functions().lower(func_index, options); + inc(&mut self.core_funcs) } - fn lift_func( - &mut self, - functions: &mut CanonicalFunctionSection, - core_func_index: u32, - type_index: u32, - options: O, - ) -> u32 + fn lift_func(&mut self, core_func_index: u32, type_index: u32, options: O) -> u32 where O: IntoIterator, O::IntoIter: ExactSizeIterator, { - functions.lift(core_func_index, type_index, options); - self.indexes.alloc_func() + self.canonical_functions() + .lift(core_func_index, type_index, options); + inc(&mut self.funcs) } - fn instantiate_core_exports<'a, E>( - &mut self, - instances: &mut InstanceSection, - exports: E, - ) -> u32 + fn instantiate_core_exports<'a, E>(&mut self, exports: E) -> u32 where E: IntoIterator, E::IntoIter: ExactSizeIterator, { - instances.export_items(exports); - self.indexes.alloc_core_instance() + self.instances().export_items(exports); + inc(&mut self.core_instances) } - fn instantiate_exports<'a, E>( - &mut self, - instances: &mut ComponentInstanceSection, - exports: E, - ) -> u32 + fn instantiate_exports<'a, E>(&mut self, exports: E) -> u32 where E: IntoIterator, E::IntoIter: ExactSizeIterator, { - instances.export_items(exports); - self.indexes.alloc_instance() + self.component_instances().export_items(exports); + inc(&mut self.instances) + } + + fn core_module(&mut self, module: &Module) -> u32 { + self.flush(); + self.component.section(&ModuleSection(module)); + inc(&mut self.core_modules) + } + + fn core_module_raw(&mut self, module: &[u8]) -> u32 { + self.flush(); + self.component.section(&wasm_encoder::RawSection { + id: ComponentSectionId::CoreModule.into(), + data: module, + }); + inc(&mut self.core_modules) + } + + fn alias_core_item(&mut self, instance: u32, kind: ExportKind, name: &str) -> u32 { + self.aliases().core_instance_export(instance, kind, name); + match kind { + ExportKind::Func => inc(&mut self.core_funcs), + ExportKind::Table => inc(&mut self.core_tables), + ExportKind::Memory => inc(&mut self.core_memories), + ExportKind::Global | ExportKind::Tag => unreachable!(), + } + } + + fn export(&mut self, name: &str, kind: ComponentExportKind, idx: u32) { + self.exports().export(name, kind, idx); + } + + fn import(&mut self, name: &str, ty: ComponentTypeRef) -> u32 { + let ret = match &ty { + ComponentTypeRef::Instance(_) => inc(&mut self.instances), + ComponentTypeRef::Func(_) => inc(&mut self.funcs), + _ => unimplemented!(), + }; + self.imports().import(name, ty); + ret } } -#[derive(Debug)] -struct DirectLowering<'a> { - name: &'a str, +macro_rules! section_accessors { + ($($method:ident => $section:ident)*) => ( + #[derive(Default)] + enum LastSection { + #[default] + None, + $($section($section),)* + } + + impl ComponentEncoding { + $( + fn $method(&mut self) -> &mut $section { + match &self.last_section { + LastSection::$section(_) => {} + _ => { + self.flush(); + self.last_section = LastSection::$section($section::new()); + } + } + match &mut self.last_section { + LastSection::$section(ret) => ret, + _ => unreachable!() + } + } + )* + + fn flush(&mut self) { + match mem::take(&mut self.last_section) { + LastSection::None => {} + $( + LastSection::$section(section) => { + self.component.section(§ion); + } + )* + } + } + + } + ) } -#[derive(Debug)] -struct IndirectLowering<'a> { - name: &'a str, - sig: WasmSignature, - options: RequiredOptions, - export_name: String, +section_accessors! { + component_instances => ComponentInstanceSection + instances => InstanceSection + canonical_functions => CanonicalFunctionSection + aliases => ComponentAliasSection + exports => ComponentExportSection + imports => ComponentImportSection } -#[derive(Debug)] -struct ImportedInterface<'a> { - ty: ComponentTypeRef, - direct: Vec>, - indirect: Vec>, +fn inc(idx: &mut u32) -> u32 { + let ret = *idx; + *idx += 1; + ret } /// The import encoder handles indirect lowering of any imports @@ -1672,64 +1689,6 @@ impl<'a> ImportEncoder<'a> { } } -#[derive(Default)] -struct Indexes { - // Core index spaces - core_modules: u32, - core_funcs: u32, - core_memories: u32, - core_tables: u32, - core_instances: u32, - - // Component index spaces - funcs: u32, - instances: u32, -} - -impl Indexes { - fn alloc_core_module(&mut self) -> u32 { - let index = self.core_modules; - self.core_modules += 1; - index - } - - fn alloc_core_func(&mut self) -> u32 { - let index = self.core_funcs; - self.core_funcs += 1; - index - } - - fn alloc_core_memory(&mut self) -> u32 { - let index = self.core_memories; - self.core_memories += 1; - index - } - - fn alloc_core_table(&mut self) -> u32 { - let index = self.core_tables; - self.core_tables += 1; - index - } - - fn alloc_core_instance(&mut self) -> u32 { - let index = self.core_instances; - self.core_instances += 1; - index - } - - fn alloc_func(&mut self) -> u32 { - let index = self.funcs; - self.funcs += 1; - index - } - - fn alloc_instance(&mut self) -> u32 { - let index = self.instances; - self.instances += 1; - index - } -} - /// An encoder of components based on `wit` interface definitions. #[derive(Default)] pub struct ComponentEncoder<'a> { @@ -1859,7 +1818,7 @@ impl<'a> InterfaceEncoder<'a> { /// Encode the interface as a component and return the bytes. pub fn encode(&self) -> Result> { - let mut component = Component::default(); + let mut component = ComponentEncoding::default(); let mut types = TypeEncoder::default(); types.encode_func_types([(self.interface, true)].into_iter(), true)?; diff --git a/crates/wit-component/tests/components/exports/component.wat b/crates/wit-component/tests/components/exports/component.wat index cc868f9e1..00b6d4100 100644 --- a/crates/wit-component/tests/components/exports/component.wat +++ b/crates/wit-component/tests/components/exports/component.wat @@ -67,33 +67,33 @@ (alias core export 0 "memory" (core memory (;0;))) (alias core export 0 "cabi_realloc" (core func (;0;))) (alias core export 0 "a" (core func (;1;))) + (func (;0;) (type 0) (canon lift (core func 1))) + (export "a" (func 0)) (alias core export 0 "b" (core func (;2;))) (alias core export 0 "cabi_post_b" (core func (;3;))) - (alias core export 0 "c" (core func (;4;))) - (func (;0;) (type 0) (canon lift (core func 1))) (func (;1;) (type 1) (canon lift (core func 2) (memory 0) string-encoding=utf8 (post-return 3))) + (export "b" (func 1)) + (alias core export 0 "c" (core func (;4;))) (func (;2;) (type 3) (canon lift (core func 4) (memory 0))) + (export "c" (func 2)) (alias core export 0 "bar#a" (core func (;5;))) (func (;3;) (type 5) (canon lift (core func 5))) + (instance (;0;) + (export "a" (func 3)) + ) + (export "bar" (instance 0)) (alias core export 0 "foo#a" (core func (;6;))) + (func (;4;) (type 0) (canon lift (core func 6))) (alias core export 0 "foo#b" (core func (;7;))) (alias core export 0 "cabi_post_foo#b" (core func (;8;))) + (func (;5;) (type 7) (canon lift (core func 7) (memory 0) (realloc 0) string-encoding=utf8 (post-return 8))) (alias core export 0 "foo#c" (core func (;9;))) (alias core export 0 "cabi_post_foo#c" (core func (;10;))) - (func (;4;) (type 0) (canon lift (core func 6))) - (func (;5;) (type 7) (canon lift (core func 7) (memory 0) (realloc 0) string-encoding=utf8 (post-return 8))) (func (;6;) (type 8) (canon lift (core func 9) (memory 0) (realloc 0) string-encoding=utf8 (post-return 10))) - (instance (;0;) - (export "a" (func 3)) - ) (instance (;1;) (export "a" (func 4)) (export "b" (func 5)) (export "c" (func 6)) ) - (export "a" (func 0)) - (export "b" (func 1)) - (export "c" (func 2)) - (export "bar" (instance 0)) (export "foo" (instance 1)) ) \ No newline at end of file diff --git a/crates/wit-component/tests/components/import-conflict/component.wat b/crates/wit-component/tests/components/import-conflict/component.wat index 9ff7c1fba..5502d9d28 100644 --- a/crates/wit-component/tests/components/import-conflict/component.wat +++ b/crates/wit-component/tests/components/import-conflict/component.wat @@ -71,15 +71,15 @@ ) (core instance (;0;) (instantiate 1)) (alias core export 0 "0" (core func (;0;))) - (alias core export 0 "1" (core func (;1;))) - (alias export 2 "a" (func (;0;))) - (core func (;2;) (canon lower (func 0))) (core instance (;1;) (export "a" (func 0)) ) + (alias core export 0 "1" (core func (;1;))) (core instance (;2;) (export "baz" (func 1)) ) + (alias export 2 "a" (func (;0;))) + (core func (;2;) (canon lower (func 0))) (core instance (;3;) (export "a" (func 2)) ) @@ -93,8 +93,8 @@ (alias core export 4 "cabi_realloc" (core func (;3;))) (alias core export 0 "$imports" (core table (;0;))) (alias export 0 "a" (func (;1;))) - (alias export 1 "baz" (func (;2;))) (core func (;4;) (canon lower (func 1) (memory 0) string-encoding=utf8)) + (alias export 1 "baz" (func (;2;))) (core func (;5;) (canon lower (func 2) (memory 0) (realloc 3))) (core instance (;5;) (export "$imports" (table 0)) diff --git a/crates/wit-component/tests/components/import-export/component.wat b/crates/wit-component/tests/components/import-export/component.wat index be01a9e06..5d93044d9 100644 --- a/crates/wit-component/tests/components/import-export/component.wat +++ b/crates/wit-component/tests/components/import-export/component.wat @@ -86,15 +86,15 @@ (alias core export 2 "a" (core func (;3;))) (alias core export 2 "cabi_post_a" (core func (;4;))) (func (;1;) (type 1) (canon lift (core func 3) (memory 0) (realloc 1) string-encoding=utf8 (post-return 4))) + (export "a" (func 1)) (alias core export 2 "bar#a" (core func (;5;))) + (func (;2;) (type 2) (canon lift (core func 5))) (alias core export 2 "bar#b" (core func (;6;))) (alias core export 2 "cabi_post_bar#b" (core func (;7;))) - (func (;2;) (type 2) (canon lift (core func 5))) (func (;3;) (type 3) (canon lift (core func 6) (memory 0) string-encoding=utf8 (post-return 7))) (instance (;1;) (export "a" (func 2)) (export "b" (func 3)) ) - (export "a" (func 1)) (export "bar" (instance 1)) ) \ No newline at end of file diff --git a/crates/wit-component/tests/components/imports/component.wat b/crates/wit-component/tests/components/imports/component.wat index 95b885b76..c6a1f36b8 100644 --- a/crates/wit-component/tests/components/imports/component.wat +++ b/crates/wit-component/tests/components/imports/component.wat @@ -91,26 +91,26 @@ (alias core export 0 "0" (core func (;0;))) (alias export 0 "bar2" (func (;0;))) (core func (;1;) (canon lower (func 0))) - (alias core export 0 "1" (core func (;2;))) - (alias export 1 "baz2" (func (;1;))) - (alias export 1 "baz3" (func (;2;))) - (core func (;3;) (canon lower (func 1))) - (core func (;4;) (canon lower (func 2))) - (alias export 2 "foo1" (func (;3;))) - (alias export 2 "foo2" (func (;4;))) - (alias export 2 "foo3" (func (;5;))) - (core func (;5;) (canon lower (func 3))) - (core func (;6;) (canon lower (func 4))) - (core func (;7;) (canon lower (func 5))) (core instance (;1;) (export "bar1" (func 0)) (export "bar2" (func 1)) ) + (alias core export 0 "1" (core func (;2;))) + (alias export 1 "baz2" (func (;1;))) + (core func (;3;) (canon lower (func 1))) + (alias export 1 "baz3" (func (;2;))) + (core func (;4;) (canon lower (func 2))) (core instance (;2;) (export "baz1" (func 2)) (export "baz2" (func 3)) (export "baz3" (func 4)) ) + (alias export 2 "foo1" (func (;3;))) + (core func (;5;) (canon lower (func 3))) + (alias export 2 "foo2" (func (;4;))) + (core func (;6;) (canon lower (func 4))) + (alias export 2 "foo3" (func (;5;))) + (core func (;7;) (canon lower (func 5))) (core instance (;3;) (export "foo1" (func 5)) (export "foo2" (func 6)) @@ -126,8 +126,8 @@ (alias core export 4 "cabi_realloc" (core func (;8;))) (alias core export 0 "$imports" (core table (;0;))) (alias export 0 "bar1" (func (;6;))) - (alias export 1 "baz1" (func (;7;))) (core func (;9;) (canon lower (func 6) (memory 0) string-encoding=utf8)) + (alias export 1 "baz1" (func (;7;))) (core func (;10;) (canon lower (func 7) (memory 0) string-encoding=utf8)) (core instance (;5;) (export "$imports" (table 0)) diff --git a/crates/wit-component/tests/components/lift-options/component.wat b/crates/wit-component/tests/components/lift-options/component.wat index cb4d9bcaa..e9dff44d3 100644 --- a/crates/wit-component/tests/components/lift-options/component.wat +++ b/crates/wit-component/tests/components/lift-options/component.wat @@ -127,55 +127,55 @@ (alias core export 0 "memory" (core memory (;0;))) (alias core export 0 "cabi_realloc" (core func (;0;))) (alias core export 0 "a" (core func (;1;))) + (func (;0;) (type 0) (canon lift (core func 1))) + (export "a" (func 0)) (alias core export 0 "b" (core func (;2;))) + (func (;1;) (type 2) (canon lift (core func 2) (memory 0) (realloc 0) string-encoding=utf8)) + (export "b" (func 1)) (alias core export 0 "c" (core func (;3;))) + (func (;2;) (type 4) (canon lift (core func 3) (memory 0) (realloc 0) string-encoding=utf8)) + (export "c" (func 2)) (alias core export 0 "d" (core func (;4;))) + (func (;3;) (type 6) (canon lift (core func 4) (memory 0) (realloc 0) string-encoding=utf8)) + (export "d" (func 3)) (alias core export 0 "e" (core func (;5;))) + (func (;4;) (type 8) (canon lift (core func 5))) + (export "e" (func 4)) (alias core export 0 "f" (core func (;6;))) + (func (;5;) (type 10) (canon lift (core func 6))) + (export "f" (func 5)) (alias core export 0 "g" (core func (;7;))) + (func (;6;) (type 12) (canon lift (core func 7) (memory 0) (realloc 0) string-encoding=utf8)) + (export "g" (func 6)) (alias core export 0 "h" (core func (;8;))) + (func (;7;) (type 14) (canon lift (core func 8) (memory 0) (realloc 0) string-encoding=utf8)) + (export "h" (func 7)) (alias core export 0 "i" (core func (;9;))) + (func (;8;) (type 16) (canon lift (core func 9) (memory 0) (realloc 0))) + (export "i" (func 8)) (alias core export 0 "j" (core func (;10;))) + (func (;9;) (type 17) (canon lift (core func 10))) + (export "j" (func 9)) (alias core export 0 "k" (core func (;11;))) + (func (;10;) (type 19) (canon lift (core func 11) (memory 0))) + (export "k" (func 10)) (alias core export 0 "l" (core func (;12;))) (alias core export 0 "cabi_post_l" (core func (;13;))) + (func (;11;) (type 20) (canon lift (core func 12) (memory 0) string-encoding=utf8 (post-return 13))) + (export "l" (func 11)) (alias core export 0 "m" (core func (;14;))) (alias core export 0 "cabi_post_m" (core func (;15;))) + (func (;12;) (type 21) (canon lift (core func 14) (memory 0) (post-return 15))) + (export "m" (func 12)) (alias core export 0 "n" (core func (;16;))) + (func (;13;) (type 22) (canon lift (core func 16))) + (export "n" (func 13)) (alias core export 0 "o" (core func (;17;))) (alias core export 0 "cabi_post_o" (core func (;18;))) + (func (;14;) (type 23) (canon lift (core func 17) (memory 0) string-encoding=utf8 (post-return 18))) + (export "o" (func 14)) (alias core export 0 "p" (core func (;19;))) (alias core export 0 "cabi_post_p" (core func (;20;))) - (func (;0;) (type 0) (canon lift (core func 1))) - (func (;1;) (type 2) (canon lift (core func 2) (memory 0) (realloc 0) string-encoding=utf8)) - (func (;2;) (type 4) (canon lift (core func 3) (memory 0) (realloc 0) string-encoding=utf8)) - (func (;3;) (type 6) (canon lift (core func 4) (memory 0) (realloc 0) string-encoding=utf8)) - (func (;4;) (type 8) (canon lift (core func 5))) - (func (;5;) (type 10) (canon lift (core func 6))) - (func (;6;) (type 12) (canon lift (core func 7) (memory 0) (realloc 0) string-encoding=utf8)) - (func (;7;) (type 14) (canon lift (core func 8) (memory 0) (realloc 0) string-encoding=utf8)) - (func (;8;) (type 16) (canon lift (core func 9) (memory 0) (realloc 0))) - (func (;9;) (type 17) (canon lift (core func 10))) - (func (;10;) (type 19) (canon lift (core func 11) (memory 0))) - (func (;11;) (type 20) (canon lift (core func 12) (memory 0) string-encoding=utf8 (post-return 13))) - (func (;12;) (type 21) (canon lift (core func 14) (memory 0) (post-return 15))) - (func (;13;) (type 22) (canon lift (core func 16))) - (func (;14;) (type 23) (canon lift (core func 17) (memory 0) string-encoding=utf8 (post-return 18))) (func (;15;) (type 25) (canon lift (core func 19) (memory 0) (post-return 20))) - (export "a" (func 0)) - (export "b" (func 1)) - (export "c" (func 2)) - (export "d" (func 3)) - (export "e" (func 4)) - (export "f" (func 5)) - (export "g" (func 6)) - (export "h" (func 7)) - (export "i" (func 8)) - (export "j" (func 9)) - (export "k" (func 10)) - (export "l" (func 11)) - (export "m" (func 12)) - (export "n" (func 13)) - (export "o" (func 14)) (export "p" (func 15)) ) \ No newline at end of file diff --git a/crates/wit-component/tests/components/lower-options/component.wat b/crates/wit-component/tests/components/lower-options/component.wat index e85cf26b3..d83170bbd 100644 --- a/crates/wit-component/tests/components/lower-options/component.wat +++ b/crates/wit-component/tests/components/lower-options/component.wat @@ -203,14 +203,14 @@ (alias core export 0 "9" (core func (;9;))) (alias core export 0 "10" (core func (;10;))) (alias export 0 "a" (func (;0;))) - (alias export 0 "e" (func (;1;))) - (alias export 0 "f" (func (;2;))) - (alias export 0 "j" (func (;3;))) - (alias export 0 "n" (func (;4;))) (core func (;11;) (canon lower (func 0))) + (alias export 0 "e" (func (;1;))) (core func (;12;) (canon lower (func 1))) + (alias export 0 "f" (func (;2;))) (core func (;13;) (canon lower (func 2))) + (alias export 0 "j" (func (;3;))) (core func (;14;) (canon lower (func 3))) + (alias export 0 "n" (func (;4;))) (core func (;15;) (canon lower (func 4))) (core instance (;1;) (export "b" (func 0)) @@ -238,26 +238,26 @@ (alias core export 2 "cabi_realloc" (core func (;16;))) (alias core export 0 "$imports" (core table (;0;))) (alias export 0 "b" (func (;5;))) - (alias export 0 "c" (func (;6;))) - (alias export 0 "d" (func (;7;))) - (alias export 0 "g" (func (;8;))) - (alias export 0 "h" (func (;9;))) - (alias export 0 "i" (func (;10;))) - (alias export 0 "k" (func (;11;))) - (alias export 0 "l" (func (;12;))) - (alias export 0 "m" (func (;13;))) - (alias export 0 "o" (func (;14;))) - (alias export 0 "p" (func (;15;))) (core func (;17;) (canon lower (func 5) (memory 0) string-encoding=utf8)) + (alias export 0 "c" (func (;6;))) (core func (;18;) (canon lower (func 6) (memory 0) string-encoding=utf8)) + (alias export 0 "d" (func (;7;))) (core func (;19;) (canon lower (func 7) (memory 0) string-encoding=utf8)) + (alias export 0 "g" (func (;8;))) (core func (;20;) (canon lower (func 8) (memory 0) string-encoding=utf8)) + (alias export 0 "h" (func (;9;))) (core func (;21;) (canon lower (func 9) (memory 0) string-encoding=utf8)) + (alias export 0 "i" (func (;10;))) (core func (;22;) (canon lower (func 10) (memory 0))) + (alias export 0 "k" (func (;11;))) (core func (;23;) (canon lower (func 11) (memory 0))) + (alias export 0 "l" (func (;12;))) (core func (;24;) (canon lower (func 12) (memory 0) (realloc 16) string-encoding=utf8)) + (alias export 0 "m" (func (;13;))) (core func (;25;) (canon lower (func 13) (memory 0) (realloc 16))) + (alias export 0 "o" (func (;14;))) (core func (;26;) (canon lower (func 14) (memory 0) (realloc 16) string-encoding=utf8)) + (alias export 0 "p" (func (;15;))) (core func (;27;) (canon lower (func 15) (memory 0) (realloc 16))) (core instance (;3;) (export "$imports" (table 0)) diff --git a/crates/wit-component/tests/components/simple/component.wat b/crates/wit-component/tests/components/simple/component.wat index 4adc4c5b0..6234f6263 100644 --- a/crates/wit-component/tests/components/simple/component.wat +++ b/crates/wit-component/tests/components/simple/component.wat @@ -47,17 +47,17 @@ (alias core export 0 "memory" (core memory (;0;))) (alias core export 0 "cabi_realloc" (core func (;0;))) (alias core export 0 "a" (core func (;1;))) + (func (;0;) (type 0) (canon lift (core func 1))) + (export "a" (func 0)) (alias core export 0 "b" (core func (;2;))) (alias core export 0 "cabi_post_b" (core func (;3;))) + (func (;1;) (type 1) (canon lift (core func 2) (memory 0) string-encoding=utf8 (post-return 3))) + (export "b" (func 1)) (alias core export 0 "c" (core func (;4;))) (alias core export 0 "cabi_post_c" (core func (;5;))) - (alias core export 0 "d" (core func (;6;))) - (func (;0;) (type 0) (canon lift (core func 1))) - (func (;1;) (type 1) (canon lift (core func 2) (memory 0) string-encoding=utf8 (post-return 3))) (func (;2;) (type 2) (canon lift (core func 4) (memory 0) (realloc 0) string-encoding=utf8 (post-return 5))) - (func (;3;) (type 4) (canon lift (core func 6) (memory 0) (realloc 0) string-encoding=utf8)) - (export "a" (func 0)) - (export "b" (func 1)) (export "c" (func 2)) + (alias core export 0 "d" (core func (;6;))) + (func (;3;) (type 4) (canon lift (core func 6) (memory 0) (realloc 0) string-encoding=utf8)) (export "d" (func 3)) ) \ No newline at end of file