Repository navigation
fix(runtime): keep the host work-loop entry out of line - #1581
Merged
Lorenzobattistela merged 1 commit intoOct 15, 2026
Merged
Conversation
Lorenzobattistela
approved these changes
Oct 15, 2026
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.
Problem and fix
Generated C can crash on arm64 when built with optimization and AddressSanitizer, even with one thread. For example,
nat_add_infixfaults instead of printing6n. Inlining the C entry into a caller with a realigned stack frame lets a call into apreserve_nonesegment clobber the caller'sx19base pointer.Add one
FARdeclaration forwork_loopinside the existing#if !DEVICEblock. It keeps the host entry out of line throughFAR's existingnoinlineattribute. The shared definition and calling convention stay as they are.Fixes #1574.
Blast radius
Only
bend2/comp.tschanges: one host-only declaration affecting evaluator and pool-worker entry. No new helper, macro, allocation, or public API change. The device dispatcher is unchanged; baseline/candidate CUDA and Metal preprocessing tokens match. This avoids the broader GPU outlining change discussed in #1433.Regression evidence
Fresh base
25233fbruns reproduce thenat_add_infixfailure at O1/O3 with ASan+UBSan on Apple Clang 17.0.0 and LLVM 23.1.3. The corrected generated C passes 24 sanitizer runs acrossnat_add_infix,binary_search, andfork_leaf_result_loop, both compilers, O1/O3, and threads 1/4 with GPU off. Candidate O0 ASan and O3 unsanitized Nat controls also pass across both compilers and thread counts. Disassembly confirms that the outlined wrapper saves and restoresx19aroundWL_FID_ENTER.A separate diagnostic build confirms
work_loopentry on actual non-main pool workers with both compilers and the expected fork result4000. Diagnostic hooks are not part of the patch or the sanitizer regression binaries.Repeatable manual regression using an existing fixture:
Expected output:
6n. The ordinary gate does not enable ASan, so a duplicate Bend fixture would pass on the broken baseline too.Checks
comp.tsis 63,495/64,000 tokens.git diff --check: passed.CPU timing used an Apple M1 Pro, Apple Clang 17.0.0,
cc -std=c11 -O3, GPU off, and threads 1/4. Each cell has one warm run per variant and five alternating base/fix pairs. All 96 release runs (16 warm, 80 measured) produced the expected output with exit 0 and empty stderr.The scratch fork workloads reuse
fork_leaf_result_loop: a depth-22 tree with 16 Result turns per leaf, and 1,000,000 repeated depth-2 calls with 16 turns per leaf. Separate diagnostics count 767 host entries for the deep tree and about 12 million for the repeated shallow case; timed binaries have no diagnostic hooks. The shared desktop had material background activity, and timings include visible outliers. These are local measurements, not a performance-neutrality claim or the cluster perf gate.Validation limits
Local checks used macOS 15.8.1 arm64 with Bun 1.3.11. The reporter's exact Apple Clang 21, Linux, Windows, TSan, and the cluster gates were not run. GPU preprocessing equality is not GPU compilation/execution: Metal preprocessing used an empty header shim because the Metal compiler is unavailable. Other than manual sanitizer coverage, no test gate was added or changed. Existing sanitizer-build
sprintfdeprecation warnings remain.