Skip to content

Commit

Permalink
♻️ Factor out semantic functions and use %sexp_of for brevity
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeta611 committed Feb 6, 2025
1 parent 3f6f420 commit ba66a5f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 30 deletions.
2 changes: 2 additions & 0 deletions lib/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(library
(name react_trace)
(preprocess
(pps ppx_jane))
(libraries recorder_intf base logs flow_parser lib_domains))
52 changes: 28 additions & 24 deletions lib/interp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -279,33 +279,35 @@ let rec eval_mult : type a. ?re_render:int -> a Expr.t -> value =
ptph_h ~ptph:(path, P_retry) (eval_mult ~re_render) expr
| Idle | Update -> v

let alloc_child (path : Path.t) ?(idx : int option) (vs : view_spec) : tree =
Logger.alloc vs;
let t =
match vs with
| Vs_null -> Leaf_null
| Vs_int i -> Leaf_int i
| Vs_comp comp_spec ->
let pt = perform Alloc_pt in
let part_view =
Node
{
comp_spec;
dec = Idle;
st_store = St_store.empty;
eff_q = Job_q.empty;
}
in
perform (Update_ent (pt, { part_view; children = [] }));
Path pt
in
let alloc_tree (vs : view_spec) : tree =
Logger.alloc_tree vs;
match vs with
| Vs_null -> Leaf_null
| Vs_int i -> Leaf_int i
| Vs_comp comp_spec ->
let pt = perform Alloc_pt in
let part_view =
Node
{
comp_spec;
dec = Idle;
st_store = St_store.empty;
eff_q = Job_q.empty;
}
in
perform (Update_ent (pt, { part_view; children = [] }));
Path pt

let mount_tree (path : Path.t) ?(idx : int option) (tree : tree) : unit =
Logger.mount_tree path ?idx tree;
let ({ children; _ } as ent) = perform (Lookup_ent path) in
let children =
let open Snoc_list in
match idx with None -> children ||> t | Some i -> replace children i t
match idx with
| None -> children ||> tree
| Some i -> replace children i tree
in
perform (Update_ent (path, { ent with children }));
t
perform (Update_ent (path, { ent with children }))

let rec render (path : Path.t) (vss : view_spec list) : unit =
Logger.render path vss;
Expand All @@ -329,7 +331,9 @@ and render1 (vs : view_spec) (t : tree) : unit =

and alloc_child_and_render1 (path : Path.t) ?(idx : int option) (vs : view_spec)
: unit =
alloc_child path ?idx vs |> render1 vs
let t = alloc_tree vs in
mount_tree path ?idx t;
render1 vs t

let rec update (path : Path.t) (arg : value option) : bool =
Logger.update path;
Expand Down
19 changes: 13 additions & 6 deletions lib/logger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,20 @@ let eval expr =
let eval_mult expr =
Logs.debug (fun m -> m "eval_mult %a" Sexp.pp_hum (Expr.sexp_of_t expr))

let alloc vs =
Logs.debug (fun m -> m "alloc [vs: %a]" Sexp.pp (sexp_of_view_spec vs))
let alloc_tree vs =
Logs.debug (fun m -> m "alloc_tree [vs: %a]" Sexp.pp (sexp_of_view_spec vs))

let mount_tree path ?idx tree =
Logs.debug (fun m ->
m "mount_tree [path: %a, idx: %a, tree: %a]" Sexp.pp (Path.sexp_of_t path)
Sexp.pp
([%sexp_of: int option] idx)
Sexp.pp (sexp_of_tree tree))

let render path vss =
Logs.debug (fun m ->
m "render [path: %a, vss: %a]" Sexp.pp (Path.sexp_of_t path) Sexp.pp
(List.sexp_of_t sexp_of_view_spec vss))
([%sexp_of: view_spec list] vss))

let render1 vs =
Logs.debug (fun m -> m "render1 [vs: %a]" Sexp.pp (sexp_of_view_spec vs))
Expand All @@ -129,14 +136,14 @@ let reconcile path old_trees vss =
Logs.debug (fun m ->
m "reconcile [path: %a, old_trees: %a, vss: %a]" Sexp.pp
(Path.sexp_of_t path) Sexp.pp
(List.sexp_of_t (Option.sexp_of_t sexp_of_tree) old_trees)
([%sexp_of: tree option list] old_trees)
Sexp.pp
(List.sexp_of_t sexp_of_view_spec vss))
([%sexp_of: view_spec list] vss))

let reconcile1 old_tree vs =
Logs.debug (fun m ->
m "reconcile1 [old_tree: %a, vs: %a]" Sexp.pp
((Option.sexp_of_t sexp_of_tree) old_tree)
([%sexp_of: tree option] old_tree)
Sexp.pp (sexp_of_view_spec vs))

let commit_effs path =
Expand Down

0 comments on commit ba66a5f

Please sign in to comment.