Skip to content

Commit 2326a84

Browse files
authored
Merge pull request #1891 from goblint/let-at
Introduce `let@` binding operator
2 parents 63e20a1 + 4d3f732 commit 2326a84

File tree

19 files changed

+49
-30
lines changed

19 files changed

+49
-30
lines changed

.semgrep/let.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
rules:
2-
- id: let-unit-in
3-
pattern: let () = $E in ...
4-
message: use ; instead (and, if needed, add surrounding parentheses to preserve precedence)
5-
languages: [ocaml]
6-
severity: WARNING
2+
[]
3+
# TODO: disabled because semgrep cannot distinguish from let@ which is fine (https://github.com/semgrep/semgrep/issues/11432)
4+
# - id: let-unit-in
5+
# pattern: let () = $E in ...
6+
# message: use ; instead (and, if needed, add surrounding parentheses to preserve precedence)
7+
# languages: [ocaml]
8+
# severity: WARNING

src/analyses/base.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ struct
280280
let rec addToOffset n (t:typ option) = function
281281
| `Index (i, `NoOffset) ->
282282
(* Binary operations on pointer types should not generate warnings in SV-COMP *)
283-
GobRef.wrap AnalysisState.executing_speculative_computations true @@ fun () ->
283+
let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in
284284
(* If we have arrived at the last Offset and it is an Index, we add our integer to it *)
285285
`Index(IdxDom.add i (iDtoIdx n), `NoOffset)
286286
| `Field (f, `NoOffset) ->

src/analyses/baseInvariant.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,6 @@ struct
890890
let invariant man st exp tv =
891891
(* The computations that happen here are not computations that happen in the programs *)
892892
(* Any overflow during the forward evaluation will already have been flagged here *)
893-
GobRef.wrap AnalysisState.executing_speculative_computations true
894-
@@ fun () -> invariant man st exp tv
893+
let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in
894+
invariant man st exp tv
895895
end

src/analyses/basePriv.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ struct
20312031
v
20322032

20332033
let dump () =
2034-
Out_channel.with_open_bin (get_string "exp.priv-prec-dump") @@ fun f ->
2034+
let@ f = Out_channel.with_open_bin (get_string "exp.priv-prec-dump") in
20352035
(* LVH.iter (fun (l, x) v ->
20362036
Logs.debug "%a %a = %a" CilType.Location.pretty l CilType.Varinfo.pretty x VD.pretty v
20372037
) lvh; *)

src/autoTune.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class findAllocsInLoops = object
6262

6363
method! vinst = function
6464
| Call (_, Lval (Var f, NoOffset), args,_,_) when LibraryFunctions.is_special f ->
65-
Goblint_backtrace.protect ~mark:(fun () -> Cilfacade.FunVarinfo f) ~finally:Fun.id @@ fun () ->
65+
let@ () = Goblint_backtrace.protect ~mark:(fun () -> Cilfacade.FunVarinfo f) ~finally:Fun.id in
6666
let desc = LibraryFunctions.find f in
6767
begin match desc.special args with
6868
| Malloc _
@@ -96,7 +96,7 @@ let functionArgs fd = (ResettableLazy.force functionCallMaps).argLists |> Functi
9696

9797
let findMallocWrappers () =
9898
let isMalloc f =
99-
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo f) @@ fun () ->
99+
let@ () = Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo f) in
100100
if LibraryFunctions.is_special f then
101101
let desc = LibraryFunctions.find f in
102102
let args = functionArgs f in
@@ -177,15 +177,15 @@ let disableIntervalContextsInRecursiveFunctions () =
177177

