Skip to content

Commit 5d5de61

Browse files
committed
Add trap_if(not may_leave) to most CABI built-ins
1 parent 072b2fa commit 5d5de61

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

design/mvp/CanonicalABI.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,7 @@ containing the given resource representation in the current component
21112111
instance's handle table:
21122112
```python
21132113
async def canon_resource_new(rt, task, rep):
2114+
trap_if(not task.inst.may_leave)
21142115
h = HandleElem(rep, own=True)
21152116
i = task.inst.handles.add(rt, h)
21162117
return [i]
@@ -2131,6 +2132,7 @@ current component instance's handle table and, if the handle was owning, calls
21312132
the resource's destructor.
21322133
```python
21332134
async def canon_resource_drop(rt, sync, task, i):
2135+
trap_if(not task.inst.may_leave)
21342136
inst = task.inst
21352137
h = inst.handles.remove(rt, i)
21362138
flat_results = [] if sync else [0]
@@ -2223,6 +2225,7 @@ caller and lowers them into the current instance:
22232225
```python
22242226
async def canon_task_start(task, core_ft, flat_args):
22252227
assert(len(core_ft.params) == len(flat_args))
2228+
trap_if(not task.inst.may_leave)
22262229
trap_if(task.opts.sync)
22272230
trap_if(core_ft != flatten_functype(CanonicalOptions(), FuncType([], task.ft.params), 'lower'))
22282231
task.start()
@@ -2253,6 +2256,7 @@ current instance and passes them to the caller:
22532256
```python
22542257
async def canon_task_return(task, core_ft, flat_args):
22552258
assert(len(core_ft.params) == len(flat_args))
2259+
trap_if(not task.inst.may_leave)
22562260
trap_if(task.opts.sync)
22572261
trap_if(core_ft != flatten_functype(CanonicalOptions(), FuncType(task.ft.results, []), 'lower'))
22582262
task.return_()
@@ -2283,6 +2287,7 @@ returning the event (which is currently simply an `AsyncCallState` value)
22832287
and writing the subtask index as an outparam:
22842288
```python
22852289
async def canon_task_wait(task, ptr):
2290+
trap_if(not task.inst.may_leave)
22862291
trap_if(task.opts.callback is not None)
22872292
event, payload = await task.wait()
22882293
store(task, payload, U32(), ptr)
@@ -2312,6 +2317,7 @@ available, returning whether or not there was such an event as a boolean and,
23122317
if there was an event, storing the `i32` event+payload pair as an outparam.
23132318
```python
23142319
async def canon_task_poll(task, ptr):
2320+
trap_if(not task.inst.may_leave)
23152321
ret = task.poll()
23162322
if ret is None:
23172323
return [0]
@@ -2333,6 +2339,7 @@ Calling `$f` calls `Task.yield_`, trapping if called when there is a `callback`.
23332339
(When there is a callback, yielding is achieved by returning with the LSB set.)
23342340
```python
23352341
async def canon_task_yield(task):
2342+
trap_if(not task.inst.may_leave)
23362343
trap_if(task.opts.callback is not None)
23372344
await task.yield_()
23382345
return []
@@ -2353,6 +2360,7 @@ on `enqueued` ensures that supertasks can only drop subtasks once they've been
23532360
officially notified of their completion (via `task.wait` or callback).
23542361
```python
23552362
async def canon_subtask_drop(task, i):
2363+
trap_if(not task.inst.may_leave)
23562364
subtask = task.inst.async_subtasks.remove(i)
23572365
trap_if(subtask.enqueued)
23582366
trap_if(subtask.state != AsyncCallState.DONE)

design/mvp/canonical-abi/definitions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,13 +1420,15 @@ def pack_async_result(i, state):
14201420
### `canon resource.new`
14211421

14221422
async def canon_resource_new(rt, task, rep):
1423+
trap_if(not task.inst.may_leave)
14231424
h = HandleElem(rep, own=True)
14241425
i = task.inst.handles.add(rt, h)
14251426
return [i]
14261427

14271428
### `canon resource.drop`
14281429

14291430
async def canon_resource_drop(rt, sync, task, i):
1431+
trap_if(not task.inst.may_leave)
14301432
inst = task.inst
14311433
h = inst.handles.remove(rt, i)
14321434
flat_results = [] if sync else [0]
@@ -1466,6 +1468,7 @@ async def canon_task_backpressure(task, flat_args):
14661468

14671469
async def canon_task_start(task, core_ft, flat_args):
14681470
assert(len(core_ft.params) == len(flat_args))
1471+
trap_if(not task.inst.may_leave)
14691472
trap_if(task.opts.sync)
14701473
trap_if(core_ft != flatten_functype(CanonicalOptions(), FuncType([], task.ft.params), 'lower'))
14711474
task.start()
@@ -1478,6 +1481,7 @@ async def canon_task_start(task, core_ft, flat_args):
14781481

14791482
async def canon_task_return(task, core_ft, flat_args):
14801483
assert(len(core_ft.params) == len(flat_args))
1484+
trap_if(not task.inst.may_leave)
14811485
trap_if(task.opts.sync)
14821486
trap_if(core_ft != flatten_functype(CanonicalOptions(), FuncType(task.ft.results, []), 'lower'))
14831487
task.return_()
@@ -1489,6 +1493,7 @@ async def canon_task_return(task, core_ft, flat_args):
14891493
### 🔀 `canon task.wait`
14901494

14911495
async def canon_task_wait(task, ptr):
1496+
trap_if(not task.inst.may_leave)
14921497
trap_if(task.opts.callback is not None)
14931498
event, payload = await task.wait()
14941499
store(task, payload, U32(), ptr)
@@ -1497,6 +1502,7 @@ async def canon_task_wait(task, ptr):
14971502
### 🔀 `canon task.poll`
14981503

14991504
async def canon_task_poll(task, ptr):
1505+
trap_if(not task.inst.may_leave)
15001506
ret = task.poll()
15011507
if ret is None:
15021508
return [0]
@@ -1506,13 +1512,15 @@ async def canon_task_poll(task, ptr):
15061512
### 🔀 `canon task.yield`
15071513

15081514
async def canon_task_yield(task):
1515+
trap_if(not task.inst.may_leave)
15091516
trap_if(task.opts.callback is not None)
15101517
await task.yield_()
15111518
return []
15121519

15131520
### 🔀 `canon subtask.drop`
15141521

15151522
async def canon_subtask_drop(task, i):
1523+
trap_if(not task.inst.may_leave)
15161524
subtask = task.inst.async_subtasks.remove(i)
15171525
trap_if(subtask.enqueued)
15181526
trap_if(subtask.state != AsyncCallState.DONE)

0 commit comments

Comments
 (0)