Skip to content

fix(effects): scan CID/FID with the source's own comment rules - #1653

Merged
Lorenzobattistela merged 2 commits into
bendlang:mainfrom
adeerkhan:fix/effect-comment-continuation
Oct 19, 2026
Merged

Lorenzobattistela merged 2 commits into
bendlang:mainfrom
adeerkhan:fix/effect-comment-continuation

Conversation

@adeerkhan

@adeerkhan adeerkhan commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #1604. Supersedes #1606, which takes the same approach; its C test cases are folded in here.

c_ids resolves CID(k)/FID(k) by scanning the text of an effect source, and it applied C's line-continuation rule to every source:

  • JS: a // comment ending in a backslash swallowed the next line, so a following io_eff(CID(...)) was left unresolved and the effect died at runtime with ReferenceError: CID is not defined.
  • C: the continuation only matched \ + LF, so a CRLF // ... \ comment did not continue, and a quoted CID(...) on the next line leaked out of the comment and failed the build. A CID token split by a backslash-newline was not resolved either.

Fix (bend2/comp.ts): effect_srcs splices a C source's backslash-newline (\, optional trailing blanks, CR? LF; clang and gcc splice the same) before scanning, and leaves JS alone. The // pattern stays //.*, so a comment still ends at CR, LS and PS. This matches what each host does: C keeps a continuation inside a comment, JS does not.

Test: tests/io/effect_comment_backslash runs on both lanes. The JS twin has a // C:\ comment right before io_eff(CID(answer), ...). The C twin is CRLF and has continued comments that quote ids, one with trailing spaces, and a CID split across lines. Both fail on main and print 42 here.

Gates on main bedc964: repo 54/54, test 1657/1657, perf 124/124, ping 62/62, safe: 0 false rejects. comp.ts 64,178 → 64,237 ttok.

🤖 Generated with Claude Code

The c_ids scanner applied C's backslash-newline continuation to every source,
so a JS `//` comment ending in a backslash swallowed the next line: a
following `io_eff(CID(...))` line was left unresolved and the effect died at
runtime (ReferenceError: CID is not defined). And it used `\\\n` for the
continuation, which misses a CRLF C comment (so a quoted CID leaked out of a
C comment and failed the build).

Splice a C source's backslash-newline (line continuation) before scanning and
leave JS lines alone, and change the line-comment pattern to end at the
newline. Resolves bendlang#1604.
Restore `//.*` so a comment still ends at CR, LS and PS, splice C's
backslash-newline after trailing blanks too, as clang and gcc do, and do it
at the C call site instead of behind a flag. The regression now has a CRLF
C twin: a continued comment that quotes ids and a CID split across lines.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

Foreign effect ID scanning uses the wrong line-continuation rules

2 participants