---
title: "Oxidizing OCaml: Locality"
description: "Jane 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."
url: "https://swe.quest/articles/oxidizing-ocaml-locality-b1f7bf98d1488c18"
canonical: "https://blog.janestreet.com/oxidizing-ocaml-locality/"
source: "Jane Street Tech Blog"
published: "2023-05-26"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 13
tags: ["functional-programming","type-systems","memory-management","language-design","compilers"]
---

# Oxidizing OCaml: Locality

A post on [Jane Street Tech Blog](https://swe.quest/sources/jane-street.md), published 2023-05-26, 13 min read, Deep dive. Original: [https://blog.janestreet.com/oxidizing-ocaml-locality/](https://blog.janestreet.com/oxidizing-ocaml-locality/)

## Summary

Jane 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.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Functional programming](https://swe.quest/tags/functional-programming.md) (Languages)
- [Type systems](https://swe.quest/tags/type-systems.md) (Compilers & runtimes)
- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)
- [Language design](https://swe.quest/tags/language-design.md) (Compilers & runtimes)
- [Compilers](https://swe.quest/tags/compilers.md) (Compilers & runtimes)

## Prerequisites

- OCaml basics ([easy posts on Functional programming](https://swe.quest/tags/functional-programming.md?difficulty=easy))
- garbage collection ([easy posts on Memory management](https://swe.quest/tags/memory-management.md?difficulty=easy))
- stack vs heap allocation
- Rust lifetimes ([easy posts on Rust](https://swe.quest/tags/rust.md?difficulty=easy))

## Keywords

OCaml, Rust, locality mode, exclave, stack allocation, Jane Street

## Related posts

- [Oxidizing OCaml: Rust-Style Ownership](https://swe.quest/articles/oxidizing-ocaml-rust-style-ownership-5670c1001a0b9cc2.md): Jane Street Tech Blog · 2023-06-21 · Hard · 14 min read · Functional programming, Type systems, Language design, Memory management, Rust
  Jane Street's OCaml extensions add Rust-style ownership through mode axes.
- [Oxidizing OCaml: Data Race Freedom](https://swe.quest/articles/oxidizing-ocaml-data-race-freedom-67442324c35f0e1c.md): Jane Street Tech Blog · 2023-09-01 · Hard · 15 min read · Functional programming, Type systems, Concurrency, Language design, Memory safety
  Jane Street's OCaml extensions use a new \`sync\` mode to make data races statically unrepresentable in multicore OCaml 5.
- [ICFP 2024](https://swe.quest/articles/icfp-2024-a2b848db9d4cf383.md): Jane Street Tech Blog · 2024-08-29 · Hard · 8 min read · Functional programming, Type systems, Language design, Memory management, Compilers
  Jane 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.
- [Using OxCaml to implement type-safe reference counting between OCaml and Python](https://swe.quest/articles/using-oxcaml-to-implement-type-safe-reference-counting-between-ocaml-and-python-6289aa53698f2fb6.md): Jane Street Tech Blog · 2026-06-15 · Hard · 12 min read · Functional programming, Memory management, Type systems, Python
  Wrapping Python objects as OCaml values in PyOCaml ties each object's release to the OCaml GC finalizer, so large data frames or GPU buffers can stay alive long after Python code drops them.
- [What the interns have wrought, 2024 edition](https://swe.quest/articles/what-the-interns-have-wrought-2024-edition-b9d6cc4b73c67320.md): Jane Street Tech Blog · 2024-08-26 · Medium · 12 min read · Functional programming, Performance engineering, Debugging, Event-driven architecture, Analytics & OLAP
  Three 2024 Jane Street intern projects get a technical walkthrough.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
