Skip to content

Commit

Permalink
return option from handler.run
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Oct 3, 2023
1 parent 03f03ed commit 627c3c1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/base/as_prover0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ module Provider = struct

open Types.Provider

let run t stack tbl (handler : Request.Handler.t) =
let run t tbl (handler : Request.Handler.t) =
match t with
| Request rc ->
let r = run rc tbl in
Request.Handler.run handler stack r
Request.Handler.run handler r
| Compute c ->
run c tbl
Some (run c tbl)
| Both (rc, c) -> (
let r = run rc tbl in
match Request.Handler.run handler stack r with
| exception _ ->
run c tbl
match Request.Handler.run handler r with
| None | (exception _) ->
Some (run c tbl)
| x ->
x )
end
Expand Down
3 changes: 1 addition & 2 deletions src/base/as_prover_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ module type Basic = sig

val run :
('a, 'f field) t
-> string list
-> ('f field Cvar.t -> 'f field)
-> Request.Handler.t
-> 'a
-> 'a option
end

module Handle : sig
Expand Down
7 changes: 5 additions & 2 deletions src/base/checked_runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,11 @@ struct
let old = Run_state.as_prover s in
Run_state.set_as_prover s true ;
let value =
As_prover.Provider.run p (Run_state.stack s) (get_value s)
(Run_state.handler s)
As_prover.Provider.run p (get_value s) (Run_state.handler s)
|> Option.value_exn
~message:
( "Unhandled request: "
^ Core_kernel.String.concat ~sep:"\n" (Run_state.stack s) )
in
Run_state.set_as_prover s old ;
let var =
Expand Down
11 changes: 4 additions & 7 deletions src/base/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ module Handler = struct

let fail = []

let run : t -> string list -> 'a req -> 'a =
fun stack0 label_stack req0 ->
let run : t -> 'a req -> 'a option =
fun stack0 req0 ->
let rec go req = function
| [] ->
raise
(Failure
( "Unhandled request: "
^ Core_kernel.String.concat ~sep:"\n" label_stack ) )
None
| { handle } :: hs -> (
match handle req with
| Provide x ->
x
Some x
| Delegate req' ->
go req' hs
| Unhandled ->
Expand Down
2 changes: 1 addition & 1 deletion src/base/request.mli
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ module Handler : sig
val push : t -> single -> t

(** Run the handler on a request. Throws an error on failure. *)
val run : t -> string list -> 'a req -> 'a
val run : t -> 'a req -> 'a option
end

0 comments on commit 627c3c1

Please sign in to comment.