-
Notifications
You must be signed in to change notification settings - Fork 98
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: parenthetical syntax for cycles
, timeout
etc.
#4608
base: master
Are you sure you want to change the base?
Changes from 118 commits
d4811e2
b6d32ec
d3b9415
3f57777
7e23ac8
b0516b0
dc5a72f
8f7df27
e5f3ca9
5eb79a3
9672a96
00b2507
3d4bb5a
d989397
892ea54
42a0471
e43b1cc
43e816c
272870b
2f22db2
b6ee8dd
812d78d
e7f13f6
ccd03db
dbe054d
835502c
b104f85
0542367
eaa577d
4f77084
38dfd70
1f61bb5
4d0d263
d472f53
48096cb
ff217f3
29110d3
463f12a
4abc9e8
261ae02
2e5b787
8c05650
f9abea4
998f689
6873747
3f4c1de
009f05d
2bbe8d5
391fedd
275e952
56d79fe
4009982
8628695
016ac58
9c611a9
ee4e2c9
4279b96
0f35682
5a9e300
3d5cdc7
e080bcb
3120931
cf7cfa4
84e42e1
b3ea1c2
6b0d54a
ebc89b4
82f2049
a7d2874
b482532
13b46f6
b5f98a9
19e8058
a0e321d
d147896
a23f97a
c475dc7
58c81b9
498dd9b
41186f3
65013fa
2f179ec
2f938cb
38fb28c
031c375
ac6928c
b9b3c17
fbaf8b4
599fe2d
30dbe01
5be4240
a5b0984
137ab9a
2b27bf9
92976f8
336de0b
8a7c490
05eb145
0a9f6c0
fb97b74
fe6107e
277789a
2a2b19a
85075eb
1982b48
a93b8e1
5a4d21f
9ae719b
f0f9436
21ce382
fff0aca
df56dcc
b7aab76
4ba0df1
8384150
360974a
309a231
64696a1
339a98e
a0d475a
c9bd84f
3bed728
cbfacdf
f1cc907
2edbcd9
83e70ab
0878d90
ec31258
ca66302
4c37385
e79c48d
b5eb704
f80ffa8
2e58517
7cb6cf0
dc37044
72900db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,6 +214,7 @@ | |
'break' <id> <exp_nullary>? | ||
'continue' <id> | ||
'debug' <exp_nest> | ||
'(' <exp_post>? 'with' <list(<exp_field>, ';')> ')' <exp_nest> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts on using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for missing this comment for some time... Yeah, it is a nice consistency argument. I was stealing the syntax from the record field separators, but I guess comma works as well. Will try and report back. @crusso any gut feelings about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd stick with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, they are fields, but where is it written that they cannot be separated by commas? ;-) Just playing the devil's advocate. Anyway, I have started a branch to get a feeling for the suggestion: #4782. I am not married to either way. |
||
'if' <exp_nullary> <exp_nest> | ||
'if' <exp_nullary> <exp_nest> 'else' <exp_nest> | ||
'try' <exp_nest> <catch> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2021,7 +2021,7 @@ module Tagged = struct | |
| T (* (T,+) *) | ||
| S (* shared ... -> ... *) | ||
type blob_sort = | ||
| B (* Blob *) | ||
| B (* Blob *) | ||
| T (* Text *) | ||
| P (* Principal *) | ||
| A (* actor { ... } *) | ||
|
@@ -2250,6 +2250,15 @@ module Tagged = struct | |
set_tag ^^ | ||
go cases | ||
|
||
(* like branch_default_with but the tag is known statically *) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes need to be transported to |
||
let branch_with env retty = function | ||
| [] -> G.i Unreachable | ||
| [_, code] -> code | ||
| (_, code) :: cases -> | ||
let (set_o, get_o) = new_local env "o" in | ||
let prep (t, code) = (t, get_o ^^ code) | ||
in set_o ^^ get_o ^^ branch_default env retty (get_o ^^ code) (List.map prep cases) | ||
|
||
let allocation_barrier env = | ||
(if !Flags.gc_strategy = Flags.Incremental then | ||
E.call_import env "rts" "allocation_barrier" | ||
|
@@ -2411,12 +2420,13 @@ module Opt = struct | |
( get_x ) (* true literal, no wrapping *) | ||
( get_x ^^ Tagged.branch_default env [I32Type] | ||
( get_x ) (* default tag, no wrapping *) | ||
[ Tagged.Null, | ||
Tagged. | ||
[ Null, | ||
(* NB: even ?null does not require allocation: We use a static | ||
singleton for that: *) | ||
compile_unboxed_const (vanilla_lit env (null_vanilla_lit env)) | ||
; Tagged.Some, | ||
Tagged.obj env Tagged.Some [get_x] | ||
; Some, | ||
obj env Some [get_x] | ||
] | ||
) | ||
) | ||
|
@@ -2540,7 +2550,7 @@ module Closure = struct | |
I32Type :: Lib.List.make n_args I32Type, | ||
FakeMultiVal.ty (Lib.List.make n_res I32Type))) in | ||
(* get the table index *) | ||
Tagged.load_forwarding_pointer env ^^ | ||
(*Tagged.load_forwarding_pointer env ^^ FIXME: NOT needed, accessing immut slots*) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure this is ok? I'd first verify with @luc. Also, not related to this PR at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have this in a separate PR? |
||
Tagged.load_field env (funptr_field env) ^^ | ||
(* All done: Call! *) | ||
let table_index = 0l in | ||
|
@@ -5500,7 +5510,7 @@ module IC = struct | |
| Flags.(ICMode | RefMode) -> | ||
system_call env "call_cycles_add128" | ||
| _ -> | ||
E.trap_with env "cannot accept cycles when running locally" | ||
E.trap_with env "cannot add cycles when running locally" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. break this out? |
||
|
||
let cycles_accept env = | ||
match E.mode env with | ||
|
@@ -9385,16 +9395,21 @@ end (* Var *) | |
that requires top-level cps conversion; | ||
use new prims instead *) | ||
module Internals = struct | ||
let call_prelude_function env ae var = | ||
let call_prelude_function_with_args env ae var args = | ||
match VarEnv.lookup_var ae var with | ||
| Some (VarEnv.Const (_, Const.Fun (mk_fi, _))) -> | ||
compile_unboxed_zero ^^ (* A dummy closure *) | ||
args ^^ | ||
G.i (Call (nr (mk_fi ()))) | ||
| _ -> assert false | ||
|
||
let call_prelude_function env ae var = | ||
call_prelude_function_with_args env ae var G.nop | ||
|
||
let add_cycles env ae = call_prelude_function env ae "@add_cycles" | ||
let reset_cycles env ae = call_prelude_function env ae "@reset_cycles" | ||
let reset_refund env ae = call_prelude_function env ae "@reset_refund" | ||
let pass_cycles env ae = call_prelude_function_with_args env ae "@pass_cycles" | ||
end | ||
|
||
(* This comes late because it also deals with messages *) | ||
|
@@ -10862,7 +10877,7 @@ and compile_prim_invocation (env : E.t) ae p es at = | |
|
||
begin match p, es with | ||
(* Calls *) | ||
| CallPrim _, [e1; e2] -> | ||
| CallPrim (_, par), [e1; e2] -> | ||
let sort, control, _, arg_tys, ret_tys = Type.(as_func (promote e1.note.Note.typ)) in | ||
let n_args = List.length arg_tys in | ||
let return_arity = match control with | ||
|
@@ -10876,8 +10891,7 @@ and compile_prim_invocation (env : E.t) ae p es at = | |
let call_as_prim = match fun_sr, sort with | ||
| SR.Const (_, Const.Fun (mk_fi, Const.PrimWrapper prim)), _ -> | ||
begin match n_args, e2.it with | ||
| 0, _ -> true | ||
| 1, _ -> true | ||
| (0 | 1), _ -> true | ||
| n, PrimE (TupPrim, es) when List.length es = n -> true | ||
| _, _ -> false | ||
end | ||
|
@@ -10908,18 +10922,23 @@ and compile_prim_invocation (env : E.t) ae p es at = | |
StackRep.of_arity return_arity, | ||
|
||
code1 ^^ | ||
compile_unboxed_zero ^^ (* A dummy closure *) | ||
Type.(match as_obj par.note.Note.typ with | ||
| Object, [] -> compile_unboxed_zero (* a dummy closure *) | ||
| _ -> compile_exp_vanilla env ae par) ^^ (* parenthetical *) | ||
compile_exp_as env ae (StackRep.of_arity n_args) e2 ^^ (* the args *) | ||
G.i (Call (nr (mk_fi ()))) ^^ | ||
FakeMultiVal.load env (Lib.List.make return_arity I32Type) | ||
| _, Type.Local -> | ||
let (set_clos, get_clos) = new_local env "clos" in | ||
let set_clos, get_clos = new_local env "clos" in | ||
|
||
StackRep.of_arity return_arity, | ||
code1 ^^ StackRep.adjust env fun_sr SR.Vanilla ^^ | ||
Closure.prepare_closure_call env ^^ (* FIXME: move to front elsewhere too *) | ||
set_clos ^^ | ||
get_clos ^^ | ||
Closure.prepare_closure_call env ^^ | ||
Type.(match as_obj par.note.Note.typ, ret_tys with | ||
| (Object, []), _ -> get_clos (* just the closure *) | ||
| _, [ret] when is_async_fut ret -> Arr.lit env Tagged.T [compile_exp_vanilla env ae par; get_clos] (* parenthetical: pass a pair *) | ||
| _ -> get_clos) ^^ (* just the closure *) | ||
compile_exp_as env ae (StackRep.of_arity n_args) e2 ^^ | ||
get_clos ^^ | ||
Closure.call_closure env n_args return_arity | ||
|
@@ -10930,8 +10949,10 @@ and compile_prim_invocation (env : E.t) ae p es at = | |
let (set_meth_pair, get_meth_pair) = new_local env "meth_pair" in | ||
let (set_arg, get_arg) = new_local env "arg" in | ||
let _, _, _, ts, _ = Type.as_func e1.note.Note.typ in | ||
let add_cycles = Internals.add_cycles env ae in | ||
|
||
let add_cycles = Type.(match as_obj par.note.Note.typ with | ||
| Object, [] -> Internals.add_cycles env ae (* legacy *) | ||
| _ -> compile_exp_vanilla env ae par ^^ Object.load_idx env par.note.Note.typ "cycles" ^^ Cycles.add env) (* parenthetical *) | ||
in | ||
StackRep.of_arity return_arity, | ||
code1 ^^ StackRep.adjust env fun_sr SR.Vanilla ^^ | ||
set_meth_pair ^^ | ||
|
@@ -12104,24 +12125,27 @@ and compile_prim_invocation (env : E.t) ae p es at = | |
| ICCallerPrim, [] -> | ||
SR.Vanilla, IC.caller env | ||
|
||
| ICCallPrim, [f;e;k;r;c] -> | ||
| ICCallPrim setup, [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 | ||
let _, _, _, ts2, _ = Type.as_func k.note.Note.typ 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 | ||
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 = match setup with | ||
| None -> Internals.add_cycles env ae | ||
| Some exp -> compile_exp_vanilla env ae exp ^^ G.i Drop 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 ^^ | ||
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;c] -> | ||
SR.unit, begin | ||
let set_meth_pair, get_meth_pair = new_local env "meth_pair" in | ||
|
@@ -12174,6 +12198,26 @@ and compile_prim_invocation (env : E.t) ae p es at = | |
SR.Vanilla, Cycles.available env | ||
| SystemCyclesRefundedPrim, [] -> | ||
SR.Vanilla, Cycles.refunded env | ||
| ICCyclesPrim, [] -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not an idempotent operation, so we have to be careful to not call it twice. E.g. it fails for paired up environment+parenthetical. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should return two options. Possibly just the |
||
SR.Vanilla, | ||
G.i (LocalGet (nr 0l)) ^^ (* closed-over bindings *) | ||
G.if1 I32Type | ||
begin | ||
G.i (LocalGet (nr 0l)) ^^ | ||
Tagged.branch_with env [I32Type] | ||
[ Tagged.Closure, | ||
G.i Drop ^^ | ||
Opt.null_lit env | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
; Tagged.(Array T), | ||
Opt.inject_simple env (Arr.load_field env 0l) ^^ | ||
G.i (LocalGet (nr 0l)) ^^ | ||
Arr.load_field env 1l ^^ | ||
G.i (LocalSet (nr 0l)) | ||
; Tagged.Object, | ||
Opt.inject_simple env G.nop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't care storing back anything, as there is no captured environment. |
||
] | ||
end | ||
(Opt.null_lit env) | ||
| SystemCyclesBurnPrim, [e1] -> | ||
SR.Vanilla, compile_exp_vanilla env ae e1 ^^ Cycles.burn env | ||
|
||
|
@@ -12349,15 +12393,19 @@ 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, exp_c) -> | ||
| SelfCallE (cyc, 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 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 | ||
let add_cycles = match cyc.it with | ||
| LitE NullLit -> Internals.add_cycles env ae (* legacy *) | ||
| _ when Type.(sub cyc.note.Note.typ (Opt (Obj (Object, [{ lab = "cycles"; typ = nat; src = empty_src}])))) -> | ||
Internals.pass_cycles env ae (compile_exp_vanilla env ae cyc) | ||
| _ -> Internals.pass_cycles env ae (Opt.null_lit env) in | ||
FuncDec.async_body env ae ts captured mk_body exp.at ^^ | ||
Tagged.load_forwarding_pointer env ^^ | ||
set_future ^^ | ||
|
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.
don't forget to revert