Skip to content

Commit

Permalink
WIP: timeout for one-shot calls
Browse files Browse the repository at this point in the history
this probably doesn't make much sense
  • Loading branch information
ggreif committed Dec 10, 2024
1 parent 2e58517 commit 7cb6cf0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/codegen/compile_classical.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
2 changes: 1 addition & 1 deletion test/run-drun/ok/par.tc.ok
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/run-drun/par.mo
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ actor A {
};

public func oneshot() {
assert 0 : Nat64 == replyDeadline();
debugPrint ("oneshot: " # debug_show(Cycles.available()));
};

Expand Down Expand Up @@ -67,6 +68,7 @@ actor A {
debugPrint "test3()";
oneshot();
(with cycles = 3456) oneshot();
(with timeout = 5) oneshot(); // FIXME: DUBIOUS!
};

public func test4() : async () {
Expand Down

0 comments on commit 7cb6cf0

Please sign in to comment.