Skip to content

Commit e9cf7b4

Browse files
committed
Track values that have been added to the pc since last fresh check
1 parent dbaed5f commit e9cf7b4

File tree

4 files changed

+40
-34
lines changed

4 files changed

+40
-34
lines changed

src/intf/thread_intf.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module type S = sig
2121
int
2222
-> Symbol_scope.t
2323
-> Symbolic_path_condition.t
24-
-> bool
24+
-> Symbolic_value.bool list
2525
-> Memory.collection
2626
-> Symbolic_table.collection
2727
-> Symbolic_global.collection
@@ -31,9 +31,9 @@ module type S = sig
3131

3232
val pc : t -> Symbolic_path_condition.t
3333

34-
val pc_is_fresh : t -> bool
34+
val pending_pc : t -> Symbolic_value.bool list
3535

36-
val mark_pc_fresh : t -> t
36+
val mark_pending_pc_done : t -> t
3737

3838
val memories : t -> Memory.collection
3939

src/symbolic/symbolic_choice.ml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ module Make (Thread : Thread_intf.S) = struct
382382
let* () = yield in
383383
let* solver in
384384
match Solver.check solver pc with
385-
| `Sat -> modify_thread Thread.mark_pc_fresh
385+
| `Sat -> modify_thread Thread.mark_pending_pc_done
386386
| `Unsat -> stop
387387
| `Unknown -> assert false
388388

@@ -392,17 +392,15 @@ module Make (Thread : Thread_intf.S) = struct
392392
*)
393393
let check_reachability =
394394
let* thread in
395-
if Thread.pc_is_fresh thread then return ()
396-
else
397-
let pc = Thread.pc thread in
398-
stop_if_unreachable (Symbolic_path_condition.to_set pc)
399-
400-
let add_to_pc_and_check_reachability v =
401-
let* () = check_reachability in
402-
let* () = add_pc v in
403-
let* thread in
404-
let pc = Symbolic_path_condition.slice (Thread.pc thread) v in
405-
stop_if_unreachable pc
395+
match Thread.pending_pc thread with
396+
| [] -> return ()
397+
| hd :: tl -> begin
398+
let pc_to_check = List.fold_left Symbolic_value.Bool.and_ hd tl in
399+
let pc_to_check =
400+
Symbolic_path_condition.slice (Thread.pc thread) pc_to_check
401+
in
402+
stop_if_unreachable pc_to_check
403+
end
406404

407405
let get_model_or_stop symbol =
408406
let* () = yield in
@@ -413,7 +411,7 @@ module Make (Thread : Thread_intf.S) = struct
413411
| `Unsat -> stop
414412
| `Sat -> begin
415413
let symbol_scopes = Symbol_scope.of_symbol symbol in
416-
let* () = modify_thread Thread.mark_pc_fresh in
414+
let* () = modify_thread Thread.mark_pending_pc_done in
417415
(* TODO: we are doing the check two times here, because Solver.model is also doing it, we should remove it! *)
418416
let model = Solver.model solver ~symbol_scopes ~pc in
419417
match Smtml.Model.evaluate model symbol with
@@ -433,15 +431,18 @@ module Make (Thread : Thread_intf.S) = struct
433431
| _ ->
434432
let true_branch =
435433
let* () = add_breadcrumb 1 in
436-
let+ () = add_to_pc_and_check_reachability v in
434+
let* () = add_pc v in
435+
let+ () = check_reachability in
437436
true
438437
in
439438
let false_branch =
440439
let neg_v = Symbolic_value.Bool.not v in
441440
let* () = add_breadcrumb 0 in
442-
let+ () = add_to_pc_and_check_reachability neg_v in
441+
let* () = add_pc neg_v in
442+
let+ () = check_reachability in
443443
false
444444
in
445+
let* () = check_reachability in
445446
if explore_first then choose true_branch false_branch
446447
else choose false_branch true_branch
447448
[@@inline]
@@ -494,15 +495,18 @@ module Make (Thread : Thread_intf.S) = struct
494495
in
495496
let this_val_branch =
496497
let* () = add_breadcrumb (Int32.to_int i) in
497-
let+ () = add_pc this_value_cond in
498+
let* () = add_pc this_value_cond in
499+
let+ () = modify_thread Thread.mark_pending_pc_done in
498500
i
499501
in
500502
let not_this_val_branch =
501503
let* () = add_pc not_this_value_cond in
504+
let* () = modify_thread Thread.mark_pending_pc_done in
502505
generator ()
503506
in
504507
choose this_val_branch not_this_val_branch
505508
in
509+
let* () = check_reachability in
506510
generator ()
507511

508512
let assertion c =

