Skip to content

fix(comp): avoid JavaScript stack overflows when counting lines - #2216

Open
sebastian-griego wants to merge 1 commit into
bendlang:mainfrom
sebastian-griego:fix/js-text-line-counts
Open

sebastian-griego wants to merge 1 commit into
bendlang:mainfrom
sebastian-griego:fix/js-text-line-counts

Conversation

@sebastian-griego

Copy link
Copy Markdown
Contributor

Counting the lines in this repository's README overflows the default Node stack. Counting the lines in the changelog also overflows the default Bun stack. Both failures occur in an ordinary call to List.length(&2, String, String.lines(text)).

Input file Node on main Bun on main Node and Bun with this fix
README.md Stack overflow 281 281
CHANGELOG.md Stack overflow Stack overflow 984

Both files end with a newline. The counts include the final empty field, as specified by String.lines.

The JavaScript backend now splits strings and counts list elements with loops. The splitter advances one Bend character at a time. This preserves separators next to empty fields and prevents matches inside a packed character. The regression test also checks partial application and the Base reduction for String.split on SCon.

I ran the new regression and six related fixtures on the Bend CLI, generated JavaScript under Node and Bun, and native CPU. All seven passed on each path. The repository gate passed 56/56.

Related to #798.

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