Skip to content

Commit 1c5c27e

Browse files
committed
Define and use ResettableLazy.map
1 parent 7271e5e commit 1c5c27e

File tree

7 files changed

+30
-30
lines changed

7 files changed

+30
-30
lines changed

src/autoTune.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ let apronOctagonOption factors file =
472472

473473

474474
let wideningOption factors file =
475-
let amountConsts = WideningThresholds.Thresholds.cardinal @@ WideningThresholds.upper_thresholds () in
475+
let amountConsts = WideningThresholds.Thresholds.cardinal @@ ResettableLazy.force WideningThresholds.upper_thresholds in
476476
let cost = amountConsts * (factors.loops * 5 + factors.controlFlowStatements) in
477477
{
478478
value = amountConsts * (factors.loops * 5 + factors.controlFlowStatements);

src/cdomain/value/cdomains/intDomain0.ml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ let should_wrap ik = not (Cil.isSigned ik) || get_string "sem.int.signed_overflo
6969
* Always false for unsigned types, true for signed types if 'sem.int.signed_overflow' is 'assume_none' *)
7070
let should_ignore_overflow ik = Cil.isSigned ik && get_string "sem.int.signed_overflow" = "assume_none"
7171

72-
let widening_thresholds = ResettableLazy.from_fun WideningThresholds.thresholds
73-
7472
type overflow_info = { overflow: bool; underflow: bool;}
7573

7674
let set_overflow_flag ~cast ~underflow ~overflow ik =
@@ -92,7 +90,6 @@ let set_overflow_flag ~cast ~underflow ~overflow ik =
9290
| false, false -> assert false
9391

9492
let reset_lazy () =
95-
ResettableLazy.reset widening_thresholds;
9693
ana_int_config.interval_threshold_widening <- None;
9794
ana_int_config.interval_narrow_by_meet <- None;
9895
ana_int_config.def_exc_widen_by_join <- None;
@@ -559,25 +556,25 @@ module IntervalArith (Ints_t : IntOps.IntOps) = struct
559556
if Ints_t.equal x1 x2 then Some x1 else None
560557

