From 7cb6cf053e6ea62c27017b6214c92ecb90507669 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 10 Dec 2024 14:05:15 +0100 Subject: [PATCH] WIP: `timeout` for one-shot calls this probably doesn't make much sense --- src/codegen/compile_classical.ml | 11 +++++++---- test/run-drun/ok/par.tc.ok | 2 +- test/run-drun/par.mo | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/codegen/compile_classical.ml b/src/codegen/compile_classical.ml index 14629b66201..3f6308136b8 100644 --- a/src/codegen/compile_classical.ml +++ b/src/codegen/compile_classical.ml @@ -10958,16 +10958,19 @@ 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 has attr attrs = None <> List.find_opt (fun Type.{lab; _} -> attr = lab) attrs 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 + | Object, attrs when has "cycles" attrs -> compile_exp_vanilla env ae par ^^ Object.load_idx env par.note.Note.typ "cycles" ^^ Cycles.add env (* parenthetical FIXME: effects! *) + | _ -> Internals.add_cycles env ae) (* legacy *) in + let add_timeout = Type.(match as_obj par.note.Note.typ with + | Object, attrs when has "timeout" attrs -> compile_exp_vanilla env ae par ^^ Object.load_idx env par.note.Note.typ "timeout" ^^ BitTagged.untag_i32 __LINE__ env Type.Nat32 ^^ IC.system_call env "call_with_best_effort_response" (* parenthetical FIXME: effects! *) + | _ -> G.nop) in StackRep.of_arity return_arity, code1 ^^ StackRep.adjust env fun_sr SR.Vanilla ^^ set_meth_pair ^^ compile_exp_vanilla env ae e2 ^^ set_arg ^^ - FuncDec.ic_call_one_shot env ts get_meth_pair get_arg add_cycles + FuncDec.ic_call_one_shot env ts get_meth_pair get_arg (add_cycles ^^ add_timeout) end (* Operators *) diff --git a/test/run-drun/ok/par.tc.ok b/test/run-drun/ok/par.tc.ok index a4c453f17d3..9b5cf6f072e 100644 --- a/test/run-drun/ok/par.tc.ok +++ b/test/run-drun/ok/par.tc.ok @@ -1 +1 @@ -par.mo:55.9-55.67: warning [M0204], unrecognised attribute yeah in parenthetical note +par.mo:56.9-56.67: warning [M0204], unrecognised attribute yeah in parenthetical note diff --git a/test/run-drun/par.mo b/test/run-drun/par.mo index 217dbc8e74c..09006a38666 100644 --- a/test/run-drun/par.mo +++ b/test/run-drun/par.mo @@ -14,6 +14,7 @@ actor A { }; public func oneshot() { + assert 0 : Nat64 == replyDeadline(); debugPrint ("oneshot: " # debug_show(Cycles.available())); }; @@ -67,6 +68,7 @@ actor A { debugPrint "test3()"; oneshot(); (with cycles = 3456) oneshot(); + (with timeout = 5) oneshot(); // FIXME: DUBIOUS! }; public func test4() : async () {