Skip to content

Commit 1266d45

Browse files
committed
Also remove async destructors
1 parent 83d6b09 commit 1266d45

4 files changed

Lines changed: 18 additions & 32 deletions

File tree

design/mvp/Binary.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ label' ::= len:<u32> l:<label> => l (if len = |l|)
215215
valtype ::= i:<typeidx> => i
216216
| pvt:<primvaltype> => pvt
217217
resourcetype ::= 0x3f v:<valtype> f?:<core:funcidx>? => (resource (rep v) (dtor f)?)
218-
| 0x3e v:<valtype> f:<core:funcidx>
219-
cb?:<core:funcidx>? => (resource (rep v) (dtor async f (callback cb)?)) 🚝
220218
functype ::= 0x40 ps:<paramlist> rs:<resultlist> => (func ps rs)
221219
| 0x43 ps:<paramlist> rs:<resultlist> => (func async ps rs)
222220
paramlist ::= lt*:vec(<labelvaltype>) => (param lt)*

design/mvp/CanonicalABI.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,14 +1290,10 @@ the `rt` field of `ResourceHandle` (above) and thus resource type equality is
12901290
class ResourceType(Type):
12911291
impl: ComponentInstance
12921292
dtor: Optional[Callable]
1293-
dtor_async: bool
1294-
dtor_callback: Optional[Callable]
12951293

1296-
def __init__(self, impl, dtor = None, dtor_async = False, dtor_callback = None):
1294+
def __init__(self, impl, dtor = None):
12971295
self.impl = impl
12981296
self.dtor = dtor
1299-
self.dtor_async = dtor_async
1300-
self.dtor_callback = dtor_callback
13011297
```
13021298

13031299

@@ -3912,22 +3908,22 @@ def canon_resource_drop(rt, i):
39123908
if rt.dtor:
39133909
rt.dtor(h.rep)
39143910
else:
3915-
caller_opts = CanonicalOptions(async_ = False)
3916-
callee_opts = CanonicalOptions(async_ = rt.dtor_async, callback = rt.dtor_callback)
3917-
ft = FuncType([U32Type()],[], async_ = False)
3911+
ft = FuncType([U32Type()], [], async_ = False)
39183912
dtor = rt.dtor or (lambda rep: [])
3919-
callee = inst.store.lift(dtor, ft, callee_opts, rt.impl)
3920-
caller = inst.store.lower(callee, ft, caller_opts, inst)
3913+
opts = CanonicalOptions(async_ = False)
3914+
callee = inst.store.lift(dtor, ft, opts, rt.impl)
3915+
caller = inst.store.lower(callee, ft, opts, inst)
39213916
caller([h.rep])
39223917
else:
39233918
h.borrow_scope.num_borrows -= 1
39243919
return []
39253920
```
3926-
The call to a resource's destructor is defined as a non-`async`-lowered,
3927-
non-`async`-typed function call to a possibly-`async`-lifted callee, passing
3928-
the private `i32` representation as a parameter. Thus, destructors *may* block
3929-
on I/O, but only after they `task.return`, ensuring that `resource.drop` never
3930-
blocks.
3921+
The call to a resource's destructor passes the `i32` representation value that
3922+
was previously supplied to `resource.new`. The call works like a normal
3923+
non-`async` cross-component call, using the same `canon_lift` and `canon_lower`
3924+
rules to, for example, catch reentrance. Because the type, lifting and
3925+
lowering are all non-`async`, the destructor may not block. However, the
3926+
destructor may spawn a cooperative thread that does.
39313927

39323928
Since there are valid reasons to call `resource.drop` in the same component
39333929
instance that defined the resource, which would otherwise trap at the

design/mvp/Explainer.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,7 @@ defvaltype ::= bool
570570
valtype ::= <typeidx>
571571
| <defvaltype>
572572
resourcetype ::= (resource (rep i32) (dtor <core:funcidx>)?)
573-
| (resource (rep i32) (dtor async <core:funcidx> (callback <core:funcidx>)?)?) 🚝
574573
| (resource (rep i64) (dtor <core:funcidx>)?) 🐘
575-
| (resource (rep i64) (dtor async <core:funcidx> (callback <core:funcidx>)?)?) 🚝🐘
576574
functype ::= (func async? (param "<label>" <valtype>)* (result <valtype>)?)
577575
componenttype ::= (component <componentdecl>*)
578576
instancetype ::= (instance <instancedecl>*)
@@ -814,9 +812,8 @@ is currently fixed to `i32` or `i64`, but will potentially be relaxed to include
814812
other types. When the last handle to a resource is dropped, the resource's
815813
destructor function specified by the `dtor` immediate will be called (if
816814
present), allowing the implementing component to perform clean-up like freeing
817-
linear memory allocations. Destructors can be declared `async`, with the same
818-
meaning for the `async` and `callback` immediates as described below for `canon
819-
lift`. A destructor for a `resource (rep $T)` must have type `($T) -> ()`.
815+
linear memory allocations. A destructor for a `resource (rep $T)` must have type
816+
`($T) -> ()`.
820817

821818
The `instance` type constructor describes a list of named, typed definitions
822819
that can be imported or exported by a component. Informally, instance types

design/mvp/canonical-abi/definitions.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,14 +686,10 @@ def __init__(self, rt, rep, own, borrow_scope = None):
686686
class ResourceType(Type):
687687
impl: ComponentInstance
688688
dtor: Optional[Callable]
689-
dtor_async: bool
690-
dtor_callback: Optional[Callable]
691689

692-
def __init__(self, impl, dtor = None, dtor_async = False, dtor_callback = None):
690+
def __init__(self, impl, dtor = None):
693691
self.impl = impl
694692
self.dtor = dtor
695-
self.dtor_async = dtor_async
696-
self.dtor_callback = dtor_callback
697693

698694
### Waitable State
699695

@@ -2249,12 +2245,11 @@ def canon_resource_drop(rt, i):
22492245
if rt.dtor:
22502246
rt.dtor(h.rep)
22512247
else:
2252-
caller_opts = CanonicalOptions(async_ = False)
2253-
callee_opts = CanonicalOptions(async_ = rt.dtor_async, callback = rt.dtor_callback)
2254-
ft = FuncType([U32Type()],[], async_ = False)
2248+
ft = FuncType([U32Type()], [], async_ = False)
22552249
dtor = rt.dtor or (lambda rep: [])
2256-
callee = inst.store.lift(dtor, ft, callee_opts, rt.impl)
2257-
caller = inst.store.lower(callee, ft, caller_opts, inst)
2250+
opts = CanonicalOptions(async_ = False)
2251+
callee = inst.store.lift(dtor, ft, opts, rt.impl)
2252+
caller = inst.store.lower(callee, ft, opts, inst)
22582253
caller([h.rep])
22592254
else:
22602255
h.borrow_scope.num_borrows -= 1

0 commit comments

Comments
 (0)