Skip to content

Commit 529a118

Browse files
committed
CABI: simplify canon_resource_drop (no behavior change)
1 parent 31719d1 commit 529a118

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

design/mvp/CanonicalABI.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,8 @@ cases are prevented via trap for several reasons:
371371
to link recursive calls and this requires opting in via some
372372
[TBD](Concurrency.md#TODO) function effect type or canonical ABI option.
373373

374-
The `call_might_be_recursive` predicate is used by `canon_lift` and
375-
`canon_resource_drop` (defined below) to conservatively detect recursive
376-
reentrance and subsequently trap.
374+
The `call_might_be_recursive` predicate is used by `canon_lift` below to
375+
conservatively detect recursive reentrance and subsequently trap.
377376
```python
378377
def call_might_be_recursive(caller: Supertask, callee_inst: ComponentInstance):
379378
if caller.inst is None:
@@ -3653,14 +3652,12 @@ def canon_resource_drop(rt, thread, i):
36533652
if rt.dtor:
36543653
rt.dtor(h.rep)
36553654
else:
3656-
if rt.dtor:
3657-
caller_opts = CanonicalOptions(async_ = False)
3658-
callee_opts = CanonicalOptions(async_ = rt.dtor_async, callback = rt.dtor_callback)
3659-
ft = FuncType([U32Type()],[], async_ = False)
3660-
callee = partial(canon_lift, callee_opts, rt.impl, ft, rt.dtor)
3661-
[] = canon_lower(caller_opts, ft, callee, thread, [h.rep])
3662-
else:
3663-
trap_if(call_might_be_recursive(thread.task, rt.impl))
3655+
caller_opts = CanonicalOptions(async_ = False)
3656+
callee_opts = CanonicalOptions(async_ = rt.dtor_async, callback = rt.dtor_callback)
3657+
ft = FuncType([U32Type()],[], async_ = False)
3658+
dtor = rt.dtor or (lambda thread, rep: [])
3659+
callee = partial(canon_lift, callee_opts, rt.impl, ft, dtor)
3660+
[] = canon_lower(caller_opts, ft, callee, thread, [h.rep])
36643661
else:
36653662
h.borrow_scope.num_borrows -= 1
36663663
return []

design/mvp/canonical-abi/definitions.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,14 +2154,12 @@ def canon_resource_drop(rt, thread, i):
21542154
if rt.dtor:
21552155
rt.dtor(h.rep)
21562156
else:
2157-
if rt.dtor:
2158-
caller_opts = CanonicalOptions(async_ = False)
2159-
callee_opts = CanonicalOptions(async_ = rt.dtor_async, callback = rt.dtor_callback)
2160-
ft = FuncType([U32Type()],[], async_ = False)
2161-
callee = partial(canon_lift, callee_opts, rt.impl, ft, rt.dtor)
2162-
[] = canon_lower(caller_opts, ft, callee, thread, [h.rep])
2163-
else:
2164-
trap_if(call_might_be_recursive(thread.task, rt.impl))
2157+
caller_opts = CanonicalOptions(async_ = False)
2158+
callee_opts = CanonicalOptions(async_ = rt.dtor_async, callback = rt.dtor_callback)
2159+
ft = FuncType([U32Type()],[], async_ = False)
2160+
dtor = rt.dtor or (lambda thread, rep: [])
2161+
callee = partial(canon_lift, callee_opts, rt.impl, ft, dtor)
2162+
[] = canon_lower(caller_opts, ft, callee, thread, [h.rep])
21652163
else:
21662164
h.borrow_scope.num_borrows -= 1
21672165
return []

0 commit comments

Comments
 (0)