Skip to content

Commit 3656304

Browse files
refactor: threads an extra 'implicit label' through types
1 parent 4c0ac9b commit 3656304

File tree

21 files changed

+202
-170
lines changed

21 files changed

+202
-170
lines changed

src/docs/html.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ and html_of_typ_field : env -> Syntax.typ_field -> t =
172172
fun env field ->
173173
(* TODO mut might be wrong here *)
174174
match field.Source.it with
175-
| Syntax.ValF (id, typ, mut) ->
175+
(* TODO display implicit name *)
176+
| Syntax.ValF (id, _, typ, mut) ->
176177
html_of_mut mut ++ string (id.Source.it ^ " : ") ++ html_of_type env typ
177178
| Syntax.TypF (id, tbs, typ) ->
178179
let ty_args = html_of_typ_binders env tbs in

src/docs/plain.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ and plain_of_typ_field :
190190
Buffer.t -> render_functions -> Syntax.typ_field -> unit =
191191
fun buf rf field ->
192192
match field.Source.it with
193-
| Syntax.ValF (id, typ, mut) ->
193+
(* TODO display implicit name *)
194+
| Syntax.ValF (id, _, typ, mut) ->
194195
plain_of_mut buf mut;
195196
bprintf buf "%s : " id.it;
196197
plain_of_typ buf rf typ

src/ir_def/check_ir.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ let rec check_exp env (exp:Ir.exp) : unit =
497497
| OptPrim, [exp1] ->
498498
T.Opt (typ exp1) <: t
499499
| TagPrim i, [exp1] ->
500-
T.Variant [{T.lab = i; typ = typ exp1; src = T.empty_src}] <: t
500+
T.Variant [{T.lab = i; implicit_lab = None; typ = typ exp1; src = T.empty_src}] <: t
501501
| ActorDotPrim n, [exp1]
502502
| DotPrim n, [exp1] ->
503503
begin
@@ -1102,7 +1102,7 @@ and check_pat_fields env t = List.iter (check_pat_field env t)
11021102

11031103
and check_pat_field env t (pf : pat_field) =
11041104
let lab = pf.it.name in
1105-
let tf = T.{lab; typ = pf.it.pat.note; src = empty_src} in
1105+
let tf = T.{lab; implicit_lab = None; typ = pf.it.pat.note; src = empty_src} in
11061106
let s, tfs = T.as_obj_sub [lab] t in
11071107
let (<:) = check_sub env pf.it.pat.at in
11081108
t <: T.Obj (s, [tf]);
@@ -1137,7 +1137,7 @@ and type_exp_field env s f : T.field =
11371137
check env f.at ((s = T.Actor) ==> T.is_shared_func t)
11381138
"public actor field must have shared function type";
11391139
end;
1140-
T.{lab = name; typ = t; src = empty_src}
1140+
T.{lab = name; implicit_lab = None; typ = t; src = empty_src}
11411141

11421142
(* Declarations *)
11431143

src/ir_def/construct.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ let optE e =
239239

240240
let tagE i e =
241241
{ it = PrimE (TagPrim i, [e]);
242-
note = Note.{ def with typ = T.Variant [{T.lab = i; typ = typ e; src = T.empty_src}]; eff = eff e };
242+
note = Note.{ def with typ = T.Variant [{T.lab = i; implicit_lab = None; typ = typ e; src = T.empty_src}]; eff = eff e };
243243
at = no_region;
244244
}
245245

src/ir_passes/async.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ let transform prog =
238238

239239
and t_prim p = Ir.map_prim t_typ (fun id -> id) p
240240

241-
and t_field {lab; typ; src} =
242-
{ lab; typ = t_typ typ; src }
241+
and t_field {lab; implicit_lab; typ; src} =
242+
{ lab; implicit_lab; typ = t_typ typ; src }
243243
in
244244

245245
let rec t_exp (exp: exp) =

src/ir_passes/erase_typ_field.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ let transform prog =
8888

8989
and t_prim p = Ir.map_prim t_typ Fun.id p
9090

91-
and t_field {lab; typ; src} =
92-
{ lab; typ = t_typ typ; src }
91+
and t_field {lab; implicit_lab; typ; src} =
92+
{ lab; implicit_lab; typ = t_typ typ; src }
9393
in
9494

9595
let rec t_exp (exp : exp) =

