Skip to content

fix(compiler)!: stabilize JS constructor tags across modules - #1488

Merged
Lorenzobattistela merged 1 commit into
bendlang:mainfrom
oxura:fix/1105-stable-js-constructor-tags-20261011
Oct 15, 2026
Merged

Lorenzobattistela merged 1 commit into
bendlang:mainfrom
oxura:fix/1105-stable-js-constructor-tags-20261011

Conversation

@oxura

@oxura oxura commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A constructor's JS tag includes the namespace of the book that loaded it. A value exported by a.bend has tag Counter, but a module that imports the same type expects a.Counter. So when one module's value goes into another, the match picks the wrong arm (on main, score(Left) gives 9 instead of 8, and flag(Off) gives 1 instead of 0).

Fixes #1105.

Change

  • A constructor's JS tag is now its name inside the file that declares it, with no namespace prefix from the loading file. This applies to JS constructor emission, type-local matches, and CID(...) for constructors.
  • Foreign-def effect identities and public def export keys keep their full namespaces.
  • Display names stay qualified, so JS and native C still print a.Counter{5n}. The show descriptor stores [tag, display] pairs.
  • tests/io/constructor_interchange.bend/.js: two real modules, each using values built by the other (record, sum arms, enum arms). The test fails on main and prints 0 here.

Breaking: a host that hard-codes a book-qualified tag string ("a.Counter") no longer matches. Hosts that use CID() are unaffected. The repo has no such literals.

Tags are unique only within a type. That is fine, because every JS dispatch on .$ is type-local.

Rebased onto main 252752c. Since #1506 removed the JS seam check (js_marshal), this PR no longer touches marshalling, marshal_tag_unknown is gone, and tests expect plain numbers (4/8/9). There is no unknown-tag check at the boundary, either on main or in this PR.

Evidence

comp.ts 63,740 tok (cap 64k). Gates: repo 54/54, test 1635/1635, ping 58/58, perf 124/124, safe 0 false rejects. Interp, JS and C agree on cross-file cases (same ctor names in two files, generic holding the other file's type, three-level imports, effect building a value with CID). CUDA and Windows were not run.

@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Thanks @oxura. A few notes on this one:

The GUIDE is supposed to be written by hand, so please drop the GUIDE.md edit. The wording there could improve, but we'll do that ourselves.

Two problems with the tests:

  1. The new test, tests/io/constructor_interchange, fails on our cluster test gate (check, interp and js lanes: "Error: null", exit 1). It spawns bun by name, and bun is not on PATH there.
  2. Please keep tests/io/marshal_tag_unknown instead of deleting it. It still covers the effect-result side of the seam, the message and the exit code. Only its expected line needs to change.

We'll discuss the tag change itself with @nicolas-abril before deciding on this PR.

@oxura

oxura commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 059c4ce:

  • The GUIDE edit is removed entirely; the file matches main again. The public cutover note is in the changelog instead.
  • In the Bun gate lanes, constructor_interchange now invokes process.execPath, not bun from PATH. The installed compiled Bend CLI invokes itself without a TypeScript entry argument. Node keeps its existing source-compilation requirement that Bun be available.
  • tests/io/marshal_tag_unknown and its original valid/invalid effect producers are restored. It exercises the effect-result unmarshalling seam, not just the JS module-argument seam: the valid result prints 6; the invalid tag must stop with status 1 before another consumer output. I kept this as a semantic status wrapper rather than pinning the changed human-readable diagnostic sentence; the old wording expectation is not restored.

Actual local verification: both fixtures print 0 in interpreter, standalone Bun JS, Node JS and installed compiled-CLI runs. Interpreter/Bun JS/compiled-CLI runs pass with empty PATH. The actual namespaced --checkup lane also prints 0 for both with empty PATH. Repository gate: 54/54. I have not rerun the mini-cluster/GPU gates.

@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Please don't change the Changelog on PRs.

@oxura

oxura commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Removed in 11ff026. CHANGELOG.md is no longer in the PR diff, and GUIDE.md remains unchanged. This commit only removes the five changelog lines; the compiler and all test blobs are unchanged. I also corrected the PR description so it no longer claims a changelog update.

Rebased onto main 252752c (bendlang#1506 removed js_marshal and marshal_tag_unknown;
Nats cross as numbers), so the seam tag check and its test are gone.
@Lorenzobattistela
Lorenzobattistela force-pushed the fix/1105-stable-js-constructor-tags-20261011 branch from 11ff026 to a9cc48b Compare October 15, 2026 14:16
@Lorenzobattistela
Lorenzobattistela merged commit 34c02a1 into bendlang:main Oct 15, 2026
1 check passed
@Lorenzobattistela Lorenzobattistela mentioned this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants