Skip to content

Commit 39ae5c2

Browse files
committed
CABI: reorder definitions (no behavior change)
1 parent c514aef commit 39ae5c2

File tree

3 files changed

+133
-133
lines changed

3 files changed

+133
-133
lines changed

design/mvp/CanonicalABI.md

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ specified here.
6161
* [`canon {stream,future}.drop-{readable,writable}`](#-canon-streamfuturedrop-readablewritable) 🔀
6262
* [`canon thread.index`](#-canon-threadindex) 🧵
6363
* [`canon thread.new-indirect`](#-canon-threadnew-indirect) 🧵
64-
* [`canon thread.switch-to`](#-canon-threadswitch-to) 🧵
65-
* [`canon thread.suspend`](#-canon-threadsuspend) 🧵
6664
* [`canon thread.resume-later`](#-canon-threadresume-later) 🧵
67-
* [`canon thread.yield-to`](#-canon-threadyield-to) 🧵
65+
* [`canon thread.suspend`](#-canon-threadsuspend) 🧵
6866
* [`canon thread.yield`](#-canon-threadyield) 🧵
67+
* [`canon thread.switch-to`](#-canon-threadswitch-to) 🧵
68+
* [`canon thread.yield-to`](#-canon-threadyield-to) 🧵
6969
* [`canon error-context.new`](#-canon-error-contextnew) 📝
7070
* [`canon error-context.debug-message`](#-canon-error-contextdebug-message) 📝
7171
* [`canon error-context.drop`](#-canon-error-contextdrop) 📝
@@ -4779,34 +4779,30 @@ actually start executing, Core WebAssembly code must call one of the other
47794779
`thread.*` built-ins defined below.
47804780

47814781

4782-
### 🧵 `canon thread.switch-to`
4782+
### 🧵 `canon thread.resume-later`
47834783

47844784
For a canonical definition:
47854785
```wat
4786-
(canon thread.switch-to $cancellable? (core func $switch-to))
4786+
(canon thread.resume-later (core func $resume-later))
47874787
```
47884788
validation specifies:
4789-
* `$switch-to` is given type `(func (param $i i32) (result i32))`
4789+
* `$resume-later` is given type `(func (param $i i32))`
47904790

4791-
Calling `$switch-to` invokes the following function which loads a thread at
4791+
Calling `$resume-later` invokes the following function which loads a thread at
47924792
index `$i` from the current component instance's `threads` table, traps if it's
4793-
not [suspended], and then switches to that thread, leaving the [current thread]
4794-
suspended.
4793+
not [suspended], and then marks that thread as ready to run at some
4794+
nondeterministic point in the future chosen by the embedder.
47954795
```python
4796-
def canon_thread_switch_to(cancellable, i):
4796+
def canon_thread_resume_later(i):
47974797
thread = current_thread()
47984798
trap_if(not thread.task.inst.may_leave)
47994799
other_thread = thread.task.inst.threads.get(i)
48004800
trap_if(not other_thread.suspended())
4801-
cancelled = thread.switch_to(cancellable, other_thread)
4802-
return [cancelled]
4801+
other_thread.resume_later()
4802+
return []
48034803
```
4804-
If `cancellable` is set, then `thread.switch-to` will return a `Cancelled`
4805-
value to indicate whether the supertask has already or concurrently requested
4806-
cancellation. `thread.switch-to` (and other cancellable operations) will only
4807-
indicate cancellation once and thus, if a caller is not prepared to propagate
4808-
cancellation, they can omit `cancellable` so that cancellation is instead
4809-
delivered at a later `cancellable` call.
4804+
`thread.resume-later` never suspends the [current thread] and so there is no
4805+
possibility of cancellation and thus no `cancellable` immediate.
48104806

48114807

48124808
### 🧵 `canon thread.suspend`
@@ -4840,94 +4836,98 @@ cancellation, they can omit `cancellable` so that cancellation is instead
48404836
delivered at a later `cancellable` call.
48414837

48424838

4843-
### 🧵 `canon thread.resume-later`
4839+
### 🧵 `canon thread.yield`
48444840

48454841
For a canonical definition:
48464842
```wat
4847-
(canon thread.resume-later (core func $resume-later))
4843+
(canon thread.yield $cancellable? (core func $yield))
48484844
```
48494845
validation specifies:
4850-
* `$resume-later` is given type `(func (param $i i32))`
4846+
* `$yield` is given type `(func (result i32))`
48514847

4852-
Calling `$resume-later` invokes the following function which loads a thread at
4853-
index `$i` from the current component instance's `threads` table, traps if it's
4854-
not [suspended], and then marks that thread as ready to run at some
4855-
nondeterministic point in the future chosen by the embedder.
4848+
Calling `$yield` invokes the following function which yields execution so that
4849+
others threads can execute, leaving the current thread ready to run at some
4850+
nondeterministic point in the future chosen by the embedder. This allows a
4851+
long-running computation that is not otherwise performing I/O to avoid starving
4852+
other threads in a cooperative setting.
48564853
```python
4857-
def canon_thread_resume_later(i):
4854+
def canon_thread_yield(cancellable):
48584855
thread = current_thread()
48594856
trap_if(not thread.task.inst.may_leave)
4860-
other_thread = thread.task.inst.threads.get(i)
4861-
trap_if(not other_thread.suspended())
4862-
other_thread.resume_later()
4863-
return []
4857+
cancelled = thread.yield_(cancellable)
4858+
return [cancelled]
48644859
```
4865-
`thread.resume-later` never suspends the [current thread] and so there is no
4866-
possibility of cancellation and thus no `cancellable` immediate.
4860+
If a non-`async`-typed function export that has not yet returned a value
4861+
transitively calls `thread.yield`, it returns immediately without blocking
4862+
(instead of trapping, as with other possibly-blocking operations like
4863+
`waitable-set.wait`). This is because, unlike other built-ins, `thread.yield`
4864+
may be scattered liberally throughout code that might show up in the transitive
4865+
call tree of a synchronous function call.
48674866

4867+
If `cancellable` is set, then `thread.yield` will return a `Cancelled`
4868+
value indicating whether the supertask has already or concurrently requested
4869+
cancellation. `thread.yield` (and other cancellable operations) will only
4870+
indicate cancellation once and thus, if a caller is not prepared to propagate
4871+
cancellation, they can omit `cancellable` so that cancellation is instead
4872+
delivered at a later `cancellable` call.
48684873

4869-
### 🧵 `canon thread.yield-to`
4874+
4875+
### 🧵 `canon thread.switch-to`
48704876

48714877
For a canonical definition:
48724878
```wat
4873-
(canon thread.yield-to $cancellable? (core func $yield-to))
4879+
(canon thread.switch-to $cancellable? (core func $switch-to))
48744880
```
48754881
validation specifies:
4876-
* `$yield-to` is given type `(func (param $i i32) (result i32))`
4882+
* `$switch-to` is given type `(func (param $i i32) (result i32))`
48774883

4878-
Calling `$yield-to` invokes the following function which loads a thread at
4884+
Calling `$switch-to` invokes the following function which loads a thread at
48794885
index `$i` from the current component instance's `threads` table, traps if it's
48804886
not [suspended], and then switches to that thread, leaving the [current thread]
4881-
ready to run at some nondeterministic point in the future chosen by the
4882-
embedder.
4887+
suspended.
48834888
```python
4884-
def canon_thread_yield_to(cancellable, i):
4889+
def canon_thread_switch_to(cancellable, i):
48854890
thread = current_thread()
48864891
trap_if(not thread.task.inst.may_leave)
48874892
other_thread = thread.task.inst.threads.get(i)
48884893
trap_if(not other_thread.suspended())
4889-
cancelled = thread.yield_to(cancellable, other_thread)
4894+
cancelled = thread.switch_to(cancellable, other_thread)
48904895
return [cancelled]
48914896
```
4892-
If `cancellable` is set, then `thread.yield-to` will return a `Cancelled`
4893-
value indicating whether the supertask has already or concurrently requested
4894-
cancellation. `thread.yield-to` (and other cancellable operations) will only
4897+
If `cancellable` is set, then `thread.switch-to` will return a `Cancelled`
4898+
value to indicate whether the supertask has already or concurrently requested
4899+
cancellation. `thread.switch-to` (and other cancellable operations) will only
48954900
indicate cancellation once and thus, if a caller is not prepared to propagate
48964901
cancellation, they can omit `cancellable` so that cancellation is instead
48974902
delivered at a later `cancellable` call.
48984903

48994904

4900-
### 🧵 `canon thread.yield`
4905+
### 🧵 `canon thread.yield-to`
49014906

49024907
For a canonical definition:
49034908
```wat
4904-
(canon thread.yield $cancellable? (core func $yield))
4909+
(canon thread.yield-to $cancellable? (core func $yield-to))
49054910
```
49064911
validation specifies:
4907-
* `$yield` is given type `(func (result i32))`
4912+
* `$yield-to` is given type `(func (param $i i32) (result i32))`
49084913

4909-
Calling `$yield` invokes the following function which yields execution so that
4910-
others threads can execute, leaving the current thread ready to run at some
4911-
nondeterministic point in the future chosen by the embedder. This allows a
4912-
long-running computation that is not otherwise performing I/O to avoid starving
4913-
other threads in a cooperative setting.
4914+
Calling `$yield-to` invokes the following function which loads a thread at
4915+
index `$i` from the current component instance's `threads` table, traps if it's
4916+
not [suspended], and then switches to that thread, leaving the [current thread]
4917+
ready to run at some nondeterministic point in the future chosen by the
4918+
embedder.
49144919
```python
4915-
def canon_thread_yield(cancellable):
4920+
def canon_thread_yield_to(cancellable, i):
49164921
thread = current_thread()
49174922
trap_if(not thread.task.inst.may_leave)
4918-
cancelled = thread.yield_(cancellable)
4923+
other_thread = thread.task.inst.threads.get(i)
4924+
trap_if(not other_thread.suspended())
4925+
cancelled = thread.yield_to(cancellable, other_thread)
49194926
return [cancelled]
49204927
```
4921-
If a non-`async`-typed function export that has not yet returned a value
4922-
transitively calls `thread.yield`, it returns immediately without blocking
4923-
(instead of trapping, as with other possibly-blocking operations like
4924-
`waitable-set.wait`). This is because, unlike other built-ins, `thread.yield`
4925-
may be scattered liberally throughout code that might show up in the transitive
4926-
call tree of a synchronous function call.
4927-
4928-
If `cancellable` is set, then `thread.yield` will return a `Cancelled`
4928+
If `cancellable` is set, then `thread.yield-to` will return a `Cancelled`
49294929
value indicating whether the supertask has already or concurrently requested
4930-
cancellation. `thread.yield` (and other cancellable operations) will only
4930+
cancellation. `thread.yield-to` (and other cancellable operations) will only
49314931
indicate cancellation once and thus, if a caller is not prepared to propagate
49324932
cancellation, they can omit `cancellable` so that cancellation is instead
49334933
delivered at a later `cancellable` call.

design/mvp/Explainer.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,11 +1458,11 @@ canon ::= ...
14581458
| (canon future.drop-writable <typeidx> (core func <id>?)) 🔀
14591459
| (canon thread.index (core func <id>?)) 🧵
14601460
| (canon thread.new-indirect <typeidx> <core:tableidx> (core func <id>?)) 🧵
1461-
| (canon thread.switch-to cancellable? (core func <id>?)) 🧵
1462-
| (canon thread.suspend cancellable? (core func <id>?)) 🧵
14631461
| (canon thread.resume-later (core func <id>?)) 🧵
1464-
| (canon thread.yield-to cancellable? (core func <id>?)) 🧵
1462+
| (canon thread.suspend cancellable? (core func <id>?)) 🧵
14651463
| (canon thread.yield cancellable? (core func <id>?)) 🧵
1464+
| (canon thread.switch-to cancellable? (core func <id>?)) 🧵
1465+
| (canon thread.yield-to cancellable? (core func <id>?)) 🧵
14661466
| (canon error-context.new <canonopt>* (core func <id>?)) 📝
14671467
| (canon error-context.debug-message <canonopt>* (core func <id>?)) 📝
14681468
| (canon error-context.drop (core func <id>?)) 📝
@@ -2101,29 +2101,19 @@ eagerly or lazily by [`thread.yield-to`](#-threadyield-to) or
21012101
For details, see [Thread Built-ins] in the concurrency explainer and
21022102
[`canon_thread_new_indirect`] in the Canonical ABI explainer.
21032103

2104-
###### 🧵 `thread.switch-to`
2105-
2106-
| Synopsis | |
2107-
| -------------------------- | --------------------------------------- |
2108-
| Approximate WIT signature | `func<cancellable?>(t: thread) -> bool` |
2109-
| Canonical ABI signature | `[t:i32] -> [i32]` |
2104+
###### 🧵 `thread.resume-later`
21102105

2111-
The `thread.switch-to` built-in suspends the [current thread] and immediately
2112-
resumes execution of the thread `t`, trapping if `t` is not in a "suspended"
2113-
state. If `cancellable` is set, `thread.switch-to` returns whether the current
2114-
task was [cancelled] by the caller; otherwise, `thread.switch-to` always returns
2115-
`false`.
2106+
| Synopsis | |
2107+
| -------------------------- | ----------------- |
2108+
| Approximate WIT signature | `func(t: thread)` |
2109+
| Canonical ABI signature | `[t:i32] -> []` |
21162110

2117-
If `thread.switch-to` is called from a synchronous- or `async callback`-lifted
2118-
export, no other threads that were implicitly created by a separate
2119-
synchronous- or `async callback`-lifted export call can start or progress in
2120-
the current component instance until `thread.switch-to` returns (thereby
2121-
ensuring non-reentrance of the core wasm code). However, explicitly-created
2122-
threads and threads implicitly created by non-`callback` `async`-lifted
2123-
("stackful async") exports may start or progress at any time.
2111+
The `thread.resume-later` built-in changes the state of thread `t` from
2112+
"suspended" to "ready" (trapping if `t` is not in a "suspended" state) so that
2113+
the runtime can nondeterministically resume `t` at some point in the future.
21242114

21252115
For details, see [Thread Built-ins] in the concurrency explainer and
2126-
[`canon_thread_switch_to`] in the Canonical ABI explainer.
2116+
[`canon_thread_resume_later`] in the Canonical ABI explainer.
21272117

21282118
###### 🧵 `thread.suspend`
21292119

@@ -2150,69 +2140,79 @@ threads and threads implicitly created by non-`callback` `async`-lifted
21502140
For details, see [Thread Built-ins] in the concurrency explainer and
21512141
[`canon_thread_suspend`] in the Canonical ABI explainer.
21522142

2153-
###### 🧵 `thread.resume-later`
2143+
###### 🧵 `thread.yield`
21542144

2155-
| Synopsis | |
2156-
| -------------------------- | ----------------- |
2157-
| Approximate WIT signature | `func(t: thread)` |
2158-
| Canonical ABI signature | `[t:i32] -> []` |
2145+
| Synopsis | |
2146+
| -------------------------- | ------------------------------ |
2147+
| Approximate WIT signature | `func<cancellable?>() -> bool` |
2148+
| Canonical ABI signature | `[] -> [i32]` |
21592149

2160-
The `thread.resume-later` built-in changes the state of thread `t` from
2161-
"suspended" to "ready" (trapping if `t` is not in a "suspended" state) so that
2162-
the runtime can nondeterministically resume `t` at some point in the future.
2150+
The `thread.yield` built-in allows the runtime to potentially switch to any
2151+
other thread in the "ready" state, enabling a long-running computation to
2152+
cooperatively interleave execution without specifically requesting another
2153+
thread to be resumed (as with `thread.yield-to`). If `cancellable` is set,
2154+
`thread.yield` returns whether the current task was [cancelled] by the caller;
2155+
otherwise, `thread.yield` always returns `false`.
2156+
2157+
If `thread.yield` is called from a synchronous- or `async callback`-lifted
2158+
export, no other threads that were implicitly created by a separate
2159+
synchronous- or `async callback`-lifted export call can start or progress in
2160+
the current component instance until `thread.yield` returns (thereby
2161+
ensuring non-reentrance of the core wasm code). However, explicitly-created
2162+
threads and threads implicitly created by non-`callback` `async`-lifted
2163+
("stackful async") exports may start or progress at any time.
21632164

21642165
For details, see [Thread Built-ins] in the concurrency explainer and
2165-
[`canon_thread_resume_later`] in the Canonical ABI explainer.
2166+
[`canon_thread_yield`] in the Canonical ABI explainer.
21662167

2167-
###### 🧵 `thread.yield-to`
2168+
###### 🧵 `thread.switch-to`
21682169

21692170
| Synopsis | |
21702171
| -------------------------- | --------------------------------------- |
21712172
| Approximate WIT signature | `func<cancellable?>(t: thread) -> bool` |
21722173
| Canonical ABI signature | `[t:i32] -> [i32]` |
21732174

2174-
The `thread.yield-to` built-in immediately resumes execution of the thread `t`,
2175-
(trapping if `t` is not in a "suspended" state) leaving the [current thread] in
2176-
a "ready" state so that the runtime can nondeterministically resume the current
2177-
thread at some point in the future. If `cancellable` is set, `thread.yield-to`
2178-
returns whether the current task was [cancelled] by the caller; otherwise,
2179-
`thread.yield-to` always returns `false`.
2175+
The `thread.switch-to` built-in suspends the [current thread] and immediately
2176+
resumes execution of the thread `t`, trapping if `t` is not in a "suspended"
2177+
state. If `cancellable` is set, `thread.switch-to` returns whether the current
2178+
task was [cancelled] by the caller; otherwise, `thread.switch-to` always returns
2179+
`false`.
21802180

2181-
If `thread.yield-to` is called from a synchronous- or `async callback`-lifted
2181+
If `thread.switch-to` is called from a synchronous- or `async callback`-lifted
21822182
export, no other threads that were implicitly created by a separate
21832183
synchronous- or `async callback`-lifted export call can start or progress in
2184-
the current component instance until `thread.yield-to` returns (thereby
2184+
the current component instance until `thread.switch-to` returns (thereby
21852185
ensuring non-reentrance of the core wasm code). However, explicitly-created
21862186
threads and threads implicitly created by non-`callback` `async`-lifted
21872187
("stackful async") exports may start or progress at any time.
21882188

21892189
For details, see [Thread Built-ins] in the concurrency explainer and
2190-
[`canon_thread_yield_to`] in the Canonical ABI explainer.
2190+
[`canon_thread_switch_to`] in the Canonical ABI explainer.
21912191

2192-
###### 🧵 `thread.yield`
2192+
###### 🧵 `thread.yield-to`
21932193

2194-
| Synopsis | |
2195-
| -------------------------- | ------------------------------ |
2196-
| Approximate WIT signature | `func<cancellable?>() -> bool` |
2197-
| Canonical ABI signature | `[] -> [i32]` |
2194+
| Synopsis | |
2195+
| -------------------------- | --------------------------------------- |
2196+
| Approximate WIT signature | `func<cancellable?>(t: thread) -> bool` |
2197+
| Canonical ABI signature | `[t:i32] -> [i32]` |
21982198

2199-
The `thread.yield` built-in allows the runtime to potentially switch to any
2200-
other thread in the "ready" state, enabling a long-running computation to
2201-
cooperatively interleave execution without specifically requesting another
2202-
thread to be resumed (as with `thread.yield-to`). If `cancellable` is set,
2203-
`thread.yield` returns whether the current task was [cancelled] by the caller;
2204-
otherwise, `thread.yield` always returns `false`.
2199+
The `thread.yield-to` built-in immediately resumes execution of the thread `t`,
2200+
(trapping if `t` is not in a "suspended" state) leaving the [current thread] in
2201+
a "ready" state so that the runtime can nondeterministically resume the current
2202+
thread at some point in the future. If `cancellable` is set, `thread.yield-to`
2203+
returns whether the current task was [cancelled] by the caller; otherwise,
2204+
`thread.yield-to` always returns `false`.
22052205

2206-
If `thread.yield` is called from a synchronous- or `async callback`-lifted
2206+
If `thread.yield-to` is called from a synchronous- or `async callback`-lifted
22072207
export, no other threads that were implicitly created by a separate
22082208
synchronous- or `async callback`-lifted export call can start or progress in
2209-
the current component instance until `thread.yield` returns (thereby
2209+
the current component instance until `thread.yield-to` returns (thereby
22102210
ensuring non-reentrance of the core wasm code). However, explicitly-created
22112211
threads and threads implicitly created by non-`callback` `async`-lifted
22122212
("stackful async") exports may start or progress at any time.
22132213

22142214
For details, see [Thread Built-ins] in the concurrency explainer and
2215-
[`canon_thread_yield`] in the Canonical ABI explainer.
2215+
[`canon_thread_yield_to`] in the Canonical ABI explainer.
22162216

22172217
###### 🧵② `thread.spawn-ref`
22182218

0 commit comments

Comments
 (0)