Repository navigation
Conversation
… on C too
The atomics' C text names the array three times. op_bare held a constant
ALeaf/ANode in a local only on the JS lane, so on C each name rebuilt the
constant and the store went into a copy that was dropped:
Array.atomic.add(ALeaf{5}, 0, 3) left the returned array's cell at 5,
where the interpreter and JS give 8. Since bendlang#1817.
Contributor
|
Confirmed on macOS arm64 with Bun 1.4.5, using this PR's
All six commands exited 0, so the native regression on main is an output mismatch, not a compilation failure. I only ran this fixture, not the full gate. |
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.
On the native lane, an
Array.atomic.*call whose array argument is a constant (ALeaf{...},ANode{...}) stores into a copy that is then dropped. This program passes--check-only:bend f.bendand-o f.jsprint 8.-o fprints 5. The same happens with all nine atomics, withALeafandANode, and withF32cells (fadd). An array built at run time, includingArray.new, is not affected.Cause
The atomics' C text names the array three times:
a32_add(blk_ptr(e.mem, blk_loc(e.mem, $0), blk_at($0, $1, 0)), ...).emit_intrsubstitutes an argument's text directly whenop_baresays it is safe to repeat, andop_bareholds a constantALeaf/ANodein a local only whenFL.js, the guardtests/run/const_array_op_js.bendcovers. On C a constant array's text isblk_new(...), so each of the three names builds its own array:This started with #1817 (3ed8746). Before it,
emit_intrheld every argument of an op whose C text is a list of templates. Native C built from 3ed8746^ prints 8.Change
op_bare: a constantALeaf/ANodeis held in a local on both lanes. The negative-F32part stays JS-only. +2 ttok (65,989 → 65,991).tests/run/const_array_atomic.bend:addon anALeafandcason anANode. It prints5,6on main's native lane and8,9with this change. The interpreter and JS print8,9either way.Verified
Linux x86_64, Bun 1.4.0, clang 23, main 6180be5.
JS and MJS output: byte-identical for all 1,963
.bendfiles undertests/,bench/anddemos/.C output: it changes in 3 files, all
Array.cloneof a constant array (tests/reg/array_keep_cow,array_copy_pair,array_clone_boxed). The copy now reads the held array instead of building the constant a second time:Native tests: the suite gives the same result per test as on main, plus the new test.
Types:
tsc --noEmitoncomp.tsreports the same diagnostics.Found while testing recent array changes with Claude Code.