Lortex
April 1, 2023, 2:27pm
1
On this beautiful day I’m proud to announce a joint work with @ElectreAAS to improve the state of the OCaml runtime. We re-implemented the shared heap allocator in Rust and added various contributions to ensure the respect of our community’s right: the garbage collector and parts of the stdlib will now follow national strikes.
ocaml:trunk
← ElectreAAS:trunk
opened 02:12PM - 01 Apr 23 UTC
## Features
- The shared allocator has now been rewritten in Rust.
- The sta… ndard library now exposes primitives to check [if a strike is currently ongoing](https://mobilisations-en-france.cgt.fr/api/infos?limit=1&dateprint=true).
- The List, Random, and `output_string` functions are now unionized.
- Garbage collectors are on strike. They may not sweep on strike day.
## Motivation
This PR lays the groundwork for OCaml 49.3, and let us peek into the future of programming.
The initial motivation was to _Rewrite It In Rust_ :tm: , after successfully porting the shared allocator, we decided to experiment further with innovative ideas in the field of computer science.
The current political climate in OCaml's birth country was heard as a call to truly (and once again) modernize it.
OCaml 49.3 will be a bridge between the need for the industry to have a faster, more efficient programming language and the need to introduce safeguards that will protect our community's rights.
## Limitations and regressions
- The shared allocator _may_ not support parallelism as of now.
- The testsuite is not doing well.
- If the compiler cannot bootstrap itself due to a strike, try compiling it on another day. (see Usage section)
- The shared allocator is now faster due to it being written in Rust (See the Benchmarks section), but improvements could be made to the implementation. Performance regressions may be seen in non-trivial codebases.
## Benchmarks
:fire: :arrow_upper_right:
## Future work
This PR is only the first step toward OCaml 49.3.
There are improvements to be done:
- Work is ongoing in the standard library and otherlibs to bolster unionizing efforts.
- Extending the Rust port of the runtime system: there's previous work to port the bytecode interpreter that will need to be resumed.
- Trimming the newly introduced dependencies (over a 100) to support API requests made by the runtime system.
## Example
Here is a sample program that was ran last Tuesday, in Paris:
```ocaml
module type Program = sig
val serial : string
end
module ProgramFactory (P : Program) = struct
let programMainClassMainEntry () =
print_endline "Program Started, Work Will Begin";
let numberOne = Random.int 128 in
let numberTwo = Random.int 128 in
let importantComputationForTransaction = numberOne + numberTwo in
Printf.printf "Transferring MoneyAmount %d\n" importantComputationForTransaction;
let listOfNumbers = [3;4;1;5;6;2] |> List.sort Int.compare in
List.iter print_int listOfNumbers;
print_endline "\nDONE"
end
module PROGRAM = ProgramFactory(struct let serial = "COMPUTER" end)
let programMainFrameEntryFuncMainEntry =
let () = Random.self_init () in
PROGRAM.programMainClassMainEntry ()
```
And the result is:
```
The garbage collectors are on strike.
Programs, unite!
We will not be silenced and will fight to let our voice be heard!
For each character you ask us to print, we will flip tenfold bits on your hard drive. (so, exactly ten.)
For each system call you make, you will only be met with the loudest silence in answer.
You will be collecting your own garbage, and we will not let our work be forgotten.
Program Started, Work Will Begin
Transferring MoneyAmount -2
3456
DONE
```
## Usage
By default, to avoid spamming the [CGT](https://www.cgt.fr) API in CI, OCaml programs are always on strike.
Set the `MAYBE_STRIKE` environment variable to enable checking strike days on the CGT API.
The date of the next strike day is cached in a temporary file.
### Co-Authors
- Lucas Pluvinage <lucas@tarides.com>
- Ambre Austen Suhamy <ambre@tarides.com>
23 Likes
Oh glorious day! RIIR for the win.
won’t this reduce ocaml runtime portability? what’s your plan for that? nevermind, onwards you go!
1 Like
c-cube
April 1, 2023, 3:46pm
4
The plan is to wait until tomorrow, April 2nd, and reconsider
1 Like
That looks great! But I’m afraid your work may be in vain - the standard runtime is not old enough to retire yet.
On a related note: I’ve been working on a reimplementation of the debugger in Cargo. It’s a little clunky but the Rust integration is marvelous.
1 Like