178178
let hasFunction pred =
179179
let relevant_static var =
180-
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo var) @@ fun () ->
180+
let@ () = Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo var) in
181181
if LibraryFunctions.is_special var then
182182
let desc = LibraryFunctions.find var in
183183
GobOption.exists (fun args -> pred desc args) (functionArgs var)
184184
else
185185
false
186186
in
187187
let relevant_dynamic var =
188-
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo var) @@ fun () ->
188+
let@ () = Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo var) in
189189
if LibraryFunctions.is_special var then
190190
let desc = LibraryFunctions.find var in
191191
(* We don't really have arguments at hand, so we cheat and just feed it a list of MyCFG.unknown_exp of appropriate length *)

src/cdomain/value/cdomains/offset.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ struct
224224
(* Interval of floor and ceil division in case bitfield offset. *)
225225
let bytes_offset = Idx.of_interval (Cilfacade.ptrdiff_ikind ()) Z.(fdiv bits_offset eight, cdiv bits_offset eight) in
226226
let remaining_offset = offset_to_index_offset ~typ:field.ftype o in
227-
GobRef.wrap AnalysisState.executing_speculative_computations true @@ fun () -> Idx.add bytes_offset remaining_offset
227+
let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in
228+
Idx.add bytes_offset remaining_offset
228229
| `Index (x, o) ->
229230
let (item_typ, item_size_in_bytes) =
230231
match Option.map unrollType typ with
@@ -235,9 +236,13 @@ struct
235236
(None, Idx.top ())
236237
in
237238
(* Binary operations on offsets should not generate overflow warnings in SV-COMP *)
238-
let bytes_offset = GobRef.wrap AnalysisState.executing_speculative_computations true @@ fun () -> Idx.mul item_size_in_bytes x in
239+
let bytes_offset =
240+
let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in
241+
Idx.mul item_size_in_bytes x
242+
in
239243
let remaining_offset = offset_to_index_offset ?typ:item_typ o in
240-
GobRef.wrap AnalysisState.executing_speculative_computations true @@ fun () -> Idx.add bytes_offset remaining_offset
244+
let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in
245+
Idx.add bytes_offset remaining_offset
241246
in
242247
offset_to_index_offset ?typ offs
243248

src/cdomain/value/util/wideningThresholds.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class extractInvariantsVisitor (exps) = object
115115
method! vinst (i: instr) =
116116
match i with
117117
| Call (_, Lval (Var f, NoOffset), args, _, _) when LibraryFunctions.is_special f ->
118-
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo f) @@ fun () ->
118+
let@ () = Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo f) in
119119
let desc = LibraryFunctions.find f in
120120
begin match desc.special args with
121121
| Assert { exp; _ } ->

src/cdomains/apron/sharedFunctions.apron.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct
157157
outside of the apron-related expression conversion.
158158
*)
159159
let simplify e =
160-
GobRef.wrap AnalysisState.executing_speculative_computations true @@ fun () ->
160+
let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in
161161
let ikind = try (Cilfacade.get_ikind_exp e) with Invalid_argument a -> raise (Unsupported_CilExp (Ikind_non_integer a)) in
162162
let simp = query e ikind in
163163
let const = IntDomain.IntDomTuple.to_int @@ IntDomain.IntDomTuple.cast_to ~kind:Internal ikind simp in (* TODO: proper castkind *)
@@ -181,11 +181,13 @@ struct
181181
| false -> (* Cast is not injective - we now try to establish suitable ranges manually *)
182182
let t_ik = Cilfacade.get_ikind t in
183183
(* retrieving a valuerange for a non-injective cast works by a query to the value-domain with subsequent value extraction from domtuple - which should be speculative, since it is not program code *)
184-
let const,res = GobRef.wrap AnalysisState.executing_speculative_computations true @@ fun () ->
184+
let const,res =
185+
let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in
185186
(* try to evaluate e by EvalInt Query *)
186187
let res = try (query e @@ Cilfacade.get_ikind_exp e) with Invalid_argument a -> raise (Unsupported_CilExp (Ikind_non_integer a)) in
187188
(* convert response to a constant *)
188-
IntDomain.IntDomTuple.to_int @@ IntDomain.IntDomTuple.cast_to ~kind:Internal t_ik res, res in (* TODO: proper castkind *)
189+
IntDomain.IntDomTuple.to_int @@ IntDomain.IntDomTuple.cast_to ~kind:Internal t_ik res, res (* TODO: proper castkind *)
190+
in
189191
match const with
190192
| Some c -> Cst (Coeff.s_of_z c) (* Got a constant value -> use it straight away *)
191193
(* I gotten top, we can not guarantee injectivity *)

src/common/framework/cfgTools.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ let fprint_hash_dot cfg =
600600
let extraNodeStyles node = []
601601
end
602602
in
603-
Out_channel.with_open_text "cfg.dot" @@ fun out ->
603+
let@ out = Out_channel.with_open_text "cfg.dot" in
604604
let iter_edges f = H.iter (fun n es -> List.iter (f n) es) cfg in
605605
let ppf = Format.formatter_of_out_channel out in
606606
fprint_dot (module CfgPrinters (NoExtraNodeStyles)) iter_edges ppf;
@@ -663,7 +663,7 @@ let dead_code_cfg ~path (module FileCfg: MyCFG.FileCfg) live =
663663
let dot_file_name = fd.svar.vname^".dot" in
664664
let file_dir = GobSys.mkdir_or_exists_absolute Fpath.(base_dir / c_file_name) in
665665
let fname = Fpath.(file_dir / dot_file_name) in
666-
Out_channel.with_open_text (Fpath.to_string fname) @@ fun out ->
666+
let@ out = Out_channel.with_open_text (Fpath.to_string fname) in
667667
let ppf = Format.formatter_of_out_channel out in
668668
fprint_fundec_html_dot (module FileCfg.Cfg) live fd ppf;
669669
Format.pp_print_flush ppf ();

src/incremental/serialize.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let gob_results_dir op =
2020
let server () = GobConfig.get_bool "server.enabled"
2121

2222
let marshal obj fileName =
23-
Out_channel.with_open_bin (Fpath.to_string fileName) @@ fun chan ->
23+
let@ chan = Out_channel.with_open_bin (Fpath.to_string fileName) in
2424
Marshal.to_channel chan obj []
2525

2626
let unmarshal fileName =

0 commit comments

Comments
 (0)