-
Notifications
You must be signed in to change notification settings - Fork 101
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 all 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
01e1ba6
6498fe3
f1e37a1
ccff46a
df50c8c
54794a6
7877986
76eadcd
8a67b0b
afb2c14
a850539
4ad010f
ff5c16e
1974e7d
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 |
---|---|---|
|
@@ -219,6 +219,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> | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -405,7 +405,7 @@ let rec check_exp env (exp:Ir.exp) : unit = | |
| PrimE (p, es) -> | ||
List.iter (check_exp env) es; | ||
begin match p, es with | ||
| CallPrim insts, [exp1; exp2] -> | ||
| CallPrim (insts, _FIXMEpars), [exp1; exp2] -> | ||
begin match T.promote (typ exp1) with | ||
| T.Func (sort, control, tbs, arg_tys, ret_tys) -> | ||
check_inst_bounds env tbs insts exp.at; | ||
|
@@ -556,6 +556,11 @@ let rec check_exp env (exp:Ir.exp) : unit = | |
check (T.shared (T.seq ots)) "DeserializeOpt is not defined for operand type"; | ||
typ exp1 <: T.blob; | ||
T.Opt (T.seq ots) <: t | ||
|
||
|
||
| ICCyclesPrim, [] -> () (* FIXME *) | ||
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. check for |
||
|
||
|
||
| CPSAwait (s, cont_typ), [a; krb] -> | ||
let (_, t1) = | ||
try T.as_async_sub s T.Non (T.normalize (typ a)) | ||
|
@@ -574,7 +579,7 @@ let rec check_exp env (exp:Ir.exp) : unit = | |
| _ -> error env exp.at "CPSAwait bad cont"); | ||
check (not (env.flavor.has_await)) "CPSAwait await flavor"; | ||
check (env.flavor.has_async_typ) "CPSAwait in post-async flavor"; | ||
| CPSAsync (s, t0), [exp] -> | ||
| CPSAsync (s, t0, _FIXME), [exp] -> | ||
(match typ exp with | ||
| T.Func (T.Local, T.Returns, [tb], | ||
T.[Func (Local, Returns, [], ts1, []); | ||
|
@@ -601,7 +606,8 @@ let rec check_exp env (exp:Ir.exp) : unit = | |
T.Non <: t | ||
| ICCallerPrim, [] -> | ||
T.caller <: t | ||
| ICCallPrim, [exp1; exp2; k; r; c] -> | ||
| ICCallPrim setup, [exp1; exp2; k; r; c] -> | ||
Option.iter (fun e -> typ e <: T.unit) setup; | ||
let t1 = T.promote (typ exp1) in | ||
begin match t1 with | ||
| T.Func (sort, T.Replies, _ (*TBR*), arg_tys, ret_tys) -> | ||
|
@@ -684,6 +690,9 @@ let rec check_exp env (exp:Ir.exp) : unit = | |
| SystemCyclesAddPrim, [e1] -> | ||
typ e1 <: T.nat; | ||
T.unit <: t | ||
| SystemTimeoutPrim, [e1] -> | ||
typ e1 <: T.nat32; | ||
T.unit <: t | ||
(* Certified Data *) | ||
| SetCertifiedData, [e1] -> | ||
typ e1 <: T.blob; | ||
|
@@ -746,7 +755,7 @@ let rec check_exp env (exp:Ir.exp) : unit = | |
check_exp (add_lab env id t0) exp1; | ||
typ exp1 <: t0; | ||
t0 <: t | ||
| AsyncE (s, tb, exp1, t0) -> | ||
| AsyncE (_FIXME, s, tb, exp1, t0) -> | ||
check env.flavor.has_await "async expression in non-await flavor"; | ||
check_typ env t0; | ||
let c, tb, ce = check_open_typ_bind env tb in | ||
|
@@ -805,13 +814,15 @@ let rec check_exp env (exp:Ir.exp) : unit = | |
, tbs, List.map (T.close cs) ts1, List.map (T.close cs) ret_tys | ||
) in | ||
fun_ty <: t | ||
| SelfCallE (ts, exp_f, exp_k, exp_r, exp_c) -> | ||
| SelfCallE (cyc, ts, exp_f, exp_k, exp_r, exp_c) -> | ||
check (not env.flavor.Ir.has_async_typ) "SelfCallE in async flavor"; | ||
check_exp env cyc; | ||
List.iter (check_typ env) ts; | ||
check_exp { env with lvl = NotTopLvl } exp_f; | ||
check_exp env exp_k; | ||
check_exp env exp_r; | ||
check_exp env exp_c; | ||
typ cyc <: T.(Opt (Obj (Object, []))); | ||
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. Instead of |
||
typ exp_f <: T.unit; | ||
typ exp_k <: T.(Construct.contT (Tup ts) unit); | ||
typ exp_r <: T.(Construct.err_contT unit); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,8 @@ let tupP pats = | |
note = T.Tup (List.map (fun p -> p.note) pats); | ||
at = no_region } | ||
|
||
let tupVarsP vs = List.map varP vs |> tupP | ||
|
||
let seqP ps = | ||
match ps with | ||
| [p] -> p | ||
|
@@ -90,10 +92,12 @@ let primE prim es = | |
| ICReplyPrim _ | ||
| ICRejectPrim -> T.Non | ||
| ICCallerPrim -> T.caller | ||
| ICStableWrite _ -> T.unit | ||
| ICStableWrite _ | ||
| ICPerformGC | ||
| SystemTimeoutPrim | ||
| SystemCyclesAddPrim -> T.unit | ||
| ICStableRead t -> t | ||
| ICMethodNamePrim -> T.text | ||
| ICPerformGC | ||
| ICStableSize _ -> T.nat64 | ||
| IdxPrim | ||
| DerefArrayOffset -> T.(as_immut (as_array_sub (List.hd es).note.Note.typ)) | ||
|
@@ -111,9 +115,10 @@ let primE prim es = | |
| SystemCyclesBurnPrim -> T.nat | ||
| DeserializePrim ts -> T.seq ts | ||
| DeserializeOptPrim ts -> T.Opt (T.seq ts) | ||
| ICCyclesPrim -> T.(Opt (Obj (Object, []))) | ||
| OtherPrim "trap" -> T.Non | ||
| OtherPrim "global_timer_set" -> T.nat64 | ||
| OtherPrim "call_perform_status" -> T.(Prim Nat32) | ||
| OtherPrim "call_perform_status" -> T.nat32 | ||
| OtherPrim "call_perform_message" -> T.text | ||
| OtherPrim "array_len" | ||
| OtherPrim "blob_size" | ||
|
@@ -152,23 +157,21 @@ let assertE e = | |
} | ||
|
||
|
||
let asyncE s typ_bind e typ1 = | ||
{ it = AsyncE (s, typ_bind, e, typ1); | ||
at = no_region; | ||
note = | ||
Note.{ def with typ = T.Async (s, typ1, typ e); | ||
eff = T.(if s = Fut then Await else Triv) } | ||
} | ||
|
||
let awaitE s e = | ||
let (s, _ , typ) = T.as_async (T.normalize (typ e)) in | ||
{ it = PrimE (AwaitPrim s, [e]); | ||
at = no_region; | ||
note = Note.{ def with typ; eff = T.Await } | ||
} | ||
|
||
let cps_asyncE s typ1 typ2 e = | ||
{ it = PrimE (CPSAsync (s, typ1), [e]); | ||
let nullE () = | ||
{ it = LitE NullLit; | ||
at = no_region; | ||
note = Note.{ def with typ = T.(Prim Null) } | ||
} | ||
|
||
let cps_asyncE s typ1 par typ2 e = | ||
{ it = PrimE (CPSAsync (s, typ1, if s = T.Fut then par else nullE ()), [e]); | ||
at = no_region; | ||
note = Note.{ def with typ = T.Async (s, typ1, typ2); eff = eff e } | ||
} | ||
|
@@ -197,10 +200,10 @@ let ic_rejectE e = | |
note = Note.{ def with typ = T.unit; eff = eff e } | ||
} | ||
|
||
let ic_callE f e k r c = | ||
let ic_callE s f e k r c = | ||
let es = [f; e; k; r; c] in | ||
let eff = map_max_effs eff es in | ||
{ it = PrimE (ICCallPrim, es); | ||
{ it = PrimE (ICCallPrim s, es); | ||
at = no_region; | ||
note = Note.{ def with typ = T.unit; eff } | ||
} | ||
|
@@ -267,7 +270,7 @@ let blockE decs exp = | |
let nat32E n = | ||
{ it = LitE (Nat32Lit n); | ||
at = no_region; | ||
note = Note.{ def with typ = T.(Prim Nat32) } | ||
note = Note.{ def with typ = T.nat32 } | ||
} | ||
|
||
let nat64E n = | ||
|
@@ -306,12 +309,6 @@ let boolE b = | |
note = Note.{ def with typ = T.bool } | ||
} | ||
|
||
let nullE () = | ||
{ it = LitE NullLit; | ||
at = no_region; | ||
note = Note.{ def with typ = T.Prim T.Null } | ||
} | ||
|
||
|
||
(* Functions *) | ||
|
||
|
@@ -329,14 +326,24 @@ let funcE name sort ctrl typ_binds args typs exp = | |
note = Note.{ def with typ; eff = T.Triv }; | ||
} | ||
|
||
let recordE' = ref (fun _ -> nullE ()) (* gets correctly filled below *) | ||
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 |
||
|
||
let asyncE s typ_bind e typ1 = | ||
{ it = AsyncE (None, s, typ_bind, e, typ1); | ||
at = no_region; | ||
note = | ||
Note.{ def with typ = T.Async (s, typ1, typ e); | ||
eff = T.(if s = Fut then Await else Triv) } | ||
} | ||
|
||
let callE exp1 typs exp2 = | ||
let typ = match T.promote (typ exp1) with | ||
| T.Func (_sort, control, _, _, ret_tys) -> | ||
T.codom control (fun () -> List.hd typs) (List.map (T.open_ typs) ret_tys) | ||
| T.Non -> T.Non | ||
| _ -> raise (Invalid_argument "callE expect a function") | ||
in | ||
let p = CallPrim typs in | ||
let p = CallPrim (typs, !recordE' []) in | ||
let es = [exp1; exp2] in | ||
{ it = PrimE (p, es); | ||
at = no_region; | ||
|
@@ -346,6 +353,10 @@ let callE exp1 typs exp2 = | |
} | ||
} | ||
|
||
let parenthetical par = function | ||
| { it = PrimE (CallPrim (typs, _), es); _ } as e when true -> | ||
{ e with it = PrimE (CallPrim (typs, par), es) } | ||
| e -> Printf.eprintf "PAR? %s\n" (Wasm.Sexpr.to_string 180 (Arrange_ir.exp e)); e | ||
|
||
let ifE exp1 exp2 exp3 = | ||
{ it = IfE (exp1, exp2, exp3); | ||
|
@@ -368,7 +379,7 @@ let orE : Ir.exp -> Ir.exp -> Ir.exp = fun e1 e2 -> | |
let impliesE : Ir.exp -> Ir.exp -> Ir.exp = fun e1 e2 -> | ||
orE (notE e1) e2 | ||
let oldE : Ir.exp -> Ir.exp = fun e -> | ||
{ it = (primE (CallPrim [typ e]) [e]).it; | ||
{ it = (primE (CallPrim ([typ e], !recordE' [])) [e]).it; | ||
at = no_region; | ||
note = Note.{ def with | ||
typ = typ e; | ||
|
@@ -384,7 +395,7 @@ let dotE exp name typ = | |
{ it = PrimE (DotPrim name, [exp]); | ||
at = no_region; | ||
note = Note.{ def with | ||
typ = typ; | ||
typ; | ||
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 out? |
||
eff = eff exp | ||
} | ||
} | ||
|
@@ -491,6 +502,9 @@ let assignE v exp2 = | |
note = Note.{ def with typ = T.unit; eff = eff exp2 }; | ||
} | ||
|
||
let assignVarE v exp = | ||
assignE (var v T.(Mut (typ exp |> as_immut))) exp | ||
|
||
let labelE l typ exp = | ||
{ it = LabelE (l, typ, exp); | ||
at = no_region; | ||
|
@@ -799,6 +813,8 @@ let objE sort typ_flds flds = | |
|
||
let recordE flds = objE T.Object [] flds | ||
|
||
let _ = recordE' := recordE | ||
|
||
let check_call_perform_status success mk_failure = | ||
ifE | ||
(callE | ||
|
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