Skip to content

Commit f44d237

Browse files
committed
Fix CABI core return values to always be arrays
1 parent 8906654 commit f44d237

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

design/mvp/CanonicalABI.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,8 @@ instance's handle table:
16571657
```python
16581658
def canon_resource_new(inst, rt, rep):
16591659
h = HandleElem(rep, own=True)
1660-
return inst.handles.add(rt, h)
1660+
i = inst.handles.add(rt, h)
1661+
return [i]
16611662
```
16621663

16631664
### `canon resource.drop`
@@ -1686,6 +1687,7 @@ def canon_resource_drop(inst, rt, i):
16861687
assert(h.scope is not None)
16871688
assert(h.scope.borrow_count > 0)
16881689
h.scope.borrow_count -= 1
1690+
return []
16891691
```
16901692
The `may_enter` guard ensures the non-reentrance [component invariant], since
16911693
a destructor call is analogous to a call to an export.
@@ -1706,7 +1708,7 @@ representation from the handle.
17061708
```python
17071709
def canon_resource_rep(inst, rt, i):
17081710
h = inst.handles.get(rt, i)
1709-
return h.rep
1711+
return [h.rep]
17101712
```
17111713
Note that the "locally-defined" requirement above ensures that only the
17121714
component instance defining a resource can access its representation.
@@ -1743,7 +1745,7 @@ In pseudocode, `$st` looks like:
17431745
def canon_thread_spawn(f, c):
17441746
trap_if(f is None)
17451747
if DETERMINISTIC_PROFILE:
1746-
return -1
1748+
return [-1]
17471749

17481750
def thread_start():
17491751
try:
@@ -1752,9 +1754,9 @@ def canon_thread_spawn(f, c):
17521754
trap()
17531755

17541756
if spawn(thread_start):
1755-
return 0
1757+
return [0]
17561758
else:
1757-
return -1
1759+
return [-1]
17581760
```
17591761

17601762
### 🧵 `canon thread.hw_concurrency`
@@ -1774,9 +1776,9 @@ component instance.
17741776
```python
17751777
def canon_thread_hw_concurrency():
17761778
if DETERMINISTIC_PROFILE:
1777-
return 1
1779+
return [1]
17781780
else:
1779-
return NUM_ALLOWED_THREADS
1781+
return [NUM_ALLOWED_THREADS]
17801782
```
17811783

17821784
[Canonical Definitions]: Explainer.md#canonical-definitions

design/mvp/canonical-abi/definitions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,8 @@ def canon_lower(opts, inst, callee, calling_import, ft, flat_args):
11531153

11541154
def canon_resource_new(inst, rt, rep):
11551155
h = HandleElem(rep, own=True)
1156-
return inst.handles.add(rt, h)
1156+
i = inst.handles.add(rt, h)
1157+
return [i]
11571158

11581159
### `canon resource.drop`
11591160

@@ -1169,9 +1170,10 @@ def canon_resource_drop(inst, rt, i):
11691170
assert(h.scope is not None)
11701171
assert(h.scope.borrow_count > 0)
11711172
h.scope.borrow_count -= 1
1173+
return []
11721174

11731175
### `canon resource.rep`
11741176

11751177
def canon_resource_rep(inst, rt, i):
11761178
h = inst.handles.get(rt, i)
1177-
return h.rep
1179+
return [h.rep]

design/mvp/canonical-abi/run_tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,9 @@ def core_wasm(args):
395395
assert(args[1] == 2)
396396
assert(args[2] == 3)
397397
assert(args[3] == 13)
398-
assert(canon_resource_rep(inst, rt, 1) == 42)
399-
assert(canon_resource_rep(inst, rt, 2) == 43)
400-
assert(canon_resource_rep(inst, rt, 3) == 44)
398+
assert(canon_resource_rep(inst, rt, 1)[0] == 42)
399+
assert(canon_resource_rep(inst, rt, 2)[0] == 43)
400+
assert(canon_resource_rep(inst, rt, 3)[0] == 44)
401401

402402
host_ft = FuncType([
403403
Borrow(rt),
@@ -412,7 +412,7 @@ def core_wasm(args):
412412
results = canon_lower(opts, inst, host_import, True, host_ft, args)
413413
assert(len(results) == 1)
414414
assert(results[0] == 4)
415-
assert(canon_resource_rep(inst, rt, 4) == 45)
415+
assert(canon_resource_rep(inst, rt, 4)[0] == 45)
416416

417417
dtor_value = None
418418
canon_resource_drop(inst, rt, 1)
@@ -421,7 +421,7 @@ def core_wasm(args):
421421
assert(inst.handles.table(rt).array[1] is None)
422422
assert(len(inst.handles.table(rt).free) == 1)
423423

424-
h = canon_resource_new(inst, rt, 46)
424+
h = canon_resource_new(inst, rt, 46)[0]
425425
assert(h == 1)
426426
assert(len(inst.handles.table(rt).array) == 5)
427427
assert(inst.handles.table(rt).array[1] is not None)

0 commit comments

Comments
 (0)