Skip to content

Commit c983be3

Browse files
committed
Change resource.drop to take a <typeidx>
1 parent a6e5f04 commit c983be3

File tree

5 files changed

+20
-25
lines changed

5 files changed

+20
-25
lines changed

design/mvp/Binary.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ Notes:
281281
```
282282
canon ::= 0x00 0x00 f:<core:funcidx> opts:<opts> ft:<typeidx> => (canon lift f opts type-index-space[ft])
283283
| 0x01 0x00 f:<funcidx> opts:<opts> => (canon lower f opts (core func))
284-
| 0x02 t:<typeidx> => (canon resource.new t (core func))
285-
| 0x03 t:<valtype> => (canon resource.drop t (core func))
286-
| 0x04 t:<typeidx> => (canon resource.rep t (core func))
284+
| 0x02 rt:<typeidx> => (canon resource.new rt (core func))
285+
| 0x03 rt:<typdidx> => (canon resource.drop rt (core func))
286+
| 0x04 rt:<typeidx> => (canon resource.rep rt (core func))
287287
opts ::= opt*:vec(<canonopt>) => opt*
288288
canonopt ::= 0x00 => string-encoding=utf8
289289
| 0x01 => string-encoding=utf16

design/mvp/CanonicalABI.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,24 +1596,22 @@ def canon_resource_new(inst, rt, rep):
15961596

15971597
For a canonical definition:
15981598
```
1599-
(canon resource.drop $t (core func $f))
1599+
(canon resource.drop $rt (core func $f))
16001600
```
16011601
validation specifies:
1602-
* `$t` must refer to a handle type `(own $rt)` or `(borrow $rt)`
1602+
* `$rt` must refer to resource type
16031603
* `$f` is given type `(func (param i32))`
16041604

16051605
Calling `$f` invokes the following function, which removes the handle from the
16061606
current component instance's handle table and, if the handle was owning, calls
16071607
the resource's destructor.
16081608
```python
1609-
def canon_resource_drop(inst, t, i):
1610-
h = inst.handles.remove(t.rt, i)
1611-
trap_if(isinstance(t, Own) and not h.own)
1612-
trap_if(isinstance(t, Borrow) and h.own)
1609+
def canon_resource_drop(inst, rt, i):
1610+
h = inst.handles.remove(rt, i)
16131611
if h.own:
1614-
trap_if(inst is not t.rt.impl and not t.rt.impl.may_enter)
1615-
if t.rt.dtor:
1616-
t.rt.dtor(h.rep)
1612+
trap_if(inst is not rt.impl and not rt.impl.may_enter)
1613+
if rt.dtor:
1614+
rt.dtor(h.rep)
16171615
```
16181616
The `may_enter` guard ensures the non-reentrance [component invariant], since
16191617
a destructor call is analogous to a call to an export.

design/mvp/Explainer.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ async is added to the proposal, [tasks][Future and Stream Types]).
11891189
```
11901190
canon ::= ...
11911191
| (canon resource.new <typeidx> (core func <id>?))
1192-
| (canon resource.drop <valtype> (core func <id>?))
1192+
| (canon resource.drop <typeidx> (core func <id>?))
11931193
| (canon resource.rep <typeidx> (core func <id>?))
11941194
```
11951195
The `resource.new` built-in has type `[i32] -> [i32]` and creates a new
@@ -1198,9 +1198,8 @@ representation and returning the `i32` index of a new handle pointing to this
11981198
resource.
11991199

12001200
The `resource.drop` built-in has type `[i32] -> []` and drops a resource handle
1201-
(of type `valtype`, which must be `own` or `borrow`) at the given `i32` index.
1202-
If the dropped handle owns the resource, the resource's `dtor` is called, if
1203-
present.
1201+
(with resource type `typeidx`) at the given `i32` index. If the dropped handle
1202+
owns the resource, the resource's `dtor` is called, if present.
12041203

12051204
The `resource.rep` built-in has type `[i32] -> [i32]` and returns the `i32`
12061205
representation of the resource (with resource type `typeidx`) pointed to by the

design/mvp/canonical-abi/definitions.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,14 +1126,12 @@ def canon_resource_new(inst, rt, rep):
11261126

11271127
### `canon resource.drop`
11281128

1129-
def canon_resource_drop(inst, t, i):
1130-
h = inst.handles.remove(t.rt, i)
1131-
trap_if(isinstance(t, Own) and not h.own)
1132-
trap_if(isinstance(t, Borrow) and h.own)
1129+
def canon_resource_drop(inst, rt, i):
1130+
h = inst.handles.remove(rt, i)
11331131
if h.own:
1134-
trap_if(inst is not t.rt.impl and not t.rt.impl.may_enter)
1135-
if t.rt.dtor:
1136-
t.rt.dtor(h.rep)
1132+
trap_if(inst is not rt.impl and not rt.impl.may_enter)
1133+
if rt.dtor:
1134+
rt.dtor(h.rep)
11371135

11381136
### `canon resource.rep`
11391137

design/mvp/canonical-abi/run_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def core_wasm(args):
424424
assert(canon_resource_rep(inst, rt, 3) == 45)
425425

426426
dtor_value = None
427-
canon_resource_drop(inst, Own(rt), 0)
427+
canon_resource_drop(inst, rt, 0)
428428
assert(dtor_value == 42)
429429
assert(len(inst.handles.table(rt).array) == 4)
430430
assert(inst.handles.table(rt).array[0] is None)
@@ -437,7 +437,7 @@ def core_wasm(args):
437437
assert(len(inst.handles.table(rt).free) == 0)
438438

439439
dtor_value = None
440-
canon_resource_drop(inst, Borrow(rt), 2)
440+
canon_resource_drop(inst, rt, 2)
441441
assert(dtor_value is None)
442442
assert(len(inst.handles.table(rt).array) == 4)
443443
assert(inst.handles.table(rt).array[2] is None)

0 commit comments

Comments
 (0)