Hazel reports · ^report(55) · hazel-jit · 2026-11-17, revised 2026-11-18 08:36 MST · work in progress · after ^report(54)

Holes Across the Boundary

A starter project for hazel-jit. In mixed mode, Hazel's interpreter runs a program and calls its fully typed functions compiled to JavaScript; when an argument holds a hole anywhere, the whole call goes back to the interpreter. Can such a value cross into compiled code and out again, unopened, and what do the checks that keep it unopened cost? Written for John, on the Hazel team, who offered on 2026-11-17 to take on the question of holes raised at the team's meeting that day, and for anyone else starting on hazel-jit, with notes on where it stands.

Outline#

  1. Where hazel-jit stands, for anyone starting on it: how to try it, what compiles and what does not, the open PRs and branches, and working with CI. As of 2026-11-17.
  2. Where holes stand: no code with a hole is compiled, by rule, and a value with a hole sends its whole call back to the interpreter.
  3. The idea: a hole as an opaque value, which compiled code may carry but never opens.
  4. Where compiled code looks inside a value, and why JavaScript will not stop it there by itself.
  5. Three places for the checks, and what each costs.
  6. A first step, and how to know it works.
  7. Where to start reading: the files, by line, and the reports.
  8. Questions to settle first, with Cyrus and Matthew.
  9. A warm-up on dev: float literals that read back, hazelgrove/hazel#2831.
  10. What next, and how this was put together.

Where hazel-jit stands#

