@@ -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 )
35
34
* [ ` canon lift ` ] ( #canon-lift )
36
35
* [ ` 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,60 +2722,21 @@ 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
-
2765
2725
### ` canon lift `
2766
2726
2767
2727
For a canonical definition:
2768
2728
``` wat
2769
2729
(canon lift $callee:<funcidx> $opts:<canonopt>* (func $f (type $ft)))
2770
2730
```
2771
2731
2772
- In addition to [ general validation of ` $opts ` ] ( #canonopt-validation ) the additional
2732
+ In addition to [ general validation of ` $opts ` ] ( #canon-opts ) the additional
2773
2733
validation is performed:
2774
2734
2775
2735
* ` $callee ` must have type ` flatten_functype($opts, $ft, 'lift') `
2776
2736
* ` $f ` is given type ` $ft `
2737
+ * a ` memory ` is present if required by lifting
2738
+ * a ` realloc ` is present if required by lifting
2777
2739
* 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.
2779
2740
2780
2741
When instantiating component instance ` $inst ` :
2781
2742
* Define ` $f ` to be the partially-bound closure ` canon_lift($opts, $inst, $ft, $callee) `
@@ -2933,12 +2894,13 @@ For a canonical definition:
2933
2894
(canon lower $callee:<funcidx> $opts:<canonopt>* (core func $f))
2934
2895
```
2935
2896
2936
- In addition to [ general validation of ` $opts ` ] ( #canonopt-validation ) the additional
2897
+ In addition to [ general validation of ` $opts ` ] ( #canon-opts ) the additional
2937
2898
validation is performed where ` $callee ` has type ` $ft ` :
2938
2899
2939
2900
* ` $f ` is given type ` flatten_functype($opts, $ft, 'lower') `
2940
- * [ ` lower_func($ft) ` above] ( #canonopt-validation ) defines extra required options.
2941
- * if ` async ` is specified, ` memory ` must be present
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
2942
2904
2943
2905
When instantiating component instance ` $inst ` :
2944
2906
* Define ` $f ` to be the partially-bound closure: ` canon_lower($opts, $ft, $callee) `
@@ -3077,6 +3039,26 @@ elimination of string operations on the labels of records and variants) as well
3077
3039
as post-MVP [ adapter functions] .
3078
3040
3079
3041
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
+
3080
3062
### ` canon resource.new `
3081
3063
3082
3064
For a canonical definition:
@@ -3249,12 +3231,11 @@ For a canonical definition:
3249
3231
(canon task.return (result $t)? $opts (core func $f))
3250
3232
```
3251
3233
3252
- In addition to [ general validation of ` $opts ` ] ( #canonopt-validation ) validation
3234
+ In addition to [ general validation of ` $opts ` ] ( #canon-opts ) validation
3253
3235
specifies:
3254
3236
3255
3237
* ` $f ` is given type ` flatten_functype($opts, (func (param $t)?), 'lower') `
3256
- * ` $opts ` may only contain ` memory ` and ` string-encoding `
3257
- * [ ` lift_func($f.result) ` above] ( #canonopt-validation ) defines required options
3238
+ * ` $opts ` may only contain ` memory ` , ` string-encoding ` and ` realloc `
3258
3239
3259
3240
Calling ` $f ` invokes the following function which uses ` Task.return_ ` to lift
3260
3241
and pass the results to the caller:
@@ -3508,12 +3489,12 @@ For canonical definitions:
3508
3489
(canon stream.read $t $opts (core func $f))
3509
3490
(canon stream.write $t $opts (core func $f))
3510
3491
```
3511
- In addition to [ general validation of ` $opts ` ] ( #canonopt-validation ) validation
3492
+ In addition to [ general validation of ` $opts ` ] ( #canon-opts ) validation
3512
3493
specifies:
3513
3494
* ` $f ` is given type ` (func (param i32 i32 i32) (result i32)) `
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
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
3517
3498
3518
3499
For canonical definitions:
3519
3500
``` wat
@@ -3522,9 +3503,9 @@ For canonical definitions:
3522
3503
```
3523
3504
validation specifies:
3524
3505
* ` $f ` is given type ` (func (param i32 i32) (result i32)) `
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
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
3528
3509
3529
3510
The implementation of these four built-ins all funnel down to a single
3530
3511
parameterized ` copy ` function:
0 commit comments