lindig / polly

OCaml bindings for Linux epoll(2)
MIT License
9 stars 4 forks source link

constants defined in OCaml: #6

Closed craff closed 1 year ago

craff commented 1 year ago

This way Events.(et lor inp lor out) is compiled into a constant (I check with -dlinear)

We also gain that exclusive is always available from OCaml even if not supported.

craff commented 1 year ago

With the current code, the compiler does not know the value of the constant and can not remove the lor at compile time. I check, it does work like that with this PR.

Note: we can also generate the ml file from the result of CPP and a bit of magic.

Le 5 août 2023 03:43:41 GMT-10:00, Christian Lindig @.***> a écrit :

@lindig commented on this pull request.

The reason I am exporting C constants using a function is to avoid having to define the constants value in OCaml where I don't have access to the original definition or header file. I don't see a draw back. These functions are called when the OCaml module is initialised and after that all values are defined and there is no function call overhead while they are being used.

-- Reply to this email directly or view it on GitHub: https://github.com/lindig/polly/pull/6#pullrequestreview-1563914630 You are receiving this because you authored the thread.

Message ID: @.***>

lindig commented 1 year ago

I agree that the constants are no longer compile-time constants. The trade off here is that I can be sure that I am using the correct constants. Given how fast bit operations are and the language we are using, I still like the trade off.

A potential middle ground could be to define the constants and to check them against the correct constants using the mechanism we have currently.

craff commented 1 year ago

For this PR, and the other one, the benefit is for those applications that uses epoll_ctl at each epoll_wait. This is not currently my use case, but it may happen.

Le 5 août 2023 06:21:45 GMT-10:00, Christian Lindig @.***> a écrit :

I agree that the constants are no longer compile-time constants. The trade off here is that I can be sure that I am using the correct constants. Given how fast bit operations are and the language we are using, I still like the trade off.

-- Reply to this email directly or view it on GitHub: https://github.com/lindig/polly/pull/6#issuecomment-1666546088 You are receiving this because you authored the thread.

Message ID: @.***>

craff commented 1 year ago

I am considering a ppx that would allow

let x= `EPOLLIN @.*** "sys/epoll.h"]

It would call the compiler once for each ml file only

Would you use such a ppx if it were on opam?

Le 5 août 2023 06:21:45 GMT-10:00, Christian Lindig @.***> a écrit :

I agree that the constants are no longer compile-time constants. The trade off here is that I can be sure that I am using the correct constants. Given how fast bit operations are and the language we are using, I still like the trade off.

-- Reply to this email directly or view it on GitHub: https://github.com/lindig/polly/pull/6#issuecomment-1666546088 You are receiving this because you authored the thread.

Message ID: @.***>

lindig commented 1 year ago

I think a PPX adds a dependency that I would rather avoid. But I could imagine something like:

let pri = 0x002
assert (pri = polly_PRI ());

Now you have compile-time constants but you also verify that they are correct.

craff commented 1 year ago

I like this! I will do it.

Le 5 août 2023 10:18:57 GMT-10:00, Christian Lindig @.***> a écrit :

I think a PPX adds a dependency that I would rather avoid. But I could imagine something like:

let pri = 0x002
assert (pri = polly_PRI ());

Now you have compile-time constants but you also verify that they are correct.

-- Reply to this email directly or view it on GitHub: https://github.com/lindig/polly/pull/6#issuecomment-1666595802 You are receiving this because you authored the thread.

Message ID: @.***>

craff commented 1 year ago

I close this PR, because I restarted from master to have a clean commit history