Skip to content

Commit 49fb117

Browse files
committed
Make <functype> in 'canon lift' symmetric to imports
1 parent 7401e4c commit 49fb117

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

design/mvp/Binary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Notes:
216216

217217
(See [Canonical Definitions](Explainer.md#canonical-definitions) in the explainer.)
218218
```
219-
canon ::= 0x00 0x00 f:<core:funcidx> ft:<typeidx> opts:<opts> => (canon lift f type-index-space[ft] opts (func))
219+
canon ::= 0x00 0x00 f:<core:funcidx> opts:<opts> ft:<typeidx> => (canon lift f opts type-index-space[ft])
220220
| 0x01 0x00 f:<funcidx> opts:<opts> => (canon lower f opts (core func))
221221
opts ::= opt*:vec(<canonopt>) => opt*
222222
canonopt ::= 0x00 => string-encoding=utf8

design/mvp/Explainer.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,8 @@ componentdecl ::= <importdecl>
433433
instancedecl ::= <type>
434434
| <alias>
435435
| <exportdecl>
436-
importdecl ::= (import <name> <importdesc>)
436+
importdecl ::= (import <name> bind-id(<externdesc>))
437437
exportdecl ::= (export <name> <externdesc>)
438-
importdesc ::= bind-id(<externdesc>)
439438
externdesc ::= (<sort> (type <u32>) )
440439
| core-prefix(<core:moduletype>)
441440
| <functype>
@@ -524,14 +523,14 @@ text format allows both references to out-of-line type definitions (via
524523
`(type <typeidx>)`) and inline type expressions that the text format desugars
525524
into out-of-line type definitions.
526525

527-
The `value` case of `importdesc`/`exportdesc` describes a runtime value
528-
that is imported or exported at instantiation time as described in the [start
529-
definitions](#start-definitions) section below.
526+
The `value` case of `externdesc` describes a runtime value that is imported or
527+
exported at instantiation time as described in the
528+
[start definitions](#start-definitions) section below.
530529

531-
The `type` case of `importdesc`/`exportdesc` describes an imported or exported
532-
type along with its bounds. The bounds currently only have an `eq` option that
533-
says that the imported/exported type must be exactly equal to the referenced
534-
type. There are two main use cases for this in the short-term:
530+
The `type` case of `externdesc` describes an imported or exported type along
531+
with its bounds. The bounds currently only have an `eq` option that says that
532+
the imported/exported type must be exactly equal to the referenced type. There
533+
are two main use cases for this in the short-term:
535534
* Type exports allow a component or interface to associate a name with a
536535
structural type (e.g., `(export "nanos" (type (eq u64)))`) which bindings
537536
generators can use to generate type aliases (e.g., `typedef uint64_t nanos;`).
@@ -611,7 +610,7 @@ two directions:
611610
Canonical definitions specify one of these two wrapping directions, the function
612611
to wrap and a list of configuration options:
613612
```
614-
canon ::= (canon lift core-prefix(<core:funcidx>) <functype> <canonopt>* (func <id>?))
613+
canon ::= (canon lift core-prefix(<core:funcidx>) <canonopt>* bind-id(<externdesc>))
615614
| (canon lower <funcidx> <canonopt>* (core func <id>?))
616615
canonopt ::= string-encoding=utf8
617616
| string-encoding=utf16
@@ -620,6 +619,10 @@ canonopt ::= string-encoding=utf8
620619
| (realloc core-prefix(<core:funcidx>))
621620
| (post-return core-prefix(<core:funcidx>))
622621
```
622+
While the production `externdesc` accepts any `sort`, the validation rules
623+
for `canon lift` would only allow the `func` sort. In the future, other sorts
624+
may be added (viz., types), hence the explicit sort.
625+
623626
The `string-encoding` option specifies the encoding the Canonical ABI will use
624627
for the `string` type. The `latin1+utf16` encoding captures a common string
625628
encoding across Java, JavaScript and .NET VMs and allows a dynamic choice
@@ -672,9 +675,9 @@ stack-switching in component function signatures.
672675
Similar to the `import` and `alias` abbreviations shown above, `canon`
673676
definitions can also be written in an inverted form that puts the sort first:
674677
```wasm
675-
(func $f (import "i" "f")) ≡ (import "i" "f" (func $f)) (WebAssembly 1.0)
676-
(func $h (canon lift ...)) ≡ (canon lift ... (func $h))
677-
(core func $h (canon lower ...)) ≡ (canon lower ... (core func $h))
678+
(func $f ...type... (import "i" "f")) ≡ (import "i" "f" (func $f ...type...)) (WebAssembly 1.0)
679+
(func $h ...type... (canon lift ...)) ≡ (canon lift ... (func $h ...type...))
680+
(core func $h ...type... (canon lower ...)) ≡ (canon lower ... (core func $h ...type...))
678681
```
679682
Note: in the future, `canon` may be generalized to define other sorts than
680683
functions (such as types), hence the explicit `sort`.
@@ -707,11 +710,11 @@ takes a string, does some logging, then returns a string.
707710
(with "libc" (instance $libc))
708711
(with "wasi:logging" (instance (export "log" (func $log))))
709712
))
710-
(func (export "run") (canon lift
713+
(func $run (param string) (result string) (canon lift
711714
(core func $main "run")
712-
(func (param string) (result string))
713715
(memory (core memory $libc "mem")) (realloc (core func $libc "realloc"))
714716
))
717+
(export "run" (func $run))
715718
)
716719
```
717720
This example shows the pattern of splitting out a reusable language runtime
@@ -764,9 +767,8 @@ exported string at instantiation time:
764767
)
765768
)
766769
(core instance $main (instantiate $Main (with "libc" (instance $libc))))
767-
(func $start (canon lift
770+
(func $start (param string) (result string) (canon lift
768771
(core func $main "start")
769-
(func (param string) (result string))
770772
(memory (core memory $libc "mem")) (realloc (core func $libc "realloc"))
771773
))
772774
(start $start (value $name) (result (value $greeting)))
@@ -782,7 +784,7 @@ of core linear memory.
782784

783785
Lastly, imports and exports are defined in terms of the above as:
784786
```
785-
import ::= (import <name> <importdesc>)
787+
import ::= <importdecl>
786788
export ::= (export <name> <sortidx>)
787789
```
788790
All import and export names within a component must be unique, respectively.

design/mvp/examples/SharedEverythingDynamicLinking.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ would look like:
157157
(with "libc" (instance $libc))
158158
(with "libzip" (instance $libzip))
159159
))
160-
(func (export "zip") (canon lift
160+
(func $zip (param (list u8)) (result (list u8)) (canon lift
161161
(func $main "zip")
162-
(func (param (list u8)) (result (list u8)))
163162
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
164163
))
164+
(export "zip" (func $zip))
165165
)
166166
```
167167
Here, `zipper` links its own private module code (`$Main`) with the shareable
@@ -236,11 +236,11 @@ component-aware `clang`, the resulting component would look like:
236236
(with "libc" (instance $libc))
237237
(with "libimg" (instance $libimg))
238238
))
239-
(func (export "transform") (canon lift
239+
(func $transform (param (list u8)) (result (list u8)) (canon lift
240240
(func $main "transform")
241-
(func (param (list u8)) (result (list u8)))
242241
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
243242
))
243+
(export "transform" (func $transform))
244244
)
245245
```
246246
Here, we see the general pattern emerging of the dependency DAG between
@@ -296,11 +296,11 @@ components. The resulting component could look like:
296296
(with "zipper" (instance (export "zip" (func $zipper "zip"))))
297297
(with "imgmgk" (instance (export "transform" (func $imgmgk "transform"))))
298298
))
299-
(func (export "run") (canon lift
299+
(func $run (param string) (result string) (canon lift
300300
(func $main "run")
301-
(func (param string) (result string))
302301
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
303302
))
303+
(export "run" (func $run))
304304
)
305305
```
306306
Note here that `$Libc` is passed to the nested `zipper` and `imgmgk` instances

0 commit comments

Comments
 (0)