ocaml-multicore / eio

Effects-based direct-style IO for multicore OCaml
Other
559 stars 72 forks source link

Relax return types of Eio.Process.Pipe #775

Open Arogbonlo opened 3 weeks ago

Arogbonlo commented 3 weeks ago

This PR relaxes the return types of the pipe function in Eio.Process to make the code more flexible. The main goal was to allow the pipe function to handle a broader range of types for input and output flows, while still maintaining compatibility with the rest of the codebase.

Changes:

Testing: I ran dune runtest and confirmed that all tests are passing with these changes. The new types work fine, and the tests ensure everything is still functioning as expected.

Relaxing the types for pipe allows us to work with a wider variety of process setups and flows, without being too restrictive about the types we return. It also makes the code easier to extend in the future.

This addresses issue https://github.com/ocaml-multicore/eio/issues/750, improving flexibility when working with various APIs that use stricter type definitions for sources and sinks.

Arogbonlo commented 3 weeks ago

Hey @talex5 @patricoferris . I'm sure this is better. Please check it out and let me know. Thank you.

Arogbonlo commented 3 weeks ago

Thanks @Arogbonlo !

I appreciate your efforts!

Arogbonlo commented 3 weeks ago

Ok. I'll get that done immediately!

Arogbonlo commented 3 weeks ago

Hey @talex5 @patricoferris . I'm sure this is better. Please check it out and let me know. Thank you.

Arogbonlo commented 3 weeks ago

Hello @talex5 ,

Each time i update eio_unix.mli with the more flexible types, the build constantly fails. Please I'd like your intervention here. Thank you

Arogbonlo commented 3 weeks ago

In the eio_unix.mli file, there is val pipe : Switch.t -> source_ty r * sink_ty r , which returns a pair of flows (source_ty r and sink_ty r), where source_ty and sink_ty are defined as:

type source_ty = [`Unix_fd | Eio.Resource.close_ty | Eio.Flow.source_ty]
type sink_ty   = [`Unix_fd | Eio.Resource.close_ty | Eio.Flow.sink_ty]

This union typing ([Unix_fd | Eio.Resource.close_ty | Eio.Flow.source_ty]forsource_ty) makes pipe’s output flexible enough to match what’s required in process.mli.

In process.mli, the pipe function has a similar signature : val pipe : sw:Switch.t -> _ mgr -> [< Flow.source_ty | Resource.close_ty] r * [< Flow.sink_ty | Resource.close_ty] r

So @talex5 , I think flexibility in eio_unix.mli ensures that the flows returned by pipe can match the input requirements of functions in process.mli.

talex5 commented 3 weeks ago

The one in process.mli now uses <. The one in eio_unix.mli doesn't. This is what you were trying change.

utop # Eio_main.run (fun _ -> Eio.Switch.run (fun sw -> let (r : Eio.Flow.source_ty Eio.Resource.t), _ = Eio_unix.pipe sw in ()));;
Error: This expression has type
         Eio_unix.source_ty Eio_unix.source * Eio_unix.sink_ty Eio_unix.source
       but an expression was expected of type
         Eio.Flow.source_ty Eio_unix.source * 'a
       Type Eio_unix.source_ty = [ `Close | `Flow | `R | `Unix_fd ]
       is not compatible with type Eio.Flow.source_ty = [ `Flow | `R ]
       The second variant type does not allow tag(s) `Close, `Unix_fd
Arogbonlo commented 1 week ago

The one in process.mli now uses <. The one in eio_unix.mli doesn't. This is what you were trying change.

utop # Eio_main.run (fun _ -> Eio.Switch.run (fun sw -> let (r : Eio.Flow.source_ty Eio.Resource.t), _ = Eio_unix.pipe sw in ()));;
Error: This expression has type
         Eio_unix.source_ty Eio_unix.source * Eio_unix.sink_ty Eio_unix.source
       but an expression was expected of type
         Eio.Flow.source_ty Eio_unix.source * 'a
       Type Eio_unix.source_ty = [ `Close | `Flow | `R | `Unix_fd ]
       is not compatible with type Eio.Flow.source_ty = [ `Flow | `R ]
       The second variant type does not allow tag(s) `Close, `Unix_fd

I just resolved that. I just uploaded the pipe function signature in eio_unix.mli

But after doing that, the build constantly fails.