Repository navigation
An operation's argument nested past 32 brackets goes to a local, so a long chain of operators builds in C (#1123) - #1239
Merged
Conversation
… long chain of operators builds in C (bendlang#1123) emit_intr wrote a chain of primitive operations as one C expression, so 86 nested U32 operators (three brackets per U32_BIN) passed clang's nesting limit of 256, and about 3000 crashed it. An argument nested past TPL_DEEP brackets now goes to a local through emit_alias, as one a template reads twice already does. Every other program emits the same C and JS. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
nicolas-abril
force-pushed
the
deep-intr
branch
from
October 1, 2026 15:08
c4c52c3 to
e4a6d3d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
emit_intrwrites a chain of primitive operations as one C expression. ANF only cuts calls, so nothing bounds the expression's depth.U32_BINopens three brackets, so 86 nested U32 operators pass clang's limit of 256.The interpreter and JS print the right value at every depth. Fixes #1123.
Change
An argument whose text nests past
TPL_DEEP(32) brackets goes to a local throughemit_alias, as an argument a template reads twice already does. It covers the C, Metal, CUDA and JS lanes.-fbracket-depthwould only reach the host build, not Metal or NVRTC, and doesn't stop the crash.tests/reg/intr_chain_deep.bendchains 100 U32 operators and 140 F32 ones. Onmaineach half alone fails to build in C.Checks
.bendfiles undertests/,bench/anddemos/, the emitted.c(720 files) and.js(741 files) and every error log are byte-identical tomain.bench/runtimeprograms (-o main.c, 15 runs each, Apple M4): −0.1% withmainrun first and +0.5% with the branch run first.comp.tsgoes from 63,107 to 63,200 ttok (+93).tscreports no errors incomp.ts.bun gates/repo.tspasses (50/50).Alternatives measured
SPIN_FARand changes which spins inline, which shifts nbody and raytrace by 10–18%. That is SPIN_FAR inlines a spin by its line count alone: one spin made FAR runs nbody 1.18x faster on the CPU and raytrace 1.23x faster on Metal #1240.🤖 Generated with Claude Code