Skip to content

Commit f4757de

Browse files
committed
Review comments
1 parent 65dd40b commit f4757de

File tree

1 file changed

+56
-37
lines changed

1 file changed

+56
-37
lines changed

design/mvp/CanonicalABI.md

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ being specified here.
3131
* [Flat Lowering](#flat-lowering)
3232
* [Lifting and Lowering Values](#lifting-and-lowering-values)
3333
* [Canonical definitions](#canonical-definitions)
34+
* [`canonopt` Validation](#canonopt-validation)
3435
* [`canon lift`](#canon-lift)
3536
* [`canon lower`](#canon-lower)
36-
* [`canon $opts`](#canon-opts)
3737
* [`canon resource.new`](#canon-resourcenew)
3838
* [`canon resource.drop`](#canon-resourcedrop)
3939
* [`canon resource.rep`](#canon-resourcerep)
@@ -2722,21 +2722,60 @@ Using the above supporting definitions, we can describe the static and dynamic
27222722
semantics of component-level [`canon`] definitions. The following subsections
27232723
cover each of these `canon` cases.
27242724

2725+
### `canonopt` Validation
2726+
2727+
Canonical options, specified here as `$opts` in a number of locations
2728+
throughout this document, can be specified at most once per `$opts`. For example
2729+
specifying `string-encoding=utf8` twice is an error. Each individual option, if
2730+
present, is validated as such:
2731+
2732+
* `string-encoding=N` - can be passed at most once, regardless of `N`.
2733+
* `memory` - this is a subtype of `(memory 1)`
2734+
* `realloc` - the function has type `(func (param i32 i32 i32 i32) (result i32))`
2735+
* if `realloc` is present, then `memory` must be present
2736+
* `post-return` - only allowed on [`canon lift`](#canon-lift), which has rules
2737+
for validation
2738+
* 🔀 `async` - cannot be present with `post-return`
2739+
* 🔀 `callback` - the function has type `(func (param i32 i32 i32 i32) (result
2740+
i32))` and cannot be present without `async` and is only allowed with [`canon
2741+
lift`](#canon-lift)
2742+
2743+
Additionally some options are required depending on lift/lower operations
2744+
performed for a component. These are defined as:
2745+
2746+
* `lower_func(ft)`
2747+
* requires options based on `lower(param)` for all parameters in `ft`
2748+
* requires options based on `lift(result)` if `ft` has a result
2749+
* if `len(flatten_types(ft.param_types())) > MAX_FLAT_PARAMS`, `memory` is required
2750+
* if `len(flatten_types(ft.result_types())) > MAX_FLAT_RESULTS`, `realloc` is required
2751+
2752+
* `lift_func(ft)`
2753+
* requires options based on `lift(param)` for all parameters in `ft`
2754+
* requires options based on `lower(result)` if `ft` has a result
2755+
* if `len(flatten_types(ft.param_types())) > MAX_FLAT_PARAMS`, `realloc` is required
2756+
* if `len(flatten_types(ft.result_types())) > MAX_FLAT_RESULTS`, `memory` is required
2757+
2758+
* `lower(T)`
2759+
* requires `memory` if `T` contains a `list` or `string`
2760+
2761+
* `lift(T)`
2762+
* requires `realloc` if `T` contains a `list` or `string`
2763+
2764+
27252765
### `canon lift`
27262766

27272767
For a canonical definition:
27282768
```wat
27292769
(canon lift $callee:<funcidx> $opts:<canonopt>* (func $f (type $ft)))
27302770
```
27312771

2732-
In addition to [general validation of `$opts`](#canon-opts) the additional
2772+
In addition to [general validation of `$opts`](#canonopt-validation) the additional
27332773
validation is performed:
27342774

27352775
* `$callee` must have type `flatten_functype($opts, $ft, 'lift')`
27362776
* `$f` is given type `$ft`
2737-
* a `memory` is present if required by lifting
2738-
* a `realloc` is present if required by lifting
27392777
* if a `post-return` is present, it has type `(func (param flatten_functype({}, $ft, 'lift').results))`
2778+
* [`lift_func($ft)` above](#canonopt-validation) defines extra required options.
27402779

27412780
When instantiating component instance `$inst`:
27422781
* Define `$f` to be the partially-bound closure `canon_lift($opts, $inst, $ft, $callee)`
@@ -2894,13 +2933,12 @@ For a canonical definition:
28942933
(canon lower $callee:<funcidx> $opts:<canonopt>* (core func $f))
28952934
```
28962935

2897-
In addition to [general validation of `$opts`](#canon-opts) the additional
2936+
In addition to [general validation of `$opts`](#canonopt-validation) the additional
28982937
validation is performed where `$callee` has type `$ft`:
28992938

29002939
* `$f` is given type `flatten_functype($opts, $ft, 'lower')`
2901-
* a `memory` is present if required by lowering
2902-
* a `realloc` is present if required by lowering
2903-
* if `contains_async_value($ft)`, then `$opts.async` must be set
2940+
* [`lower_func($ft)` above](#canonopt-validation) defines extra required options.
2941+
* if `async` is specified, `memory` must be present
29042942

29052943
When instantiating component instance `$inst`:
29062944
* Define `$f` to be the partially-bound closure: `canon_lower($opts, $ft, $callee)`
@@ -3039,26 +3077,6 @@ elimination of string operations on the labels of records and variants) as well
30393077
as post-MVP [adapter functions].
30403078

30413079

3042-
### `canon $opts`
3043-
3044-
Canonical options, specified here as `$opts` in a number of locations
3045-
throughout this document, can be specified at most once per `$opts`. For example
3046-
specifying `string-encoding=utf8` twice is an error. Each individual option, if
3047-
present, is validated as such:
3048-
3049-
* `string-encoding=utf8` - cannot be combined with `utf16` or `latin1+utf16`
3050-
* `string-encoding=utf16` - cannot be combined with `utf8` or `latin1+utf16`
3051-
* `string-encoding=latin1+utf16` - cannot be combined with `utf8` or `utf16`
3052-
* `memory` - this is a subtype of `(memory 1)`
3053-
* `realloc` - the function has type `(func (param i32 i32 i32 i32) (result i32))`
3054-
* `post-return` - only allowed on [`canon lift`](#canon-lift), which has rules
3055-
for validation
3056-
* 🔀 `async` - cannot be present with `post-return`
3057-
* 🔀 `callback` - the function has type `(func (param i32 i32 i32 i32) (result
3058-
i32))` and cannot be present without `async` and is only allowed with [`canon
3059-
lift`](#canon-lift)
3060-
3061-
30623080
### `canon resource.new`
30633081

30643082
For a canonical definition:
@@ -3231,11 +3249,12 @@ For a canonical definition:
32313249
(canon task.return (result $t)? $opts (core func $f))
32323250
```
32333251

3234-
In addition to [general validation of `$opts`](#canon-opts) validation
3252+
In addition to [general validation of `$opts`](#canonopt-validation) validation
32353253
specifies:
32363254

32373255
* `$f` is given type `flatten_functype($opts, (func (param $t)?), 'lower')`
3238-
* `$opts` may only contain `memory`, `string-encoding` and `realloc`
3256+
* `$opts` may only contain `memory` and `string-encoding`
3257+
* [`lift_func($f.result)` above](#canonopt-validation) defines required options
32393258

32403259
Calling `$f` invokes the following function which uses `Task.return_` to lift
32413260
and pass the results to the caller:
@@ -3489,12 +3508,12 @@ For canonical definitions:
34893508
(canon stream.read $t $opts (core func $f))
34903509
(canon stream.write $t $opts (core func $f))
34913510
```
3492-
In addition to [general validation of `$opts`](#canon-opts) validation
3511+
In addition to [general validation of `$opts`](#canonopt-validation) validation
34933512
specifies:
34943513
* `$f` is given type `(func (param i32 i32 i32) (result i32))`
3495-
* `memory` is required for `stream.write` if required by lowering
3496-
* `memory` is required for `stream.read` if required by lifting
3497-
* `realloc` is required for `stream.read` if required by lifting
3514+
* [`lower($t)` above](#canonopt-validation) defines required options for `stream.write`
3515+
* [`lift($t)` above](#canonopt-validation) defines required options for `stream.read`
3516+
* `memory` is required to be present
34983517

34993518
For canonical definitions:
35003519
```wat
@@ -3503,9 +3522,9 @@ For canonical definitions:
35033522
```
35043523
validation specifies:
35053524
* `$f` is given type `(func (param i32 i32) (result i32))`
3506-
* `memory` is required for `future.write` if required by lowering
3507-
* `memory` is required for `future.read` if required by lifting
3508-
* `realloc` is required for `future.read` if required by lifting
3525+
* [`lower($t)` above](#canonopt-validation) defines required options for `future.write`
3526+
* [`lift($t)` above](#canonopt-validation) defines required options for `future.read`
3527+
* `memory` is required to be present
35093528

35103529
The implementation of these four built-ins all funnel down to a single
35113530
parameterized `copy` function:

0 commit comments

Comments
 (0)