Skip to content

Commit 5375983

Browse files
committed
cut trie branches to minimize memory consumption
1 parent 238a7e6 commit 5375983

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

src/tracedAtomic.ml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,20 +413,19 @@ let round_robin previous =
413413
let rec explore func time state trie current_schedule (last_read, last_write) =
414414
let s = List.hd state in
415415
assert (IdMap.is_empty s.backtrack) ;
416-
let existed, todo_next =
417-
begin match T.next trie with
416+
let todo_next =
417+
match T.next trie with
418418
| None ->
419419
begin match round_robin s with
420420
| None ->
421421
assert (IdSet.is_empty s.enabled) ;
422-
false, None
422+
None
423423
| Some p ->
424424
let init_step = IdMap.find p s.procs in
425-
false, Some (init_step, T.todo)
425+
Some (init_step, T.todo)
426426
end
427427
| Some (step, new_trie) ->
428-
true, Some (step, new_trie)
429-
end
428+
Some (step, new_trie)
430429
in
431430
match todo_next with
432431
| None -> false, T.ok 1
@@ -443,7 +442,8 @@ let rec explore func time state trie current_schedule (last_read, last_write) =
443442
:: state
444443
in
445444
let new_time = time + 1 in
446-
mark_backtrack step.run new_time new_state (last_read, last_write);
445+
if T.nb_oks new_trie = 0 && not (T.has_error new_trie)
446+
then mark_backtrack step.run new_time new_state (last_read, last_write);
447447
let add ptr map =
448448
IdMap.update
449449
ptr
@@ -482,7 +482,6 @@ let rec explore func time state trie current_schedule (last_read, last_write) =
482482
Printexc.print_backtrace stdout ;
483483
print_trace () ;
484484

485-
assert (not existed) ;
486485
true, trie
487486
end
488487

@@ -528,5 +527,5 @@ let trace func =
528527
print_header () ;
529528
num_runs := 0 ;
530529
let _ = explore_all func T.todo in
531-
Format.printf "@.Found %i errors after %i runs.@." !error_count !num_runs ;
530+
Format.printf "@.Found %#i errors after %#i runs.@." !error_count !num_runs ;
532531
()

src/trie.ml

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)