diff --git a/crates/wit-component/src/encoding.rs b/crates/wit-component/src/encoding.rs index d6b493d82..3930997cf 100644 --- a/crates/wit-component/src/encoding.rs +++ b/crates/wit-component/src/encoding.rs @@ -1685,8 +1685,8 @@ impl<'a> ComponentEncoder<'a> { let mut state = EncodingState::default(); let mut types = TypeEncoder::default(); let mut imports = ImportEncoder::default(); - types.encode_instance_imports(self.imports, &required_imports, &mut imports)?; types.encode_func_types(exports.clone(), false)?; + types.encode_instance_imports(self.imports, &required_imports, &mut imports)?; types.finish(&mut state.component); if self.types_only { diff --git a/crates/wit-component/tests/components/ensure-default-type-exports/component.wat b/crates/wit-component/tests/components/ensure-default-type-exports/component.wat new file mode 100644 index 000000000..9877f0950 --- /dev/null +++ b/crates/wit-component/tests/components/ensure-default-type-exports/component.wat @@ -0,0 +1,43 @@ +(component + (type (;0;) u8) + (type (;1;) (record (field "x" 0))) + (type (;2;) (func (param "b" 1))) + (type (;3;) + (instance + (alias outer 1 2 (type (;0;))) + (export "a" (func (type 0))) + ) + ) + (export "foo" (type 0)) + (export "bar" (type 1)) + (import "foo" (instance (;0;) (type 3))) + (core module (;0;) + (type (;0;) (func (param i32))) + (type (;1;) (func (param i32 i32 i32 i32) (result i32))) + (import "foo" "a" (func (;0;) (type 0))) + (func (;1;) (type 1) (param i32 i32 i32 i32) (result i32) + unreachable + ) + (func (;2;) (type 0) (param i32) + unreachable + ) + (memory (;0;) 1) + (export "memory" (memory 0)) + (export "canonical_abi_realloc" (func 1)) + (export "a" (func 2)) + ) + (alias export 0 "a" (func (;0;))) + (core func (;0;) (canon lower (func 0))) + (core instance (;0;) + (export "a" (func 0)) + ) + (core instance (;1;) (instantiate 0 + (with "foo" (instance 0)) + ) + ) + (core alias export 1 "memory" (memory (;0;))) + (core alias export 1 "canonical_abi_realloc" (func (;1;))) + (core alias export 1 "a" (func (;2;))) + (func (;1;) (type 2) (canon lift (core func 2))) + (export "a" (func 1)) +) \ No newline at end of file diff --git a/crates/wit-component/tests/components/ensure-default-type-exports/default.wit b/crates/wit-component/tests/components/ensure-default-type-exports/default.wit new file mode 100644 index 000000000..462deaa74 --- /dev/null +++ b/crates/wit-component/tests/components/ensure-default-type-exports/default.wit @@ -0,0 +1,7 @@ +type foo = u8 + +record bar { + x: foo +} + +a: func(b: bar) diff --git a/crates/wit-component/tests/components/ensure-default-type-exports/import-foo.wit b/crates/wit-component/tests/components/ensure-default-type-exports/import-foo.wit new file mode 100644 index 000000000..462deaa74 --- /dev/null +++ b/crates/wit-component/tests/components/ensure-default-type-exports/import-foo.wit @@ -0,0 +1,7 @@ +type foo = u8 + +record bar { + x: foo +} + +a: func(b: bar) diff --git a/crates/wit-component/tests/components/ensure-default-type-exports/module.wat b/crates/wit-component/tests/components/ensure-default-type-exports/module.wat new file mode 100644 index 000000000..78c731484 --- /dev/null +++ b/crates/wit-component/tests/components/ensure-default-type-exports/module.wat @@ -0,0 +1,6 @@ +(module + (import "foo" "a" (func (param i32))) + (memory (export "memory") 1) + (func (export "canonical_abi_realloc") (param i32 i32 i32 i32) (result i32) unreachable) + (func (export "a") (param i32) unreachable) +) diff --git a/crates/wit-component/tests/components/import-export/component.wat b/crates/wit-component/tests/components/import-export/component.wat index be8204b0f..cec59b6f9 100644 --- a/crates/wit-component/tests/components/import-export/component.wat +++ b/crates/wit-component/tests/components/import-export/component.wat @@ -1,15 +1,15 @@ (component - (type (;0;) (func (result string))) - (type (;1;) + (type (;0;) (tuple string u32 string)) + (type (;1;) (func (param "x" string) (result 0))) + (type (;2;) (func)) + (type (;3;) (func (result string))) + (type (;4;) (instance - (alias outer 1 0 (type (;0;))) + (alias outer 1 3 (type (;0;))) (export "a" (func (type 0))) ) ) - (type (;2;) (tuple string u32 string)) - (type (;3;) (func (param "x" string) (result 2))) - (type (;4;) (func)) - (import "foo" (instance (;0;) (type 1))) + (import "foo" (instance (;0;) (type 4))) (core module (;0;) (type (;0;) (func (param i32))) (type (;1;) (func (param i32 i32 i32 i32) (result i32))) @@ -76,11 +76,11 @@ ) ) (core alias export 2 "a" (func (;3;))) - (func (;1;) (type 3) (canon lift (core func 3) (memory 0) (realloc 1) string-encoding=utf8)) + (func (;1;) (type 1) (canon lift (core func 3) (memory 0) (realloc 1) string-encoding=utf8)) (core alias export 2 "bar#a" (func (;4;))) (core alias export 2 "bar#b" (func (;5;))) - (func (;2;) (type 4) (canon lift (core func 4))) - (func (;3;) (type 0) (canon lift (core func 5) (memory 0) (realloc 1) string-encoding=utf8)) + (func (;2;) (type 2) (canon lift (core func 4))) + (func (;3;) (type 3) (canon lift (core func 5) (memory 0) (realloc 1) string-encoding=utf8)) (instance (;1;) (export "a" (func 2)) (export "b" (func 3))