Skip to content
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

Merge Preparation: Try-Finally to Integrated EOP #4599

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
f113ced
amend `S.TryE`
ggreif Apr 22, 2024
9a82bde
interpret the happy path
ggreif Apr 22, 2024
7ebb915
postcompose on the `catch` paths too
ggreif Apr 22, 2024
de5ba2a
add prelim. test
ggreif Apr 23, 2024
d193689
complicate the test a bit
ggreif Apr 24, 2024
1d384d5
show that `catch` works, `return` not
ggreif Apr 24, 2024
6403328
nested `try`, no cigar!
ggreif Apr 25, 2024
290b184
fix up the return continuation too
ggreif Apr 25, 2024
cfe61aa
check that `finally` not running twice
ggreif Apr 29, 2024
32ba4f6
test `break`
ggreif Apr 29, 2024
9933eca
fix up outwards label continuations
ggreif Apr 29, 2024
f73231a
accept IR interpreters
ggreif Apr 30, 2024
d6763a0
checkpoint
ggreif Apr 30, 2024
fc64612
add a todo
ggreif May 2, 2024
25464c3
happy path when `unit` result
ggreif May 2, 2024
023b4ee
accept IR happy
ggreif May 2, 2024
86ec31a
simplify for special case
ggreif May 2, 2024
90e247d
post compose cleanup with cases too
ggreif May 2, 2024
8d649be
cleanup
ggreif May 2, 2024
a419d80
WIP
ggreif May 2, 2024
2f455bf
WIP
ggreif May 6, 2024
82f355a
more WIP
ggreif May 7, 2024
0e4d181
sharing fix
ggreif May 7, 2024
8bc89b7
WIP: analyse the context
ggreif May 8, 2024
f8fb9b0
WIP
ggreif May 8, 2024
7dd2eaa
disable flawed check
ggreif May 10, 2024
278f860
WIP: try precomposing the `finally`-thunk on the label continuation
ggreif May 13, 2024
ebdeeb7
use the respons variable
ggreif May 13, 2024
a428afa
WIP: try to implement the nested `try` case
ggreif May 13, 2024
6c7f0ad
cleanup
ggreif May 13, 2024
4791040
test with `drun`
ggreif May 14, 2024
f0e15e8
tweaks
ggreif May 14, 2024
067a35b
more tweaks
ggreif May 14, 2024
7456f5a
`Label` cannot happen, see `BreakPrim` below
ggreif May 14, 2024
60cd293
cleanups
ggreif May 14, 2024
5f82252
test `return`
ggreif May 14, 2024
1e59052
cover `Return` "labels" too
ggreif May 14, 2024
279f61e
cleanup
ggreif May 14, 2024
e3713c2
tweaks
ggreif May 17, 2024
85ee9b7
WIP
ggreif May 22, 2024
70e96b7
WIP: more
ggreif May 22, 2024
c6a1329
WIP: roll back some wrong ideas
ggreif May 22, 2024
63fc12f
tweaks
ggreif May 22, 2024
120c313
WIP: undo more
ggreif May 22, 2024
8726208
tweak
ggreif May 22, 2024
ef93fb3
WIP: cleanups
ggreif May 23, 2024
10e38dd
tweak
ggreif May 23, 2024
a9e93bc
WIP: start propagating the cleanup
ggreif May 23, 2024
cf03986
tweaks
ggreif May 24, 2024
c0ad414
WIP: back towards plan A
ggreif May 28, 2024
88420fb
WIP: some progress with ir_check
ggreif May 29, 2024
ae35133
WIP: minimal progress
ggreif May 29, 2024
4659205
WIP: progress
ggreif May 29, 2024
4daf367
WIP: unalias things
ggreif May 31, 2024
93a05a7
WIP: revert a few things and fix others
ggreif May 31, 2024
8823455
WIP: towards backend support for the third continuation
ggreif Jun 3, 2024
0b92793
WIP: fixup `future_array_index`
ggreif Jun 3, 2024
3a2e4bc
invoke the cleanup closure
ggreif Jun 4, 2024
6ad57d7
WIP: checkpoint
ggreif Jun 4, 2024
c73e61b
WIP: back to business
ggreif Jun 5, 2024
108b188
WIP: twist & shout!
ggreif Jun 5, 2024
8efe8c9
cleanup a bit
ggreif Jun 6, 2024
ab73471
tweak
ggreif Jun 6, 2024
f515bda
WIP: set up the `Cleanup` chain
ggreif Jun 6, 2024
4cce7fe
WIP: fix typing
ggreif Jun 6, 2024
0a84c5d
WIP: store the chain on `enqueue`
ggreif Jun 6, 2024
2ca816c
introduce `finally` keyword and update parser
ggreif Jun 7, 2024
eb4c53c
fix `ICCallRawPrim` and remove some obsolete changes
ggreif Jun 7, 2024
a9e84d1
new keyword
ggreif Jun 7, 2024
88b3a7e
add test for raw
ggreif Jun 7, 2024
0b5cfeb
enable `t6` again
ggreif Jun 7, 2024
38ebdac
WIP: cover the "trap after second `await`" case
ggreif Jun 8, 2024
f5ed26b
add `t0d` test which exercises the double-`await` codegen
ggreif Jun 10, 2024
fe343c1
improve comment
ggreif Jun 10, 2024
5cc86c6
add negative testcase
ggreif Jun 11, 2024
4a62db7
add error for messaging from `finally`
ggreif Jun 11, 2024
2d6e27e
another fixme
ggreif Jun 11, 2024
1ef333e
fix
ggreif Jun 11, 2024
f440e29
fix a syntax quirk
ggreif Jun 11, 2024
027430e
remove obsolete
ggreif Jun 11, 2024
2ff67b0
accept
ggreif Jun 12, 2024
fe5e6af
add tests for nested last-resort cleanups
ggreif Jun 12, 2024
1a6ac26
allow non-unit resuts for `try`
ggreif Jun 12, 2024
58a906c
WIP: reduce IR sharing by reconstructing the `VarE`
ggreif Jun 13, 2024
0c28b83
WIP: fix the type of the cleanup continuation
ggreif Jun 13, 2024
3b6a956
fixes and tweaks
ggreif Jun 13, 2024
4c84e41
tweaks
ggreif Jun 13, 2024
76214cd
communicate intent better (not done yet)
ggreif Jun 14, 2024
eed2ba3
WIP: prepare for elimination of nat32
ggreif Jun 14, 2024
6338f22
clean-up
ggreif Jun 14, 2024
c8ffb0c
align
ggreif Jun 14, 2024
33b4e64
simplify
ggreif Jun 14, 2024
11f2e47
undo
ggreif Jun 14, 2024
2c7ccbe
simplify the type for `@cleanup`
ggreif Jun 14, 2024
b010d40
these are equal types, but slightly different semantics
ggreif Jun 14, 2024
222aab8
fix for completeness
ggreif Jun 14, 2024
a096356
yet
ggreif Jun 19, 2024
0522458
simplify the logic
ggreif Jun 19, 2024
d5ba0c9
WIP: try to pass `var` via `TryE`
ggreif Jun 19, 2024
1afaf35
fix the import loop
ggreif Jun 19, 2024
064ef7f
tweak
ggreif Jun 20, 2024
2f5fc5e
WIP: improve the aliasing situation by eta-expansion
ggreif Jun 20, 2024
09c0575
fix the aliasing situation using `varE` just-in-time
ggreif Jun 20, 2024
3b21f51
done (almost)
ggreif Jun 20, 2024
16a4f84
WIP: first shot at the IR-interpreter
ggreif Jun 20, 2024
ce0c3f5
WIP: activate the interpreters
ggreif Jun 24, 2024
3c9b323
more tests
ggreif Jun 24, 2024
ed4e6d9
WIP: arrange the non-trapping ones to the front
ggreif Jun 24, 2024
93e73f7
another test
ggreif Jun 24, 2024
54e7f93
expose the double invocation in `src/mo_interpreter/interpret.ml`
ggreif Jun 24, 2024
cbc658b
fix the double-invocation
ggreif Jun 24, 2024
9c13b49
tweak
ggreif Jun 24, 2024
dd1dc6a
typos
ggreif Jun 24, 2024
3da4290
interpreting `TryE` makes only sense in non-lowered code, as it gets …
ggreif Jun 24, 2024
837dd18
fix the IR interpreter
ggreif Jun 24, 2024
8fcfb8b
cleanup
ggreif Jun 24, 2024
89b5a08
accept
ggreif Jun 24, 2024
eb7c7f2
add a test that traps in `catch`
ggreif Jun 25, 2024
aceb323
test trap in nested `catch`
ggreif Jun 25, 2024
70cb14b
first `async*` test
ggreif Jun 25, 2024
b3c0a60
add `Changelog.md` entry for `finally`
ggreif Jun 25, 2024
d727380
add another `await*` testcase
ggreif Jun 26, 2024
606a945
more `await*` tests
ggreif Jun 26, 2024
65e585e
arrange the finally thunk
ggreif Jun 27, 2024
813ede9
arrange the finally expression
ggreif Jun 27, 2024
62c298d
elim a FIXME
ggreif Jun 27, 2024
ae686d6
preserve the `Cleanup` chain for `await` and `await*`
ggreif Jun 27, 2024
560cbca
test `async* { ... }` trapping too
ggreif Jun 27, 2024
da124b2
reverts
ggreif Jun 27, 2024
f39b966
tweaks
ggreif Jun 27, 2024
5938aca
point to security best practices
ggreif Jun 27, 2024
d47e978
tweak
ggreif Jun 27, 2024
24cab37
words
ggreif Jun 27, 2024
2f6b6ef
italic
ggreif Jun 27, 2024
f1faeab
smith
ggreif Jun 27, 2024
bf93408
this needs to be done
ggreif Jun 28, 2024
b1480db
IR-interpreter: pass through the _cleanup_ continuation
ggreif Jun 28, 2024
f058d40
refactor
ggreif Jun 28, 2024
f3dadd3
simplify by assuming that `Cleanup` cont exists already
ggreif Jun 28, 2024
3b95664
tweaks
ggreif Jun 28, 2024
0a1e759
reject `throw` from `finally`
ggreif Jun 28, 2024
d8ef292
prohibit `return` and accessing external labels
ggreif Jul 1, 2024
40aab57
WIP: start implementing the `Triv` block
ggreif Jul 1, 2024
aaf7f17
pre-massage the continuations
ggreif Jul 1, 2024
0b6c528
Merge branch 'master' into gabor/finally
ggreif Jul 3, 2024
0775cd3
use builtin
ggreif Jul 1, 2024
1ea9792
out-edge from `catch`
ggreif Jul 3, 2024
3f041f5
step towards deduplication
ggreif Jul 3, 2024
1c95539
now we can deduplicate
ggreif Jul 3, 2024
b7db1f9
Merge remote-tracking branch 'origin/gabor/finally' into luc/merge-fi…
luc-blaeser Jul 4, 2024
8d1245f
Manual merge conflict resolution
luc-blaeser Jul 4, 2024
4a85e92
Merge branch 'luc/merge-finally-stable-heap' into luc/merge-finally-s…
luc-blaeser Jul 4, 2024
1a3fd4b
Merge branch 'luc/merge-finally-stable-heap64' into luc/merge-finally…
luc-blaeser Jul 4, 2024
2c633d8
Merge branch 'luc/merge-finally-graph-copy' into luc/merge-finally-in…
luc-blaeser Jul 4, 2024
0084937
Merge try-finally to classical persistence backend
luc-blaeser Jul 4, 2024
7e4581e
Manual merge conflict resolution
luc-blaeser Jul 4, 2024
f83da8b
WIP: remove the `finally`-insertion from `desugar.ml` and add it to `…
ggreif Jul 4, 2024
c4bd5b1
fix the re-`throw` to not ignore a `finally`
ggreif Jul 4, 2024
27bba80
simplify
ggreif Jul 4, 2024
cdb70e3
rearchitect the interpreter
ggreif Jul 4, 2024
aa63c74
correctly endow the inner environment with the precomposed `throws`
ggreif Jul 4, 2024
e9091eb
prepare for fusing
ggreif Jul 4, 2024
ecbd0d9
deduplicate
ggreif Jul 4, 2024
e65574b
indent
ggreif Jul 4, 2024
ff5227b
model the IR-interpreter after the AST one
ggreif Jul 4, 2024
0f261ac
fuse the cases
ggreif Jul 4, 2024
f511bb0
simplify
ggreif Jul 4, 2024
81e1593
Merge branch 'master' into gabor/finally
ggreif Jul 8, 2024
84aa3e2
Allow `try` without `catch` (#4600)
ggreif Jul 9, 2024
59a14d9
document `finally`
ggreif Jul 9, 2024
0fabab4
fix: this was missed when merging #4600
ggreif Jul 9, 2024
2329069
optimisation: don't rethrow if there is an irrefutable `catch` pattern
ggreif Jul 9, 2024
5f4fb41
Merge branch 'master' into gabor/finally
ggreif Jul 9, 2024
b0998cb
undo
ggreif Jul 9, 2024
47bf1d1
tweak
ggreif Jul 9, 2024
51bb8a1
remove fuzz
ggreif Jul 9, 2024
007fc75
Update src/ir_def/check_ir.ml
ggreif Jul 18, 2024
e43d309
Merge branch 'master' into gabor/finally
ggreif Jul 18, 2024
70ba3c2
post-merge fixup
ggreif Jul 18, 2024
5340312
Update src/mo_interpreter/interpret.ml
ggreif Jul 18, 2024
9c8bcb9
Update src/ir_interpreter/interpret_ir.ml
ggreif Jul 18, 2024
d848aa6
Update Changelog.md
ggreif Jul 18, 2024
580642c
Update doc/md/reference/language-manual.md
ggreif Jul 18, 2024
156ee7f
bug in checking of try catch finally that sends in finally
crusso Jul 18, 2024
7968356
bug
crusso Jul 18, 2024
ed8aae3
fix bug using NullCap; update test output; remove error code
crusso Jul 18, 2024
cddd55c
clean up test files
crusso Jul 18, 2024
5d676ad
Merge branch 'luc/integrate-enhanced-orthogonal-persistence' into luc…
luc-blaeser Jul 22, 2024
87d90f5
Merge remote-tracking branch 'origin/gabor/finally' into luc/merge-fi…
luc-blaeser Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Motoko compiler changelog

## 0.12.0 (to come)

* motoko (`moc`)

* feat: `finally` clauses for `try` expressions (#4507).

A trailing `finally` clause to `try`/`catch` expressions facilitates structured
resource deallocation (e.g. acquired locks, etc.) and similar cleanups in the
presence of control-flow expressions (`return`, `break`, `continue`, `throw`).

_Note_: `finally`-expressions that are in scope will be executed even if an execution
path _following_ an `await`-expression traps. This feature, not available before in Motoko,
allows programmers to implement cleanups even in the presence of traps. For trapping
execution paths prior to any `await`, the replica-provided state roll back mechanism must
ensure no cleanup is required.

The relevant security best practices are accessible at
https://internetcomputer.org/docs/current/developer-docs/security/security-best-practices/inter-canister-calls#recommendation

BREAKING CHANGE (Minor): `finally` is now a reserved keyword,
programs using this identifier will break.

## 0.11.3 (2024-07-16)

* motoko (`moc`)
Expand Down
2 changes: 2 additions & 0 deletions doc/md/examples/grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@
'if' <exp_nullary> <exp_nest>
'if' <exp_nullary> <exp_nest> 'else' <exp_nest>
'try' <exp_nest> <catch>
'try' <exp_nest> <catch> 'finally' <exp_nest>
'try' <exp_nest> 'finally' <exp_nest>
'throw' <exp_nest>
'switch' <exp_nullary> '{' <list(<case>, ';')> '}'
'while' <exp_nullary> <exp_nest>
Expand Down
10 changes: 9 additions & 1 deletion doc/md/reference/language-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The following keywords are reserved and may not be used as identifiers:
``` bnf

