@@ -128,35 +128,36 @@ known to not contain `borrow`. The `CanonicalOptions`, `ComponentInstance`,
128
128
129
129
### Canonical ABI Options
130
130
131
- The following two classes list the various Canonical ABI options ([ ` canonopt ` ] )
132
- that can be set on various Canonical ABI definitions. The default values of the
133
- Python fields are the default values when the associated ` canonopt ` is not
134
- present in the binary or text format definition.
131
+ The following classes list the various Canonical ABI options ([ ` canonopt ` ] )
132
+ that can be set on various Canonical ABI definitions. The default values of
133
+ the Python fields are the default values when the associated ` canonopt ` is
134
+ not present in the binary or text format definition.
135
135
136
- The ` LiftLowerContext ` class contains the subset of [ ` canonopt ` ] which are
137
- used to lift and lower the individual parameters and results of function
138
- calls:
136
+ The ` LiftOptions ` class contains the subset of [ ` canonopt ` ] which are needed
137
+ when lifting individual parameters and results:
139
138
``` python
140
139
@dataclass
141
- class LiftLowerOptions :
140
+ class LiftOptions :
142
141
string_encoding: str = ' utf8'
143
142
memory: Optional[bytearray ] = None
144
- realloc: Optional[Callable] = None
145
143
146
- def __eq__ (self , other ):
147
- return self .string_encoding == other.string_encoding and \
148
- self .memory is other.memory and \
149
- self .realloc is other.realloc
144
+ def equal (lhs , rhs ):
145
+ return lhs.string_encoding == rhs.string_encoding and \
146
+ lhs.memory is rhs.memory
147
+ ```
148
+ The ` equal ` static method is used by ` task.return ` below to dynamically
149
+ compare equality of just this subset of ` canonopt ` .
150
150
151
- def copy (opts ):
152
- return LiftLowerOptions(opts.string_encoding, opts.memory, opts.realloc)
151
+ The ` LiftLowerOptions ` class contains the subset of [ ` canonopt ` ] which are
152
+ needed when lifting * or* lowering individual parameters and results:
153
+ ``` python
154
+ @dataclass
155
+ class LiftLowerOptions (LiftOptions ):
156
+ realloc: Optional[Callable] = None
153
157
```
154
- The ` __eq__ ` override specifies that equality of ` LiftLowerOptions ` (as used
155
- by, e.g., ` canon_task_return ` below) is defined in terms of the identity of
156
- the memory and ` realloc ` -function instances.
157
158
158
- The ` CanonicalOptions ` class contains the rest of the [ ` canonopt ` ] options
159
- that affect how an overall function is lifted/lowered:
159
+ The ` CanonicalOptions ` class contains the rest of the [ ` canonopt ` ]
160
+ options that affect how an overall function is lifted/lowered:
160
161
``` python
161
162
@dataclass
162
163
class CanonicalOptions (LiftLowerOptions ):
@@ -3207,7 +3208,7 @@ For a canonical definition:
3207
3208
```
3208
3209
validation specifies:
3209
3210
* ` $f ` is given type ` flatten_functype($opts, (func (param $t)?), 'lower') `
3210
- * ` $opts ` may only contain ` memory ` , ` string-encoding ` and ` realloc `
3211
+ * ` $opts ` may only contain ` memory ` and ` string-encoding `
3211
3212
3212
3213
Calling ` $f ` invokes the following function which uses ` Task.return_ ` to lift
3213
3214
and pass the results to the caller:
@@ -3216,7 +3217,7 @@ async def canon_task_return(task, result_type, opts: LiftLowerOptions, flat_args
3216
3217
trap_if(not task.inst.may_leave)
3217
3218
trap_if(task.opts.sync and not task.opts.always_task_return)
3218
3219
trap_if(result_type != task.ft.results)
3219
- trap_if(opts != LiftLowerOptions.copy( task.opts))
3220
+ trap_if(not LiftOptions.equal(opts, task.opts))
3220
3221
task.return_(flat_args)
3221
3222
return []
3222
3223
```
@@ -3225,13 +3226,18 @@ component with multiple exported functions of different types, `task.return` is
3225
3226
not called with a mismatched result type (which, due to indirect control flow,
3226
3227
can in general only be caught dynamically).
3227
3228
3228
- The ` trap_if(opts != LiftLowerOptions.copy( task.opts)) ` guard ensures that
3229
- the return value is lifted the same way as the ` canon lift ` from which this
3229
+ The ` trap_if(not LiftOptions.equal(opts, task.opts)) ` guard ensures that the
3230
+ return value is lifted the same way as the ` canon lift ` from which this
3230
3231
` task.return ` is returning. This ensures that AOT fusion of ` canon lift ` and
3231
3232
` canon lower ` can generate a thunk that is indirectly called by ` task.return `
3232
- after these guards. The ` LiftLowerOptions.copy ` method is used to select just
3233
- the ` LiftLowerOptions ` subset of ` CanonicalOptions ` (since fields like
3234
- ` async ` and ` callback ` aren't relevant to ` task.return ` ).
3233
+ after these guards. Inside ` LiftOptions.equal ` , ` opts.memory ` is compared with
3234
+ ` task.opts.memory ` via object identity of the mutable memory instance. Since
3235
+ ` memory ` refers to a mutable * instance* of memory, this comparison is not
3236
+ concerned with the static memory indices (in ` canon lift ` and `canon
3237
+ task.return`), only the identity of the memories created
3238
+ at instantiation-/ run-time. In Core WebAssembly spec terms, the test is on the
3239
+ equality of the [ ` memaddr ` ] values stored in the instance's [ ` memaddrs ` table]
3240
+ which is indexed by the static [ ` memidx ` ] .
3235
3241
3236
3242
3237
3243
### 🔀 ` canon yield `
@@ -3919,6 +3925,9 @@ def canon_thread_available_parallelism():
3919
3925
[ WASI ] : https://github.com/webassembly/wasi
3920
3926
[ Deterministic Profile ] : https://github.com/WebAssembly/profiles/blob/main/proposals/profiles/Overview.md
3921
3927
[ stack-switching ] : https://github.com/WebAssembly/stack-switching
3928
+ [ `memaddr` ] : https://webassembly.github.io/spec/core/exec/runtime.html#syntax-memaddr
3929
+ [ `memaddrs` table ] : https://webassembly.github.io/spec/core/exec/runtime.html#syntax-moduleinst
3930
+ [ `memidx` ] : https://webassembly.github.io/spec/core/syntax/modules.html#syntax-memidx
3922
3931
3923
3932
[ Alignment ] : https://en.wikipedia.org/wiki/Data_structure_alignment
3924
3933
[ UTF-8 ] : https://en.wikipedia.org/wiki/UTF-8
0 commit comments