Skip to content

Commit ca2e46a

Browse files
Define find_default_delayed helper and replace S.Dom.bot() try/Not_found patterns
Agent-Logs-Url: https://github.com/goblint/analyzer/sessions/c0745a92-b9e7-48ca-962c-ee3a8c19c6e7 Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
1 parent 15ae6b3 commit ca2e46a

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/solver/td3.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ module Base =
5858

5959
let exists_key f hm = HM.exists (fun k _ -> f k) hm
6060

61+
let find_default_delayed h k f = Option.default_delayed f (HM.find_option h k)
62+
6163
let assert_can_receive_side x =
6264
if Hooks.system x <> None then (
6365
failwith ("side-effect to unknown w/ rhs: " ^ GobPretty.sprint S.Var.pretty_trace x);
@@ -666,7 +668,7 @@ module Base =
666668
else
667669
destabilize_normal;
668670

669-
let sys_change = S.sys_change (fun v -> try HM.find rho v with Not_found -> S.Dom.bot ()) in
671+
let sys_change = S.sys_change (fun v -> find_default_delayed rho v S.Dom.bot) in
670672

671673
let old_ret = HM.create 103 in
672674
if reluctant then (
@@ -861,7 +863,7 @@ module Base =
861863
let check_side x y d =
862864
HM.replace visited y ();
863865
let mem = HM.mem rho y in
864-
let d' = try HM.find rho y with Not_found -> S.Dom.bot () in
866+
let d' = find_default_delayed rho y S.Dom.bot in
865867
if not (S.Dom.leq d d') then Logs.error "TDFP Fixpoint not reached in restore step at side-effected variable (mem: %b) %a from %a: %a not leq %a" mem S.Var.pretty_trace y S.Var.pretty_trace x S.Dom.pretty d S.Dom.pretty d'
866868
in
867869
let rec eq check x =
@@ -1049,7 +1051,7 @@ module Base =
10491051
if incr_verify then (
10501052
HM.iter (fun x w ->
10511053
HM.iter (fun y d ->
1052-
let old_d = try HM.find rho y with Not_found -> S.Dom.bot () in
1054+
let old_d = find_default_delayed rho y S.Dom.bot in
10531055
(* Logs.debug "rho_write retrigger %a %a %a %a" S.Var.pretty_trace x S.Var.pretty_trace y S.Dom.pretty old_d S.Dom.pretty d; *)
10541056
HM.replace rho y (S.Dom.join old_d d);
10551057
HM.replace init_reachable y ();

src/solver/topDown.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module WP =
2121

2222
module HPM = Hashtbl.Make (P)
2323

24+
let find_default_delayed h k f = Option.default_delayed f (HPM.find_option h k)
25+
2426
let solve st vs =
2527
let stable = HM.create 10 in
2628
let infl = HM.create 10 in (* y -> xs *)
@@ -102,7 +104,7 @@ module WP =
102104
d
103105
and side x y d =
104106
if tracing then trace "sol2" "side %a ## %a (wpx: %b) ## %a" S.Var.pretty_trace x S.Var.pretty_trace y (HM.mem rho y) S.Dom.pretty d;
105-
let old = try HPM.find rho' (x,y) with Not_found -> S.Dom.bot () in
107+
let old = find_default_delayed rho' (x,y) S.Dom.bot in
106108
if not (S.Dom.equal old d) then (
107109
add_set x y (S.Dom.join old d);
108110
HM.remove stable y;

src/solver/topDown_space_cache_term.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module WP =
2020

2121
type phase = Widen | Narrow
2222

23+
let find_default_delayed h k f = Option.default_delayed f (HM.find_option h k)
24+
2325
let solve st vs =
2426
let stable = HM.create 10 in
2527
let infl = HM.create 10 in (* y -> xs *)
@@ -45,7 +47,7 @@ module WP =
4547
let old = HM.find rho x in
4648
let l = HM.create 10 in
4749
let tmp = eq x (eval l x) (side l) in
48-
let tmp = S.Dom.join tmp (try HM.find rho' x with Not_found -> S.Dom.bot ()) in
50+
let tmp = S.Dom.join tmp (find_default_delayed rho' x S.Dom.bot) in
4951
if tracing then trace "sol" "Var: %a" S.Var.pretty_trace x ;
5052
if tracing then trace "sol" "Contrib:%a" S.Dom.pretty tmp;
5153
HM.remove called x;
@@ -94,7 +96,7 @@ module WP =
9496
tmp
9597
and side l y d =
9698
if tracing then trace "sol2" "side to %a (wpx: %b) ## value: %a" S.Var.pretty_trace y (HM.mem rho y) S.Dom.pretty d;
97-
let old = try HM.find rho' y with Not_found -> S.Dom.bot () in
99+
let old = find_default_delayed rho' y S.Dom.bot in
98100
if not (S.Dom.leq d old) then (
99101
HM.replace rho' y (S.Dom.join old d);
100102
HM.remove l y;
@@ -148,7 +150,7 @@ module WP =
148150
) else (
149151
HM.replace visited x ();
150152
let check_side y d =
151-
let d' = try HM.find rho y with Not_found -> S.Dom.bot () in
153+
let d' = find_default_delayed rho y S.Dom.bot in
152154
if not (S.Dom.leq d d') then Logs.error "Fixpoint not reached in restore step at side-effected variable %a: %a not leq %a" S.Var.pretty_trace y S.Dom.pretty d S.Dom.pretty d'
153155
in
154156
let eq x =

src/solver/topDown_term.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module WP =
2020

2121
type phase = Widen | Narrow
2222

23+
let find_default_delayed h k f = Option.default_delayed f (HM.find_option h k)
24+
2325
let solve st vs =
2426
let stable = HM.create 10 in
2527
let infl = HM.create 10 in (* y -> xs *)
@@ -49,7 +51,7 @@ module WP =
4951
init x;
5052
let old = HM.find rho x in
5153
let tmp = eq x (eval x) side in
52-
let tmp = S.Dom.join tmp (try HM.find rho' x with Not_found -> S.Dom.bot ()) in
54+
let tmp = S.Dom.join tmp (find_default_delayed rho' x S.Dom.bot) in
5355
if tracing then trace "sol" "Var: %a" S.Var.pretty_trace x ;
5456
if tracing then trace "sol" "Contrib:%a" S.Dom.pretty tmp;
5557
HM.remove called x;
@@ -83,7 +85,7 @@ module WP =
8385
add_infl y x;
8486
HM.find rho y
8587
and side y d =
86-
let old = try HM.find rho' y with Not_found -> S.Dom.bot () in
88+
let old = find_default_delayed rho' y S.Dom.bot in
8789
if not (S.Dom.leq d old) then (
8890
HM.replace rho' y (S.Dom.widen old (S.Dom.join old d));
8991
HM.remove stable y;

0 commit comments

Comments
 (0)