Skip to content

fix(runtime): size effect table to program constructor IDs - #1378

Merged
Lorenzobattistela merged 3 commits into
bendlang:mainfrom
vicmcorrea:fix/runtime-effect-table
Oct 7, 2026
Merged

Lorenzobattistela merged 3 commits into
bendlang:mainfrom
vicmcorrea:fix/runtime-effect-table

Conversation

@vicmcorrea

@vicmcorrea vicmcorrea commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1163. Clang can fold effect constructors into an initialized 65,536-slot callback table, adding 512 KiB to small native programs with -fno-common.

Size io_eff_rows by the generated CID_T rows, as requested in maintainer review. Generated effect IDs and dispatched requests already share that metadata domain. The runtime diff is one declaration; registration, dispatch, external linkage and diagnostics remain unchanged.

The two regression fixtures cover native artifact size below 256 KiB and IO without registered effects. They are unchanged from the initial PR. The native size regression is compiler-dependent: Apple Clang's default common-symbol behavior already passes the original fixture; -fno-common, Homebrew Clang and Linux Clang reproduce the failure. CLI and JS lanes measure their source entries.

Validation:

  • 119 local IO probes pass across CLI, emitted JS and native one/four-thread runs; 58 native Linux probes also pass.
  • Duplicate registration, missing callbacks and request dispatch at the maximum valid ID preserve their behavior. Maximum-ID generated-C controls extend the corresponding CID_T metadata.
  • Apple Clang 17, Homebrew Clang 23 and Linux Clang 19 pass native size/empty/hello builds with -fno-common and LTO. The original declaration reproduces oversized binaries and False; the revised size fixture prints True.
  • gpu_mark and gpu_reach pass CLI, JS, CPU and Metal. Both new fixtures pass --checkup.
  • Two independent correctness reviews pass with no findings. git diff --check and the repository gate pass (50/50).
  • comp.ts measures 63,852 ttok on this branch and 63,943 when combined with current main, below the unchanged 64,000 cap.

The full cluster test gate cannot resolve the cluster host. Full perf, ping, safe and CUDA gates are not claimed.

Make callback slots volatile so Clang retains constructor registration at
runtime instead of embedding the full effect table in initialized data.
Dispatch checks and calls one callback value, preserving the registry's
external linkage, capacity, static lifetime and registration API.
@Lorenzobattistela Lorenzobattistela self-assigned this Oct 7, 2026
@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Thanks @vicmcorrea, the diagnosis is right and the fix works. I reproduced it with Apple clang 21 by adding
-fno-common, which is upstream clang's default. On main, hello is 582 KB and your size test prints False.
With the PR it's 70 KB and prints True. The duplicate-registration and alien-request errors are unchanged.
All gates pass, and the emitted C differs only in the table and dispatch lines.

Also worth knowing: Apple clang leaves the table as a common symbol, and that's why dropping static in
#1281 looked like a fix. Our gate machines use Apple clang, so the new size test passes on main there and
can't catch a revert. It only catches one on Linux or Homebrew clang.

One ask: instead of volatile, could the table be sized to the program's constructor ids?

  Effect io_eff_rows[sizeof CID_T / sizeof *CID_T];

Every CID(k) an effect registers, and every request io_step dispatches, is already a row of CID_T (cid_arity
reads it first). The table then has a few dozen rows (117 at most in the test corpus), so it doesn't matter
whether clang folds it. That holds with -fno-common, -flto and gcc, and needs no volatile access or change to
io_step. With it, hello is 54 KB with -fno-common and 53 KB with -flto. It's +18 tokens on comp.ts, against
+12 for the PR. Your two tests can stay as they are.

@vicmcorrea vicmcorrea changed the title fix(runtime): keep effect registration out of binary data fix(runtime): size effect table to program constructor IDs Oct 7, 2026

@Lorenzobattistela Lorenzobattistela 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 @vicmcorrea!

@Lorenzobattistela
Lorenzobattistela merged commit 55923f1 into bendlang:main Oct 7, 2026
1 check passed
@Lorenzobattistela Lorenzobattistela mentioned this pull request Oct 13, 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.

Every compiled IO program carries ~1 MiB of zeros: io_eff_rows is baked into .data.rel.ro by clang

2 participants