Skip to content

fix(runtime): correct JS text boundaries after the Char rewrite - #1549

Closed
oxura wants to merge 4 commits into
bendlang:mainfrom
oxura:fix/1411-js-text-boundaries-20261013
Closed

oxura wants to merge 4 commits into
bendlang:mainfrom
oxura:fix/1411-js-text-boundaries-20261013

Conversation

@oxura

@oxura oxura commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to the reproduced review findings on #1411, which merged while I was verifying them. Based on current main 63b2c0d, preserving the maintainer's later edits and the merged channel/F32.round work.

Correctness

  • A module return is converted using the type after the function's actual n parameters (tele_fill), not the eventual result after every type parameter. Exporting pre(a: String) -> String -> String no longer passes a closure to str_out. Output conversion runs once after run_lib finishes the trampoline and survives partial application.
  • A non-scalar u32 is packed in four low-surrogate units: DC00..DC03 carries the high two bits; three DC00..DFFF units carry ten bits each. No raw NUL/control/ASCII payload leaks into nested host-visible text. Length/decoder/display/output all recognize the same valid packet; malformed lone-marker text does not swallow subsequent ASCII.
  • A Char getter recognizes packets, rather than treating any four-unit string as a packet. A trusted wide host Char such as gbab now yields the leading code 103, not 411240546.
  • Non-string direct Char/String inputs and effect answers produce a Bend-category diagnostic rather than an opaque .replace TypeError.
  • Host conversion selection uses explicit converter names. Non-text continuations reuse the original callback.

Runtime work

  • String length walks by Char without creating a converted string or a code-point array.
  • Matched/captured Char codes are held once per binder body/invocation. Private emitted field-read markers preserve constructor-view folding; user string literals escape the marker and remain unchanged.
  • Direct effect text is converted once by the effect wrapper. Redundant passes in io_bytes, get_env, and the direct Process.run program name are removed. Nested process args and Halt messages retain their explicit conversion.

Verification

The retained module_text_boundaries fixture invokes the actual compiler and generated host module. It failed on merged main, and now exercises exported/curried closures, DC00/DC05 nested text with preserved tails, control-free packets, scalar/non-scalar text, all u32 marker classes and Unicode boundaries, wrong host types, captured code, literal marker preservation, and Char rebuilds.

Actual consumer work Merged baseline This change
Ordinary repeated-code binder: code-point calls 3 1
Two captured-function invocations: code-point calls 4 2
String length: replacement passes / iterators 1 / 1 0 / 0
IO.print: replacement passes, same text 2 1
Char identity: Char constructor calls 0 0
  • 76 actual runtime/fixture outcomes passed: 23 interpreter, 23 emitted-Bun, 21 emitted-Node, 9 native C. Marshal-only fixtures have no C counterpart; Node Process.run and the old module-export-keys child-compiler driver are excluded for known lane limitations.
  • The non-scalar Halt probe produced exact EF BF BD EF BF BD 0A, exit 7, in interpreter/Bun/Node/native; the invalid host effect answer produced a Bend-category error instead of a TypeError.
  • Staged repository shape/cap gate 54/54; comp.ts 63,972 ttok, cap 64,000 unchanged. Latest commit 13e612e also removes the compiler's temporary emitted-lines array; the complete 76-outcome runtime matrix passed again.
  • Local Node v22.23.1, three interleaved fresh processes per state, 1M ASCII code units, 3 warmups and 50 measured public module calls: median 362 ms → 212 ms. This is one local case, not a general speed guarantee; max RSS was identical in all six measurements, so no RSS reduction is claimed.
  • No CUDA/Metal/macOS/mini-cluster or safe.ts --verdict claim.

Limits

This does not add a recursive host-value marshaler. Nested host strings still use the existing pass-through ABI; a well-formed reserved four-low-surrogate packet remains Bend's internal encoding. It does not address #1468's existing Node Process.run Worker limitation. No edits to human-written bend.ts, GUIDE.md, gates or caps; no CHANGELOG entry.

@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Closing. #1825 takes the opposite approach to the JS effect boundary: each effect converts its own text, as C effects do, rather than the wrapper converting it. That covers the effect-side part of this PR. The rest no longer applies cleanly: main moved char_new into a shared TS function used by the constant folder, and comp.ts is at its 66k ttok cap. Thanks for tracking down the #1411 findings.

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.

2 participants