actor and assert async async* await await* break case catch class
composite continue debug debug_show do else flexible false for
composite continue debug debug_show do else false flexible finally for
from_candid func if ignore import in module not null object or label
let loop private public query return shared stable switch system throw
to_candid true try type var while with
Expand Down Expand Up @@ -514,6 +514,9 @@ The syntax of an expression is as follows:
await* <block-or-exp> Await a delayed computation (only in async)
throw <exp> Raise an error (only in async)
try <block-or-exp> catch <pat> <block-or-exp> Catch an error (only in async)
try <block-or-exp> finally <block-or-exp> Guard with cleanup
try <block-or-exp> catch <pat> <block-or-exp> finally <block-or-exp>
Catch an error (only in async) and cleanup
assert <block-or-exp> Assertion
<exp> : <typ> Type annotation
<dec> Declaration
Expand Down Expand Up @@ -2547,6 +2550,11 @@ Because the [`Error`](../base/Error.md) type is opaque, the pattern match cannot

:::

The `try` expression can be provided with a `finally` cleanup clause to facilitate structured rollback of temporary state changes (e.g. to release a lock).
The preceding `catch` clause may be omitted in the presence of a `finally` clause.

This form is `try <block-or-exp1> (catch <pat> <block-or-exp2>)? finally <block-or-exp3>`, and evaluation proceeds as above with the crucial addition that every control-flow path leaving `<block-or-exp1>` or `<block-or-exp2>` will execute the unit-valued `<block-or-exp3>` before the entire `try` expression obtains its value. The cleanup expression will additionaly also be executed when the processing after an intervening `await` (directly, or indirectly as `await*`) traps.

