@@ -22,12 +22,13 @@ module Make (Edge : EDGE) = struct
2222 and s =
2323 | Ok
2424 | Skip
25+ | Todo
2526 | Error of string
2627 | Branch of t M. t
27- | Todo
2828
2929 let min_depth t = t.todo
3030 let nb_todos t = t.nb
31+ let nb_oks t = t.nb_ok
3132 let has_error t = t.error
3233
3334 let min_todo a b = match a, b with
@@ -57,9 +58,22 @@ module Make (Edge : EDGE) = struct
5758
5859 let simplify t =
5960 match t.s with
60- | Branch children when M. for_all (fun _ c -> c.s = Ok ) children ->
61- assert (t.nb_ok > 0 ) ;
62- ok t.nb_ok
61+ | _ when t.error || t.todo <> None -> t
62+ | Branch children ->
63+ let ok_children, has_skip = ref 0 , ref false in
64+ M. iter
65+ (fun _ c -> match c.s with
66+ | Ok -> incr ok_children
67+ | Skip -> has_skip := true
68+ | Branch _ ->
69+ assert (c.todo = None ) ;
70+ assert (c.error = false ) ;
71+ assert (c.nb_ok > 0 )
72+ | _ -> assert false )
73+ children ;
74+ if ! ok_children = 1 && ! has_skip
75+ then t
76+ else ok t.nb_ok
6377 | _ -> t
6478
6579 let add edge child t =
@@ -74,7 +88,7 @@ module Make (Edge : EDGE) = struct
7488 edges
7589 todo
7690
77- let rec insert_todos ~skip_edge todos t =
91+ let insert_todos ~skip_edge todos t =
7892 match t.s, todos with
7993 | Todo , []
8094 | Skip , _
@@ -83,22 +97,14 @@ module Make (Edge : EDGE) = struct
8397 t
8498 | Todo , todos -> todolist ~skip_edge todos
8599 | Branch m , edge ::todos ->
86- assert (Edge. compare skip_edge edge <> 0 ) ;
87- let m = match M. find_opt edge m with
88- | None ->
89- let t = todolist ~skip_edge todos in
90- M. add edge t m
91- | Some child ->
92- let child = insert_todos ~skip_edge todos child in
93- M. add edge child m
94- in
95- let m =
96- if M. mem skip_edge m
97- then m
98- else M. add skip_edge skip m
99- in
100- assert (M. mem skip_edge m) ;
101- branch m
100+ if M. mem edge m
101+ then t
102+ else begin
103+ let t = todolist ~skip_edge todos in
104+ let m = M. add edge t m in
105+ assert (M. mem skip_edge m) ;
106+ branch m
107+ end
102108
103109 let next t = match t.todo, t.s with
104110 | None , _ -> None
0 commit comments