-
Notifications
You must be signed in to change notification settings - Fork 77
Add HACKING.md with hints for working on Eio #443
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
## Installing Eio from Git | ||
|
||
If you want to run the latest development version from Git, run these commands: | ||
|
||
``` | ||
git clone https://github.com/ocaml-multicore/eio.git | ||
cd eio | ||
opam pin -yn . | ||
opam install eio_main | ||
``` | ||
|
||
## Layout of the code | ||
|
||
`lib_eio/core` contains the core logic about fibers, promises, switches, etc. | ||
`lib_eio` extends this with e.g. streams, buffered readers, buffered writers, | ||
and a load of types for OS resources (files, networks, etc). | ||
|
||
There is one directory for each backend (e.g. `eio_linux`). | ||
Each backend provides a scheduler that integrates with a particular platform, | ||
and implements some or all of the cross-platform resource APIs. | ||
For example, `eio_linux` implements the network interface using `io_uring` to send data. | ||
|
||
`lib_main` just selects an appropriate backend for the current system. | ||
|
||
## Writing a backend | ||
|
||
It's best to start by reading `lib_eio/mock/backend.ml`, which implements a mock backend with no actual IO. | ||
You can then read one of the real backends to see how to integrate this with the OS. | ||
|
||
Most backends are built in two layers: | ||
|
||
- A "low-level" module directly wraps the platform's own API, just adding support for suspending fibers for concurrency | ||
and basic safety features (such wrapping `Unix.file_descr` to prevent use-after-close races). | ||
|
||
- An implementation of the cross-platform API defined in the `eio` package that uses the low-level API internally. | ||
This should ensure that errors are reported using the `Eio.Io` exception. | ||
|
||
## Tests | ||
|
||
Eio has tests in many places... | ||
|
||
### Cross-platform unit tests | ||
|
||
These are in the top-level `tests` directory. | ||
They are run against whichever backend `Eio_main.run` selects, and therefore must get the same result for all backends. | ||
|
||
### Concurrency primitives | ||
|
||
`lib_eio/tests` tests some internal data structures, such as the lock-free cells abstraction. | ||
The `.md` files in that directory provide a simple walk-through to demonstrate the basic operation, | ||
while `lib_eio/tests/dscheck` uses [dscheck][] to perform exhaustive testing of all atomic interleavings | ||
|
||
At the time of writing, dscheck has some performance problems that make it unusable by default, so | ||
you must use the version in https://github.com/ocaml-multicore/dscheck/pull/3 instead. | ||
|
||
### Benchmarks | ||
|
||
The `bench` directory contains various speed tests. | ||
`make bench` is a convenient way to run all of them. | ||
This is useful to check for regressions. | ||
|
||
If you want to contibute an optimisation, please add a benchmark so that we can measure the improvement. | ||
If you are changing something, make sure the benchmark doesn't get significantly worse. | ||
|
||
### Stress and fuzz testing | ||
|
||
The `fuzz` directory uses afl-fuzz to search for bugs. | ||
|
||
Using it properly requires an instrumented version of the OCaml compiler | ||
(see https://v2.ocaml.org/manual/afl-fuzz.html for instructions). | ||
The `dune` build rules don't use afl-fuzz; they just do a few random tests and then stop. | ||
|
||
To run e.g. the `fuzz_buf_read` tests with afl-fuzz: | ||
|
||
``` | ||
mkdir input | ||
date > input/seed | ||
afl-fuzz -m 1000 -i input -o output ./_build/default/fuzz/fuzz_buf_read.exe @@ | ||
``` | ||
|
||
- `Fork server handshake failed` indicates that you are not using an AFL-enabled version of OCaml. | ||
- `The current memory limit (75.0 MB) is too restrictive` means you forgot to use `-m`. | ||
|
||
The `stress` directory contains stress tests (that try to trigger races by brute force). | ||
|
||
### Backend-specific tests | ||
|
||
There are also backend-specific tests, e.g. | ||
|
||
- `lib_eio_linux/tests` | ||
- `lib_eio_luv/tests` | ||
|
||
Use these for tests that only make sense for one platform. | ||
|
||
## Code formatting | ||
|
||
Eio's code is indented using ocp-indent. | ||
When making PRs, please do not apply other formatting tools to existing code unrelated to your PR. | ||
Try to avoid making unnecessary changes; this makes review harder and clutters up the Git history. | ||
`ocamlformat` may be useful to get badly messed up code to a baseline unformatted state, | ||
from which human formatting can be added where needed. | ||
|
||
[dscheck]: https://github.com/ocaml-multicore/dscheck |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Broken link here?
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.
It works for me.
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.
I'm using the preview at https://github.com/ocaml-multicore/eio/blob/e332fdbfec500f7ac6f4380f32278f734053990c/HACKING.md#concurrency-primitives - does that work for you?
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.
Yes, it does. I didn't know about reference-style links — and now that I do, I notice they are actually documented on a page I'm pretty sure I've read before on markdown! What is this magic, a heisenfeature? 😅
Carry on! LGTM