Skip to content

Commit 5cdd14f

Browse files
committed
Tidy CABI: change order of definitions (no behavior change)
1 parent 8500bc0 commit 5cdd14f

File tree

3 files changed

+138
-138
lines changed

3 files changed

+138
-138
lines changed

design/mvp/CanonicalABI.md

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ specified here.
6060
* [`canon {stream,future}.drop-{readable,writable}`](#-canon-streamfuturedrop-readablewritable) 🔀
6161
* [`canon thread.index`](#-canon-threadindex) 🧵
6262
* [`canon thread.new-indirect`](#-canon-threadnew-indirect) 🧵
63-
* [`canon thread.switch-to`](#-canon-threadswitch-to) 🧵
64-
* [`canon thread.suspend`](#-canon-threadsuspend) 🧵
6563
* [`canon thread.resume-later`](#-canon-threadresume-later) 🧵
66-
* [`canon thread.yield-to`](#-canon-threadyield-to) 🧵
64+
* [`canon thread.suspend`](#-canon-threadsuspend) 🧵
6765
* [`canon thread.yield`](#-canon-threadyield) 🧵
66+
* [`canon thread.switch-to`](#-canon-threadswitch-to) 🧵
67+
* [`canon thread.yield-to`](#-canon-threadyield-to) 🧵
6868
* [`canon error-context.new`](#-canon-error-contextnew) 📝
6969
* [`canon error-context.debug-message`](#-canon-error-contextdebug-message) 📝
7070
* [`canon error-context.drop`](#-canon-error-contextdrop) 📝
@@ -4632,33 +4632,29 @@ actually start executing, Core WebAssembly code must call one of the other
46324632
`thread.*` built-ins defined below.
46334633

46344634

4635-
### 🧵 `canon thread.switch-to`
4635+
### 🧵 `canon thread.resume-later`
46364636

46374637
For a canonical definition:
46384638
```wat
4639-
(canon thread.switch-to $cancellable? (core func $switch-to))
4639+
(canon thread.resume-later (core func $resume-later))
46404640
```
46414641
validation specifies:
4642-
* `$switch-to` is given type `(func (param $i i32) (result i32))`
4642+
* `$resume-later` is given type `(func (param $i i32))`
46434643

4644-
Calling `$switch-to` invokes the following function which loads a thread at
4644+
Calling `$resume-later` invokes the following function which loads a thread at
46454645
index `$i` from the current component instance's `threads` table, traps if it's
4646-
not [suspended], and then switches to that thread, leaving the [current thread]
4647-
suspended.
4646+
not [suspended], and then marks that thread as ready to run at some
4647+
nondeterministic point in the future chosen by the embedder.
46484648
```python
4649-
def canon_thread_switch_to(cancellable, thread, i):
4649+
def canon_thread_resume_later(thread, i):
46504650
trap_if(not thread.task.inst.may_leave)
46514651
other_thread = thread.task.inst.threads.get(i)
46524652
trap_if(not other_thread.suspended())
4653-
resume_arg = thread.switch_to(cancellable, other_thread)
4654-
return [resume_arg]
4653+
other_thread.resume_later()
4654+
return []
46554655
```
4656-
If `cancellable` is set, then `thread.switch-to` will return a `ResumeArg` value
4657-
to indicate whether the supertask has already or concurrently requested
4658-
cancellation. `thread.switch-to` (and other cancellable operations) will only
4659-
indicate cancellation once and thus, if a caller is not prepared to propagate
4660-
cancellation, they can omit `cancellable` so that cancellation is instead
4661-
delivered at a later `cancellable` call.
4656+
`thread.resume-later` never suspends the [current thread] and so there is no
4657+
possibility of cancellation and thus no `cancellable` immediate.
46624658

46634659

46644660
### 🧵 `canon thread.suspend`
@@ -4691,91 +4687,95 @@ cancellation, they can omit `cancellable` so that cancellation is instead
46914687
delivered at a later `cancellable` call.
46924688

46934689

4694-
### 🧵 `canon thread.resume-later`
4690+
### 🧵 `canon thread.yield`
46954691

46964692
For a canonical definition:
46974693
```wat
4698-
(canon thread.resume-later (core func $resume-later))
4694+
(canon thread.yield $cancellable? (core func $yield))
46994695
```
47004696
validation specifies:
4701-
* `$resume-later` is given type `(func (param $i i32))`
4697+
* `$yield` is given type `(func (result i32))`
47024698

4703-
Calling `$resume-later` invokes the following function which loads a thread at
4704-
index `$i` from the current component instance's `threads` table, traps if it's
4705-
not [suspended], and then marks that thread as ready to run at some
4706-
nondeterministic point in the future chosen by the embedder.
4699+
Calling `$yield` invokes the following function which yields execution so that
4700+
others threads can execute, leaving the current thread ready to run at some
4701+
nondeterministic point in the future chosen by the embedder. This allows a
4702+
long-running computation that is not otherwise performing I/O to avoid starving
4703+
other threads in a cooperative setting.
47074704
```python
4708-
def canon_thread_resume_later(thread, i):
4705+
def canon_thread_yield(cancellable, thread):
47094706
trap_if(not thread.task.inst.may_leave)
4710-
other_thread = thread.task.inst.threads.get(i)
4711-
trap_if(not other_thread.suspended())
4712-
other_thread.resume_later()
4713-
return []
4707+
resume_arg = thread.yield_(cancellable)
4708+
return [resume_arg]
47144709
```
4715-
`thread.resume-later` never suspends the [current thread] and so there is no
4716-
possibility of cancellation and thus no `cancellable` immediate.
4710+
If called during a non-`async`-typed function export, this function does not
4711+
trap. Instead, `Thread.yield_` will simply return without blocking. This allows
4712+
`thread.yield` calls to be sprinkled liberally throughout code. Furthermore,
4713+
even when called from an `async`-typed function export, `Thread.yield_`
4714+
nondeterministically allows the embedder to continue executing the current thread
4715+
based on heuristics (like timing).
47174716

4717+
If `cancellable` is set, then `thread.yield` will return a `ResumeArg` value
4718+
indicating whether the supertask has already or concurrently requested
4719+
cancellation. `thread.yield` (and other cancellable operations) will only
4720+
indicate cancellation once and thus, if a caller is not prepared to propagate
4721+
cancellation, they can omit `cancellable` so that cancellation is instead
4722+
delivered at a later `cancellable` call.
47184723

4719-
### 🧵 `canon thread.yield-to`
4724+
4725+
### 🧵 `canon thread.switch-to`
47204726

47214727
For a canonical definition:
47224728
```wat
4723-
(canon thread.yield-to $cancellable? (core func $yield-to))
4729+
(canon thread.switch-to $cancellable? (core func $switch-to))
47244730
```
47254731
validation specifies:
4726-
* `$yield-to` is given type `(func (param $i i32) (result i32))`
4732+
* `$switch-to` is given type `(func (param $i i32) (result i32))`
47274733

4728-
Calling `$yield-to` invokes the following function which loads a thread at
4734+
Calling `$switch-to` invokes the following function which loads a thread at
47294735
index `$i` from the current component instance's `threads` table, traps if it's
47304736
not [suspended], and then switches to that thread, leaving the [current thread]
4731-
ready to run at some nondeterministic point in the future chosen by the
4732-
embedder.
4737+
suspended.
47334738
```python
4734-
def canon_thread_yield_to(cancellable, thread, i):
4739+
def canon_thread_switch_to(cancellable, thread, i):
47354740
trap_if(not thread.task.inst.may_leave)
47364741
other_thread = thread.task.inst.threads.get(i)
47374742
trap_if(not other_thread.suspended())
4738-
resume_arg = thread.yield_to(cancellable, other_thread)
4743+
resume_arg = thread.switch_to(cancellable, other_thread)
47394744
return [resume_arg]
47404745
```
4741-
If `cancellable` is set, then `thread.yield-to` will return a `ResumeArg` value
4742-
indicating whether the supertask has already or concurrently requested
4743-
cancellation. `thread.yield-to` (and other cancellable operations) will only
4746+
If `cancellable` is set, then `thread.switch-to` will return a `ResumeArg` value
4747+
to indicate whether the supertask has already or concurrently requested
4748+
cancellation. `thread.switch-to` (and other cancellable operations) will only
47444749
indicate cancellation once and thus, if a caller is not prepared to propagate
47454750
cancellation, they can omit `cancellable` so that cancellation is instead
47464751
delivered at a later `cancellable` call.
47474752

47484753

4749-
### 🧵 `canon thread.yield`
4754+
### 🧵 `canon thread.yield-to`
47504755

47514756
For a canonical definition:
47524757
```wat
4753-
(canon thread.yield $cancellable? (core func $yield))
4758+
(canon thread.yield-to $cancellable? (core func $yield-to))
47544759
```
47554760
validation specifies:
4756-
* `$yield` is given type `(func (result i32))`
4761+
* `$yield-to` is given type `(func (param $i i32) (result i32))`
47574762

4758-
Calling `$yield` invokes the following function which yields execution so that
4759-
others threads can execute, leaving the current thread ready to run at some
4760-
nondeterministic point in the future chosen by the embedder. This allows a
4761-
long-running computation that is not otherwise performing I/O to avoid starving
4762-
other threads in a cooperative setting.
4763+
Calling `$yield-to` invokes the following function which loads a thread at
4764+
index `$i` from the current component instance's `threads` table, traps if it's
4765+
not [suspended], and then switches to that thread, leaving the [current thread]
4766+
ready to run at some nondeterministic point in the future chosen by the
4767+
embedder.
47634768
```python
4764-
def canon_thread_yield(cancellable, thread):
4769+
def canon_thread_yield_to(cancellable, thread, i):
47654770
trap_if(not thread.task.inst.may_leave)
4766-
resume_arg = thread.yield_(cancellable)
4771+
other_thread = thread.task.inst.threads.get(i)
4772+
trap_if(not other_thread.suspended())
4773+
resume_arg = thread.yield_to(cancellable, other_thread)
47674774
return [resume_arg]
47684775
```
4769-
If called during a non-`async`-typed function export, this function does not
4770-
trap. Instead, `Thread.yield_` will simply return without blocking. This allows
4771-
`thread.yield` calls to be sprinkled liberally throughout code. Furthermore,
4772-
even when called from an `async`-typed function export, `Thread.yield_`
4773-
nondeterministically allows the embedder to continue executing the current thread
4774-
based on heuristics (like timing).
4775-
4776-
If `cancellable` is set, then `thread.yield` will return a `ResumeArg` value
4776+
If `cancellable` is set, then `thread.yield-to` will return a `ResumeArg` value
47774777
indicating whether the supertask has already or concurrently requested
4778-
cancellation. `thread.yield` (and other cancellable operations) will only
4778+
cancellation. `thread.yield-to` (and other cancellable operations) will only
47794779
indicate cancellation once and thus, if a caller is not prepared to propagate
47804780
cancellation, they can omit `cancellable` so that cancellation is instead
47814781
delivered at a later `cancellable` call.

design/mvp/Explainer.md

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,11 +1456,11 @@ canon ::= ...
14561456
| (canon future.drop-writable <typeidx> (core func <id>?)) 🔀
14571457
| (canon thread.index (core func <id>?)) 🧵
14581458
| (canon thread.new-indirect <typeidx> <core:tableidx> (core func <id>?)) 🧵
1459-
| (canon thread.switch-to cancellable? (core func <id>?)) 🧵
1460-
| (canon thread.suspend cancellable? (core func <id>?)) 🧵
14611459
| (canon thread.resume-later (core func <id>?)) 🧵
1462-
| (canon thread.yield-to cancellable? (core func <id>?)) 🧵
1460+
| (canon thread.suspend cancellable? (core func <id>?)) 🧵
14631461
| (canon thread.yield cancellable? (core func <id>?)) 🧵
1462+
| (canon thread.switch-to cancellable? (core func <id>?)) 🧵
1463+
| (canon thread.yield-to cancellable? (core func <id>?)) 🧵
14641464
| (canon error-context.new <canonopt>* (core func <id>?)) 📝
14651465
| (canon error-context.debug-message <canonopt>* (core func <id>?)) 📝
14661466
| (canon error-context.drop (core func <id>?)) 📝
@@ -2099,34 +2099,19 @@ eagerly or lazily by [`thread.yield-to`](#-threadyield-to) or
20992099
For details, see [Thread Built-ins] in the concurrency explainer and
21002100
[`canon_thread_new_indirect`] in the Canonical ABI explainer.
21012101

2102-
###### 🧵 `thread.switch-to`
2103-
2104-
| Synopsis | |
2105-
| -------------------------- | ------------------------------------------------- |
2106-
| Approximate WIT signature | `func<cancellable?>(t: thread) -> suspend-result` |
2107-
| Canonical ABI signature | `[t:i32] -> [i32]` |
2108-
2109-
where `suspend-result` is defined in WIT as:
2110-
```wit
2111-
enum suspend-result { completed, cancelled }
2112-
```
2102+
###### 🧵 `thread.resume-later`
21132103

2114-
The `thread.switch-to` built-in suspends the [current thread] and
2115-
immediately resumes execution of the thread `t`, trapping if `t` is not in a
2116-
"suspended" state. When the current thread is resumed by some other thread or,
2117-
if `cancellable` was set, [cancellation], `thread.switch-to` will return,
2118-
indicating what happened.
2104+
| Synopsis | |
2105+
| -------------------------- | ----------------- |
2106+
| Approximate WIT signature | `func(t: thread)` |
2107+
| Canonical ABI signature | `[t:i32] -> []` |
21192108

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

21282113
For details, see [Thread Built-ins] in the concurrency explainer and
2129-
[`canon_thread_switch_to`] in the Canonical ABI explainer.
2114+
[`canon_thread_resume_later`] in the Canonical ABI explainer.
21302115

21312116
###### 🧵 `thread.suspend`
21322117

@@ -2153,19 +2138,59 @@ threads and threads implicitly created by non-`callback` `async`-lifted
21532138
For details, see [Thread Built-ins] in the concurrency explainer and
21542139
[`canon_thread_suspend`] in the Canonical ABI explainer.
21552140

2156-
###### 🧵 `thread.resume-later`
2141+
###### 🧵 `thread.yield`
21572142

2158-
| Synopsis | |
2159-
| -------------------------- | ----------------- |
2160-
| Approximate WIT signature | `func(t: thread)` |
2161-
| Canonical ABI signature | `[t:i32] -> []` |
2143+
| Synopsis | |
2144+
| -------------------------- | ---------------------------------------- |
2145+
| Approximate WIT signature | `func<cancellable?>() -> suspend-result` |
2146+
| Canonical ABI signature | `[] -> [i32]` |
21622147

2163-
The `thread.resume-later` built-in changes the state of thread `t` from
2164-
"suspended" to "ready" (trapping if `t` is not in a "suspended" state) so that
2165-
the runtime can nondeterministically resume `t` at some point in the future.
2148+
where `suspend-result` is defined in WIT as:
2149+
```wit
2150+
enum suspend-result { completed, cancelled }
2151+
```
2152+
2153+
The `thread.yield` built-in allows the runtime to potentially switch to any
2154+
other thread in the "ready" state, enabling a long-running computation to
2155+
cooperatively interleave execution without specifically requesting another
2156+
thread to be resumed (as with `thread.yield-to`). When the current thread is
2157+
resumed either due to runtime scheduling or, if `cancellable` was set,
2158+
[cancellation], `thread.yield` will return, indicating what happened.
2159+
2160+
If `thread.yield` is called from a synchronous- or `async callback`-lifted
2161+
export, no other threads that were implicitly created by a separate
2162+
synchronous- or `async callback`-lifted export call can start or progress in
2163+
the current component instance until `thread.yield` returns (thereby
2164+
ensuring non-reentrance of the core wasm code). However, explicitly-created
2165+
threads and threads implicitly created by non-`callback` `async`-lifted
2166+
("stackful async") exports may start or progress at any time.
21662167

21672168
For details, see [Thread Built-ins] in the concurrency explainer and
2168-
[`canon_thread_resume_later`] in the Canonical ABI explainer.
2169+
[`canon_thread_yield`] in the Canonical ABI explainer.
2170+
2171+
###### 🧵 `thread.switch-to`
2172+
2173+
| Synopsis | |
2174+
| -------------------------- | ------------------------------------------------- |
2175+
| Approximate WIT signature | `func<cancellable?>(t: thread) -> suspend-result` |
2176+
| Canonical ABI signature | `[t:i32] -> [i32]` |
2177+
2178+
The `thread.switch-to` built-in suspends the [current thread] and
2179+
immediately resumes execution of the thread `t`, trapping if `t` is not in a
2180+
"suspended" state. When the current thread is resumed by some other thread or,
2181+
if `cancellable` was set, [cancellation], `thread.switch-to` will return,
2182+
indicating what happened.
2183+
2184+
If `thread.switch-to` is called from a synchronous- or `async callback`-lifted
2185+
export, no other threads that were implicitly created by a separate
2186+
synchronous- or `async callback`-lifted export call can start or progress in
2187+
the current component instance until `thread.switch-to` returns (thereby
2188+
ensuring non-reentrance of the core wasm code). However, explicitly-created
2189+
threads and threads implicitly created by non-`callback` `async`-lifted
2190+
("stackful async") exports may start or progress at any time.
2191+
2192+
For details, see [Thread Built-ins] in the concurrency explainer and
2193+
[`canon_thread_switch_to`] in the Canonical ABI explainer.
21692194

21702195
###### 🧵 `thread.yield-to`
21712196

@@ -2192,31 +2217,6 @@ threads and threads implicitly created by non-`callback` `async`-lifted
21922217
For details, see [Thread Built-ins] in the concurrency explainer and
21932218
[`canon_thread_yield_to`] in the Canonical ABI explainer.
21942219

2195-
###### 🧵 `thread.yield`
2196-
2197-
| Synopsis | |
2198-
| -------------------------- | ---------------------------------------- |
2199-
| Approximate WIT signature | `func<cancellable?>() -> suspend-result` |
2200-
| Canonical ABI signature | `[] -> [i32]` |
2201-
2202-
The `thread.yield` built-in allows the runtime to potentially switch to any
2203-
other thread in the "ready" state, enabling a long-running computation to
2204-
cooperatively interleave execution without specifically requesting another
2205-
thread to be resumed (as with `thread.yield-to`). When the current thread is
2206-
resumed either due to runtime scheduling or, if `cancellable` was set,
2207-
[cancellation], `thread.yield` will return, indicating what happened.
2208-
2209-
If `thread.yield` is called from a synchronous- or `async callback`-lifted
2210-
export, no other threads that were implicitly created by a separate
2211-
synchronous- or `async callback`-lifted export call can start or progress in
2212-
the current component instance until `thread.yield` returns (thereby
2213-
ensuring non-reentrance of the core wasm code). However, explicitly-created
2214-
threads and threads implicitly created by non-`callback` `async`-lifted
2215-
("stackful async") exports may start or progress at any time.
2216-
2217-
For details, see [Thread Built-ins] in the concurrency explainer and
2218-
[`canon_thread_yield`] in the Canonical ABI explainer.
2219-
22202220
###### 🧵② `thread.spawn-ref`
22212221

22222222
| Synopsis | |

0 commit comments

Comments
 (0)