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#
- 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.
- 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.
- The idea: a hole as an opaque value, which compiled code may carry but never opens.
- Where compiled code looks inside a value, and why JavaScript will not stop it there by itself.
- Three places for the checks, and what each costs.
- A first step, and how to know it works.
- Where to start reading: the files, by line, and the reports.
- Questions to settle first, with Cyrus and Matthew.
- A warm-up on dev: float literals that read back, hazelgrove/hazel#2831.
- 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:
- Compiled views, in the nut menu, on by default on this branch;
?jit=offor?jit=onin the address sets it for one visit, to compare. ?hudshows the frames drawn in the last second and two seconds of frame times against 16.7 ms.- The browser's console says, once for each reason, why something was not compiled (
hazel-jit: ...), andglobalThis.hazelJitholds the counts.
^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):
| Programs | How many | Why |
|---|---|---|
| Checked | 313 | every program the evaluator's tests evaluate |
| Not compiled, by rule | 49 | a 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 limit | 4 | four 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 () -> []. |
| Compiled | 260 | |
| Compiled, nothing to compare | 25 | ill-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 compared | 235 | all 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:
- The slides. Of the 129 programs in
hazel-programs, 20 compile on build 50, and all 20 agree (15 on build 49). The check found one real difference on the way, now fixed: a projection through a list of rows, which the interpreter projects row by row (t.col). - A larger program. The astrology oracle of hazeljs-oracles, eleven modules of floating-point code, compiles whole and runs one reading 170 times as fast as the interpreter, with the same answer (
^report(54), A larger program). - The Witch slide, compiled views on: 6.5 ms a frame (about 154 fps) over a slider drag in Firefox on GitHub's machines, build 50 (
^report(54), What it all costs).
What it does not do yet#
Some things stay with the interpreter by rule; the rest are limits, each a reason the compiler names.
- By rule (Matthew and Cyrus, 2026-11-13): code with a hole or a type hole; a program with a static error, which keeps the whole program interpreted; the stepper's filters, and anything the stepper shows, which it steps with the interpreter.
- Limits the slides meet (the slides' branch, CI run 44184122601): a type hole 29 times and a hole 28, both by rule;
test ... end28 times, a limit (TestandHintedTest,HazelJit.reline 1029), the largest one left on the slides and a contained piece of work; a splice pattern, the builtingroup_by_label, and a closure with its own environment, once each; 21 slides have a static error. - Holes at the boundary. In mixed mode, a value with a hole in it cannot cross into compiled code, so its call goes back to the interpreter: the project in the sections below.
- Mixed mode (
^ticket(766)) runs only in the tests: there is no setting in the app yet. A module's member that calls another module's member is not compiled. A call across the boundary costs more than a tiny function saves: 500 calls of a one-line function took 27 ms mixed against 22 interpreted. - Probes. In mixed mode today, a compiled function's own probes record nothing, and the stepper does not see its calls (
HazelJitMixed.re, its opening comment). Mixed mode runs only in the tests, so no one meets this yet. Probes in compiled code wait on step counts; until then, the plan is to leave a function with a probe uncompiled (^report(54), question 5). - Step counts (
^ticket(767)). The meeting of 2026-11-13 asked compiled code to count the interpreter's steps, so that probes and the stepper's budget mean the same compiled. The interpreter's costs are calibrated; compiled code does not count them yet. - A budget. A compiled run can be given a budget of calls and time (
Runtime.limit); mixed mode gives each call 50 million calls and a second, and a run past it falls back. Whether mixed mode runs on the main thread or only in the evaluator's worker is an open question. - hazeljs, the library apps use, has the interpreter alone; two problems an app met there are filed, not fixed: float literals print with six decimals (hazelgrove/hazel#2831), and an answer that is a function grows past gigabytes (hazelgrove/hazel#2832).
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 branch | What | State |
|---|---|---|
hazelgrove/hazel#2817, trial/694-view-jit | hazel-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-jit | The 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-bits | SInt 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-zero | Modulo 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-hud | The 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 50 | Operators 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 PR | The 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.
- Two suites. The quick tests (
make ci-quick, run with-q) have 20 minutes, the full tests (make ci) 100. On build 49 they took 15.4 and 72 minutes; on build 50, 9 to 14 and 77 to 94.5 (the jobs' times: CI runs 44184122601 and 44211080673 on the slides' branch, and 44319161267 on the prototype). A test added to the quick suite could push build 49's past: the astrology test did, four times. The cause, confirmed when the same branch passed with build 50 merged in (CI run 44320263066): build 49's consistency check times each program it compares by running it at least ten more times in the interpreter, however long one run takes. Build 50 runs a program that already takes 20 ms only once more, has the slides' check in the full tests, and leaves the full tests' runs untimed. So the full tests are now the close ones: the slides' check is 13 of their minutes, by the trail below, and a run's time varies by 15 minutes from one run to the next. - A killed run says nothing. Test output is printed at the end of a run, so a run stopped at its limit prints none of it. On the two trial branches above, the tests append to
hazel-jit-trail.txtas they go, and a CI step prints it after the tests, pass or fail. - Parsing big programs in a test. The tests'
parse_expreads text by inserting it, as typing would, which is very slow for a large program; parse with FastParse instead, as hazeljs does (parse_fastontrial/768-astrology-timed). - One group at a time.
bash test/run_node.sh test HazelJitruns the hazel-jit tests alone. Alcotest'stestsubcommand exits after the run, so a filtered run skips writing JUnit and coverage; reports printed at exit still print. - The Firefox check.
.github/workflows/jit.ymlloads the slides compiled and not, compares every livelit's drawing, and times the Witch slide's slider;gh workflow run jit.yml --ref BRANCH -f only=Witchruns it by hand.
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:
| Program | Mixed mode today | With 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 back | compiled; 3, never looking at an element |
let inc : Int -> Int = fun x -> x + 1 in inc(?) | falls back; ? + 1 | still 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 stuck | still 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.
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.- In: where
to_jsmeets a value it cannot represent (an empty hole, a multihole, or any indeterminate term, such as? + 1or a stuck match), it gives a fresh object standing for it, say{$opaque: k}, and keeps the Hazel term itself in a table atk, its hole ids and environment as they are. - Through: compiled code moves it as it moves any value: into a list, a tuple or a constructor's argument, and out as the answer.
- Never opened: an operation that would look inside it stops the run as an indeterminate result, as reaching
undefineddoes since^ticket(761)(Runtime.indet), and the call falls back, so its answer is the interpreter's. - Out:
of_js, meeting{$opaque: k}, gives back the term from the table, exactly, so a probe or fill-and-resume sees what it would have seen.
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:
| Where | What the compiled code does | With an opaque object |
|---|---|---|
| A pattern on a constructor | v.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 pattern | v === null (line 529) | false, so the cons arm runs and reads v.h: undefined. Wrong. |
| Float arithmetic | a + b | a string such as "[object Object]1", or NaN. Wrong. |
| Equality | ===, and the runtime's eq for structures | false, where the interpreter is stuck. Wrong. |
| A tuple's part | v[0] | undefined, carried on. Wrong. |
| A call | f(x) | a TypeError when f is opaque: the run stops and falls back. Safe. |
| A labeled projection | the runtime's project_labels | already 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).
- 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. - 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.
- Two compiled versions of each function.
to_jsalready 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.
- The boundary.
to_jsandof_jscarry opaque values and keep their table (HazelJitValue.re). - 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 whento_jsmet a hole (HazelJitMixed.re). - Tests beside the mixed-mode tests in
test/Test_HazelJit.re:swap(1, ?)andlen([1, ?, 3])compiled, with the interpreter's answers, compared bysame_value, which must find the same hole;inc(?)andround(?)still falling back; a hole inside a constructor's argument; a hole's environment kept. - 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. - 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 thejit.ymlcheck 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/.
| File | Where | What it holds |
|---|---|---|
HazelJit.re | lines 1 to 60 | What hazel-jit leaves to the interpreter, and why. |
HazelJit.re | lines 60 to 250 | The runtime the compiled code calls: invalid, indet, limit, the ways a compiled run stops. |
HazelJit.re | lines 480 to 590 | Patterns, compiled to tests and bindings; holes refused (lines 483 and 585). |
HazelJitValue.re | lines 192 and 300 | to_js and of_js, the boundary. |
HazelJitMixed.re | lines 136, 157, 183 | fall_back, call, rewrite: mixed mode. |
test/Test_HazelJit.re | from line 1960 | The mixed-mode tests; "mixed: a hole in the argument, that call the interpreter's" at line 1989. |
test/Test_HazelJit_Agree.re | lines 73, 294, 317 | agree, 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.
- 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. - Which values are opaque: empty holes only, or every indeterminate term (a stuck application, a failed cast)? Lean: every value
to_jscannot represent, since the interpreter's answer holds the term itself either way. - 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.
- 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.
- Settle the four questions with Cyrus and Matthew.
- If wanted first, the warm-up PR for hazelgrove/hazel#2831.
- Opaque values at the boundary, passing through only:
to_js,of_js, and the pass-through tests. - The checked version, mixed mode's choice of it, and tests for each silent case.
- Measure: the quick tests' timings and the Witch slide's frame time, before and after.
- 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#
- The numbers, for programs too: every table in this report, and what its numbers measure, is also in this page as JSON, in its
<script type="application/json" id="report-data">element, so a reader or an agent that fetches the page alone has the dataset. The same, with any raw files that survive, is in055/data/.