Update wasm-tools crates (#4246)

This commit updates the wasm-tools family of crates, notably pulling in
the refactorings and updates from bytecodealliance/wasm-tools#621 for
the latest iteration of the component model. This commit additionally
updates all support for the component model for these changes, notably:

* Many bits and pieces of type information was refactored. Many
  `FooTypeIndex` namings are now `TypeFooIndex`. Additionally there is
  now `TypeIndex` as well as `ComponentTypeIndex` for the two type index
  spaces in a component.

* A number of new sections are now processed to handle the core and
  component variants.

* Internal maps were split such as the `funcs` map into
  `component_funcs` and `funcs` (same for `instances`).

* Canonical options are now processed individually instead of one bulk
  `into` definition.

Overall this was not a major update to the internals of handling the
component model in Wasmtime. Instead this was mostly a surface-level
refactoring to make sure that everything lines up with the new binary
format for components.

* All text syntax used in tests was updated to the new syntax.
This commit is contained in:
Alex Crichton
2022-06-09 11:16:07 -05:00
committed by GitHub
parent c15c3061ca
commit 7d7ddceb17
32 changed files with 1201 additions and 1078 deletions

View File

@@ -1,54 +1,72 @@
;; basic function lifting
(component
(module $m
(core module $m
(func (export ""))
)
(instance $i (instantiate (module $m)))
(core instance $i (instantiate $m))
(func (export "thunk")
(canon.lift (func) (func $i ""))
(canon lift (core func $i ""))
)
)
;; use an aliased type
(component $c
(module $m
(core module $m
(func (export ""))
)
(instance $i (instantiate (module $m)))
(core instance $i (instantiate $m))
(type $to_alias (func))
(alias outer $c $to_alias (type $alias))
(func (export "thunk")
(canon.lift (type $alias) (func $i ""))
(func (export "thunk") (type $alias)
(canon lift (core func $i ""))
)
)
;; test out some various canonical abi
(component $c
(module $m
(core module $m
(func (export "") (param i32 i32))
(memory (export "memory") 1)
(func (export "canonical_abi_realloc") (param i32 i32 i32 i32) (result i32)
(func (export "realloc") (param i32 i32 i32 i32) (result i32)
unreachable)
(func (export "canonical_abi_free") (param i32 i32 i32))
)
(instance $i (instantiate (module $m)))
(core instance $i (instantiate $m))
(func (export "thunk")
(canon.lift (func (param string)) (into $i) (func $i ""))
(func (export "thunk") (param string)
(canon lift
(core func $i "")
(memory $i "memory")
(realloc (func $i "realloc"))
)
)
(func (export "thunk8")
(canon.lift (func (param string)) string=utf8 (into $i) (func $i ""))
(func (export "thunk8") (param string)
(canon lift
(core func $i "")
string-encoding=utf8
(memory $i "memory")
(realloc (func $i "realloc"))
)
)
(func (export "thunk16")
(canon.lift (func (param string)) string=utf16 (into $i) (func $i ""))
(func (export "thunk16") (param string)
(canon lift
(core func $i "")
string-encoding=utf16
(memory $i "memory")
(realloc (func $i "realloc"))
)
)
(func (export "thunklatin16")
(canon.lift (func (param string)) string=latin1+utf16 (into $i) (func $i ""))
(func (export "thunklatin16") (param string)
(canon lift
(core func $i "")
string-encoding=latin1+utf16
(memory $i "memory")
(realloc (func $i "realloc"))
)
)
)

View File

@@ -1,30 +1,30 @@
(component
(module $m)
(instance (instantiate (module $m)))
(core module $m)
(core instance (instantiate $m))
)
(component
(module $m
(core module $m
(func (export ""))
)
(instance $i (instantiate (module $m)))
(core instance $i (instantiate $m))
(module $m2
(core module $m2
(func (import "" ""))
)
(instance (instantiate (module $m2) (with "" (instance $i))))
(core instance (instantiate $m2 (with "" (instance $i))))
)
(component
(module $m
(core module $m
(func (export "a"))
)
(instance $i (instantiate (module $m)))
(core instance $i (instantiate $m))
(module $m2
(core module $m2
(func (import "" "b"))
)
(instance (instantiate (module $m2)
(core instance (instantiate $m2
(with "" (instance (export "b" (func $i "a"))))
))
)
@@ -32,15 +32,15 @@
;; all kinds of imports for core wasm modules, and register a start function on
;; one module to ensure that everything is correct
(component
(module $m
(core module $m
(func (export "a"))
(table (export "b") 1 funcref)
(memory (export "c") 1)
(global (export "d") i32 i32.const 1)
)
(instance $i (instantiate (module $m)))
(core instance $i (instantiate $m))
(module $m2
(core module $m2
(import "" "a" (func $f))
(import "" "b" (table 1 funcref))
(import "" "c" (memory 1))
@@ -62,7 +62,7 @@
(data (i32.const 0) "hello")
(elem (i32.const 0) $start)
)
(instance (instantiate (module $m2)
(core instance (instantiate $m2
(with "" (instance $i))
))
)
@@ -71,12 +71,12 @@
;; sees the wrong value for the global import
(assert_trap
(component
(module $m
(core module $m
(global (export "g") i32 i32.const 1)
)
(instance $i (instantiate (module $m)))
(core instance $i (instantiate $m))
(module $m2
(core module $m2
(import "" "g" (global $g i32))
(func $start
@@ -90,27 +90,27 @@
(start $start)
)
(instance (instantiate (module $m2) (with "" (instance $i))))
(core instance (instantiate $m2 (with "" (instance $i))))
)
"unreachable")
;; shuffle around imports to get to what the target core wasm module needs
(component
(module $m
(core module $m
(func (export "1"))
(table (export "2") 1 funcref)
(memory (export "3") 1)
(global (export "4") i32 i32.const 1)
)
(instance $i (instantiate (module $m)))
(core instance $i (instantiate $m))
(module $m2
(core module $m2
(import "" "a" (func $f))
(import "" "b" (table 1 funcref))
(import "" "c" (memory 1))
(import "" "d" (global $g i32))
)
(instance (instantiate (module $m2)
(core instance (instantiate $m2
(with "" (instance
(export "a" (func $i "1"))
(export "b" (table $i "2"))

View File

@@ -1,6 +1,6 @@
(assert_unlinkable
(component
(import "undefined-name" (module))
(import "undefined-name" (core module))
)
"import `undefined-name` not defined")
(component $i)
@@ -8,7 +8,7 @@
(import "i" (instance))
)
(assert_unlinkable
(component (import "i" (module)))
(component (import "i" (core module)))
"expected module found instance")
(assert_unlinkable
(component (import "i" (func)))

View File

@@ -1,18 +1,18 @@
(component $foo
(module (export "a-module"))
(core module (export "a-module"))
)
;; the above instance can be imported into this component
(component
(import "foo" (instance
(export "a-module" (module))
(export "a-module" (core module))
))
)
;; specifying extra imports is ok
(component
(import "foo" (instance
(export "a-module" (module
(export "a-module" (core module
(import "foo" "bar" (func))
))
))
@@ -22,7 +22,7 @@
(assert_unlinkable
(component
(import "foo" (instance
(export "a-module" (module
(export "a-module" (core module
(export "the-export" (func))
))
))
@@ -30,7 +30,7 @@
"module export `the-export` not defined")
(component $foo
(module (export "a-module")
(core module (export "a-module")
(import "env" "something" (func))
)
)
@@ -39,14 +39,14 @@
(assert_unlinkable
(component
(import "foo" (instance
(export "a-module" (module))
(export "a-module" (core module))
))
)
"module import `env::something` not defined")
(component
(import "foo" (instance
(export "a-module" (module
(export "a-module" (core module
(import "env" "something" (func))
))
))
@@ -55,7 +55,7 @@
;; extra imports still ok
(component
(import "foo" (instance
(export "a-module" (module
(export "a-module" (core module
(import "env" "something" (func))
(import "env" "other" (global i32))
))
@@ -63,7 +63,7 @@
)
(component $foo
(module (export "a-module")
(core module (export "a-module")
(func (export "f"))
)
)
@@ -71,13 +71,13 @@
;; dropping exports is ok
(component
(import "foo" (instance
(export "a-module" (module))
(export "a-module" (core module))
))
)
(component
(import "foo" (instance
(export "a-module" (module
(export "a-module" (core module
(export "f" (func))
))
))
@@ -86,7 +86,7 @@
(assert_unlinkable
(component
(import "foo" (instance
(export "a-module" (module
(export "a-module" (core module
(export "f" (func (param i32)))
))
))
@@ -96,7 +96,7 @@
(assert_unlinkable
(component
(import "foo" (instance
(export "a-module" (module
(export "a-module" (core module
(export "f" (global i32))
))
))
@@ -104,7 +104,7 @@
"expected global found func")
(component $foo
(module (export "m")
(core module (export "m")
(func (export "f"))
(table (export "t") 1 funcref)
(memory (export "m") 1)
@@ -116,28 +116,28 @@
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (export "f" (global i32))))
(export "m" (core module (export "f" (global i32))))
))
)
"expected global found func")
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (export "t" (func))))
(export "m" (core module (export "t" (func))))
))
)
"expected func found table")
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (export "m" (func))))
(export "m" (core module (export "m" (func))))
))
)
"expected func found memory")
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (export "g" (func))))
(export "m" (core module (export "g" (func))))
))
)
"expected func found global")
@@ -146,42 +146,42 @@
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (export "f" (func (param i32)))))
(export "m" (core module (export "f" (func (param i32)))))
))
)
"export `f` has the wrong type")
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (export "t" (table 1 externref))))
(export "m" (core module (export "t" (table 1 externref))))
))
)
"export `t` has the wrong type")
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (export "t" (table 2 funcref))))
(export "m" (core module (export "t" (table 2 funcref))))
))
)
"export `t` has the wrong type")
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (export "m" (memory 2))))
(export "m" (core module (export "m" (memory 2))))
))
)
"export `m` has the wrong type")
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (export "g" (global f32))))
(export "m" (core module (export "g" (global f32))))
))
)
"export `g` has the wrong type")
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (export "g" (global (mut i32)))))
(export "m" (core module (export "g" (global (mut i32)))))
))
)
"export `g` has the wrong type")
@@ -189,7 +189,7 @@
;; subtyping ok
(component
(import "foo" (instance
(export "m" (module
(export "m" (core module
(export "t" (table 0 funcref))
(export "m" (memory 0))
))
@@ -197,38 +197,38 @@
)
(component $foo
(module (export "f") (func (import "" "")))
(module (export "t") (table (import "" "") 1 funcref))
(module (export "m") (memory (import "" "") 1))
(module (export "g") (global (import "" "") i32))
(core module (export "f") (func (import "" "")))
(core module (export "t") (table (import "" "") 1 funcref))
(core module (export "m") (memory (import "" "") 1))
(core module (export "g") (global (import "" "") i32))
)
;; wrong class of item
(assert_unlinkable
(component
(import "foo" (instance
(export "f" (module (import "" "" (global i32))))
(export "f" (core module (import "" "" (global i32))))
))
)
"expected func found global")
(assert_unlinkable
(component
(import "foo" (instance
(export "t" (module (import "" "" (func))))
(export "t" (core module (import "" "" (func))))
))
)
"expected table found func")
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (import "" "" (func))))
(export "m" (core module (import "" "" (func))))
))
)
"expected memory found func")
(assert_unlinkable
(component
(import "foo" (instance
(export "g" (module (import "" "" (func))))
(export "g" (core module (import "" "" (func))))
))
)
"expected global found func")
@@ -237,42 +237,42 @@
(assert_unlinkable
(component
(import "foo" (instance
(export "f" (module (import "" "" (func (param i32)))))
(export "f" (core module (import "" "" (func (param i32)))))
))
)
"module import `::` has the wrong type")
(assert_unlinkable
(component
(import "foo" (instance
(export "t" (module (import "" "" (table 1 externref))))
(export "t" (core module (import "" "" (table 1 externref))))
))
)
"module import `::` has the wrong type")
(assert_unlinkable
(component
(import "foo" (instance
(export "t" (module (import "" "" (table 0 funcref))))
(export "t" (core module (import "" "" (table 0 funcref))))
))
)
"module import `::` has the wrong type")
(assert_unlinkable
(component
(import "foo" (instance
(export "m" (module (import "" "" (memory 0))))
(export "m" (core module (import "" "" (memory 0))))
))
)
"module import `::` has the wrong type")
(assert_unlinkable
(component
(import "foo" (instance
(export "g" (module (import "" "" (global f32))))
(export "g" (core module (import "" "" (global f32))))
))
)
"module import `::` has the wrong type")
(assert_unlinkable
(component
(import "foo" (instance
(export "g" (module (import "" "" (global (mut i32)))))
(export "g" (core module (import "" "" (global (mut i32)))))
))
)
"module import `::` has the wrong type")
@@ -280,45 +280,45 @@
;; subtyping ok, but in the opposite direction of imports
(component
(import "foo" (instance
(export "t" (module (import "" "" (table 2 funcref))))
(export "m" (module (import "" "" (memory 2))))
(export "t" (core module (import "" "" (table 2 funcref))))
(export "m" (core module (import "" "" (memory 2))))
))
)
;; An instance can reexport a module, define a module, and everything can be
;; used by something else
(component $src
(module (export "m")
(core module (export "m")
(global (export "g") i32 i32.const 2)
)
)
(component $reexport
(module $m1
(core module $m1
(global (export "g") i32 i32.const 1)
)
(import "src" (instance $src
(export "m" (module (export "g" (global i32))))
(export "m" (core module (export "g" (global i32))))
))
(module $m3
(core module $m3
(global (export "g") i32 i32.const 3)
)
(export "m1" (module $m1))
(export "m2" (module $src "m"))
(export "m3" (module $m3))
(export "m1" (core module $m1))
(export "m2" (core module $src "m"))
(export "m3" (core module $m3))
)
(component
(type $modulety (module (export "g" (global i32))))
(core type $modulety (module (export "g" (global i32))))
(import "reexport" (instance $reexport
(export "m1" (module (type $modulety)))
(export "m2" (module (type $modulety)))
(export "m3" (module (type $modulety)))
(export "m1" (core module (type $modulety)))
(export "m2" (core module (type $modulety)))
(export "m3" (core module (type $modulety)))
))
(module $assert_ok
(core module $assert_ok
(import "m1" "g" (global $m1 i32))
(import "m2" "g" (global $m2 i32))
(import "m3" "g" (global $m3 i32))
@@ -350,11 +350,11 @@
(start $assert_ok)
)
(instance $m1 (instantiate (module $reexport "m1")))
(instance $m2 (instantiate (module $reexport "m2")))
(instance $m3 (instantiate (module $reexport "m3")))
(core instance $m1 (instantiate (module $reexport "m1")))
(core instance $m2 (instantiate (module $reexport "m2")))
(core instance $m3 (instantiate (module $reexport "m3")))
(instance (instantiate (module $assert_ok)
(core instance (instantiate $assert_ok
(with "m1" (instance $m1))
(with "m2" (instance $m2))
(with "m3" (instance $m3))
@@ -364,7 +364,7 @@
;; order of imports and exports can be shuffled between definition site and
;; use-site
(component $provider
(module (export "m")
(core module (export "m")
(import "" "1" (global $i1 i32))
(import "" "2" (global $i2 i32))
(import "" "3" (global $i3 i32))
@@ -413,7 +413,7 @@
(component
(import "provider" (instance $provider
(export "m" (module
(export "m" (core module
(import "" "4" (global i32))
(import "" "3" (global i32))
(import "" "2" (global i32))
@@ -426,18 +426,18 @@
))
))
(module $imports
(core module $imports
(global (export "1") i32 (i32.const 1))
(global (export "3") i32 (i32.const 3))
(global (export "2") i32 (i32.const 2))
(global (export "4") i32 (i32.const 4))
)
(instance $imports (instantiate (module $imports)))
(instance $m (instantiate (module $provider "m")
(core instance $imports (instantiate $imports))
(core instance $m (instantiate (module $provider "m")
(with "" (instance $imports))
))
(module $import_globals
(core module $import_globals
(import "" "g4" (global $g4 i32))
(import "" "g3" (global $g3 i32))
(import "" "g2" (global $g2 i32))
@@ -473,5 +473,5 @@
(start $assert_imports)
)
(instance (instantiate (module $import_globals) (with "" (instance $m))))
(core instance (instantiate $import_globals (with "" (instance $m))))
)

View File

@@ -1,21 +1,21 @@
(component)
(component
(module)
(core module)
)
(component
(module)
(module)
(module)
(core module)
(core module)
(core module)
)
(component
(module
(core module
(func (export "a") (result i32) i32.const 0)
(func (export "b") (result i64) i64.const 0)
)
(module
(core module
(func (export "c") (result f32) f32.const 0)
(func (export "d") (result f64) f64.const 0)
)

View File

@@ -52,7 +52,8 @@
(type $empty (func))
(type (func (param string) (result u32)))
(type (component))
(type (module))
(core type (module))
(core type (func))
(type (instance))
(type (component
@@ -62,7 +63,7 @@
(type $t (instance))
(export "a" (module))
(export "a" (core module))
(export "b" (instance (type $t)))
))
@@ -73,11 +74,11 @@
(type $t (instance))
(export "a" (module))
(export "a" (core module))
(export "b" (instance (type $t)))
))
(type (module
(core type (module
(import "" "" (func (param i32)))
(import "" "1" (func (result i32)))
(export "1" (global i32))