Skip to content

Commit affacdc

Browse files
committed
Tweak section titles, fix typo in CanonicalABI.md
1 parent 9bec4e2 commit affacdc

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

design/mvp/CanonicalABI.md

+18-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ being specified here.
1111
* [Despecialization](#despecialization)
1212
* [Alignment](#alignment)
1313
* [Element Size](#element-size)
14+
* [Call Context](#call-context)
15+
* [Canonical ABI Options](#canonical-abi-options)
1416
* [Runtime State](#runtime-state)
1517
* [Loading](#loading)
1618
* [Storing](#storing)
@@ -223,17 +225,21 @@ def num_i32_flags(labels):
223225
return math.ceil(len(labels) / 32)
224226
```
225227

226-
### Runtime State
228+
### Call Context
227229

228230
The subsequent definitions of loading and storing a value from linear memory
229-
require additional runtime state, which is threaded through most subsequent
230-
definitions via the `cx` parameter of type `CallContext`:
231+
require additional configuration and state, which is threaded through most
232+
subsequent definitions via the `cx` parameter of type `CallContext`:
231233
```python
232234
@dataclass
233235
class CallContext:
234236
opts: CanonicalOptions
235237
inst: ComponentInstance
236238
```
239+
Note that the `Task` and `Subtask` classes defined below derive `CallContext`,
240+
adding additional state only used for export and import calls, resp.
241+
242+
### Canonical ABI Options
237243

238244
The `opts` field of `CallContext` contains all the possible `canonopt`
239245
immediates that can be passed to the `canon` definition being implemented.
@@ -247,6 +253,11 @@ class CanonicalOptions:
247253
sync: bool = True # = !canonopt.async
248254
callback: Optional[Callable] = None
249255
```
256+
(Note that the `async` `canonopt` is inverted to `sync` here for the practical
257+
reason that `async` is a keyword and most branches below want to start with the
258+
`sync = True` case.)
259+
260+
### Runtime State
250261

251262
The `inst` field of `CallContext` points to the component instance which the
252263
`canon`-generated function is closed over. Component instances contain all the
@@ -1499,8 +1510,8 @@ With only the definitions above, the Canonical ABI would be forced to place all
14991510
parameters and results in linear memory. While this is necessary in the general
15001511
case, in many cases performance can be improved by passing small-enough values
15011512
in registers by using core function parameters and results. To support this
1502-
optimization, the Canonical ABI defines `flatten` to map component function
1503-
types to core function types by attempting to decompose all the
1513+
optimization, the Canonical ABI defines `flatten_functype` to map component
1514+
function types to core function types by attempting to decompose all the
15041515
non-dynamically-sized component value types into core value types.
15051516

15061517
For a variety of [practical][Implementation Limits] reasons, we need to limit
@@ -1519,7 +1530,7 @@ have already allocated space for the return value (e.g., efficiently on the
15191530
stack), passing in an `i32` pointer as an parameter instead of returning an
15201531
`i32` as a return value.
15211532

1522-
Given all this, the top-level definition of `flatten` is:
1533+
Given all this, the top-level definition of `flatten_functype` is:
15231534
```python
15241535
MAX_FLAT_PARAMS = 16
15251536
MAX_FLAT_RESULTS = 1
@@ -1881,7 +1892,7 @@ def lift_heap_values(cx, vi, ts):
18811892

18821893
Symmetrically, the `lower_flat_values` function defines how to lower a
18831894
list of component-level values `vs` of types `ts` into a list of core
1884-
values. As already described for [`flatten`](#flattening) above,
1895+
values. As already described for [`flatten_functype`](#flattening) above,
18851896
lowering handles the greater-than-`max_flat` case by either allocating
18861897
storage with `realloc` or accepting a caller-allocated buffer as an
18871898
out-param:

design/mvp/canonical-abi/definitions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,15 @@ def elem_size_flags(labels):
274274
def num_i32_flags(labels):
275275
return math.ceil(len(labels) / 32)
276276

277-
### Runtime State
277+
### Call Context
278278

279279
@dataclass
280280
class CallContext:
281281
opts: CanonicalOptions
282282
inst: ComponentInstance
283283

284+
### Canonical ABI Options
285+
284286
@dataclass
285287
class CanonicalOptions:
286288
memory: Optional[bytearray] = None
@@ -290,6 +292,8 @@ class CanonicalOptions:
290292
sync: bool = True # = !canonopt.async
291293
callback: Optional[Callable] = None
292294

295+
### Runtime State
296+
293297
class ComponentInstance:
294298
# core module instance state
295299
may_leave: bool

0 commit comments

Comments
 (0)