Skip to content

Commit f4ee91d

Browse files
committed
Add missing In_channel function on some OCaml versions
1 parent b02767f commit f4ee91d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

compiler/lib/stdlib.ml

+21-1
Original file line numberDiff line numberDiff line change
@@ -1227,9 +1227,17 @@ module Fun = struct
12271227
end
12281228

12291229
module In_channel = struct
1230-
include In_channel
1230+
let stdlib_input_line = input_line
1231+
[@@if ocaml_version >= (4, 14, 0)]
1232+
1233+
module In_channel = In_channel
12311234
[@@if ocaml_version >= (4, 14, 0)]
12321235

1236+
module In_channel = struct end
1237+
[@@if ocaml_version < (4, 14, 0)]
1238+
1239+
include In_channel
1240+
12331241
(* Read up to [len] bytes into [buf], starting at [ofs]. Return total bytes
12341242
read. *)
12351243
let read_upto ic buf ofs len =
@@ -1325,6 +1333,18 @@ module In_channel = struct
13251333
end
13261334
[@@if ocaml_version < (4, 14, 0)]
13271335

1336+
(* [In_channel.input_lines] only exists in the stdlib since 5.1. We would
1337+
also like to use tail modulo cons (introduced in 4.14.0) to implement it
1338+
here for versions between 4.14.0 and 5.1.0, because it gives better
1339+
performance. Here we reimplement it for all versions of OCaml due to a
1340+
limitation of [ppx_optcompt_light], namely, that it doesn't support
1341+
version ranges. *)
1342+
let [@tail_mod_cons] rec input_lines ic =
1343+
match stdlib_input_line ic with
1344+
| line -> line :: input_lines ic
1345+
| exception End_of_file -> []
1346+
[@@if ocaml_version >= (4, 14, 0)]
1347+
13281348
let input_lines ic =
13291349
let rec aux acc =
13301350
match input_line ic with

0 commit comments

Comments
 (0)