See [Error type](#error-type).

### Assert
Expand Down
1 change: 1 addition & 0 deletions emacs/motoko-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"debug"
"debug_show"
"else"
"finally"
"flexible"
"for"
"from_candid"
Expand Down
2 changes: 1 addition & 1 deletion rts/motoko-rts/src/continuation_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub unsafe fn remember_continuation<M: Memory>(mem: &mut M, ptr: Value) -> usize

// Position of the future in explicit self-send ContinuationTable entries
// Invariant: keep this synchronised with compiler.ml (see future_array_index)
const FUTURE_ARRAY_INDEX: usize = 2;
const FUTURE_ARRAY_INDEX: usize = 3;

#[no_mangle]
pub unsafe extern "C" fn peek_future_continuation(idx: usize) -> Value {
Expand Down
80 changes: 46 additions & 34 deletions src/codegen/compile_classical.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9220,39 +9220,39 @@ module FuncDec = struct
))

let message_start env sort = match sort with
| Type.Shared Type.Write ->
Lifecycle.trans env Lifecycle.InUpdate
| Type.Shared Type.Query ->
Lifecycle.trans env Lifecycle.InQuery
| Type.Shared Type.Composite ->
Lifecycle.trans env Lifecycle.InComposite
| Type.(Shared Write) ->
Lifecycle.(trans env InUpdate)
| Type.(Shared Query) ->
Lifecycle.(trans env InQuery)
| Type.(Shared Composite) ->
Lifecycle.(trans env InComposite)
| _ -> assert false

let message_cleanup env sort = match sort with
| Type.Shared Type.Write ->
| Type.(Shared Write) ->
GC.collect_garbage env ^^
Lifecycle.trans env Lifecycle.Idle
| Type.Shared Type.Query ->
Lifecycle.trans env Lifecycle.PostQuery
| Type.Shared Type.Composite ->
Lifecycle.(trans env Idle)
| Type.(Shared Query) ->
Lifecycle.(trans env PostQuery)
| Type.(Shared Composite) ->
(* Stay in composite query state such that callbacks of
composite queries can also use the memory reserve.
The state is isolated since memory changes of queries
are rolled back by the IC runtime system. *)
Lifecycle.trans env Lifecycle.InComposite
Lifecycle.(trans env InComposite)
| _ -> assert false

let callback_start env =
Lifecycle.is_in env Lifecycle.InComposite ^^
Lifecycle.(is_in env InComposite) ^^
G.if0
(G.nop)
(message_start env (Type.Shared Type.Write))
(message_start env Type.(Shared Write))

let callback_cleanup env =
Lifecycle.is_in env Lifecycle.InComposite ^^
Lifecycle.(is_in env InComposite) ^^
G.if0
(G.nop)
(message_cleanup env (Type.Shared Type.Write))
(message_cleanup env Type.(Shared Write))

