Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions design/mvp/Binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Notes:
(See [Instance Definitions](Explainer.md#instance-definitions) in the explainer.)
```
instance ::= ie:<instance-expr> => (instance ie)
instanceexpr ::= 0x00 0x00 m:<moduleidx> a*:vec(<modulearg>) => (instantiate (module m) (import a)*)
| 0x00 0x01 c:<componentidx> a*:vec(<componentarg>) => (instantiate (component c) (import a)*)
instanceexpr ::= 0x00 0x00 m:<moduleidx> a*:vec(<modulearg>) => (instantiate (module m) (with a)*)
| 0x00 0x01 c:<componentidx> a*:vec(<componentarg>) => (instantiate (component c) (with a)*)
| 0x01 e*:vec(<export>) => e*
| 0x02 e*:vec(<core:export>) => e*
modulearg ::= n:<name> 0x02 i:<instanceidx> => n (instance i)
Expand Down
31 changes: 16 additions & 15 deletions design/mvp/Explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ supplying a set of named *arguments* which satisfy all the named *imports* of
the selected module/component:
```
instance ::= (instance <id>? <instanceexpr>)
instanceexpr ::= (instantiate (module <moduleidx>) (import <name> <modulearg>)*)
| (instantiate (component <componentidx>) (import <name> <componentarg>)*)
instanceexpr ::= (instantiate (module <moduleidx>) (with <name> <modulearg>)*)
| (instantiate (component <componentidx>) (with <name> <componentarg>)*)
| <export>*
| core <core:export>*
modulearg ::= (instance <instanceidx>)
Expand All @@ -125,8 +125,9 @@ componentarg ::= (module <moduleidx>)
| (instance <export>*)
export ::= (export <name> <componentarg>)
```
When instantiating a module via `(instantiate (module $M) <modulearg>*)`, the
two-level imports of the module `$M` are resolved as follows:
When instantiating a module via
`(instantiate (module $M) (with <name> <modulearg>)*)`, the two-level imports of
the module `$M` are resolved as follows:
1. The first `name` of an import is looked up in the named list of `modulearg`
to select a module instance.
2. The second `name` of an import is looked up in the named list of exports of
Expand All @@ -144,7 +145,7 @@ following component:
(func (import "a" "one") (result i32))
)
(instance $a (instantiate (module $A)))
(instance $b (instantiate (module $B) (import "a" (instance $a))))
(instance $b (instantiate (module $B) (with "a" (instance $a))))
)
```
Components, as we'll see below, have single-level imports, i.e., each import
Expand Down Expand Up @@ -216,13 +217,13 @@ For `export` aliases, the inline sugar has the form `(kind <instanceidx> <name>+
and can be used anywhere a `kind` index appears in the AST. For example, the
following snippet uses an inline function alias:
```wasm
(instance $j (instantiate (component $J) (import "f" (func $i "f"))))
(instance $j (instantiate (component $J) (with "f" (func $i "f"))))
(export "x" (func $j "g" "h"))
```
which is desugared into:
```wasm
(alias export $i "f" (func $f_alias))
(instance $j (instantiate (component $J) (import "f" (func $f_alias))))
(instance $j (instantiate (component $J) (with "f" (func $f_alias))))
(alias export $j "g" (instance $g_alias))
(alias export $g_alias "h" (func $h_alias))
(export "x" (func $h_alias))
Expand Down Expand Up @@ -263,16 +264,16 @@ With what's defined so far, we're able to link modules with arbitrary renamings:
)
(instance $a (instantiate (module $A)))
(instance $b1 (instantiate (module $B)
(import "a" (instance $a)) ;; no renaming
(with "a" (instance $a)) ;; no renaming
))
(alias export $a "two" (func $a_two))
(instance $b2 (instantiate (module $B)
(import "a" (instance
(with "a" (instance
(export "one" (func $a_two)) ;; renaming, using explicit alias
))
))
(instance $b3 (instantiate (module $B)
(import "a" (instance
(with "a" (instance
(export "one" (func $a "three")) ;; renaming, using inline alias sugar
))
))
Expand Down Expand Up @@ -521,8 +522,8 @@ does some logging, then returns a string.
)
)
(instance $main (instantiate (module $Main)
(import "libc" (instance $libc))
(import "wasi:logging" (instance (export "log" (func $log))))
(with "libc" (instance $libc))
(with "wasi:logging" (instance (export "log" (func $log))))
))
(func (export "run")
(canon.lift (func (param string) (result string)) (into $libc) (func $main "run"))
Expand Down Expand Up @@ -593,7 +594,7 @@ exported string, all at instantiation time:
... general-purpose compute
)
)
(instance $main (instantiate (module $Main) (import "libc" (instance $libc))))
(instance $main (instantiate (module $Main) (with "libc" (instance $libc))))
(func $start
(canon.lift (func (param string) (result string)) (into $libc) (func $main "start"))
)
Expand Down Expand Up @@ -631,10 +632,10 @@ exports other components:
(export "g" (func (result string)))
))
(instance $d1 (instantiate (component $D)
(import "c" (instance $c))
(with "c" (instance $c))
))
(instance $d2 (instantiate (component $D)
(import "c" (instance
(with "c" (instance
(export "f" (func $d1 "g"))
))
))
Expand Down
8 changes: 4 additions & 4 deletions design/mvp/examples/LinkTimeVirtualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ We now write the parent component by composing `child.wasm` with
(import "./virtualize.wasm" (component $Virtualize ...))
(import "./child.wasm" (component $Child ...))
(instance $virtual-fs (instantiate (component $Virtualize)
(import "wasi:filesystem" (instance $real-fs))
(with "wasi:filesystem" (instance $real-fs))
))
(instance $child (instantiate (component $Child)
(import "wasi:filesystem" (instance $virtual-fs))
(with "wasi:filesystem" (instance $virtual-fs))
))
)
```
Expand All @@ -69,10 +69,10 @@ definitions in place of imports:
(component $Virtualize ... copied inline ...)
(component $Child ... copied inline ...)
(instance $virtual-fs (instantiate (component $Virtualize)
(import "wasi:filesystem" (instance $real-fs))
(with "wasi:filesystem" (instance $real-fs))
))
(instance $child (instantiate (component $Child)
(import "wasi:filesystem" (instance $virtual-fs))
(with "wasi:filesystem" (instance $virtual-fs))
))
)
```
36 changes: 18 additions & 18 deletions design/mvp/examples/SharedEverythingDynamicLinking.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ would look like:

(instance $libc (instantiate (module $Libc)))
(instance $libzip (instantiate (module $Libzip))
(import "libc" (instance $libc))
(with "libc" (instance $libc))
))
(instance $main (instantiate (module $Main)
(import "libc" (instance $libc))
(import "libzip" (instance $libzip))
(with "libc" (instance $libc))
(with "libzip" (instance $libzip))
))
(func (export "zip")
(canon.lift (func (param (list u8)) (result (list u8))) (into $libc) (func $main "zip"))
Expand Down Expand Up @@ -224,15 +224,15 @@ component-aware `clang`, the resulting component would look like:

(instance $libc (instantiate (module $Libc)))
(instance $libzip (instantiate (module $Libzip)
(import "libc" (instance $libc))
(with "libc" (instance $libc))
))
(instance $libimg (instantiate (module $Libimg)
(import "libc" (instance $libc))
(import "libzip" (instance $libzip))
(with "libc" (instance $libc))
(with "libzip" (instance $libzip))
))
(instance $main (instantiate (module $Main)
(import "libc" (instance $libc))
(import "libimg" (instance $libimg))
(with "libc" (instance $libc))
(with "libimg" (instance $libimg))
))
(func (export "transform")
(canon.lift (func (param (list u8)) (result (list u8))) (into $libc) (func $main "transform"))
Expand Down Expand Up @@ -269,13 +269,13 @@ components. The resulting component could look like:
)

(instance $zipper (instantiate (component $Zipper)
(import "libc" (module $Libc))
(import "libzip" (module $Libzip))
(with "libc" (module $Libc))
(with "libzip" (module $Libzip))
))
(instance $imgmgk (instantiate (component $Imgmgk)
(import "libc" (module $Libc))
(import "libzip" (module $Libzip))
(import "libimg" (module $Libimg))
(with "libc" (module $Libc))
(with "libzip" (module $Libzip))
(with "libimg" (module $Libimg))
))

(instance $libc (instantiate (module $Libc)))
Expand All @@ -286,9 +286,9 @@ components. The resulting component could look like:
(canon.lower (into $libc) (func $imgmgk "transform"))
)
(instance $main (instantiate (module $Main)
(import "libc" (instance $libc))
(import "zipper" (instance (export "zip" (func $zipper "zip"))))
(import "imgmgk" (instance (export "transform" (func $imgmgk "transform"))))
(with "libc" (instance $libc))
(with "zipper" (instance (export "zip" (func $zipper "zip"))))
(with "imgmgk" (instance (export "transform" (func $imgmgk "transform"))))
))
(func (export "run")
(canon.lift (func (param string) (result string)) (func $main "run"))
Expand Down Expand Up @@ -358,11 +358,11 @@ function table and `bar-index` mutable global.
)
(instance $linkage (instantiate (module $Linkage)))
(instance $a (instantiate (module $A)
(import "linkage" (instance $linkage))
(with "linkage" (instance $linkage))
))
(instance $b (instantiate (module $B)
(import "a" (instance $a))
(import "linkage" (instance $linkage))
(with "linkage" (instance $linkage))
))
)
```
Expand Down