eio icon indicating copy to clipboard operation
eio copied to clipboard

Relax return types of Eio.Process.Pipe

Open Arogbonlo opened this issue 1 year ago • 8 comments

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:

  • Relaxed Type Definitions: I’ve updated the return types for pipe so they can accept any subtype of Flow.source_ty and Flow.sink_ty. This will give us more flexibility when working with processes that require different types of flows.

  • Polymorphic Variants: I used polymorphic variants ([< .. ]) to allow for more flexible types, ensuring that the code still works with the broader variants expected in other parts of the system.

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 avatar Oct 28 '24 20:10 Arogbonlo

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

Arogbonlo avatar Oct 28 '24 20:10 Arogbonlo

Thanks @Arogbonlo !

I appreciate your efforts!

Arogbonlo avatar Oct 29 '24 12:10 Arogbonlo

Ok. I'll get that done immediately!

Arogbonlo avatar Oct 29 '24 15:10 Arogbonlo

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

Arogbonlo avatar Oct 29 '24 16:10 Arogbonlo

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 avatar Oct 31 '24 11:10 Arogbonlo

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.

Arogbonlo avatar Oct 31 '24 14:10 Arogbonlo

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
```

talex5 avatar Nov 01 '24 11:11 talex5

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.

Arogbonlo avatar Nov 10 '24 21:11 Arogbonlo