Oxidizing OCaml: Data Race Freedom
Jane Street's OCaml extensions use a new `sync` mode to make data races statically unrepresentable in multicore OCaml 5. Immutable and exclusively mutable values are `sync` and shareable across domains, while ordinary mutable values are `unsync` and confined to one domain. Mode-annotated mutexes give roughly safe-Rust capabilities. Capsules go further: they encapsulate unrestricted shared mutability, such as cyclic mutable structures, behind existentially typed keys, so code can mutate shared-ownership data in parallel without Rust-style fine-grained ownership tracking or unsafe code.
Related posts
- Oxidizing OCaml: Rust-Style Ownership
Jane Street Tech Blog hardMasterJane Street's OCaml extensions add Rust-style ownership through mode axes. A uniqueness axis (unique, exclusive, shared) enables in-place functional updates, type-changing strong updates and safe resource APIs. Borrowing via `&` combines with locality so values can be lent without consuming them. Exclusively mutable fields give mutation without move semantics, and a linearity axis (once vs many) stops closures that capture unique values from being invoked twice, which would otherwise break type safety. Unlike Rust, these modes carry no lifetime variables, so they avoid higher-order polymorphism and don't interfere with type inference.
- Oxidizing OCaml: Locality
Jane Street Tech Blog hardMasterJane Street is extending OCaml with modes, starting with a locality mode that marks values as local (cannot escape their region) or global, so the compiler can stack-allocate short-lived values while keeping garbage collection everywhere else. Locality is inferred automatically and checked by the compiler. An `exclave` keyword lets a function return a local value into its caller's region, and local parameters let APIs like `with_file` guarantee that resources are not used after release. Unlike Rust's lifetime variables, modes are separate from types and do not affect type inference. They are deep and form a sub-mode order (global ≤ local), which forbids heap-to-stack pointers.
- ICFP 2024
Jane Street Tech Blog hardMasterJane Street's OCaml Language team brings nine papers and talks to ICFP 2024 and describes its compiler-branch extensions: modal types (modes like local and unique) for Rust-like control over allocation and data-race-free parallelism, and a kind system for unboxed layouts. Examples include a redesigned Bonsai API that uses a local-mode witness and escape analysis to enforce its two-phase graph-building model, mixed blocks for records combining boxed and unboxed fields, ppx_template for stamping out kind/mode-specialized code until real polymorphism lands, and a zero-overhead or_null option type that uses kinds to forbid nesting. The team also released a bleeding-edge opam repo with the extended compiler and its libraries so outsiders can try the features ahead of any upstreaming.
- Eliminating Data Races in Firefox – A Technical Report
Mozilla Hacks hardMasterMozilla deployed ThreadSanitizer across Firefox's C/C++ and Rust code, using a compiled-in suppression list to gate new races in CI while legacy ones were triaged toward a "no data races" policy. So-called benign races are easily misclassified, yet fixing them proved cheap: most fixes were atomics conversions, suppressions or code removal. Notable finds include lost writes from adjacent bitfields (fixed with a MOZ_ATOMIC_BITFIELDS macro), a PreferencesWriter race likely corrupting prefs.js, and fragile late-validated racy reads. Rust needed -Zbuild-std hacks for instrumentation but surfaced only two pure-Rust races, in parking_lot and a WebRender shim, both in unsafe low-level code.
- What the interns have wrought, 2022 edition
Jane Street Tech Blog mediumAdeptThree Jane Street intern projects from 2022 show substantial tooling work in OCaml. magic-trace gained a sampling mode that can cover 20 seconds to 20 minutes on Intel or AMD hardware, plus multi-process tracing, CPU-frequency transition reporting and a perf dlfilter backend that speeds trace decoding by 10–50%. Datafetcher jobs can now be compiled into Incremental computations, using a Response_or_waiting type to represent async state and mandatory memoization of fetch nodes. Quickcheck gained a [@@contract] syntax for deriving property tests from interface signatures, along with early support for bisimulation testing of two implementations of the same API.