As of 2026-11-18, hazel-jit lives on one prototype branch, build 50 (build 49 and the slides' builtins). It compiles 260 of the evaluator's 313 test programs and gives the interpreter's answer on every one it can compare. It is not on dev, and three small PRs to dev are waiting for review. This section is for anyone starting on it. ^report(54) has the story and the numbers; ^report(51) explains how compiled livelit views work.

Trying it#

The live build is build.hazel.org/trial/694-view-jit/, build 50. Build 50 is commit 55e4757a4b, deployed there 2026-11-18 at 07:01 MST (Deploy run 44319161240); CI deploys every push to the branch there. In the app:

^report(51)'s How to use it in your own PR is still right about the setting, the OCaml calls, the command line (./hazel jit FILE.hz, with --check, --views, --step, -n), the HazelJit test group and the Firefox check, all checked against build 49, which build 50 changes in none of these. It is out of date on two points: hazelgrove/hazel#2819 no longer hosts the same build (below), and its results are build 8's, where build 50's are those here.

What compiles#

Of the evaluator's 313 test programs, 260 compile and 235 are compared with the interpreter, all agreeing; the other 78 are holes, type holes, free variables, four limits, and 25 ill-typed tests with nothing to compare. The consistency check runs each evaluator test program through hazel-jit in CI, compares its answer with the interpreter's, and fails the build on a difference (^report(54), The same answers, checked in CI). On build 50 (CI run 44211080673, on the slides' branch before it moved; build 49's, CI run 44137711359, differ only in the last three rows, as said there):

ProgramsHow manyWhy
Checked313every program the evaluator's tests evaluate
Not compiled, by rule49a hole, among them a label that is a hole (15); a type hole (10); a free variable, the tests' own unbound names (24). The interpreter keeps these on purpose.
Not compiled, a limit4four ill-typed fixpoints over a pattern that is not a name (fix _ : (), fix (_ : Bool), fix 0, fix ()), left so on purpose. Corrected 2026-11-18: this said one was a recursive definition a finer check could compile; CI, printing each program by name (^report(56)), shows it is fix () -> [].
Compiled260
Compiled, nothing to compare25ill-typed tests whose interpreter run stops at a failed run-time check, so its answer is not a value; listed by name. On build 49, 27.
Compiled and compared235all give the interpreter's answer; none differ. 233 give the same value. The other two are ill-typed projections, such as (true).a, which the interpreter leaves stuck and the compiled run stops at as indeterminate; build 49 counted them with nothing to compare. The 233 with a value are the programs timed in ^report(54)'s The same programs, timed: run again and again, the median is 222 times as fast compiled; run once with its compile, 1.2 times.

Beyond the evaluator's tests:

What it does not do yet#

Some things stay with the interpreter by rule; the rest are limits, each a reason the compiler names.

The PRs and branches#

Five PRs are open, none merged: the prototype as a draft, its stale twin, and three small PRs to dev waiting on a review. Two branches carry work not yet on the prototype. As of 2026-11-17, 16:30 MST.

PR or branchWhatState
hazelgrove/hazel#2817, trial/694-view-jithazel-jit, the prototype: compiled livelit views and a slide's whole run, the consistency check, mixed mode in the tests.Draft, against integration/livelits-modular-editors (hazelgrove/hazel#2635), not dev. Build 50, 55e4757a4b, since 2026-11-18, all of CI green on its branch first, all of CI green on the prototype too (CI run 44319161267); previewed at build.hazel.org/trial/694-view-jit/. ^report(53) proposes redoing it by hand in small PRs to dev.
hazelgrove/hazel#2819, livelits-x-jitThe same branch against dev, for trying.Draft, stale: c419e01559, 2026-11-09, 123 commits behind build 50. Use the preview above instead.
hazelgrove/hazel#2828, fix/758-sint-32-bitsSInt is 32 bits everywhere, and overflow an error.To dev. All checks green, Codecov too; waiting for a review (hazel-core requested).
hazelgrove/hazel#2825, fix/764-mod-by-zeroModulo by zero stops at Divide by Zero instead of crashing the interpreter.To dev. All checks green; waiting for a review (hazel-core requested).
hazelgrove/hazel#2818, fps-hudThe frame-rate overlay, ?hud, alone.To dev. All checks green; waiting for a review (hazel-core requested).
trial/761-slide-builtins, no PR, now build 50Operators passed as functions, to_lvs, and a projection through a list compiled as the interpreter's (t.col over a list of rows); the slides' check in the full tests, with a budget on each compiled run; the full tests leave a trail.Done: on the prototype branch as build 50 since 2026-11-18. All of CI green on the branch first (CI run 44211080673: static checks, fast checks, and the full tests in 92 minutes): all 20 compiled slides agree, none stops at the budget, and the evaluator's 235 agree. Then the prototype's own CI passed on build 50 (CI run 44319161267), and the Firefox check (run 44319161252).
trial/768-astrology-timed, no PRThe astrology oracle compiled whole and timed, on build 49.Measured (above). Merged with build 50, its quick tests pass (CI run 44320263066), so build 49's timing rule was what ran them long. Its compiled rules run the astrology page by default since hazeljs-oracles 0.0.16 (printed by trial/768-astrology-aot).

Working with the tests and CI#

CI is the place to run the suite, and its time limits are close: build 50's full tests took 77, 92 and 94.5 of their 100 minutes in three runs.

Where holes stand#

No code with a hole is compiled, by rule, and today a value with a hole cannot cross into compiled code at all: the call goes back to the interpreter whole.

hazel-jit compiles Hazel to JavaScript (^report(50) to ^report(54)). What it leaves to the interpreter by rule, not as a gap to close, was settled at Matthew Hammer and Cyrus Omar's meeting of 2026-11-13: "for the output of hazel-jit, we should continue to avoid translating code with holes". The interpreter evaluates around holes, and its indeterminate results are the point of them (^report(54), What stays with the interpreter). That rule stands here.

Mixed mode (^report(54), Mixed mode; on the prototype branch only) is where values meet compiled code. The interpreter runs the program as always. Each function bound at the program's top, or in a module there, whose whole type is declared (let f : A -> B = fun ...) is compiled, and the interpreter calls it as it calls a builtin: the argument is converted to a JavaScript value (HazelJitValue.to_js), the compiled function runs, and its answer is converted back by the declared result type (of_js). On any stop, that call falls back: the interpreter applies its own closure to the same argument, and its answer is the answer.

The conversion knows numbers, booleans, strings, lists, tuples, labeled tuples and constructors. On anything else, a hole among them, it raises, and the call falls back, even when the function would never have looked at the hole:

ProgramMixed mode todayWith this project
let swap : (Int, Int) -> (Int, Int) = fun (a, b) -> (b, a) in swap(1, ?)falls back; the interpreter answers (?, 1)compiled; the same (?, 1), the same hole
let len : [Int] -> Int = fun xs -> case xs | [] => 0 | _ :: rest => 1 + len(rest) end in len([1, ?, 3])falls backcompiled; 3, never looking at an element
let inc : Int -> Int = fun x -> x + 1 in inc(?)falls back; ? + 1still falls back: + looks inside
type Shape = + Circle(Float) + Square(Float) in let round : Shape -> Bool = fun s -> case s | Circle(_) => true | _ => false end in round(?)falls back; the interpreter's match is stuckstill falls back, which takes a check: see below

It matters because a program being edited usually has a hole somewhere, and data with holes in it (a livelit's model with a field not yet filled, a list being typed) reaches functions that only move it around.

The idea#

Carry a hole as an opaque JavaScript value: compiled code may store it, pass it and return it, but any operation that would look inside it stops the run, and that call goes back to the interpreter.

The interpreter swap((1, ?)) (?, 1) the same hole, its id and environment Compiled swap [1, {$opaque: 0}] [{$opaque: 0}, 1] moves it, never opens it ? the table keeps the term: 0 → ? to_js of_js an operation that would open it (x + 1, a match): the run stops, and the call falls back
A hole crossing the boundary in mixed mode, as proposed. Going in, to_js turns the hole into an opaque object and keeps the Hazel term in a table; the compiled function moves the object without opening it; coming out, of_js gives back the very term that went in. An operation that would open it stops the compiled run, and the interpreter answers that call, as every call that cannot cross does today.

Compiled code still contains no hole; only the data does, and compiled code never inspects it. So the rule of 2026-11-13 holds.

Where compiled code looks inside a value#

JavaScript will not stop by itself: an opaque object in the wrong place gives a wrong answer silently, so the checks have to be written. Where an operation throws, the run stops and the call falls back, which is safe. Where it returns, it is wrong:

WhereWhat the compiled code doesWith an opaque object
A pattern on a constructorv.c === "Some" (HazelJit.re, line 577)false, so the next arm is tried, and a wildcard arm then matches, where the interpreter's match is stuck. Wrong.
The empty-list patternv === null (line 529)false, so the cons arm runs and reads v.h: undefined. Wrong.
Float arithmetica + ba string such as "[object Object]1", or NaN. Wrong.
Equality===, and the runtime's eq for structuresfalse, where the interpreter is stuck. Wrong.
A tuple's partv[0]undefined, carried on. Wrong.
A callf(x)a TypeError when f is opaque: the run stops and falls back. Safe.
A labeled projectionthe runtime's project_labelsalready stops as indeterminate on a value that is not a tuple. Safe.

Three places for the checks#

The checks can go everywhere, only where a silent wrong answer can come out, or into a second compiled version used only when a hole arrives; the third keeps calls without holes at today's speed. The cost that matters is the one on calls with no hole in them, the common case: the Witch slide's compiled views must stay within a frame at 60 a second (^report(54), What it all costs: 6.5 ms a frame on build 50).

  1. Everywhere compiled code looks inside a value: a test before each operation, pattern test and part (typeof v === "object" && v !== null && "$opaque" in v). Simple, and every call pays, holes or not.
  2. Only where a wrong answer comes out silently (the rows marked wrong above), leaving the rest to JavaScript's own errors. Fewer tests; still paid by every call.
  3. Two compiled versions of each function. to_js already walks the whole argument, so it knows whether a hole was in it: with none, today's unchecked code runs; with one, a checked version, with the second design's tests, compiled the first time such an argument arrives. Calls without holes cost what they cost today, and the price is compile time and code size, once per function that ever meets a hole.

Our lean, for discussion: the third, its checked version carrying the second's tests. Whether any of this pays is a measurement, not a guess (below).

A first step#

Start with values that only pass through, checked by tests that already exist and measured by timings that already run in CI.

  1. The boundary. to_js and of_js carry opaque values and keep their table (HazelJitValue.re).
  2. The checked version. The second design's tests generated under a flag in HazelJit.re's code generation, and mixed mode choosing the checked version when to_js met a hole (HazelJitMixed.re).
  3. Tests beside the mixed-mode tests in test/Test_HazelJit.re: swap(1, ?) and len([1, ?, 3]) compiled, with the interpreter's answers, compared by same_value, which must find the same hole; inc(?) and round(?) still falling back; a hole inside a constructor's argument; a hole's environment kept.
  4. The consistency check. mixed_sweep (test/Test_HazelJit_Agree.re) already runs every evaluator test program in mixed mode and compares its answer with the interpreter's; the programs that pass holes to typed functions start taking the new path.
  5. The cost. The timings in ^report(54)'s The same programs, timed come from the quick tests on every push, and the Witch slide's frame time from the jit.yml check in Firefox, so a change to the code generation shows its cost on its next push.

Where to start reading#

Five files on the prototype branch, and three reports. The branch is trial/694-view-jit (hazelgrove/hazel#2817), build 49, 0e56bdbd0a; line numbers are that commit's. The files are in src/language/dynamics/ and test/.

FileWhereWhat it holds
HazelJit.relines 1 to 60What hazel-jit leaves to the interpreter, and why.
HazelJit.relines 60 to 250The runtime the compiled code calls: invalid, indet, limit, the ways a compiled run stops.
HazelJit.relines 480 to 590Patterns, compiled to tests and bindings; holes refused (lines 483 and 585).
HazelJitValue.relines 192 and 300to_js and of_js, the boundary.
HazelJitMixed.relines 136, 157, 183fall_back, call, rewrite: mixed mode.
test/Test_HazelJit.refrom line 1960The mixed-mode tests; "mixed: a hole in the argument, that call the interpreter's" at line 1989.
test/Test_HazelJit_Agree.relines 73, 294, 317agree, same_value, mixed_sweep: how answers are compared.

The reports: 054 (its sections What hazel-jit is, What stays with the interpreter, Mixed mode, and Questions for the team), 053 (why the prototype is to be redone by hand in small PRs), and 050 to 052 (how compiled livelit views came about). CI runs the tests on every push to a branch of hazelgrove/hazel; the quick tests take 10 to 15 minutes there.

Questions to settle first#

Four, with Cyrus and Matthew, before code: where the work lives, which values are opaque, whether a hole keeps its identity, and when the checked version is compiled. Each has our lean.

  1. Does it live on the prototype branch? ^report(53) proposes redoing hazel-jit by hand, in small PRs to dev, and mixed mode is so far only on the prototype. Lean: design and measure there; it lands on dev with mixed mode.
  2. Which values are opaque: empty holes only, or every indeterminate term (a stuck application, a failed cast)? Lean: every value to_js cannot represent, since the interpreter's answer holds the term itself either way.
  3. Must a hole keep its identity through compiled code, its id and its closure's environment, so that fill-and-resume and probes still work? Lean: yes; the table gives back the very term that went in.
  4. The checked version: compiled up front, or the first time a hole arrives? Lean: the first time; most functions never meet one.

A warm-up on dev#

A smaller first PR, independent of the prototype: make float literals print so that they read back as the same number (hazelgrove/hazel#2831). Atom.to_literal prints a float with %f, six decimal places (src/language/term/Atom.re, line 208 on dev), so a literal such as 280.4606184 does not survive the fast parser's round trip, and its module falls to the slow parser, whose cost grows much faster than the module. The fix is the shortest form that reads back. Atom's derived equality compares floats by the same six decimals (lines 30 to 32); evaluation does not, it compares by value. It is a tour of the parser and of review on dev.

What next#

Settle the questions, then the boundary, the checks, and the measurements.

  1. Settle the four questions with Cyrus and Matthew.
  2. If wanted first, the warm-up PR for hazelgrove/hazel#2831.
  3. Opaque values at the boundary, passing through only: to_js, of_js, and the pass-through tests.
  4. The checked version, mixed mode's choice of it, and tests for each silent case.
  5. Measure: the quick tests' timings and the Witch slide's frame time, before and after.
  6. Write it up, with the numbers, here or in a report of its own.

How this was put together#

Written from the code of build 49 (0e56bdbd0a, 2026-11-17 10:30 MST) and ^report(54), on 2026-11-17, after John's offer. Nothing here is measured yet; the examples' answers today are mixed mode's documented behaviour (a call whose argument does not convert falls back), and the "with this project" column is what the design intends. The file references and the examples are in the data below and in 055/data.

The data#