diff --git a/design/mvp/Binary.md b/design/mvp/Binary.md index 1438956f..6e9bae44 100644 --- a/design/mvp/Binary.md +++ b/design/mvp/Binary.md @@ -50,8 +50,8 @@ Notes: (See [Instance Definitions](Explainer.md#instance-definitions) in the explainer.) ``` instance ::= ie: => (instance ie) -instanceexpr ::= 0x00 0x00 m: a*:vec() => (instantiate (module m) (import a)*) - | 0x00 0x01 c: a*:vec() => (instantiate (component c) (import a)*) +instanceexpr ::= 0x00 0x00 m: a*:vec() => (instantiate (module m) (with a)*) + | 0x00 0x01 c: a*:vec() => (instantiate (component c) (with a)*) | 0x01 e*:vec() => e* | 0x02 e*:vec() => e* modulearg ::= n: 0x02 i: => n (instance i) diff --git a/design/mvp/Explainer.md b/design/mvp/Explainer.md index 7af9985b..296704f7 100644 --- a/design/mvp/Explainer.md +++ b/design/mvp/Explainer.md @@ -110,8 +110,8 @@ supplying a set of named *arguments* which satisfy all the named *imports* of the selected module/component: ``` instance ::= (instance ? ) -instanceexpr ::= (instantiate (module ) (import )*) - | (instantiate (component ) (import )*) +instanceexpr ::= (instantiate (module ) (with )*) + | (instantiate (component ) (with )*) | * | core * modulearg ::= (instance ) @@ -125,8 +125,9 @@ componentarg ::= (module ) | (instance *) export ::= (export ) ``` -When instantiating a module via `(instantiate (module $M) *)`, the -two-level imports of the module `$M` are resolved as follows: +When instantiating a module via +`(instantiate (module $M) (with )*)`, 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 @@ -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 @@ -216,13 +217,13 @@ For `export` aliases, the inline sugar has the form `(kind + 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)) @@ -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 )) )) @@ -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")) @@ -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")) ) @@ -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")) )) )) diff --git a/design/mvp/examples/LinkTimeVirtualization.md b/design/mvp/examples/LinkTimeVirtualization.md index 584e6c13..2af28970 100644 --- a/design/mvp/examples/LinkTimeVirtualization.md +++ b/design/mvp/examples/LinkTimeVirtualization.md @@ -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)) )) ) ``` @@ -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)) )) ) ``` diff --git a/design/mvp/examples/SharedEverythingDynamicLinking.md b/design/mvp/examples/SharedEverythingDynamicLinking.md index b03d1695..b5b5370d 100644 --- a/design/mvp/examples/SharedEverythingDynamicLinking.md +++ b/design/mvp/examples/SharedEverythingDynamicLinking.md @@ -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")) @@ -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")) @@ -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))) @@ -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")) @@ -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)) )) ) ```