hn.today

Native regions: a borrow-checked sublanguage inside Clojure

yogthos.net5 points0 comments
Screenshot of Native regions: a borrow-checked sublanguage inside Clojure

Native regions add a small, statically typed, borrow-checked sublanguage to Jolt, a Clojure runtime. A region compiles numeric code to C, letting it operate directly on Jolt’s existing primitive-array storage rather than copying data through the foreign-function interface. This avoids the costly allocation and marshalling that can make ordinary FFI calls unsuitable for small workloads: native code can run much faster than hinted Jolt, while region calls add only a few nanoseconds of overhead. Regions can be compiled ahead of time or JIT-compiled when first called, and helper functions can serve both as Clojure functions and as C functions within regions.

Because region-allocated arrays bypass garbage collection, a compiler pass enforces single ownership: arrays are moved when ownership is transferred, borrowed when read, and freed when their scope ends or an error occurs. It also infers whether helpers borrow or take ownership, reporting unsafe uses. Regions use existing type hints, with other types inferred, and optimize loops through range and bounds analysis, stack allocation, and register-friendly handling of small arrays. To prevent long-running native calls from blocking collection, Jolt pins borrowed arrays and uses safe foreign calls; a faster option holds off garbage collection for short regions. Runtime specialization can compile variants for particular parameter values, while generated regions can parse binary layouts. The design targets numerical hot loops, keeping the broader program in dynamic Clojure while providing tightly controlled access to native performance.

Read on yogthos.net0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Show HN: Rust Commander

Show HN: Rust Commander

Rust Commander is a Rust terminal file manager modeled on Midnight Commander, with dual-pane navigation, a persistent shell, archive and remote browsing, and background file operations. Version 0.3.1 adds file-change alerts, viewer copy controls, customizable skins, and faster SFTP previews and copying. (github.com)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.