Skip to content

Reset layout caches before showing a new book - #1324

Merged
nicolas-abril merged 3 commits into
bendlang:mainfrom
jasisz:fix/compiler-cache-show-layout
Oct 5, 2026
Merged

nicolas-abril merged 3 commits into
bendlang:mainfrom
jasisz:fix/compiler-cache-show-layout

Conversation

@jasisz

@jasisz jasisz commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

What

  • clear the global node and layout caches before building a pure main show descriptor
  • run an in-process B → A → B C-emission regression with independently loaded books that reuse type and constructor names at different layouts

Why

compile_book calls show_main before file_book performs its per-book cache reset. After compiling one book, a second book that reuses a datatype and constructor name with a different field layout can therefore make show_main consume the first book layout. The minimal one-field → two-field sequence throws at fs[f].ks; compiling the second book alone prints the expected value.

This is a concrete cache-purity failure exposed by the test gap in #1310; it is narrower than that issue’s full acceptance criteria.

Verification

  • both fixtures: checker and --verdict pass
  • both fixtures: interpreter, JS, and native C print the expected values
  • before the fix: the in-process sequence throws in show_main
  • after the fix: both B emissions are byte-identical and both native binaries print correctly
  • gates/test.ts reaches cluster acquisition after its new local cache check; the remaining full gate could not run here because the cluster hostname is unavailable

@cristianoc

Copy link
Copy Markdown

Reproduced and verified independently on main at 565d7fd (Bun, Darwin arm64):

  • Without the fix, with only the two fixtures added, compiling B → A → B in one process throws TypeError: undefined is not an object (evaluating 'fs[f].ks') in show_main. Each fixture alone prints its expected value through the CLI.
  • With only the comp.ts change applied, B → A → B → A succeeds. Both B emissions are byte-identical to a fresh compilation of B, and both A emissions are identical to each other. The final C for each builds with clang and prints CacheLayoutOne{7} and CacheLayoutOne{8, 9}.

I did not run the full gate.

@nicolas-abril
nicolas-abril force-pushed the fix/compiler-cache-show-layout branch from 16b78dd to 3f81276 Compare October 5, 2026 10:39

@nicolas-abril nicolas-abril left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the diagnosis is right: compile_book runs show_main before file_book, which is where the per-book caches are cleared, so show_main reads the previous book's NODES and LAYS. I reproduced the B → A → B crash on main. I rebased onto main (1159f0b) and pushed two commits on top of yours: one moves the fix and drops the gate check, the other renames the two cache-clearing functions. Reasons:

Where the reset goes. Clearing NODES and LAYS at the top of show_main treats the symptom:

  • show_main doesn't own the compilation's lifetime. js_book calls it after js_lib, where the clear just throws away caches the same book filled.
  • It picks 2 of the 11 per-book caches. I instrumented show_main with the clears removed and compiled all 702 runnable tests in one process. It found LAYS, NODES and TELES already filled. TELES is keyed by term identity, so it's harmless; NODES and LAYS are exactly the two the PR clears. That's right today, but if show_main ever reads FUNS or SRCS the bug comes back.

The commits move file_book's reset into memo_gc_book() and call it first in the two compile entry points, compile_book and js_lib. js_book and io_run go through js_lib. memo_gc becomes memo_gc_def, and memo_gc_book starts by calling it, so the names say which scope each one clears. show_main keeps its place before file_book, since #1067 needs its result to build the roots. file_book keeps its name checks, and show_main is unchanged from main.

One consequence: emission now reuses what show_main cached, which is only LAYS, NODES and TELES, instead of recomputing it after file_book cleared it. So the printed descriptor and the emitted code always use the same layouts.

The gate check. gates/test.ts only orchestrates: it splits tests into shards, runs them on the cluster, and parses the output. It never loads the compiler. compiler_cache compiles on the gate host, before the cluster is acquired and inside the 30 s cap, and reports failure by throwing instead of through the PASS count. The two fixtures can't be ordinary tests either, since the sequence they describe only runs from that function. So I removed the check and both fixtures. Nothing in the current test path compiles C for several books in one process: --checkup runs a whole shard in one process but never emits C. A proper harness is #1310's job. For sizing: compiling the C for all 702 tests in one process takes about 3 s, so roughly 0.2 s per shard if it ran on the minis.

Verification:

  • In one process (before the rebase onto 1159f0b): all 702 tests plus B → A → B (705 compiles), forward and reverse order. Every result matches its fresh single-process build; main throws on the final B.
  • JS unchanged (also before the rebase): js_book and js_lib (module mode) output is byte-identical to main's for all 702.
  • Bench C: all 17 benches compile to byte-identical C on 1159f0b and on this branch.
  • Gates on the rebased branch:
    • repo 50/50; comp.ts is at 63,971 of its 64,000-token cap.
    • test 1546/1546.
    • perf 123/124; the one failing cell is mandelbrot GPU at 1.16x, a flaky cell that also fails on main. Earlier runs on both this branch and main lost whole cells to builds deleted mid-run on the cluster, apparently another perf run hitting the same minis.
    • ping was skipped because there's no site checkout here.
  • tsc reports no errors in the changed files.

jasisz and others added 3 commits October 5, 2026 13:16
compile_book read the last book's NODES and LAYS in show_main before
file_book cleared them. The per-book reset moves into memo_reset, the
first call of compile_book and js_lib, so nothing a compilation reads
precedes it; show_main no longer clears caches itself. The in-process
check in gates/test.ts and its two fixtures go with it: the gate driver
does not compile.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The names say which scope each clears, so memo_gc_book needs no comment.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@nicolas-abril
nicolas-abril force-pushed the fix/compiler-cache-show-layout branch from 3f81276 to 12f0848 Compare October 5, 2026 11:30
@nicolas-abril
nicolas-abril merged commit e132829 into bendlang:main Oct 5, 2026
1 check passed
Lorenzobattistela added a commit to nicolas-abril/bend that referenced this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants