@@ -31,9 +31,9 @@ being specified here.
31
31
* [ Flat Lowering] ( #flat-lowering )
32
32
* [ Lifting and Lowering Values] ( #lifting-and-lowering-values )
33
33
* [ Canonical definitions] ( #canonical-definitions )
34
+ * [ ` canonopt ` Validation] ( #canonopt-validation )
34
35
* [ ` canon lift ` ] ( #canon-lift )
35
36
* [ ` canon lower ` ] ( #canon-lower )
36
- * [ ` canon $opts ` ] ( #canon-opts )
37
37
* [ ` canon resource.new ` ] ( #canon-resourcenew )
38
38
* [ ` canon resource.drop ` ] ( #canon-resourcedrop )
39
39
* [ ` canon resource.rep ` ] ( #canon-resourcerep )
@@ -2722,21 +2722,60 @@ Using the above supporting definitions, we can describe the static and dynamic
2722
2722
semantics of component-level [ ` canon ` ] definitions. The following subsections
2723
2723
cover each of these ` canon ` cases.
2724
2724
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
+
2725
2765
### ` canon lift `
2726
2766
2727
2767
For a canonical definition:
2728
2768
``` wat
2729
2769
(canon lift $callee:<funcidx> $opts:<canonopt>* (func $f (type $ft)))
2730
2770
```
2731
2771
2732
- In addition to [ general validation of ` $opts ` ] ( #canon-opts ) the additional
2772
+ In addition to [ general validation of ` $opts ` ] ( #canonopt-validation ) the additional
2733
2773
validation is performed:
2734
2774
2735
2775
* ` $callee ` must have type ` flatten_functype($opts, $ft, 'lift') `
2736
2776
* ` $f ` is given type ` $ft `
2737
- * a ` memory ` is present if required by lifting
2738
- * a ` realloc ` is present if required by lifting
2739
2777
* 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.
2740
2779
2741
2780
When instantiating component instance ` $inst ` :
2742
2781
* Define ` $f ` to be the partially-bound closure ` canon_lift($opts, $inst, $ft, $callee) `
@@ -2894,13 +2933,12 @@ For a canonical definition:
2894
2933
(canon lower $callee:<funcidx> $opts:<canonopt>* (core func $f))
2895
2934
```
2896
2935
2897
- In addition to [ general validation of ` $opts ` ] ( #canon-opts ) the additional
2936
+ In addition to [ general validation of ` $opts ` ] ( #canonopt-validation ) the additional
2898
2937
validation is performed where ` $callee ` has type ` $ft ` :
2899
2938
2900
2939
* ` $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
2904
2942
2905
2943
When instantiating component instance ` $inst ` :
2906
2944
* 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
3039
3077
as post-MVP [ adapter functions] .
3040
3078
3041
3079
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
-
3062
3080
### ` canon resource.new `
3063
3081
3064
3082
For a canonical definition:
@@ -3231,11 +3249,12 @@ For a canonical definition:
3231
3249
(canon task.return (result $t)? $opts (core func $f))
3232
3250
```
3233
3251
3234
- In addition to [ general validation of ` $opts ` ] ( #canon-opts ) validation
3252
+ In addition to [ general validation of ` $opts ` ] ( #canonopt-validation ) validation
3235
3253
specifies:
3236
3254
3237
3255
* ` $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
3239
3258
3240
3259
Calling ` $f ` invokes the following function which uses ` Task.return_ ` to lift
3241
3260
and pass the results to the caller:
@@ -3489,12 +3508,12 @@ For canonical definitions:
3489
3508
(canon stream.read $t $opts (core func $f))
3490
3509
(canon stream.write $t $opts (core func $f))
3491
3510
```
3492
- In addition to [ general validation of ` $opts ` ] ( #canon-opts ) validation
3511
+ In addition to [ general validation of ` $opts ` ] ( #canonopt-validation ) validation
3493
3512
specifies:
3494
3513
* ` $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
3498
3517
3499
3518
For canonical definitions:
3500
3519
``` wat
@@ -3503,9 +3522,9 @@ For canonical definitions:
3503
3522
```
3504
3523
validation specifies:
3505
3524
* ` $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
3509
3528
3510
3529
The implementation of these four built-ins all funnel down to a single
3511
3530
parameterized ` copy ` function:
0 commit comments