let compile_const_message outer_env outer_ae sort control args mk_body ret_tys at : E.func_with_names =
let ae0 = VarEnv.mk_fun_ae outer_ae in
Expand Down Expand Up @@ -9454,7 +9454,7 @@ module FuncDec = struct
(* result is a function that accepts a list of closure getters, from which
the first and second must be the reply and reject continuations. *)
fun closure_getters ->
let (set_cb_index, get_cb_index) = new_local env "cb_index" in
let set_cb_index, get_cb_index = new_local env "cb_index" in
Arr.lit env Tagged.T closure_getters ^^
ContinuationTable.remember env ^^
set_cb_index ^^
Expand Down Expand Up @@ -9482,7 +9482,12 @@ module FuncDec = struct
Func.define_built_in env name ["env", I32Type] [] (fun env ->
G.i (LocalGet (nr 0l)) ^^
ContinuationTable.recall env ^^
G.i Drop);
Arr.load_field env 2l ^^ (* get the cleanup closure *)
let set_closure, get_closure = new_local env "closure" in
set_closure ^^ get_closure ^^
Closure.prepare_closure_call env ^^
get_closure ^^
Closure.call_closure env 0 0);
compile_unboxed_const (E.add_fun_ptr env (E.built_in env name))

let ic_call_threaded env purpose get_meth_pair push_continuations
Expand Down Expand Up @@ -9531,29 +9536,29 @@ module FuncDec = struct
| _ ->
E.trap_with env (Printf.sprintf "cannot perform %s when running locally" purpose)