src/symbolic/thread.ml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct
1313
{ num_symbols : int
1414
; symbol_scopes : Symbol_scope.t
1515
; pc : Symbolic_path_condition.t
16-
; pc_fresh : bool
16+
; pending_pc : Symbolic_value.bool list
1717
; memories : Memory.collection
1818
; tables : Symbolic_table.collection
1919
; globals : Symbolic_global.collection
@@ -23,12 +23,12 @@ struct
2323
; labels : (int * string) list
2424
}
2525

26-
let create num_symbols symbol_scopes pc pc_fresh memories tables globals
26+
let create num_symbols symbol_scopes pc pending_pc memories tables globals
2727
breadcrumbs labels =
2828
{ num_symbols
2929
; symbol_scopes
3030
; pc
31-
; pc_fresh
31+
; pending_pc
3232
; memories
3333
; tables
3434
; globals
@@ -40,13 +40,13 @@ struct
4040
let num_symbols = 0 in
4141
let symbol_scopes = Symbol_scope.empty in
4242
let pc = Symbolic_path_condition.empty in
43-
let pc_fresh = true in
43+
let pending_pc = [] in
4444
let memories = Memory.init () in
4545
let tables = Symbolic_table.init () in
4646
let globals = Symbolic_global.init () in
4747
let breadcrumbs = [] in
4848
let labels = [] in
49-
create num_symbols symbol_scopes pc pc_fresh memories tables globals
49+
create num_symbols symbol_scopes pc pending_pc memories tables globals
5050
breadcrumbs labels
5151

5252
let num_symbols t = t.num_symbols
@@ -55,9 +55,9 @@ struct
5555

5656
let pc t = t.pc
5757

58-
let pc_is_fresh t = t.pc_fresh
58+
let pending_pc t = t.pending_pc
5959

60-
let mark_pc_fresh t = { t with pc_fresh = true }
60+
let mark_pending_pc_done t = { t with pending_pc = [] }
6161

6262
let memories t = t.memories
6363

@@ -75,7 +75,7 @@ struct
7575

7676
let add_pc t c =
7777
let pc = Symbolic_path_condition.add t.pc c in
78-
{ t with pc; pc_fresh = false }
78+
{ t with pc; pending_pc = c :: t.pending_pc }
7979

8080
let add_breadcrumb t crumb =
8181
let breadcrumbs = crumb :: t.breadcrumbs in
@@ -99,20 +99,22 @@ struct
9999
{ num_symbols
100100
; symbol_scopes
101101
; pc
102-
; pc_fresh
102+
; pending_pc
103103
; memories
104104
; tables
105105
; globals
106106
; breadcrumbs
107107
; labels
108108
} =
109+
if not @@ List.is_empty pending_pc then
110+
Fmt.epr "Warning: cloning thread with a non empty pending pc";
109111
let memories = Memory.clone memories in
110112
let tables = Symbolic_table.clone tables in
111113
let globals = Symbolic_global.clone globals in
112114
{ num_symbols
113115
; symbol_scopes
114116
; pc
115-
; pc_fresh
117+
; pending_pc
116118
; memories
117119
; tables
118120
; globals

src/symbolic/thread_with_memory.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ let project (th : t) : Thread_without_memory.t * _ =
99
let num_symbols = num_symbols th in
1010
let symbol_scopes = symbol_scopes th in
1111
let pc = pc th in
12-
let pc_fresh = pc_is_fresh th in
12+
let pending_pc = pending_pc th in
1313
let memories = Thread_without_memory.Memory.init () in
1414
let tables = tables th in
1515
let globals = globals th in
1616
let breadcrumbs = breadcrumbs th in
1717
let labels = labels th in
18-
Thread_without_memory.create num_symbols symbol_scopes pc pc_fresh memories
19-
tables globals breadcrumbs labels
18+
Thread_without_memory.create num_symbols symbol_scopes pc pending_pc
19+
memories tables globals breadcrumbs labels
2020
in
2121
let backup = memories th in
2222
(projected, backup)
@@ -25,7 +25,7 @@ let restore backup th =
2525
let num_symbols = Thread_without_memory.num_symbols th in
2626
let symbol_scopes = Thread_without_memory.symbol_scopes th in
2727
let pc = Thread_without_memory.pc th in
28-
let pc_fresh = Thread_without_memory.pc_is_fresh th in
28+
let pending_pc = Thread_without_memory.pending_pc th in
2929
let memories =
3030
if Thread_without_memory.memories th then
3131
Symbolic_memory_concretizing.clone backup
@@ -35,5 +35,5 @@ let restore backup th =
3535
let globals = Thread_without_memory.globals th in
3636
let breadcrumbs = Thread_without_memory.breadcrumbs th in
3737
let labels = Thread_without_memory.labels th in
38-
create num_symbols symbol_scopes pc pc_fresh memories tables globals
38+
create num_symbols symbol_scopes pc pending_pc memories tables globals
3939
breadcrumbs labels

0 commit comments

Comments
 (0)