561558
let upper_threshold u max_ik =
562-
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.upper_thresholds () else ResettableLazy.force widening_thresholds in
559+
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.upper_thresholds else WideningThresholds.thresholds in
563560
let u = Ints_t.to_bigint u in
564561
let max_ik' = Ints_t.to_bigint max_ik in
565-
let t = WideningThresholds.Thresholds.find_first_opt (fun x -> Z.compare u x <= 0 && Z.compare x max_ik' <= 0) ts in
562+
let t = WideningThresholds.Thresholds.find_first_opt (fun x -> Z.compare u x <= 0 && Z.compare x max_ik' <= 0) (ResettableLazy.force ts) in
566563
BatOption.map_default Ints_t.of_bigint max_ik t
567564
let lower_threshold l min_ik =
568-
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.lower_thresholds () else ResettableLazy.force widening_thresholds in
565+
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.lower_thresholds else WideningThresholds.thresholds in
569566
let l = Ints_t.to_bigint l in
570567
let min_ik' = Ints_t.to_bigint min_ik in
571-
let t = WideningThresholds.Thresholds.find_last_opt (fun x -> Z.compare l x >= 0 && Z.compare x min_ik' >= 0) ts in
568+
let t = WideningThresholds.Thresholds.find_last_opt (fun x -> Z.compare l x >= 0 && Z.compare x min_ik' >= 0) (ResettableLazy.force ts) in
572569
BatOption.map_default Ints_t.of_bigint min_ik t
573570
let is_upper_threshold u =
574-
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.upper_thresholds () else ResettableLazy.force widening_thresholds in
571+
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.upper_thresholds else WideningThresholds.thresholds in
575572
let u = Ints_t.to_bigint u in
576-
WideningThresholds.Thresholds.exists (Z.equal u) ts
573+
WideningThresholds.Thresholds.exists (Z.equal u) (ResettableLazy.force ts)
577574
let is_lower_threshold l =
578-
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.lower_thresholds () else ResettableLazy.force widening_thresholds in
575+
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.lower_thresholds else WideningThresholds.thresholds in
579576
let l = Ints_t.to_bigint l in
580-
WideningThresholds.Thresholds.exists (Z.equal l) ts
577+
WideningThresholds.Thresholds.exists (Z.equal l) (ResettableLazy.force ts)
581578
end
582579

583580
module IntInvariant =

src/cdomain/value/util/wideningThresholds.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,11 @@ let conditional_widening_thresholds = ResettableLazy.from_fun (fun () ->
7474
visitCilFileSameGlobals thisVisitor (!Cilfacade.current_file);
7575
!upper, !lower, !octagon)
7676

77-
let upper_thresholds () =
78-
let (u,_,_) = ResettableLazy.force conditional_widening_thresholds in u
77+
let upper_thresholds = ResettableLazy.map Tuple3.first conditional_widening_thresholds
7978

80-
let lower_thresholds () =
81-
let (_,l,_) = ResettableLazy.force conditional_widening_thresholds in l
79+
let lower_thresholds = ResettableLazy.map Tuple3.second conditional_widening_thresholds
8280

83-
let octagon_thresholds () =
84-
let (_,_,o) = ResettableLazy.force conditional_widening_thresholds in o
81+
let octagon_thresholds = ResettableLazy.map Tuple3.third conditional_widening_thresholds
8582

8683

8784
class extractConstantsVisitor(widening_thresholds,widening_thresholds_incl_mul2) = object
@@ -107,11 +104,9 @@ let widening_thresholds = ResettableLazy.from_fun (fun () ->
107104
visitCilFileSameGlobals thisVisitor (!Cilfacade.current_file);
108105
!set, !set_incl_mul2)
109106

110-
let thresholds () =
111-
fst @@ ResettableLazy.force widening_thresholds
107+
let thresholds = ResettableLazy.map fst widening_thresholds
112108

113-
let thresholds_incl_mul2 () =
114-
snd @@ ResettableLazy.force widening_thresholds
109+
let thresholds_incl_mul2 = ResettableLazy.map snd widening_thresholds
115110

116111
module EH = BatHashtbl.Make (CilType.Exp)
117112

@@ -153,4 +148,9 @@ let exps = ResettableLazy.from_fun (fun () ->
153148
let reset_lazy () =
154149
ResettableLazy.reset widening_thresholds;
155150
ResettableLazy.reset conditional_widening_thresholds;
156-
ResettableLazy.reset exps
151+
ResettableLazy.reset exps;
152+
ResettableLazy.reset thresholds;
153+
ResettableLazy.reset thresholds_incl_mul2;
154+
ResettableLazy.reset upper_thresholds;
155+
ResettableLazy.reset lower_thresholds;
156+
ResettableLazy.reset octagon_thresholds;

src/cdomain/value/util/wideningThresholds.mli

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
module Thresholds : Set.S with type elt = Z.t
44

5-
val thresholds : unit -> Thresholds.t
6-
val thresholds_incl_mul2 : unit -> Thresholds.t
5+
val thresholds : Thresholds.t ResettableLazy.t
6+
val thresholds_incl_mul2 : Thresholds.t ResettableLazy.t
77
val exps: GoblintCil.exp list ResettableLazy.t
88

99
val reset_lazy : unit -> unit
10-
val upper_thresholds : unit -> Thresholds.t
11-
val lower_thresholds : unit -> Thresholds.t
12-
val octagon_thresholds : unit -> Thresholds.t
10+
val upper_thresholds : Thresholds.t ResettableLazy.t
11+
val lower_thresholds : Thresholds.t ResettableLazy.t
12+
val octagon_thresholds : Thresholds.t ResettableLazy.t

src/cdomains/apron/apronDomain.apron.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ module M = Messages
1818
- heterogeneous environments: https://link.springer.com/chapter/10.1007%2F978-3-030-17184-1_26 (Section 4.1) *)
1919

2020
let widening_thresholds_apron = ResettableLazy.from_fun (fun () ->
21-
let t = if GobConfig.get_string "ana.apron.threshold_widening_constants" = "comparisons" then WideningThresholds.octagon_thresholds () else WideningThresholds.thresholds_incl_mul2 () in
22-
let r = List.map Scalar.of_z (WideningThresholds.Thresholds.elements t) in
21+
let t = if GobConfig.get_string "ana.apron.threshold_widening_constants" = "comparisons" then WideningThresholds.octagon_thresholds else WideningThresholds.thresholds_incl_mul2 in
22+
let r = List.map Scalar.of_z (WideningThresholds.Thresholds.elements (ResettableLazy.force t)) in
2323
Array.of_list r
2424
)
2525

src/common/util/resettableLazy.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ let from_fun f = make_map ~gen:f
77
let force cache = cache.get ()
88

99
let reset cache = cache.del ()
10+
11+
let map f cache = from_fun (fun () -> f (force cache))

src/common/util/resettableLazy.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ type 'a t
55
val from_fun: (unit -> 'a) -> 'a t
66
val force: 'a t -> 'a
77
val reset: 'a t -> unit
8+
val map: ('a -> 'b) -> 'a t -> 'b t

0 commit comments

Comments
 (0)