Skip to content

Commit b6f6418

Browse files
committed
Store pc freshness in thread
1 parent fcf6a06 commit b6f6418

File tree

4 files changed

+83
-42
lines changed

4 files changed

+83
-42
lines changed

src/intf/thread_intf.ml

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module type S = sig
2121
int
2222
-> Smtml.Symbol.t list
2323
-> Symbolic_value.bool list
24+
-> bool
2425
-> Memory.collection
2526
-> Symbolic_table.collection
2627
-> Symbolic_global.collection
@@ -29,6 +30,10 @@ module type S = sig
2930

3031
val pc : t -> Symbolic_value.bool list
3132

33+
val pc_is_fresh : t -> bool
34+
35+
val mark_pc_fresh : t -> t
36+
3237
val memories : t -> Memory.collection
3338

3439
val tables : t -> Symbolic_table.collection

src/symbolic/symbolic_choice.ml

+35-32
Original file line numberDiff line numberDiff line change
@@ -381,38 +381,41 @@ module Make (Thread : Thread.S) = struct
381381
~other_machine:n_chck.other_machine )
382382
| None -> default
383383
in
384-
let* () = yield in
385384
let* thread in
386-
let* solver in
387-
let interrupter = fun () -> Solver.interrupt solver in
388-
let other_unsat =
389-
on_n_chck false (fun ~self_machine ~other_machine ->
390-
match !other_machine with
391-
| Done `Unsat -> true
392-
| Done `SatOrUnknown -> false
393-
| Init | Running _ ->
394-
self_machine := Running interrupter;
395-
false )
396-
in
397-
let pc = Thread.pc thread in
398-
let our_result = if other_unsat then `Sat else Solver.check solver pc in
399-
match our_result with
400-
| `Sat ->
401-
on_n_chck () (fun ~self_machine ~other_machine:_ ->
402-
self_machine := Done `SatOrUnknown );
403-
return ()
404-
| `Unsat ->
405-
on_n_chck () (fun ~self_machine ~other_machine ->
406-
self_machine := Done `Unsat;
407-
match !other_machine with Running inter -> inter () | _ -> () );
408-
stop
409-
| `Unknown ->
410-
(* Unknown is what is returned when interrupted *)
411-
on_n_chck stop (fun ~self_machine ~other_machine ->
412-
self_machine := Done `SatOrUnknown;
413-
match !other_machine with
414-
| Init | Done `SatOrUnknown | Running _ -> stop
415-
| Done `Unsat -> return () )
385+
let pc_fresh = Thread.pc_is_fresh thread in
386+
if pc_fresh then return ()
387+
else
388+
let* () = yield in
389+
let* solver in
390+
let interrupter = fun () -> Solver.interrupt solver in
391+
let other_unsat =
392+
on_n_chck false (fun ~self_machine ~other_machine ->
393+
match !other_machine with
394+
| Done `Unsat -> true
395+
| Done `SatOrUnknown -> false
396+
| Init | Running _ ->
397+
self_machine := Running interrupter;
398+
false )
399+
in
400+
let pc = Thread.pc thread in
401+
let our_result = if other_unsat then `Sat else Solver.check solver pc in
402+
match our_result with
403+
| `Sat ->
404+
on_n_chck () (fun ~self_machine ~other_machine:_ ->
405+
self_machine := Done `SatOrUnknown );
406+
modify_thread Thread.mark_pc_fresh
407+
| `Unsat ->
408+
on_n_chck () (fun ~self_machine ~other_machine ->
409+
self_machine := Done `Unsat;
410+
match !other_machine with Running inter -> inter () | _ -> () );
411+
stop
412+
| `Unknown ->
413+
(* Unknown is what is returned when interrupted *)
414+
on_n_chck stop (fun ~self_machine ~other_machine ->
415+
self_machine := Done `SatOrUnknown;
416+
match !other_machine with
417+
| Init | Done `SatOrUnknown | Running _ -> stop
418+
| Done `Unsat -> modify_thread Thread.mark_pc_fresh )
416419

417420
let get_model_or_stop symbol =
418421
let* () = yield in
@@ -438,7 +441,7 @@ module Make (Thread : Thread.S) = struct
438441
| Val False -> return false
439442
| Val (Num (I32 _)) -> Fmt.failwith "unreachable (type error)"
440443
| _ ->
441-
let* () = check_reachability None in
444+
let* () = check_reachability None in
442445
let machine_a = ref Init in
443446
let machine_b = ref Init in
444447
let mutex = Mutex.create () in

src/symbolic/thread.ml