let ic_call env ts1 ts2 get_meth_pair get_arg get_k get_r =
let ic_call env ts1 ts2 get_meth_pair get_arg get_k get_r get_c =
ic_call_threaded
env
"remote call"
get_meth_pair
(closures_to_reply_reject_callbacks env ts2 [get_k; get_r])
(closures_to_reply_reject_callbacks env ts2 [get_k; get_r; get_c])
(fun _ -> get_arg ^^ Serialization.serialize env ts1)

let ic_call_raw env get_meth_pair get_arg get_k get_r =
let ic_call_raw env get_meth_pair get_arg get_k get_r get_c =
ic_call_threaded
env
"raw call"
get_meth_pair
(closures_to_raw_reply_reject_callbacks env [get_k; get_r])
(closures_to_raw_reply_reject_callbacks env [get_k; get_r; get_c])
(fun _ -> get_arg ^^ Blob.as_ptr_len env)

let ic_self_call env ts get_meth_pair get_future get_k get_r =
let ic_self_call env ts get_meth_pair get_future get_k get_r get_c =
ic_call_threaded
env
"self call"
get_meth_pair
(* Storing the tuple away, future_array_index = 2, keep in sync with rts/continuation_table.rs *)
(closures_to_reply_reject_callbacks env ts [get_k; get_r; get_future])
(* Storing the tuple away, future_array_index = 3, keep in sync with rts/continuation_table.rs *)
(closures_to_reply_reject_callbacks env ts [get_k; get_r; get_c; get_future])
(fun get_cb_index ->
get_cb_index ^^
BoxedSmallWord.box env Type.Nat32 ^^
Expand Down Expand Up @@ -11865,7 +11870,7 @@ and compile_prim_invocation (env : E.t) ae p es at =
| ICCallerPrim, [] ->
SR.Vanilla, IC.caller env

| ICCallPrim, [f;e;k;r] ->
| ICCallPrim, [f;e;k;r;c] ->
SR.unit, begin
(* TBR: Can we do better than using the notes? *)
let _, _, _, ts1, _ = Type.as_func f.note.Note.typ in
Expand All @@ -11874,19 +11879,22 @@ and compile_prim_invocation (env : E.t) ae p es at =
let (set_arg, get_arg) = new_local env "arg" in
let (set_k, get_k) = new_local env "k" in
let (set_r, get_r) = new_local env "r" in
let (set_c, get_c) = new_local env "c" in
let add_cycles = Internals.add_cycles env ae in
compile_exp_vanilla env ae f ^^ set_meth_pair ^^
compile_exp_vanilla env ae e ^^ set_arg ^^
compile_exp_vanilla env ae k ^^ set_k ^^
compile_exp_vanilla env ae r ^^ set_r ^^
FuncDec.ic_call env ts1 ts2 get_meth_pair get_arg get_k get_r add_cycles
compile_exp_vanilla env ae c ^^ set_c ^^
FuncDec.ic_call env ts1 ts2 get_meth_pair get_arg get_k get_r get_c add_cycles
end
| ICCallRawPrim, [p;m;a;k;r] ->
| ICCallRawPrim, [p;m;a;k;r;c] ->
SR.unit, begin
let (set_meth_pair, get_meth_pair) = new_local env "meth_pair" in
let (set_arg, get_arg) = new_local env "arg" in
let (set_k, get_k) = new_local env "k" in
let (set_r, get_r) = new_local env "r" in
let set_meth_pair, get_meth_pair = new_local env "meth_pair" in
let set_arg, get_arg = new_local env "arg" in
let set_k, get_k = new_local env "k" in
let set_r, get_r = new_local env "r" in
let set_c, get_c = new_local env "c" in
let add_cycles = Internals.add_cycles env ae in
compile_exp_vanilla env ae p ^^
compile_exp_vanilla env ae m ^^ Text.to_blob env ^^
Expand All @@ -11895,7 +11903,8 @@ and compile_prim_invocation (env : E.t) ae p es at =
compile_exp_vanilla env ae a ^^ set_arg ^^
compile_exp_vanilla env ae k ^^ set_k ^^
compile_exp_vanilla env ae r ^^ set_r ^^
FuncDec.ic_call_raw env get_meth_pair get_arg get_k get_r add_cycles
compile_exp_vanilla env ae c ^^ set_c ^^
FuncDec.ic_call_raw env get_meth_pair get_arg get_k get_r get_c add_cycles
end

| ICMethodNamePrim, [] ->
Expand Down Expand Up @@ -12104,11 +12113,12 @@ and compile_exp_with_hint (env : E.t) ae sr_hint exp =
let return_arity = List.length return_tys in
let mk_body env1 ae1 = compile_exp_as env1 ae1 (StackRep.of_arity return_arity) e in
FuncDec.lit env ae x sort control captured args mk_body return_tys exp.at
| SelfCallE (ts, exp_f, exp_k, exp_r) ->
| SelfCallE (ts, exp_f, exp_k, exp_r, exp_c) ->
SR.unit,
let (set_future, get_future) = new_local env "future" in
let (set_k, get_k) = new_local env "k" in
let (set_r, get_r) = new_local env "r" in
let (set_c, get_c) = new_local env "c" in
let mk_body env1 ae1 = compile_exp_as env1 ae1 SR.unit exp_f in
let captured = Freevars.captured exp_f in
let add_cycles = Internals.add_cycles env ae in
Expand All @@ -12118,13 +12128,15 @@ and compile_exp_with_hint (env : E.t) ae sr_hint exp =

compile_exp_vanilla env ae exp_k ^^ set_k ^^
compile_exp_vanilla env ae exp_r ^^ set_r ^^
compile_exp_vanilla env ae exp_c ^^ set_c ^^

FuncDec.ic_self_call env ts
IC.(get_self_reference env ^^
actor_public_field env async_method_name)
get_future
get_k
get_r
get_c
add_cycles
| ActorE (ds, fs, _, _) ->
fatal "Local actors not supported by backend"
Expand Down
Loading