-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: finally
to also clean up after trapping continuations
#4507
Conversation
these check various continuations that should be present in `__motoko_async_helper` too
Co-authored-by: Claudio Russo <[email protected]>
@@ -313,6 +315,21 @@ actor A { | |||
try await t6t() catch _ {}; | |||
try await t6d() catch _ {}; | |||
try await t8t() catch _ {}; | |||
|
|||
// other side problem tests | |||
try await async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think this is behaving correctly. Maybe refactor into a separate subtest/function (like the others)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do this in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's something fishy in await.ml. Hold off merging for a bit
anticipating 0.12.0
Co-authored-by: Claudio Russo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can merge but I think it would be good to do the follow up PR addressing code duplication before releasing.
Introduces an optional
finally
clause totry
expressions that can be used for disciplined (structured) resource management. The clause comprises a unit-valued expression (or block) that may not perform sends (or similar). It gets executed for all control paths that leave thetry
-expression, i.e.return
,break
, etc. code paths. For nestedtry
expressions the cleanups are performed in innermost to outermost order.For last-resort cleanups (i.e. code paths trapping after an
await
) the replica invokes the callback registered asic0.call_on_cleanup
, and this will result in the execution of (exclusively) thefinally
blocks in (dynamic) scope. This is a new mechanism in Motoko, which was not possible to achieve earlier, and puts certain resource deallocations (e.g. of acquired locks) under the programmer's control.TODO:
catch
optional (non-trapping when missing) — Allowtry
withoutcatch
#4600throw
, so we were fine. Optimised, though.arrange.ml
, etc.)Triv
intry
(respect edges)finally
blocksmeta
(wouldassert
currently, thus causing minor code duplication) — could be follow-up PRThrow
and regular continuations inawait.ml
(instead of desugaring)catch
, as the exception will escapecontext
key sortCleanup
, stack up continuations of finally blocks onlykr
inawait.ml
tokrc
(CPSAwait
), passCleanup
continuations asc
async.ml
lowerCPSAwait
to that toocheck_ir.ml
, etc.await*
do
...finally
(when there is nocatch
clause necessary)means:TryE
needscases list option
finally
clausetry
block hasawait
effect — nope!try
OtherPrim "call_raw"
+ tests — nope!cps_asyncE
similarly toCallPrim/3
— nope!finally
emacs
moc
to 0.11.2 vscode-motoko#288