+38-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Make (Symbolic_memory : M) :
1212
{ symbols : int
1313
; symbol_set : Smtml.Symbol.t list
1414
; pc : Symbolic_value.bool list
15+
; pc_fresh : bool
1516
; memories : Memory.collection
1617
; tables : Symbolic_table.collection
1718
; globals : Symbolic_global.collection
@@ -20,25 +21,39 @@ module Make (Symbolic_memory : M) :
2021
; breadcrumbs : int32 list
2122
}
2223

23-
let create symbols symbol_set pc memories tables globals breadcrumbs =
24-
{ symbols; symbol_set; pc; memories; tables; globals; breadcrumbs }
24+
let create symbols symbol_set pc pc_fresh memories tables globals breadcrumbs
25+
=
26+
{ symbols
27+
; symbol_set
28+
; pc
29+
; pc_fresh
30+
; memories
31+
; tables
32+
; globals
33+
; breadcrumbs
34+
}
2535

2636
let init () =
2737
let symbols = 0 in
2838
let symbol_set = [] in
2939
let pc = [] in
40+
let pc_fresh = true in
3041
let memories = Memory.init () in
3142
let tables = Symbolic_table.init () in
3243
let globals = Symbolic_global.init () in
3344
let breadcrumbs = [] in
34-
create symbols symbol_set pc memories tables globals breadcrumbs
45+
create symbols symbol_set pc pc_fresh memories tables globals breadcrumbs
3546

3647
let symbols t = t.symbols
3748

3849
let symbols_set t = t.symbol_set
3950

4051
let pc t = t.pc
4152

53+
let pc_is_fresh t = t.pc_fresh
54+
55+
let mark_pc_fresh t = { t with pc_fresh = true }
56+
4257
let memories t = t.memories
4358

4459
let tables t = t.tables
@@ -49,16 +64,32 @@ module Make (Symbolic_memory : M) :
4964

5065
let add_symbol t s = { t with symbol_set = s :: t.symbol_set }
5166

52-
let add_pc t c = { t with pc = c :: t.pc }
67+
let add_pc t c = { t with pc = c :: t.pc; pc_fresh = false }
5368

5469
let add_breadcrumb t crumb = { t with breadcrumbs = crumb :: t.breadcrumbs }
5570

5671
let incr_symbols t = { t with symbols = succ t.symbols }
5772

58-
let clone { symbols; symbol_set; pc; memories; tables; globals; breadcrumbs }
59-
=
73+
let clone
74+
{ symbols
75+
; symbol_set
76+
; pc
77+
; pc_fresh
78+
; memories
79+
; tables
80+
; globals
81+
; breadcrumbs
82+
} =
6083
let memories = Memory.clone memories in
6184
let tables = Symbolic_table.clone tables in
6285
let globals = Symbolic_global.clone globals in
63-
{ symbols; symbol_set; pc; memories; tables; globals; breadcrumbs }
86+
{ symbols
87+
; symbol_set
88+
; pc
89+
; pc_fresh
90+
; memories
91+
; tables
92+
; globals
93+
; breadcrumbs
94+
}
6495
end

src/symbolic/thread_with_memory.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ let project (th : t) : Thread_without_memory.t * _ =
99
let symbols = symbols th in
1010
let symbols_set = symbols_set th in
1111
let pc = pc th in
12+
let pc_fresh = pc_is_fresh th in
1213
let memories = Thread_without_memory.Memory.init () in
1314
let tables = tables th in
1415
let globals = globals th in
1516
let breadcrumbs = breadcrumbs th in
16-
Thread_without_memory.create symbols symbols_set pc memories tables globals
17-
breadcrumbs
17+
Thread_without_memory.create symbols symbols_set pc pc_fresh memories tables
18+
globals breadcrumbs
1819
in
1920
let backup = memories th in
2021
(projected, backup)
@@ -23,6 +24,7 @@ let restore backup th =
2324
let symbols = Thread_without_memory.symbols th in
2425
let symbols_set = Thread_without_memory.symbols_set th in
2526
let pc = Thread_without_memory.pc th in
27+
let pc_fresh = Thread_without_memory.pc_is_fresh th in
2628
let memories =
2729
if Thread_without_memory.memories th then
2830
Symbolic_memory_concretizing.clone backup
@@ -31,4 +33,4 @@ let restore backup th =
3133
let tables = Thread_without_memory.tables th in
3234
let globals = Thread_without_memory.globals th in
3335
let breadcrumbs = Thread_without_memory.breadcrumbs th in
34-
create symbols symbols_set pc memories tables globals breadcrumbs
36+
create symbols symbols_set pc pc_fresh memories tables globals breadcrumbs

0 commit comments

Comments
 (0)