src/lowering/desugar.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ and call_system_func_opt name es obj_typ =
442442
let msg = fresh_var "msg" msg_typ in
443443
let record_typ =
444444
T.Obj (T.Object, List.sort T.compare_field
445-
[{T.lab = "caller"; T.typ = typ_of_var caller; T.src = T.empty_src};
446-
{T.lab = "arg"; T.typ = typ_of_var arg; T.src = T.empty_src};
447-
{T.lab = "msg"; T.typ = typ_of_var msg; T.src = T.empty_src}])
445+
[{T.lab = "caller"; implicit_lab = None; T.typ = typ_of_var caller; T.src = T.empty_src};
446+
{T.lab = "arg"; implicit_lab = None; T.typ = typ_of_var arg; T.src = T.empty_src};
447+
{T.lab = "msg"; implicit_lab = None; T.typ = typ_of_var msg; T.src = T.empty_src}])
448448
in
449449
let record = fresh_var "record" record_typ in
450450
let msg_variant =
@@ -511,7 +511,7 @@ and export_footprint self_id expr =
511511
let scope_con2 = Cons.fresh "T2" (Abs ([], Any)) in
512512
let bind1 = typ_arg scope_con1 Scope scope_bound in
513513
let bind2 = typ_arg scope_con2 Scope scope_bound in
514-
let ret_typ = T.Obj(Object,[{lab = "size"; typ = T.nat64; src = empty_src}]) in
514+
let ret_typ = T.Obj(Object,[{lab = "size"; implicit_lab = None; typ = T.nat64; src = empty_src}]) in
515515
let caller = fresh_var "caller" caller in
516516
([ letD (var v typ) (
517517
funcE v (Shared Query) Promises [bind1] [] [ret_typ] (
@@ -620,7 +620,7 @@ and build_actor at ts (exp_opt : Ir.exp option) self_id es obj_typ =
620620
let idss = List.map fst pairs in
621621
let ids = List.concat idss in
622622
let stab_fields = List.sort T.compare_field
623-
(List.map (fun (i, t) -> T.{lab = i; typ = t; src = empty_src}) ids)
623+
(List.map (fun (i, t) -> T.{lab = i; implicit_lab = None; typ = t; src = empty_src}) ids)
624624
in
625625
let mem_fields =
626626
List.map

src/mo_def/arrange.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ module Make (Cfg : Config) = struct
244244
| Stable -> Atom "Stable")
245245

246246
and typ_field (tf : typ_field) = source tf.at (match tf.it with
247-
| ValF (lab, t, m) -> "ValF" $$ [id lab; typ t; mut m]
247+
(* TODO *)
248+
| ValF (lab, implicit_lab, t, m) -> "ValF" $$ [id lab; typ t; mut m]
248249
| TypF (lab, tbs, t) -> "TypF" $$ id lab :: List.map typ_bind tbs @ [typ t])
249250

250251
and typ_item ((id, ty) : typ_item) =

src/mo_def/syntax.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ and typ' =
6666
and scope = typ
6767
and typ_field = typ_field' Source.phrase
6868
and typ_field' =
69-
| ValF of id * typ * mut
69+
| ValF of id * id option * typ * mut
7070
| TypF of typ_id * typ_bind list * typ
7171

7272
and typ_tag = typ_tag' Source.phrase

src/mo_frontend/parser.mly

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ let share_typ t =
145145

146146
let share_typfield' = function
147147
| TypF (c, tps, t) -> TypF (c, tps, t)
148-
| ValF (x, t, m) -> ValF (x, share_typ t, m)
148+
| ValF (x, ix, t, m) -> ValF (x, ix, share_typ t, m)
149149

150150
let share_typfield (tf : typ_field) = { tf with it = share_typfield' tf.it }
151151

@@ -518,11 +518,12 @@ typ_field :
518518
| TYPE c=typ_id tps=type_typ_params_opt EQ t=typ
519519
{ TypF (c, tps, t) @@ at $sloc }
520520
| mut=var_opt x=id COLON t=typ
521-
{ ValF (x, t, mut) @@ at $sloc }
521+
{ ValF (x, None, t, mut) @@ at $sloc }
522522
| x=id tps=typ_params_opt t1=typ_nullary COLON t2=typ
523523
{ let t = funcT(Type.Local @@ no_region, tps, t1, t2)
524524
@! span x.at t2.at in
525-
ValF (x, t, Const @@ no_region) @@ at $sloc }
525+
(* TODO *)
526+
ValF (x, None, t, Const @@ no_region) @@ at $sloc }
526527

527528
typ_tag :
528529
| HASH x=id t=annot_opt
@@ -1089,11 +1090,11 @@ typ_dec :
10891090

10901091
stab_field :
10911092
| STABLE mut=var_opt x=id COLON t=typ
1092-
{ ValF (x, t, mut) @@ at $sloc }
1093+
{ ValF (x, None, t, mut) @@ at $sloc }
10931094

10941095
pre_stab_field :
10951096
| r=req mut=var_opt x=id COLON t=typ
1096-
{ (r, ValF (x, t, mut) @@ at $sloc) }
1097+
{ (r, ValF (x, None, t, mut) @@ at $sloc) }
10971098

10981099
%inline req :
10991100
| STABLE { false @@ at $sloc }

0 commit comments

Comments
 (0)