-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
constants defined in OCaml: #6
Conversation
…ompiled into a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I am exporting C constants using a function is to avoid having to define the constant values 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.
What is gained by defining the constants in OCaml?
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:
#6 (review)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
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. |
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:
#6 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
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:
#6 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
I think a PPX adds a dependency that I would rather avoid. But I could imagine something like:
Now you have compile-time constants but you also verify that they are correct. |
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:
#6 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
I close this PR, because I restarted from master to have a clean commit history |
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.