Skip to content

Commit

Permalink
move a few type definitions
Browse files Browse the repository at this point in the history
review feedback
  • Loading branch information
ggreif committed Jan 15, 2025
1 parent 021dfcb commit 980cd23
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/ir_passes/await.ml
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ and t_ignore_throw context exp = t_on_throw context exp (tupE[])
(* if self-call queue full: expire global timer soon and retry *)
and t_timer_throw context exp =
t_on_throw context exp
(blockE [expD (primE
(blockE
[expD (primE
(OtherPrim "global_timer_set")
[Mo_values.Numerics.Nat64.of_int 1 |> nat64E])]
(tupE[]))
Expand Down
4 changes: 2 additions & 2 deletions src/lowering/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ and call_system_func_opt name es obj_typ =
let timer =
blockE
[ expD T.(callE (varE (var id.it note)) [Any]
(varE (var "@set_global_timer" Mo_frontend.Typing.global_timer_set_type))) ]
(varE (var "@set_global_timer" T.global_timer_set_type))) ]
(unitE()) in
{ timer with at }
| "heartbeat" ->
Expand Down Expand Up @@ -605,7 +605,7 @@ and build_actor at ts self_id es obj_typ =
| Some call -> call
| None when !Mo_config.Flags.global_timer ->
blockE
[ expD T.(callE (varE (var "@timer_helper" Mo_frontend.Typing.heartbeat_type)) [unit] (unitE())) ]
[ expD T.(callE (varE (var "@timer_helper" T.heartbeat_type)) [unit] (unitE())) ]
(unitE())
| None -> tupE []);
inspect =
Expand Down
14 changes: 2 additions & 12 deletions src/mo_frontend/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -386,20 +386,10 @@ let infer_mut mut : T.typ -> T.typ =

(* System method types *)

let heartbeat_type =
T.(Func (Local, Returns, [scope_bind], [], [Async (Fut, Var (default_scope_var, 0), unit)]))

let global_timer_set_type = T.(Func (Local, Returns, [], [Prim Nat64], []))

let timer_type =
T.(Func (Local, Returns, [scope_bind],
[global_timer_set_type],
[Async (Fut, Var (default_scope_var, 0), unit)]))

let system_funcs tfs =
[
("heartbeat", heartbeat_type);
("timer", timer_type);
("heartbeat", T.heartbeat_type);
("timer", T.timer_type);
T.("preupgrade", Func (Local, Returns, [scope_bind], [], []));
T.("postupgrade", Func (Local, Returns, [scope_bind], [], []));
("inspect",
Expand Down
3 changes: 0 additions & 3 deletions src/mo_frontend/typing.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ val infer_prog : ?viper_mode:bool -> scope -> string option -> Async_cap.async_c
val check_lib : scope -> string option -> Syntax.lib -> scope Diag.result
val check_actors : ?viper_mode:bool -> ?check_actors:bool -> scope -> Syntax.prog list -> unit Diag.result
val check_stab_sig : scope -> Syntax.stab_sig -> (field list) Diag.result

val heartbeat_type : typ
val global_timer_set_type : typ
16 changes: 15 additions & 1 deletion src/mo_types/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ let compare_field f1 f2 =
| {lab = l1; typ = _; _}, {lab = l2; typ = _; _} -> compare l1 l2


(* Short-hands *)
(* Shorthands *)

let unit = Tup []
let bool = Prim Bool
Expand All @@ -321,6 +321,7 @@ let char = Prim Char
let principal = Prim Principal
let region = Prim Region


let fields flds =
List.sort compare_field
(List.map (fun (lab, typ) -> {lab; typ; src = empty_src}) flds)
Expand Down Expand Up @@ -1341,6 +1342,19 @@ let default_scope_var = scope_var ""
let scope_bound = Any
let scope_bind = { var = default_scope_var; sort = Scope; bound = scope_bound }

(* Shorthands for replica callbacks *)

let heartbeat_type =
Func (Local, Returns, [scope_bind], [], [Async (Fut, Var (default_scope_var, 0), unit)])

let global_timer_set_type = Func (Local, Returns, [], [Prim Nat64], [])

let timer_type =
Func (Local, Returns, [scope_bind],
[global_timer_set_type],
[Async (Fut, Var (default_scope_var, 0), unit)])


(* Well-known fields *)

let motoko_async_helper_fld =
Expand Down
5 changes: 4 additions & 1 deletion src/mo_types/type.mli
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ end
val is_shared_sort : 'a shared -> bool


(* Short-hands *)
(* Shorthands *)

val unit : typ
val bool : typ
Expand All @@ -97,6 +97,9 @@ val error : typ
val char : typ
val principal : typ
val region : typ
val heartbeat_type : typ
val timer_type : typ
val global_timer_set_type : typ

val sum : (lab * typ) list -> typ
val obj : obj_sort -> (lab * typ) list -> typ
Expand Down

0 comments on commit 980cd23

Please sign in to comment.