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

bugfix: check that timer servicing worked #4846

Merged
merged 11 commits into from
Jan 17, 2025
10 changes: 7 additions & 3 deletions src/lowering/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,10 @@ 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" (Func (Local, Returns, [], [Prim Nat64], []))))) ]
(unitE ()) in
(varE (var "@set_global_timer" Mo_frontend.Typing.global_timer_set_type))) ]
T.(callE
(varE (var "@check_timer_send" (Func (Local, Returns, [], [], [])))) []
(unitE())) in
{ timer with at }
| "heartbeat" ->
blockE
Expand Down Expand Up @@ -606,7 +608,9 @@ and build_actor at ts self_id es obj_typ =
| None when !Mo_config.Flags.global_timer ->
blockE
[ expD T.(callE (varE (var "@timer_helper" Mo_frontend.Typing.heartbeat_type)) [unit] (unitE())) ]
(unitE ())
T.(callE
(varE (var "@check_timer_send" (Func (Local, Returns, [], [], [])))) []
(unitE()))
| None -> tupE []);
inspect =
(match call_system_func_opt "inspect" es obj_typ with
Expand Down
4 changes: 3 additions & 1 deletion src/mo_frontend/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ let infer_mut mut : T.typ -> T.typ =
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],
[Func (Local, Returns, [], [Prim Nat64], [])],
[global_timer_set_type],
[Async (Fut, Var (default_scope_var, 0), unit)]))

let system_funcs tfs =
Expand Down
1 change: 1 addition & 0 deletions src/mo_frontend/typing.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ val check_actors : ?viper_mode:bool -> ?check_actors:bool -> scope -> Syntax.pro
val check_stab_sig : scope -> Syntax.stab_sig -> (field list) Diag.result

val heartbeat_type : typ
val global_timer_set_type : typ
ggreif marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 9 additions & 1 deletion src/prelude/internals.mo
Original file line number Diff line number Diff line change
Expand Up @@ -675,5 +675,13 @@ func @cancelTimer(id : Nat) {
}
};


func @set_global_timer(time : Nat64) = ignore (prim "global_timer_set" : Nat64 -> Nat64) time;

// Function called by backend to check if self-send worked.
// DO NOT RENAME without modifying compilation.
func @check_timer_send() {
if (not @call_succeeded()) {
ggreif marked this conversation as resolved.
Show resolved Hide resolved
// i.e. self-call queue full: expire soon and retry
ignore (prim "global_timer_set" : Nat64 -> Nat64) 1;
}
};
Loading