Skip to content

Commit cd56116

Browse files
committed
Translate 'Lwt_io.flush'
1 parent 2fec339 commit cd56116

File tree

4 files changed

+36
-32
lines changed

4 files changed

+36
-32
lines changed

bin/lwt_to_direct_style/ast_rewrite.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ let rewrite_apply ~backend ~state full_ident args =
385385
take @@ fun str -> return (Some (backend#io_write_str chan str))
386386
| "Lwt_io", "length" -> take @@ fun fd -> return (Some (backend#io_length fd))
387387
| "Lwt_io", "close" -> take @@ fun fd -> return (Some (backend#io_close fd))
388+
| "Lwt_io", "flush" -> take @@ fun fd -> return (Some (backend#io_flush fd))
388389
| "Lwt_main", "run" ->
389390
take @@ fun promise -> return (Some (backend#main_run promise))
390391
| _ -> return None

bin/lwt_to_direct_style/concurrency_backend.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ let eio ~eio_sw_as_fiber_var ~eio_env_as_fiber_var add_comment =
233233
unbuffered IO.";
234234
None
235235

236+
method io_flush output =
237+
mk_apply_simple [ "Eio"; "Buf_write"; "flush" ] [ output ]
238+
236239
method fd_close fd =
237240
(* TODO: See [of_unix_file_descr]. mk_apply_simple [ "Eio_unix"; "Fd" ] [ fd ] *)
238241
mk_apply_simple [ "Unix"; "close" ] [ fd ]

test/lwt_to_direct_style/to_direct_style.t/run.t

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -228,41 +228,42 @@ Make a writable directory tree:
228228
Lwt_mutex.lock (line 136 column 9)
229229
Lwt_mutex.unlock (line 137 column 9)
230230
Lwt_mutex.with_lock (line 138 column 9)
231-
lib/test_lwt_unix.ml: (40 occurrences)
231+
lib/test_lwt_unix.ml: (41 occurrences)
232232
Lwt_io (line 7 column 8)
233233
Lwt.return (line 12 column 3)
234234
Lwt.let* (line 10 column 3)
235235
Lwt.let* (line 11 column 3)
236-
Lwt.let* (line 32 column 3)
237-
Lwt.let* (line 36 column 3)
236+
Lwt.let* (line 29 column 3)
237+
Lwt.let* (line 33 column 3)
238238
Lwt.Syntax (line 1 column 6)
239-
Lwt_io.Input (line 23 column 32)
240-
Lwt_io.Output (line 24 column 32)
239+
Lwt_io.Input (line 22 column 32)
240+
Lwt_io.Output (line 23 column 32)
241241
Lwt_io.input (line 7 column 28)
242-
Lwt_io.input (line 32 column 36)
243-
Lwt_io.output (line 22 column 32)
244-
Lwt_io.output (line 36 column 36)
245-
Lwt_io.output_channel (line 27 column 9)
246-
Lwt_io.close (line 33 column 3)
242+
Lwt_io.input (line 29 column 36)
243+
Lwt_io.output (line 21 column 32)
244+
Lwt_io.output (line 33 column 36)
245+
Lwt_io.output_channel (line 25 column 9)
246+
Lwt_io.close (line 30 column 3)
247247
Lwt_io.of_fd (line 7 column 16)
248+
Lwt_io.of_fd (line 21 column 13)
248249
Lwt_io.of_fd (line 22 column 13)
249250
Lwt_io.of_fd (line 23 column 13)
250-
Lwt_io.of_fd (line 24 column 13)
251-
Lwt_io.read_line (line 29 column 15)
252-
Lwt_io.read (line 42 column 15)
253-
Lwt_io.read (line 43 column 15)
254-
Lwt_io.read (line 44 column 15)
255-
Lwt_io.read_into (line 10 column 19)
251+
Lwt_io.read_line (line 26 column 15)
252+
Lwt_io.read (line 38 column 15)
253+
Lwt_io.read (line 39 column 15)
254+
Lwt_io.read (line 40 column 15)
255+
Lwt_io.read_into (line 10 column 21)
256256
Lwt_io.read_into_exactly (line 11 column 13)
257-
Lwt_io.write (line 25 column 19)
258-
Lwt_io.length (line 37 column 3)
259-
Lwt_io.stdout (line 27 column 33)
260-
Lwt_io.open_file (line 32 column 13)
261-
Lwt_io.open_file (line 36 column 13)
257+
Lwt_io.flush (line 41 column 15)
258+
Lwt_io.write (line 24 column 19)
259+
Lwt_io.length (line 34 column 3)
260+
Lwt_io.stdout (line 25 column 33)
261+
Lwt_io.open_file (line 29 column 13)
262+
Lwt_io.open_file (line 33 column 13)
262263
Lwt_unix.Timeout (line 14 column 9)
263264
Lwt_unix.of_unix_file_descr (line 6 column 8)
264-
Lwt_unix.stat (line 39 column 16)
265-
Lwt_unix.lstat (line 40 column 16)
265+
Lwt_unix.stat (line 36 column 16)
266+
Lwt_unix.lstat (line 37 column 16)
266267
Lwt_unix.sockaddr (line 15 column 9)
267268
Lwt_unix.ADDR_UNIX (line 15 column 29)
268269
Lwt_unix.ADDR_UNIX (line 17 column 6)
@@ -300,9 +301,9 @@ Make a writable directory tree:
300301
Lwt.let* (line 163 column 21)
301302
Lwt.Fail (line 179 column 9)
302303
Warning: lib/test_lwt_unix.ml: 3 occurrences have not been rewritten.
303-
Lwt_io.stdout (line 27 column 33)
304-
Lwt_io.read (line 43 column 15)
305-
Lwt_io.read (line 44 column 15)
304+
Lwt_io.stdout (line 25 column 33)
305+
Lwt_io.read (line 39 column 15)
306+
Lwt_io.read (line 40 column 15)
306307
Warning: lib/test.mli: 2 occurrences have not been rewritten.
307308
Lwt_mutex.t (line 2 column 10)
308309
Lwt_mutex.t (line 3 column 10)
@@ -693,7 +694,7 @@ Make a writable directory tree:
693694
: [ `R | `Flow | `Close ] r)
694695
in
695696
let buf = Bytes.create 1024 in
696-
let _n : int =
697+
let (_n : int) =
697698
Eio.Flow.single_read
698699
(* TODO: lwt-to-direct-style: [buf] should be a [Cstruct.t]. *)
699700
(* TODO: lwt-to-direct-style: [Eio.Flow.single_read] operates on a [Flow.source] but [inp] is likely of type [Eio.Buf_read.t]. Rewrite this code to use [Buf_read] (which contains an internal buffer) or change the call to [Eio.Buf_read.of_flow] used to create the buffer. *)
@@ -801,3 +802,5 @@ Make a writable directory tree:
801802
(* TODO: lwt-to-direct-style: Eio doesn't have a direct equivalent of [Lwt_io.read ~count]. Rewrite the code using [Eio.Buf_read]'s lower level API or switch to unbuffered IO. *)
802803
(* TODO: lwt-to-direct-style: Eio doesn't have a direct equivalent of [Lwt_io.read ~count]. Rewrite the code using [Eio.Buf_read]'s lower level API or switch to unbuffered IO. *)
803804
?count:(Some 42) chan
805+
806+
let _f chan = Eio.Buf_write.flush chan

test/lwt_to_direct_style/to_direct_style.t/src/lib/test_lwt_unix.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let _f fname =
77
|> Lwt_io.(of_fd ~mode:input)
88
in
99
let buf = Bytes.create 1024 in
10-
let* _n : int = Lwt_io.read_into inp buf 0 1024 in
10+
let* (_n : int) = Lwt_io.read_into inp buf 0 1024 in
1111
let* () = Lwt_io.read_into_exactly inp buf 0 1024 in
1212
Lwt.return ()
1313

@@ -18,14 +18,11 @@ let (Lwt_unix.ADDR_UNIX _ | ADDR_INET _) =
1818
Lwt_unix.ADDR_INET (Unix.inet_addr_any, 0)
1919

2020
let _ = Lwt_unix.getaddrinfo
21-
2221
let _f fd = Lwt_io.of_fd ~mode:Lwt_io.output fd
2322
let _f fd = Lwt_io.of_fd ~mode:Lwt_io.Input fd
2423
let _f fd = Lwt_io.of_fd ~mode:Lwt_io.Output fd
2524
let _f out_chan = Lwt_io.write out_chan "str"
26-
2725
let _ : Lwt_io.output_channel = Lwt_io.stdout
28-
2926
let _f chan = Lwt_io.read_line chan
3027

3128
let _f fname =
@@ -38,7 +35,7 @@ let _f fname =
3835

3936
let _f fname = Lwt_unix.stat fname
4037
let _f fname = Lwt_unix.lstat fname
41-
4238
let _f chan = Lwt_io.read chan
4339
let _f chan = Lwt_io.read ~count:42 chan
4440
let _f chan = Lwt_io.read ?count:(Some 42) chan
41+
let _f chan = Lwt_io.flush chan

0 commit comments

Comments
 (0)