Skip to content

Commit 97d6301

Browse files
replace PTR with memory.addrtype
1 parent 0270ee3 commit 97d6301

File tree

3 files changed

+51
-50
lines changed

3 files changed

+51
-50
lines changed

design/mvp/CanonicalABI.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,12 +3217,11 @@ specifying `string-encoding=utf8` twice is an error. Each individual option, if
32173217
present, is validated as such:
32183218

32193219
* `string-encoding=N` - can be passed at most once, regardless of `N`.
3220-
* `memory` - this is a subtype of `(memory 1)` or `(memory i64 1)`. In the rest
3221-
of the explainer, `PTR` will refer to either `i32` or `i64` core Wasm types
3222-
as determined by the type of this `memory`.
3223-
* `realloc` - the function has type `(func (param PTR PTR PTR PTR) (result PTR))`
3224-
where `PTR` is `i32` or `i64` as described above.
3225-
* if `realloc` is present, then `memory` must be present
3220+
* `memory` - this is a subtype of `(memory 1)` or `(memory i64 1)`.
3221+
* `realloc` - the function has type `(func (param addr addr addr addr) (result addr))`
3222+
where `addr` is the address type (`i32` or `i64`) coming from the [`memory type`]
3223+
of the `memory` canonopt.
3224+
* If `realloc` is present then `memory` must be present.
32263225
* `post-return` - only allowed on [`canon lift`](#canon-lift), which has rules
32273226
for validation
32283227
* 🔀 `async` - cannot be present with `post-return`
@@ -4269,7 +4268,9 @@ context switches. Next, the stream's `state` is updated based on the result
42694268
being delivered to core wasm so that, once a stream end has been notified that
42704269
the other end dropped, calling anything other than `stream.drop-*` traps.
42714270
Lastly, `stream_event` packs the `CopyResult` and number of elements copied up
4272-
until this point into a single `PTR`-sized payload for core wasm.
4271+
until this point into a single `i32` or `i64`-sized payload for core wasm. The
4272+
size is determined by the `addrtype` coming from the [`memory type`] of the
4273+
`memory` immediate.
42734274
```python
42744275
def stream_event(result, reclaim_buffer):
42754276
reclaim_buffer()

design/mvp/Concurrency.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ and the asynchronous ABI has the signature:
957957
(func (param $f i32) (param $out-ptr i32) (result i32))
958958
```
959959
where `$f` is the index of a future (not a pointer to one) while while
960-
`$out-ptr` is a pointer to a linear memory location that will receive an `i32`
960+
`$out-ptr` is a pointer to a linear memory location that will receive an `i32`
961961
index.
962962

963963
For the runtime semantics of this `i32` index, see `lift_stream`,
@@ -1040,8 +1040,8 @@ must also be exported with signature:
10401040

10411041
The `(result i32)` has the same interpretation as the stackless export function
10421042
and the runtime will repeatedly call the callback until a value of `0` is
1043-
returned. The `i32` parameters describe what happened that caused the
1044-
callback to be called again.
1043+
returned. The `i32` parameters describe what happened that caused the callback
1044+
to be called again.
10451045

10461046
For a complete description of how async exports work, see [`canon_lift`] in the
10471047
Canonical ABI Explainer.

design/mvp/Explainer.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,19 +1300,18 @@ default is `utf8`. It is a validation error to include more than one
13001300
The `(memory ...)` option specifies the memory that the Canonical ABI will
13011301
use to load and store values. If the Canonical ABI needs to load or store,
13021302
validation requires this option to be present (there is no default). The types
1303-
of lowered functions may also depend on whether this memory is a 32-bit or
1304-
64-bit memory if pointers are transitively contained in parameters or results.
1305-
In what follows the notation `PTR` will refer to the core Wasm type `i32` or
1306-
`i64` corresponding to the type of the `(memory ...)` option.
1303+
of lowered functions may also depend on the [`core:memory-type`] of this memory,
1304+
specifically it's [`core:address-type`] (indicated by `memory.addrtype`), if pointers
1305+
are transitively contained in parameters or results.
13071306

13081307
The `(realloc ...)` option specifies a core function that is validated to
13091308
have the following core function type:
13101309
```wat
1311-
(func (param $originalPtr PTR)
1312-
(param $originalSize PTR)
1313-
(param $alignment PTR)
1314-
(param $newSize PTR)
1315-
(result PTR))
1310+
(func (param $originalPtr memory.addrtype)
1311+
(param $originalSize memory.addrtype)
1312+
(param $alignment memory.addrtype)
1313+
(param $newSize memory.addrtype)
1314+
(result memory.addrtype))
13161315
```
13171316
The Canonical ABI will use `realloc` both to allocate (passing `0` for the first
13181317
two parameters) and reallocate. If the Canonical ABI needs `realloc`, validation
@@ -1339,10 +1338,9 @@ validated to have the following core function type:
13391338
```wat
13401339
(func (param $ctx i32)
13411340
(param $event i32)
1342-
(param $payload PTR)
1341+
(param $payload i32)
13431342
(result $done i32))
13441343
```
1345-
where `PTR` is determined by the `memory` canonopt as described above.
13461344
Again, see the [concurrency explainer] for more details.
13471345

13481346
Based on this description of the AST, the [Canonical ABI explainer] gives a
@@ -1675,10 +1673,10 @@ For details, see [Waitables and Waitable Sets] in the concurrency explainer and
16751673

16761674
###### 🔀 `waitable-set.wait`
16771675

1678-
| Synopsis | |
1679-
| -------------------------- | ---------------------------------------------- |
1680-
| Approximate WIT signature | `func<cancellable?>(s: waitable-set) -> event` |
1681-
| Canonical ABI signature | `[s:i32 payload-addr:PTR] -> [event-code:i32]` |
1676+
| Synopsis | |
1677+
| -------------------------- | ---------------------------------------------------------- |
1678+
| Approximate WIT signature | `func<cancellable?,memory>(s: waitable-set) -> event` |
1679+
| Canonical ABI signature | `[s:i32 payload-addr:memory.addrtype] -> [event-code:i32]` |
16821680

16831681
where `event` is defined in WIT as:
16841682
```wit
@@ -1740,10 +1738,10 @@ For details, see [Waitables and Waitable Sets] in the concurrency explainer and
17401738

17411739
###### 🔀 `waitable-set.poll`
17421740

1743-
| Synopsis | |
1744-
| -------------------------- | ---------------------------------------------- |
1745-
| Approximate WIT signature | `func<cancellable?>(s: waitable-set) -> event` |
1746-
| Canonical ABI signature | `[s:i32 payload-addr:PTR] -> [event-code:i32]` |
1741+
| Synopsis | |
1742+
| -------------------------- | ---------------------------------------------------------- |
1743+
| Approximate WIT signature | `func<cancellable?,memory>(s: waitable-set) -> event` |
1744+
| Canonical ABI signature | `[s:i32 payload-addr:memory.addrtype] -> [event-code:i32]` |
17471745

17481746
where `event` is defined as in [`waitable-set.wait`](#-waitable-setwait).
17491747

@@ -1857,11 +1855,11 @@ For details, see [Streams and Futures] in the concurrency explainer and
18571855

18581856
###### 🔀 `stream.read` and `stream.write`
18591857

1860-
| Synopsis | |
1861-
| -------------------------------------------- | ----------------------------------------------------------------------------------------------- |
1862-
| Approximate WIT signature for `stream.read` | `func<stream<T?>>(e: readable-stream-end<T?>, b: writable-buffer<T>?) -> option<stream-result>` |
1863-
| Approximate WIT signature for `stream.write` | `func<stream<T?>>(e: writable-stream-end<T?>, b: readable-buffer<T>?) -> option<stream-result>` |
1864-
| Canonical ABI signature | `[stream-end:i32 ptr:PTR num:PTR] -> [PTR]` |
1858+
| Synopsis | |
1859+
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
1860+
| Approximate WIT signature for `stream.read` | `func<stream<T?>,memory>(e: readable-stream-end<T?>, b: writable-buffer<T>?) -> option<stream-result>` |
1861+
| Approximate WIT signature for `stream.write` | `func<stream<T?>,memory>(e: writable-stream-end<T?>, b: readable-buffer<T>?) -> option<stream-result>` |
1862+
| Canonical ABI signature | `[stream-end:i32 ptr:memory.addrtype num:memory.addrtype] -> [memory.addrtype]` |
18651863

18661864
where `stream-result` is defined in WIT as:
18671865
```wit
@@ -1917,10 +1915,10 @@ any subsequent operation on the stream other than `stream.drop-{readable,writabl
19171915
traps.
19181916

19191917
In the Canonical ABI, the `{readable,writable}-stream-end` is passed as an
1920-
`i32` index into the component instance's table followed by a pair of `PTR`s
1918+
`i32` index into the component instance's table followed by a pair of `memory.addrtype`s
19211919
describing the linear memory offset and size-in-elements of the
19221920
`{readable,writable}-buffer<T>`. The `option<stream-result>` return value is
1923-
bit-packed into a single `PTR` where:
1921+
bit-packed into a single `memory.addrtype` where:
19241922
* all-ones represents `none`.
19251923
* Otherwise, the `result` is in the low 4 bits and the `progress` is in the
19261924
remaining high bits.
@@ -1930,11 +1928,11 @@ For details, see [Streams and Futures] in the concurrency explainer and
19301928

19311929
###### 🔀 `future.read` and `future.write`
19321930

1933-
| Synopsis | |
1934-
| -------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
1935-
| Approximate WIT signature for `future.read` | `func<future<T?>>(e: readable-future-end<T?>, b: writable-buffer<T; 1>?) -> option<future-read-result>` |
1936-
| Approximate WIT signature for `future.write` | `func<future<T?>>(e: writable-future-end<T?>, v: readable-buffer<T; 1>?) -> option<future-write-result>` |
1937-
| Canonical ABI signature | `[readable-future-end:i32 ptr:PTR] -> [i32]` |
1931+
| Synopsis | |
1932+
| -------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
1933+
| Approximate WIT signature for `future.read` | `func<future<T?>,memory>(e: readable-future-end<T?>, b: writable-buffer<T; 1>?) -> option<future-read-result>` |
1934+
| Approximate WIT signature for `future.write` | `func<future<T?>,memory>(e: writable-future-end<T?>, v: readable-buffer<T; 1>?) -> option<future-write-result>` |
1935+
| Canonical ABI signature | `[readable-future-end:i32 ptr:memory.addrtype] -> [i32]` |
19381936

19391937
where `future-{read,write}-result` are defined in WIT as:
19401938
```wit
@@ -1985,7 +1983,7 @@ called before successfully writing a value.
19851983

19861984
In the Canonical ABI, the `{readable,writable}-future-end` is passed as an
19871985
`i32` index into the component instance's table followed by a single
1988-
`PTR` describing the linear memory offset of the
1986+
`memory.addrtype` describing the linear memory offset of the
19891987
`{readable,writable}-buffer<T; 1>`. The `option<future-{read,write}-result>`
19901988
return value is bit-packed into the single `i32` return value where all-ones
19911989
represents `none`. And, `future-read-result.cancelled` is encoded
@@ -2254,10 +2252,10 @@ explainer.
22542252

22552253
###### 📝 `error-context.new`
22562254

2257-
| Synopsis | |
2258-
| -------------------------------- | ---------------------------------------- |
2259-
| Approximate WIT signature | `func(message: string) -> error-context` |
2260-
| Canonical ABI signature | `[ptr:PTR len:PTR] -> [i32]` |
2255+
| Synopsis | |
2256+
| -------------------------------- | ---------------------------------------------------- |
2257+
| Approximate WIT signature | `func<memory>(message: string) -> error-context` |
2258+
| Canonical ABI signature | `[ptr:memory.addrtype len:memory.addrtype] -> [i32]` |
22612259

22622260
The `error-context.new` built-in returns a new `error-context` value. The given
22632261
string is non-deterministically transformed to produce the `error-context`'s
@@ -2270,10 +2268,10 @@ For details, see [`canon_error_context_new`] in the Canonical ABI explainer.
22702268

22712269
###### 📝 `error-context.debug-message`
22722270

2273-
| Synopsis | |
2274-
| -------------------------------- | --------------------------------------- |
2275-
| Approximate WIT signature | `func(errctx: error-context) -> string` |
2276-
| Canonical ABI signature | `[errctxi:i32 ptr:PTR] -> []` |
2271+
| Synopsis | |
2272+
| -------------------------------- | ----------------------------------------------- |
2273+
| Approximate WIT signature | `func<memory>(errctx: error-context) -> string` |
2274+
| Canonical ABI signature | `[errctxi:i32 ptr:memory.addrtype] -> []` |
22772275

22782276
The `error-context.debug-message` built-in returns the
22792277
[debug message](#error-context-type) of the given `error-context`.
@@ -3176,6 +3174,8 @@ For some use-case-focused, worked examples, see:
31763174
[func-import-abbrev]: https://webassembly.github.io/spec/core/text/modules.html#text-func-abbrev
31773175
[`core:version`]: https://webassembly.github.io/spec/core/binary/modules.html#binary-version
31783176
[`core:tableidx`]: https://webassembly.github.io/spec/core/syntax/modules.html#syntax-tableidx
3177+
[`core:address-type`]: https://webassembly.github.io/spec/core/syntax/types.html#address-types
3178+
[`core:memory-type`]: https://webassembly.github.io/spec/core/syntax/types.html#memory-types
31793179
[`core:table-type`]: https://webassembly.github.io/spec/core/syntax/types.html#table-types
31803180

31813181
[Embedder]: https://webassembly.github.io/spec/core/appendix/embedding.html

0 commit comments

Comments
 (0)