Skip to content

A Nat crosses to a JS host as a plain number - #1506

Open
nicolas-abril wants to merge 1 commit into
bendlang:mainfrom
nicolas-abril:simplify-c2-nat-number
Open

nicolas-abril wants to merge 1 commit into
bendlang:mainfrom
nicolas-abril:simplify-c2-nat-number

Conversation

@nicolas-abril

Copy link
Copy Markdown
Collaborator

The JS runtime has held Nats as numbers since 87a1e9c (2.3x), and it kept BigInt only at the host seam. This PR removes that seam conversion. An effect's .js gets and answers a number, and a def exported through the .bend loader or -o x.mjs takes and returns one. js_marshal, js_host, nat_host and the marsh memo are gone, which frees 1,163 ttok in comp.ts (63,929 → 62,766).

Breaking for JS callers: a host that passed or expected 5n now uses 5. GUIDE.md, EFFECTS.md, main.ts's header, effs/now.js and the app_win_is_bug_2d demo are updated. A Nat is still capped at 2^48-1 by nat_chk, so no value loses precision as a number.

Tests

This also takes away the Nat half of #1105 and the return-type marshal behind #1150.

Validation

  • Generated C: byte-identical to main for all 17 runtime benches.
  • Gates on the cluster: repo 54/54, test 1600/1600 (two tests fewer).
  • Perf: 3 interleaved gates/perf.ts runs against main. Geomean compiler 0.992, runtime 0.999, no cell over 3%.
  • JS export calls: about 4x faster, since there's no BigInt round trip (2M calls: 140 → 36 ms).

🤖 Generated with Claude Code

The JS runtime has held Nats as numbers since 87a1e9c; only the host
seam converted them to BigInt and back. js_marshal, js_host and nat_host
are gone: an effect gets and answers a number, and an exported def takes
and returns one, so the C and JS lanes agree on the value model.

Deletes nat_host_neg (a negative host Nat was caught only by the
marshal) and marshal_tag_unknown (the bendlang#1105 tag check ran only for types
holding a Nat). Renames marshal_nat_bigint to marshal_nat_number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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