Browse Source

Update to latest wasm-tools crates (#6378)

* Update to latest wasm-tools crates

This commit pushes through the full update of the wasm-tools crates
through Wasmtime. There are two major features which changed, both
related to components, which required updates in Wasmtime:

* Resource types are now implemented in wasm-tools and they're not yet
  implemented in Wasmtime so I've stubbed out the integration point with
  panics as reminders to come back and implement them.

* There are new validation rules about how aggregate types must be
  named. This doesn't affect runtime internals at all but was done on
  behalf of code generators. This did however affect a number of tests
  which have to ensure that types are exported.

* Fix more tests

* Add vet entries
pull/6386/head
Alex Crichton 2 years ago
committed by GitHub
parent
commit
f928bf728c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 76
      Cargo.lock
  2. 14
      Cargo.toml
  3. 6
      crates/environ/src/component/translate.rs
  4. 12
      crates/environ/src/component/types.rs
  5. 4
      deny.toml
  6. 35
      supply-chain/imports.lock
  7. 9
      tests/all/component_model.rs
  8. 84
      tests/all/component_model/bindgen/results.rs
  9. 105
      tests/all/component_model/dynamic.rs
  10. 4
      tests/misc_testsuite/component-model/adapter.wast
  11. 152
      tests/misc_testsuite/component-model/fused.wast
  12. 5
      tests/misc_testsuite/component-model/instance.wast

76
Cargo.lock

@ -677,7 +677,7 @@ dependencies = [
"target-lexicon",
"thiserror",
"toml",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wat",
]
@ -853,7 +853,7 @@ dependencies = [
"serde",
"smallvec",
"target-lexicon",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmtime-types",
"wat",
]
@ -3651,30 +3651,30 @@ dependencies = [
[[package]]
name = "wasm-mutate"
version = "0.2.23"
version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50e95b75cb9d63543aafcf63678b2aee1453872ce77e06f226f5306780c73411"
checksum = "77e6309ff390c0389b5ced7ad7812a0bc091976c606e661e71184f077bfd0ddc"
dependencies = [
"egg",
"log",
"rand 0.8.5",
"thiserror",
"wasm-encoder 0.25.0",
"wasmparser 0.103.0",
"wasm-encoder 0.26.0",
"wasmparser 0.104.0",
]
[[package]]
name = "wasm-smith"
version = "0.12.6"
version = "0.12.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d4865ce3f78be697d178a6a247544d1b0eb772bb723aa13b471b7a06562e8b0"
checksum = "649447f144ee5db453e2b5ce7d3f60a9d7dd0bb5b2fde500125d3aa79a9387c8"
dependencies = [
"arbitrary",
"flagset",
"indexmap",
"leb128",
"wasm-encoder 0.25.0",
"wasmparser 0.103.0",
"wasm-encoder 0.26.0",
"wasmparser 0.104.0",
]
[[package]]
@ -3724,16 +3724,6 @@ dependencies = [
"indexmap",
]
[[package]]
name = "wasmparser"
version = "0.103.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c437373cac5ea84f1113d648d51f71751ffbe3d90c00ae67618cf20d0b5ee7b"
dependencies = [
"indexmap",
"url",
]
[[package]]
name = "wasmparser"
version = "0.104.0"
@ -3755,12 +3745,12 @@ dependencies = [
[[package]]
name = "wasmprinter"
version = "0.2.55"
version = "0.2.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51befda9d7eefac615a2ef75f42d2f2bd243cdabaa141a8ea0f9ffa3fc79ccf4"
checksum = "731da2505d5437cd5d6feb09457835f76186be13be7677fe00781ae99d5bbe8a"
dependencies = [
"anyhow",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
]
[[package]]
@ -3787,7 +3777,7 @@ dependencies = [
"target-lexicon",
"tempfile",
"wasi-cap-std-sync",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmtime-cache",
"wasmtime-component-macro",
"wasmtime-component-util",
@ -3903,7 +3893,7 @@ dependencies = [
"tokio",
"walkdir",
"wasm-encoder 0.26.0",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmtime",
"wasmtime-cache",
"wasmtime-cli-flags",
@ -3918,7 +3908,7 @@ dependencies = [
"wasmtime-wasi-nn",
"wasmtime-wasi-threads",
"wasmtime-wast",
"wast 56.0.0",
"wast 57.0.0",
"wat",
"windows-sys 0.48.0",
]
@ -3971,7 +3961,7 @@ dependencies = [
"object",
"target-lexicon",
"thiserror",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmtime-cranelift-shared",
"wasmtime-environ",
]
@ -4007,7 +3997,7 @@ dependencies = [
"target-lexicon",
"thiserror",
"wasm-encoder 0.26.0",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmprinter",
"wasmtime-component-util",
"wasmtime-types",
@ -4022,7 +4012,7 @@ dependencies = [
"component-fuzz-util",
"env_logger 0.10.0",
"libfuzzer-sys",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmprinter",
"wasmtime-environ",
"wat",
@ -4076,7 +4066,7 @@ dependencies = [
"rand 0.8.5",
"smallvec",
"target-lexicon",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmtime",
"wasmtime-fuzzing",
]
@ -4101,7 +4091,7 @@ dependencies = [
"wasm-smith",
"wasm-spec-interpreter",
"wasmi",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmprinter",
"wasmtime",
"wasmtime-wast",
@ -4183,7 +4173,7 @@ dependencies = [
"cranelift-entity",
"serde",
"thiserror",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
]
[[package]]
@ -4257,7 +4247,7 @@ dependencies = [
"anyhow",
"log",
"wasmtime",
"wast 56.0.0",
"wast 57.0.0",
]
[[package]]
@ -4269,7 +4259,7 @@ dependencies = [
"gimli",
"object",
"target-lexicon",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmtime-cranelift-shared",
"wasmtime-environ",
"winch-codegen",
@ -4296,23 +4286,23 @@ dependencies = [
[[package]]
name = "wast"
version = "56.0.0"
version = "57.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b54185c051d7bbe23757d50fe575880a2426a2f06d2e9f6a10fd9a4a42920c0"
checksum = "6eb0f5ed17ac4421193c7477da05892c2edafd67f9639e3c11a82086416662dc"
dependencies = [
"leb128",
"memchr",
"unicode-width",
"wasm-encoder 0.25.0",
"wasm-encoder 0.26.0",
]
[[package]]
name = "wat"
version = "1.0.62"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56681922808216ab86d96bb750f70d500b5a7800e41564290fd46bb773581299"
checksum = "ab9ab0d87337c3be2bb6fc5cd331c4ba9fd6bcb4ee85048a0dd59ed9ecf92e53"
dependencies = [
"wast 56.0.0",
"wast 57.0.0",
]
[[package]]
@ -4440,14 +4430,14 @@ dependencies = [
"regalloc2",
"smallvec",
"target-lexicon",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
]
[[package]]
name = "winch-environ"
version = "0.8.0"
dependencies = [
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmtime-environ",
"winch-codegen",
]
@ -4493,7 +4483,7 @@ dependencies = [
"similar",
"target-lexicon",
"toml",
"wasmparser 0.103.0",
"wasmparser 0.104.0",
"wasmtime-environ",
"wat",
"winch-codegen",

14
Cargo.toml

@ -181,14 +181,14 @@ byte-array-literals = { path = "crates/wasi-preview1-component-adapter/byte-arra
target-lexicon = { version = "0.12.3", default-features = false, features = ["std"] }
anyhow = "1.0.22"
wasmparser = "0.103.0"
wat = "1.0.62"
wast = "56.0.0"
wasmprinter = "0.2.55"
wasmparser = "0.104.0"
wat = "1.0.63"
wast = "57.0.0"
wasmprinter = "0.2.56"
wasm-encoder = "0.26.0"
wasm-smith = "0.12.6"
wasm-mutate = "0.2.23"
wit-parser = "0.7.0"
wasm-smith = "0.12.7"
wasm-mutate = "0.2.24"
wit-parser = "0.7.1"
windows-sys = "0.48.0"
env_logger = "0.10"
rustix = "0.37.13"

6
crates/environ/src/component/translate.rs

@ -525,6 +525,12 @@ impl<'a, 'data> Translator<'a, 'data> {
.initializers
.push(LocalInitializer::Lower(func, options));
}
wasmparser::CanonicalFunction::ResourceNew { .. }
| wasmparser::CanonicalFunction::ResourceDrop { .. }
| wasmparser::CanonicalFunction::ResourceRep { .. } => {
unimplemented!("resource types")
}
}
}
}

12
crates/environ/src/component/types.rs

@ -446,6 +446,9 @@ impl ComponentTypesBuilder {
wasmparser::ComponentType::Instance(ty) => {
TypeDef::ComponentInstance(self.component_instance_type(ty)?)
}
wasmparser::ComponentType::Resource { .. } => {
unimplemented!("resource types")
}
})
}
@ -467,7 +470,7 @@ impl ComponentTypesBuilder {
self.core_outer_type(0, TypeIndex::from_u32(*ty))
}
wasmparser::ComponentTypeRef::Func(ty)
| wasmparser::ComponentTypeRef::Type(wasmparser::TypeBounds::Eq, ty)
| wasmparser::ComponentTypeRef::Type(wasmparser::TypeBounds::Eq(ty))
| wasmparser::ComponentTypeRef::Instance(ty)
| wasmparser::ComponentTypeRef::Component(ty) => {
self.component_outer_type(0, ComponentTypeIndex::from_u32(*ty))
@ -475,6 +478,9 @@ impl ComponentTypesBuilder {
wasmparser::ComponentTypeRef::Value(..) => {
unimplemented!("references to value types");
}
wasmparser::ComponentTypeRef::Type(wasmparser::TypeBounds::SubResource) => {
unimplemented!("resource types");
}
}
}
@ -704,6 +710,10 @@ impl ComponentTypesBuilder {
wasmparser::ComponentDefinedType::Result { ok, err } => {
InterfaceType::Result(self.result_type(ok, err))
}
wasmparser::ComponentDefinedType::Own(_)
| wasmparser::ComponentDefinedType::Borrow(_) => {
unimplemented!("resource types")
}
};
let info = self.type_information(&result);
if info.depth > MAX_TYPE_DEPTH {

4
deny.toml

@ -63,7 +63,3 @@ skip-tree = [
# dependency appears to be benign.
{ name = "windows-sys", depth = 3 },
]
skip = [
{ name = "wasm-encoder", version = "=0.25.0" }
]

35
supply-chain/imports.lock

@ -71,6 +71,13 @@ user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"
[[publisher.wasm-mutate]]
version = "0.2.24"
when = "2023-04-27"
user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"
[[publisher.wasm-smith]]
version = "0.12.6"
when = "2023-04-13"
@ -78,6 +85,13 @@ user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"
[[publisher.wasm-smith]]
version = "0.12.7"
when = "2023-04-27"
user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"
[[publisher.wasmparser]]
version = "0.103.0"
when = "2023-04-13"
@ -99,6 +113,13 @@ user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"
[[publisher.wasmprinter]]
version = "0.2.56"
when = "2023-04-27"
user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"
[[publisher.wast]]
version = "56.0.0"
when = "2023-04-13"
@ -106,6 +127,13 @@ user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"
[[publisher.wast]]
version = "57.0.0"
when = "2023-04-27"
user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"
[[publisher.wat]]
version = "1.0.62"
when = "2023-04-13"
@ -113,6 +141,13 @@ user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"
[[publisher.wat]]
version = "1.0.63"
when = "2023-04-27"
user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"
[[publisher.wit-bindgen]]
version = "0.6.0"
when = "2023-04-27"

9
tests/all/component_model.rs

@ -179,6 +179,12 @@ fn make_echo_component_with_params(type_definition: &str, params: &[Param]) -> S
)
};
let type_section = if type_definition.contains("(type ") {
type_definition.to_string()
} else {
format!("(type $Foo' {type_definition})")
};
format!(
r#"
(component
@ -191,7 +197,8 @@ fn make_echo_component_with_params(type_definition: &str, params: &[Param]) -> S
(core instance $i (instantiate $m))
(type $Foo {type_definition})
{type_section}
(export $Foo "foo" (type $Foo'))
(func (export "echo") (param "a" $Foo) (result "b" $Foo)
(canon lift

84
tests/all/component_model/bindgen/results.rs

@ -243,8 +243,10 @@ mod enum_error {
format!(
r#"
(component
(type $err' (enum "a" "b" "c"))
(import "imports" (instance $i
(export "enum-error" (func (param "a" float64) (result (result float64 (error (enum "a" "b" "c"))))))
(export $err "err" (type (eq $err')))
(export "enum-error" (func (param "a" float64) (result (result float64 (error $err)))))
))
(core module $libc
(memory (export "memory") 1)
@ -276,13 +278,22 @@ mod enum_error {
))
(func $f_enum_error
(param "a" float64)
(result (result float64 (error (enum "a" "b" "c"))))
(result (result float64 (error $err')))
(canon lift (core func $i "core_enum_error_export") (memory $libc "memory"))
)
(instance (export "foo")
(export "enum-error" (func $f_enum_error))
(component $nested
(import "f-err" (type $err (eq $err')))
(import "f" (func $f (param "a" float64) (result (result float64 (error $err)))))
(export $err2 "err" (type $err'))
(export "enum-error" (func $f) (func (param "a" float64) (result (result float64 (error $err2)))))
)
(instance $n (instantiate $nested
(with "f-err" (type $err'))
(with "f" (func $f_enum_error))
))
(export "foo" (instance $n))
)
"#
),
@ -392,8 +403,14 @@ mod record_error {
format!(
r#"
(component
(type $e2' (record
(field "line" u32)
(field "col" u32)
))
(import "imports" (instance $i
(export "record-error" (func (param "a" float64) (result (result float64 (error (record (field "line" u32) (field "col" u32)))))))
(export $e2 "e2" (type (eq $e2')))
(type $result (result float64 (error $e2)))
(export "record-error" (func (param "a" float64) (result $result)))
))
(core module $libc
(memory (export "memory") 1)
@ -429,9 +446,17 @@ mod record_error {
(canon lift (core func $i "core_record_error_export") (memory $libc "memory"))
)
(instance (export "foo")
(export "record-error" (func $f_record_error))
(component $nested
(import "f-e2" (type $f-e2 (eq $e2')))
(import "f" (func $f (param "a" float64) (result (result float64 (error $f-e2)))))
(export $e2 "e2" (type $e2'))
(export "record-error" (func $f) (func (param "a" float64) (result (result float64 (error $e2)))))
)
(instance (export "foo") (instantiate $nested
(with "f-e2" (type $e2'))
(with "f" (func $f_record_error))
))
)
"#
),
@ -528,8 +553,22 @@ mod variant_error {
format!(
r#"
(component
(type $e1' (enum "a" "b" "c"))
(type $e2' (record (field "line" u32) (field "col" u32)))
(type $e3' (variant
(case "E1" $e1')
(case "E2" $e2')
))
(import "imports" (instance $i
(export "variant-error" (func (param "a" float64) (result (result float64 (error (variant (case "E1" (enum "a" "b" "c")) (case "E2" (record (field "line" u32) (field "col" u32)))))))))
(export $e1 "e1" (type (eq $e1')))
(export $e2 "e2" (type (eq $e2')))
(type $e3' (variant
(case "E1" $e1)
(case "E2" $e2)
))
(export $e3 "e3" (type (eq $e3')))
(type $result (result float64 (error $e3)))
(export "variant-error" (func (param "a" float64) (result $result)))
))
(core module $libc
(memory (export "memory") 1)
@ -561,13 +600,36 @@ mod variant_error {
))
(func $f_variant_error
(param "a" float64)
(result (result float64 (error (variant (case "E1" (enum "a" "b" "c")) (case "E2"(record (field "line" u32) (field "col" u32)))))))
(result (result float64 (error $e3')))
(canon lift (core func $i "core_variant_error_export") (memory $libc "memory"))
)
(instance (export "foo")
(export "variant-error" (func $f_variant_error))
(component $nested
(import "f-e1" (type $e1i (eq $e1')))
(import "f-e2" (type $e2i (eq $e2')))
(type $e3i' (variant
(case "E1" $e1i)
(case "E2" $e2i)
))
(import "f-e3" (type $e3i (eq $e3i')))
(import "f" (func $f (param "a" float64) (result (result float64 (error $e3i)))))
(export $e1 "e1" (type $e1'))
(export $e2 "e2" (type $e2'))
(type $e3' (variant
(case "E1" $e1)
(case "E2" $e2)
))
(export $e3 "e3" (type $e3'))
(export "variant-error" (func $f)
(func (param "a" float64) (result (result float64 (error $e3)))))
)
(instance (export "foo") (instantiate $nested
(with "f-e1" (type $e1'))
(with "f-e2" (type $e2'))
(with "f-e3" (type $e3'))
(with "f" (func $f_variant_error))
))
)
"#
),

105
tests/all/component_model/dynamic.rs

@ -151,7 +151,18 @@ fn records() -> Result<()> {
let component = Component::new(
&engine,
make_echo_component_with_params(
r#"(record (field "A" u32) (field "B" float64) (field "C" (record (field "D" bool) (field "E" u32))))"#,
r#"
(type $c' (record
(field "D" bool)
(field "E" u32)
))
(export $c "c" (type $c'))
(type $Foo' (record
(field "A" u32)
(field "B" float64)
(field "C" $c)
))
"#,
&[
Param(Type::I32, Some(0)),
Param(Type::F64, Some(8)),
@ -239,10 +250,20 @@ fn variants() -> Result<()> {
let engine = super::engine();
let mut store = Store::new(&engine, ());
let fragment = r#"
(type $c' (record (field "D" bool) (field "E" u32)))
(export $c "c" (type $c'))
(type $Foo' (variant
(case "A" u32)
(case "B" float64)
(case "C" $c)
))
"#;
let component = Component::new(
&engine,
make_echo_component_with_params(
r#"(variant (case "A" u32) (case "B" float64) (case "C" (record (field "D" bool) (field "E" u32))))"#,
fragment,
&[
Param(Type::U8, Some(0)),
Param(Type::I64, Some(8)),
@ -266,7 +287,7 @@ fn variants() -> Result<()> {
let component = Component::new(
&engine,
make_echo_component_with_params(
r#"(variant (case "A" u32) (case "B" float64) (case "C" (record (field "D" bool) (field "E" u32))))"#,
fragment,
&[
Param(Type::U8, Some(0)),
Param(Type::I64, Some(8)),
@ -319,12 +340,19 @@ fn variants() -> Result<()> {
&engine,
make_echo_component_with_params(
r#"
(record
(field "A" (variant
(case "A" u32)
(case "B" float64)
(case "C" (record (field "D" bool) (field "E" u32)))))
(field "B" u32))"#,
(type $c' (record (field "D" bool) (field "E" u32)))
(export $c "c" (type $c'))
(type $a' (variant
(case "A" u32)
(case "B" float64)
(case "C" $c)
))
(export $a "a" (type $a'))
(type $Foo' (record
(field "A" $a)
(field "B" u32)
))
"#,
&[
Param(Type::U8, Some(0)),
Param(Type::I64, Some(8)),
@ -394,28 +422,43 @@ fn everything() -> Result<()> {
&engine,
make_echo_component_with_params(
r#"
(record
(field "A" u32)
(field "B" (enum "a" "b"))
(field "C" (record (field "D" bool) (field "E" u32)))
(field "F" (list (flags "G" "H" "I")))
(field "J" (variant
(case "K" u32)
(case "L" float64)
(case "M" (record (field "N" bool) (field "O" u32)))))
(field "P" s8)
(field "Q" s16)
(field "R" s32)
(field "S" s64)
(field "T" float32)
(field "U" float64)
(field "V" string)
(field "W" char)
(field "Y" (tuple u32 u32))
(field "Z" (union u32 float64))
(field "AA" (option u32))
(field "BB" (result string (error string)))
)"#,
(type $b' (enum "a" "b"))
(export $b "b" (type $b'))
(type $c' (record (field "D" bool) (field "E" u32)))
(export $c "c" (type $c'))
(type $f' (flags "G" "H" "I"))
(export $f "f" (type $f'))
(type $m' (record (field "N" bool) (field "O" u32)))
(export $m "m" (type $m'))
(type $j' (variant
(case "K" u32)
(case "L" float64)
(case "M" $m)
))
(export $j "j" (type $j'))
(type $z' (union u32 float64))
(export $z "z" (type $z'))
(type $Foo' (record
(field "A" u32)
(field "B" $b)
(field "C" $c)
(field "F" (list $f))
(field "J" $j)
(field "P" s8)
(field "Q" s16)
(field "R" s32)
(field "S" s64)
(field "T" float32)
(field "U" float64)
(field "V" string)
(field "W" char)
(field "Y" (tuple u32 u32))
(field "Z" $z)
(field "AA" (option u32))
(field "BB" (result string (error string)))
))
"#,
&[
Param(Type::I32, Some(0)),
Param(Type::U8, Some(4)),

4
tests/misc_testsuite/component-model/adapter.wast

@ -121,7 +121,9 @@
(memory (export "memory") 0)
)
(core instance $m (instantiate $m))
(func $f (param "a" (list (record)))
(type $t' (record))
(export $t "t" (type $t'))
(func $f (param "a" (list $t))
(canon lift
(core func $m "x")
(realloc (func $m "realloc"))

152
tests/misc_testsuite/component-model/fused.wast

@ -637,10 +637,12 @@
;; simple variant translation
(component
(type $a (variant (case "x")))
(type $b (variant (case "y")))
(component $c1
(type $a' (variant (case "x")))
(export $a "a" (type $a'))
(type $b' (variant (case "y")))
(export $b "b" (type $b'))
(core module $m
(func (export "r") (param i32) (result i32)
(if (i32.ne (local.get 0) (i32.const 0)) (unreachable))
@ -651,6 +653,11 @@
(func (export "r") (param "a" $a) (result $b) (canon lift (core func $m "r")))
)
(component $c2
(type $a' (variant (case "x")))
(import "a" (type $a (eq $a')))
(type $b' (variant (case "y")))
(import "b" (type $b (eq $b')))
(import "r" (func $r (param "a" $a) (result $b)))
(core func $r (canon lower (func $r)))
@ -670,15 +677,19 @@
))
)
(instance $c1 (instantiate $c1))
(instance $c2 (instantiate $c2 (with "r" (func $c1 "r"))))
(instance $c2 (instantiate $c2
(with "a" (type $c1 "a"))
(with "b" (type $c1 "b"))
(with "r" (func $c1 "r"))
))
)
;; invalid variant discriminant in a parameter
(assert_trap
(component
(type $a (variant (case "x")))
(component $c1
(type $a' (variant (case "x")))
(export $a "a" (type $a'))
(core module $m
(func (export "r") (param i32))
)
@ -686,6 +697,8 @@
(func (export "r") (param "a" $a) (canon lift (core func $m "r")))
)
(component $c2
(type $a' (variant (case "x")))
(import "a" (type $a (eq $a')))
(import "r" (func $r (param "a" $a)))
(core func $r (canon lower (func $r)))
@ -702,16 +715,19 @@
))
)
(instance $c1 (instantiate $c1))
(instance $c2 (instantiate $c2 (with "r" (func $c1 "r"))))
(instance $c2 (instantiate $c2
(with "a" (type $c1 "a"))
(with "r" (func $c1 "r"))
))
)
"unreachable")
;; invalid variant discriminant in a result
(assert_trap
(component
(type $a (variant (case "x")))
(component $c1
(type $a' (variant (case "x")))
(export $a "a" (type $a'))
(core module $m
(func (export "r") (result i32) i32.const 1)
)
@ -719,6 +735,8 @@
(func (export "r") (result $a) (canon lift (core func $m "r")))
)
(component $c2
(type $a' (variant (case "x")))
(import "a" (type $a (eq $a')))
(import "r" (func $r (result $a)))
(core func $r (canon lower (func $r)))
@ -732,7 +750,10 @@
))
)
(instance $c1 (instantiate $c1))
(instance $c2 (instantiate $c2 (with "r" (func $c1 "r"))))
(instance $c2 (instantiate $c2
(with "a" (type $c1 "a"))
(with "r" (func $c1 "r"))
))
)
"unreachable")
@ -803,19 +824,24 @@
;; translation of locals between different types
(component
(type $a (variant (case "a" u8) (case "b" float32)))
(type $b (variant (case "a" u16) (case "b" s64)))
(type $c (variant (case "a" u64) (case "b" float64)))
(type $d (variant (case "a" float32) (case "b" float64)))
(type $e (variant (case "a" float32) (case "b" s64)))
(type $func_a (func (param "x" bool) (param "a" $a)))
(type $func_b (func (param "x" bool) (param "b" $b)))
(type $func_c (func (param "x" bool) (param "c" $c)))
(type $func_d (func (param "x" bool) (param "d" $d)))
(type $func_e (func (param "x" bool) (param "e" $d)))
(component $c1
(type $a' (variant (case "a" u8) (case "b" float32)))
(type $b' (variant (case "a" u16) (case "b" s64)))
(type $c' (variant (case "a" u64) (case "b" float64)))
(type $d' (variant (case "a" float32) (case "b" float64)))
(type $e' (variant (case "a" float32) (case "b" s64)))
(export $a "t-a" (type $a'))
(export $b "t-b" (type $b'))
(export $c "t-c" (type $c'))
(export $d "t-d" (type $d'))
(export $e "t-e" (type $e'))
(type $func_a (func (param "x" bool) (param "a" $a)))
(type $func_b (func (param "x" bool) (param "b" $b)))
(type $func_c (func (param "x" bool) (param "c" $c)))
(type $func_d (func (param "x" bool) (param "d" $d)))
(type $func_e (func (param "x" bool) (param "e" $d)))
(core module $m
(func (export "a") (param i32 i32 i32)
(i32.eqz (local.get 0))
@ -877,6 +903,22 @@
)
(component $c2
(import "a" (instance $i
(type $a' (variant (case "a" u8) (case "b" float32)))
(type $b' (variant (case "a" u16) (case "b" s64)))
(type $c' (variant (case "a" u64) (case "b" float64)))
(type $d' (variant (case "a" float32) (case "b" float64)))
(type $e' (variant (case "a" float32) (case "b" s64)))
(export $a "t-a" (type (eq $a')))
(export $b "t-b" (type (eq $b')))
(export $c "t-c" (type (eq $c')))
(export $d "t-d" (type (eq $d')))
(export $e "t-e" (type (eq $e')))
(type $func_a (func (param "x" bool) (param "a" $a)))
(type $func_b (func (param "x" bool) (param "b" $b)))
(type $func_c (func (param "x" bool) (param "c" $c)))
(type $func_d (func (param "x" bool) (param "d" $d)))
(type $func_e (func (param "x" bool) (param "e" $d)))
(export "a" (func (type $func_a)))
(export "b" (func (type $func_b)))
(export "c" (func (type $func_c)))
@ -933,14 +975,17 @@
;; different size variants
(component
(type $a (variant
(case "a")
(case "b" float32)
(case "c" (tuple float32 u32))
(case "d" (tuple float32 (record) u64 u8))
))
(component $c1
(type $r' (record))
(export $r "t-r" (type $r'))
(type $a' (variant
(case "a")
(case "b" float32)
(case "c" (tuple float32 u32))
(case "d" (tuple float32 $r u64 u8))
))
(export $a "t-a" (type $a'))
(core module $m
(func (export "a") (param i32 i32 f32 i64 i32)
(if (i32.eq (local.get 0) (i32.const 0))
@ -984,6 +1029,15 @@
)
(component $c2
(import "a" (instance $i
(type $r' (record))
(export $r "t-r" (type (eq $r')))
(type $a' (variant
(case "a")
(case "b" float32)
(case "c" (tuple float32 u32))
(case "d" (tuple float32 $r u64 u8))
))
(export $a "t-a" (type (eq $a')))
(export "a" (func (param "x" u8) (param "a" $a)))
))
@ -1154,33 +1208,33 @@
;; test that flags get their upper bits all masked off
(component
(type $f0 (flags))
(type $f1 (flags "f1"))
(type $f8 (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"))
(type $f9 (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" "f9"))
(type $f16 (flags
(type $f0' (flags))
(type $f1' (flags "f1"))
(type $f8' (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"))
(type $f9' (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" "f9"))
(type $f16' (flags
"f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"
"g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8"
))
(type $f17 (flags
(type $f17' (flags
"f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"
"g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8"
"g9"
))
(type $f32 (flags
(type $f32' (flags
"f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"
"g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8"
"h1" "h2" "h3" "h4" "h5" "h6" "h7" "h8"
"i1" "i2" "i3" "i4" "i5" "i6" "i7" "i8"
))
(type $f33 (flags
(type $f33' (flags
"f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"
"g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8"
"h1" "h2" "h3" "h4" "h5" "h6" "h7" "h8"
"i1" "i2" "i3" "i4" "i5" "i6" "i7" "i8"
"i9"
))
(type $f64 (flags
(type $f64' (flags
"f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"
"g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8"
"h1" "h2" "h3" "h4" "h5" "h6" "h7" "h8"
@ -1190,7 +1244,7 @@
"l1" "l2" "l3" "l4" "l5" "l6" "l7" "l8"
"m1" "m2" "m3" "m4" "m5" "m6" "m7" "m8"
))
(type $f65 (flags
(type $f65' (flags
"f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"
"g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8"
"h1" "h2" "h3" "h4" "h5" "h6" "h7" "h8"
@ -1203,6 +1257,16 @@
))
(component $c1
(export $f0 "t-f0" (type $f0'))
(export $f1 "t-f1" (type $f1'))
(export $f8 "t-f8" (type $f8'))
(export $f9 "t-f9" (type $f9'))
(export $f16 "t-f16" (type $f16'))
(export $f17 "t-f17" (type $f17'))
(export $f32 "t-f32" (type $f32'))
(export $f33 "t-f33" (type $f33'))
(export $f64 "t-f64" (type $f64'))
(export $f65 "t-f65" (type $f65'))
(core module $m
(func (export "f0"))
(func (export "f1") (param i32)
@ -1253,6 +1317,16 @@
(component $c2
(import "a" (instance $i
(export $f0 "t-f0" (type (eq $f0')))
(export $f1 "t-f1" (type (eq $f1')))
(export $f8 "t-f8" (type (eq $f8')))
(export $f9 "t-f9" (type (eq $f9')))
(export $f16 "t-f16" (type (eq $f16')))
(export $f17 "t-f17" (type (eq $f17')))
(export $f32 "t-f32" (type (eq $f32')))
(export $f33 "t-f33" (type (eq $f33')))
(export $f64 "t-f64" (type (eq $f64')))
(export $f65 "t-f65" (type (eq $f65')))
(export "f0" (func (param "a" $f0)))
(export "f1" (func (param "a" $f1)))
(export "f8" (func (param "a" $f8)))

5
tests/misc_testsuite/component-model/instance.wast

@ -181,7 +181,10 @@
(component
(import "host" (instance $i
(type $rec (record (field "x" (record)) (field "y" string)))
(type $x' (record))
(export $x "x" (type (eq $x')))
(type $rec' (record (field "x" $x) (field "y" string)))
(export $rec "rec" (type (eq $rec')))
(export "some-record" (type (eq $rec)))))
)

Loading…
Cancel
Save