Skip to content

Commit 4ca3597

Browse files
Use OCaml 4.14 features: TRMC, In_channel, Out_channel, Seq.uncons
Agent-Logs-Url: https://github.com/goblint/analyzer/sessions/c1370c59-ec35-42df-b0d5-d48a7f47e2f2 Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
1 parent 545f5cb commit 4ca3597

6 files changed

Lines changed: 18 additions & 26 deletions

File tree

src/cdomain/value/cdomains/int/defExcDomain.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module BISet = struct
77
let is_singleton s = cardinal s = 1
88

99
let map_reduce f g s =
10-
s |> to_seq |> Seq.map f |> BatSeq.reduce g
10+
match s |> to_seq |> Seq.map f |> Seq.uncons with
11+
| None -> invalid_arg "BISet.map_reduce"
12+
| Some (x, rest) -> Seq.fold_left g x rest
1113
end
1214

1315
(* The module [Exclusion] constains common functionality about handling of exclusion sets between [DefExc] and [Enums] *)

src/common/util/messages.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ let out = ref stdout
184184

185185
let get_out name alternative = match get_string "dbg.dump" with
186186
| "" -> alternative
187-
| path -> open_out (Filename.concat path (name ^ ".out"))
187+
| path -> Out_channel.open_text (Filename.concat path (name ^ ".out"))
188188

189189

190190
let print ?(ppf= !formatter) (m: Message.t) =

src/incremental/makefileUtil.ml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
open Unix
44

5-
let buff_size = 1024
6-
75
(* Suffix of files combined by CIL *)
86
let comb_suffix = "_comb.c"
97

@@ -16,18 +14,10 @@ let exec_command ?path (command: string) =
1614
) path;
1715
Logs.debug "%s" ("executing command `" ^ command ^ "` in " ^ Sys.getcwd ());
1816
let (std_out, std_in) = open_process command in
19-
let output = Buffer.create buff_size in
20-
try
21-
while true do
22-
let line = input_char std_out in
23-
Buffer.add_char output line
24-
done;
25-
assert false;
26-
with End_of_file ->
27-
let exit_code = close_process (std_out,std_in) in
28-
let output = Buffer.contents output in
29-
Sys.chdir current_dir;
30-
(exit_code, output)
17+
let output = In_channel.input_all std_out in
18+
let exit_code = close_process (std_out, std_in) in
19+
Sys.chdir current_dir;
20+
(exit_code, output)
3121

3222

3323
(* BFS for a file with a given suffix in a directory or any subdirectoy *)

src/maingoblint.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ let handle_flags () =
197197
match get_string "dbg.dump" with
198198
| "" -> ()
199199
| path ->
200-
Messages.formatter := Format.formatter_of_out_channel (open_out (Legacy.Filename.concat path "warnings.out"));
200+
Messages.formatter := Format.formatter_of_out_channel (Out_channel.open_text (Filename.concat path "warnings.out"));
201201
set_string "outfile" ""
202202

203203
let handle_options () =
@@ -487,7 +487,7 @@ let parse_preprocessed preprocessed =
487487
(** Merge parsed files *)
488488
let merge_parsed parsed =
489489
let cilout =
490-
if get_string "dbg.cilout" = "" then Legacy.stderr else Legacy.open_out (get_string "dbg.cilout")
490+
if get_string "dbg.cilout" = "" then Out_channel.stderr else Out_channel.open_text (get_string "dbg.cilout")
491491
in
492492

493493
Errormsg.logChannel := Messages.get_out "cil" cilout;
@@ -523,7 +523,7 @@ let do_stats () =
523523
Goblint_solver.SolverStats.print ();
524524
Logs.newline ();
525525
Logs.info "Timings:";
526-
Timing.Default.print (Stdlib.Format.formatter_of_out_channel @@ Messages.get_out "timing" Legacy.stderr);
526+
Timing.Default.print (Stdlib.Format.formatter_of_out_channel @@ Messages.get_out "timing" Out_channel.stderr);
527527
flush_all ()
528528
)
529529

@@ -536,9 +536,9 @@ let reset_stats () =
536536
let do_analyze change_info merged_AST =
537537
(* direct the output to file if requested *)
538538
if get_string "outfile" <> "" then (
539-
if !Messages.out <> Legacy.stdout then
540-
Legacy.close_out !Messages.out;
541-
Messages.out := Legacy.open_out (get_string "outfile"));
539+
if !Messages.out <> Out_channel.stdout then
540+
Out_channel.close !Messages.out;
541+
Messages.out := Out_channel.open_text (get_string "outfile"));
542542

543543
let module L = Printable.Liszt (CilType.Fundec) in
544544
if get_bool "justcil" then

src/solver/generic.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ struct
106106
if save_run_str <> "" then (
107107
let save_run = Fpath.v save_run_str in
108108
GobSys.mkdir_or_exists save_run;
109-
Fpath.(to_string (save_run / "solver_stats.csv")) |> open_out |> Option.some
109+
Fpath.(to_string (save_run / "solver_stats.csv")) |> Out_channel.open_text |> Option.some
110110
) else None
111-
let write_csv xs oc = output_string oc @@ String.concat ",\t" xs ^ "\n"
111+
let write_csv xs oc = Out_channel.output_string oc @@ String.concat ",\t" xs ^ "\n"
112112

113113
(* print generic and specific stats *)
114114
let print_stats _ =
@@ -123,7 +123,7 @@ struct
123123
Logs.newline ();
124124
(* Timing.print (M.get_out "timing" Legacy.stdout) "Timings:\n"; *)
125125
(* Gc.print_stat stdout; (* too verbose, slow and words instead of MB *) *)
126-
let gc = GobGc.print_quick_stat Legacy.stderr in
126+
let gc = GobGc.print_quick_stat Out_channel.stderr in
127127
Logs.newline ();
128128
Option.may (write_csv [GobSys.string_of_time (); string_of_int !SolverStats.vars; string_of_int !SolverStats.evals; string_of_int !ncontexts; string_of_int gc.Gc.top_heap_words]) stats_csv
129129
(* print_string "Do you want to continue? [Y/n]"; *)

src/util/std/gobList.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open Batteries
22

33
(** The normal haskell zip that throws no exception *)
4-
let rec combine_short l1 l2 = match l1, l2 with
4+
let[@tail_mod_cons] rec combine_short l1 l2 = match l1, l2 with
55
| x1 :: l1, x2 :: l2 -> (x1, x2) :: combine_short l1 l2
66
| _, _ -> []
77

0 commit comments

Comments
 (0)