Skip to content

fix(compiler): reset probes between compilations - #976

Merged
nicolas-abril merged 2 commits into
bendlang:mainfrom
vicmcorrea:dev/compiler-probe-lifetime
Sep 22, 2026
Merged

nicolas-abril merged 2 commits into
bendlang:mainfrom
vicmcorrea:dev/compiler-probe-lifetime

Conversation

@vicmcorrea

@vicmcorrea vicmcorrea commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Why

i'm evaluating Bend for small survey-scoring helpers in our TypeScript monorepo. While testing rebuilds with the Bun plugin, I noticed compiler objects accumulating even after GC. PROBES keeps the binder variables from every previous compilation.

What changed

this resets PROBES in carb_book after the existing cache clears, keeping DUMMY at index zero. Probes stay valid through emission. The per-definition memo_gc would reset them too early. One file, one added line.

Validation

Checked on macOS arm64 with Bun 1.3.11:

  • 250 Bun builds in one process. After warmup, main retains 250 more objects per 50 builds. The patched count stays flat. Every bundle is identical and the scoring function returns 22.
  • 99 existing fixtures across C and JS. All 168 generated files and 30 rejection diagnostics match main. Another 96 mixed compilation operations, including empty roots, also match.
  • Also checked with feature/js-plains #974 at c03b845. The changes merge cleanly, and 250 Bun builds still return 22. From build 50 to 250, feature/js-plains #974 alone retains 1,000 more objects; with this fix the count stays flat.
  • Repository gate passed, 46/46. git diff --check passed. Cluster and GPU tests were not run.

Reproduction

Reproduction, run from the checkout root

The current test gate uses separate compiler processes, so it cannot catch this accumulation. This executable repro uses repeated Bun builds instead of adding a new test harness.

BEND_NO_TELEMETRY=1 bun - <<'TS'
import {heapStats} from "bun:jsc";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";

const {default: bend} = await import(path.resolve("bend2/main.ts"));
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bend-probes-"));
try {
  fs.writeFileSync(path.join(dir, "score.bend"),
    "import Base\ndef score(x: U32) -> U32:\n  (x * 3 + 7 : U32)\n");
  fs.writeFileSync(path.join(dir, "entry.ts"),
    "import scoring from './score.bend'; export const result = scoring.score(5);\n");
  const build = async () => {
    const result = await Bun.build({entrypoints: [path.join(dir, "entry.ts")],
      plugins: [bend], target: "bun", write: false});
    if (!result.success) throw new AggregateError(result.logs);
    return result.outputs[0].text();
  };
  const expected = await build();
  for (let i = 0; i < 10; i++) await build();
  for (let batch = 0; batch <= 5; batch++) {
    if (batch > 0) {
      for (let i = 0; i < 50; i++) {
        if (await build() !== expected) throw new Error("bundle changed");
      }
    }
    await new Promise((resolve) => setTimeout(resolve, 0));
    Bun.gc(true);
    console.log(batch * 50, heapStats().objectTypeCounts.Object);
  }
  const mod = await import("data:text/javascript;base64," + Buffer.from(expected).toString("base64"));
  if (mod.result !== 22) throw new Error("wrong result");
  console.log("result", mod.result);
} finally {
  fs.rmSync(dir, {recursive: true, force: true});
}
TS

The columns are rebuilds and retained Object instances after GC. Absolute counts can vary. On main the count keeps growing, while the patch levels off:

main              patched
50 84608          50 84308
100 84858         100 84308
150 85108         150 84308
200 85358         200 84308
250 85608         250 84308

Both print result 22. The fix bounds probe retention to the latest compilation; it does not release all compiler state immediately after a build.

@nicolas-abril
nicolas-abril merged commit ad424af into bendlang:main Sep 22, 2026
phenomenon0 pushed a commit to phenomenon0/bend that referenced this pull request Sep 23, 2026
Canon brings the Lit node for string and nat literals and the soundness fixes around it (bendlang#905 template binders, bendlang#941/bendlang#954 literals, bendlang#902, bendlang#852), per-constructor native descriptors in the JS emitter, whole-word matches on U32 and F32, one BEND_RTC macro for the device compilers, prefixed C locals, the select IO loop for FIFOs on macOS (bendlang#928), fresh layout and probe memos per book (bendlang#976), and its effect, base and doc changes. bend2/bend.ts auto-merged; it is canon's plus the fork's F64 literal.

WORDS keeps canon's null prototype and the fork's F64, U64 and I64 rows. The native table takes canon's shape, one descriptor per constructor; F64, U64 and I64 carry their builder and field reader in it, Char reads through char_code and SCon builds with str_prepend as the adaptive strings need. emit_match reads the datatype with canon's adt_of and matches a 32-bit word as canon does, whole words; U64 and I64 still open into their bit node and match their one constructor, which the whole-word walk cannot do past 32 bits. The C template includes sys/select.h and, on Linux, sys/epoll.h; the Metal fp64 note stays above canon's BEND_RTC branch. The IO loop keeps the fork's epoll loop, EPOLLONESHOT registrations and deadline heap on Linux, and canon's select loop is the other platforms' loop in place of poll. The JS io_text keeps the fork's one replacement per ill-formed byte.

Two seams the Lit node opened: bend2/export.ts writes a literal as the constructor chain it stands for, and str_constant reads through comp.ts's term_strip, so a literal string is still a static image. gates/repo.ts takes the union of both allow lists and the larger of each cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01S4szbK155RvUkyET5spFdw
HaileyStorm added a commit to HaileyStorm/rift-chess that referenced this pull request Sep 23, 2026
Move the compiler pin from a495242 to upstream main ff7a40c (both Bend
2.0.25; Bun 1.4.2 unchanged). Upstream changed a README link, EFFECTS.md
prose, and one comp.ts line that resets the probe list per compiled book
(bendlang/bend#976), which this project's multi-book loader relies on.

Frozen manifests stay byte-identical. A new append-only amendment chain
(bend2/laws/amendments, tools/amendments.mjs and amend.mjs) records reviewed
hash substitutions for the pin, gate tools and English documents only; law,
proof, implementation, fixture and reference bytes stay protected. freeze.mjs
and freeze-v2.mjs resolve recorded hashes through the chain.

Receipts under the new pin (v1 readiness with negative probes, v2 aggregate
proof and conformance, six mutation controls, graphics library, browser build)
and an AI-subagent review are in docs/evidence/amendments/001-bend-ff7a40c.

Co-authored-by: Cursor <[email protected]>
Phylliida pushed a commit to Phylliida/bend that referenced this pull request Sep 27, 2026
…endlang#976)

carb_book truncates PROBES to DUMMY's slot beside the other cache clears: before, the binder variables of every previous compilation stayed retained, so a process that compiles many books (the bun loader, io_run) grew by a few hundred objects per batch of builds. Every probe stays valid through emission; the per-definition memo_gc would drop them too early. Bundles are byte-identical before and after.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.

2 participants