Skip to content

Fix for recent Nim JS changes: swizzle setters read before they write - #92

Merged
treeform merged 1 commit into
masterfrom
fix-js-swizzle-self-assignment
Sep 21, 2026
Merged

treeform merged 1 commit into
masterfrom
fix-js-swizzle-self-assignment

Conversation

@treeform

Copy link
Copy Markdown
Owner

Summary

CI on master fails the "vec4 swizzle self-assignment" test in the JavaScript object based layout since treeform/setup-nim-action@v6 moved to Nim 2.2.12. Nim 2.2.12's JS backend no longer makes a copy for let b = b on an object parameter, so in the object based layout the swizzle setter's source and destination alias the same JS object and b.wzyx = b clobbers its own input while writing.

The fix is in tools/genswizzle.nim: every setter now reads its components into scalars first and only then assigns, which cannot alias on any backend or layout and no longer relies on copy semantics. src/vmath/swizzle.nim is regenerated, so the diff is large but mechanical (1008 setters).

Testing

tests/tests.nim passes in the default, -d:vmathObjBased and -d:vmathArrayBased layouts:

  • Nim 2.2.12, JavaScript backend (the failing configuration) and C backend.
  • Nim 2.2.6, C backend.

🤖 Generated with Claude Code

Nim 2.2.12's JS backend no longer copies an object for `let b = b`, so
the object based layout aliased source and destination in swizzle
setters and `b.wzyx = b` clobbered its own input. The generator now
reads every component into a scalar before assigning, which cannot alias
on any backend or layout.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@treeform
treeform merged commit bc26014 into master Sep 21, 2026
3 checks passed
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.

1 participant