You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JS lane: a Nat inside a value passed between two loaded .bend libraries stays a BigInt (constructor tags depend on the importing root), since 2.0.29 (still in 2.0.30) #1105
Bend 2.0.29 (c8691aa) and 2.0.30 (56330b2), bun loader (bun --preload bend2/main.ts), macOS arm64, Bun 1.3.14.
a.bend
import Base
type Counter is Data:
Counter{count: Nat}
def Counter.make() -> Counter:
Counter{5n}
b.bend
import Base
import ./a.bend as A
def dec(c: A.Counter) -> Nat:
A.Counter{count} = c
Nat.sub(count, 1n)
t.ts
import A from './a.bend';
import B from './b.bend';
const c = A'Counter.make'; // c.$ === "Counter", c.count === 5n
B'dec'; // 2.0.29: TypeError: Invalid mix of BigInt and other type in subtraction
B['dec']({$: 'Counter', count: 5n}); // same TypeError
B['dec']({$: 'a.Counter', count: 5n}); // 4n
2.0.29 and 2.0.30: the first two throw. The host wrapper's in-marshal (js_marshal) dispatches on the tag string: case "a.Counter": ... count: nat_host(v.count), and default: at[key] = v passes a value with any other tag through unconverted. The BigInt then reaches code that now treats a Nat as a JS number (The JS lane loops tail cycles and calls every def directly (on top of #1043) #1061 / 87a1e9c), and fails far from the boundary, or silently compares unequal (BigInt vs number with ===) instead of throwing.
The cross-library case has no host-side fix: two libraries compiled from the same source disagree on one constructor's tag, so a value one library returns is not recognised by the other. Either the tag should not depend on which file is the root of the book (a file's namespace being its real path, as #1042 says, for the root too), or the in-marshal should convert by type rather than by tag for a single-constructor type, and an unrecognised tag should fail at the boundary instead of passing through.
Seen in a real program: a record built by one module (a jitter buffer inside a bridge) returned to TS and passed into a function of another module throws in Jitter.emit_ready on count - 1; another returns false from a validity check because a BigInt count compares unequal to a number.
Update on current main (565d7fd): the repro above no longer returns a BigInt silently; the host-boundary dispatch now refuses it, as the TODO(#1105) in comp.ts describes:
tag "Counter" count bigint 5
from A -> bend: a.Counter has no tag Counter (its tags: a.Counter); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)
tag Counter -> (same error)
tag a.Counter -> 4
So a value one library returns still cannot be passed to another library that imports the same type.
In case it helps with that later version: we have been running an approach downstream that tags a constructor with its name in its own file, as the loader's header promises ({$: "Name", field: value}), so the tag no longer depends on which file is the root of the book.
bend.ts records each constructor's namespace, as a Def already does (we know bend.ts is human-maintained, so this is only a suggestion):
comp.ts spells every JS-lane tag through one function: where the lane builds a constructor, matches one, converts one at the host boundary, and resolves CID(Name) in a .js effect source. main's printed value keeps the full key, as the C lane does. Dispatch is per type and a file's constructor names are unique, so dropping the namespace from the tag cannot make two arms of one match collide.
Evidence from when we introduced it (on 2.0.31; the same approach is carried on 2.0.34): the repro returns 4n both for the value from the other library and for a host value with the short tag; and the 1,343 tests under tests/ that define main, built with -o t.js and run under bun, print identical output with and without the change. Our comp.ts side is a 46-line change against 2.0.34; happy to rebase it onto main and share it if that is useful.
Activity
Bend 2.0.32: the issue triage, root fixes, one verdict everywhere
moorbrook commentedon Oct 4, 2026
Update on current
main(565d7fd): the repro above no longer returns a BigInt silently; the host-boundary dispatch now refuses it, as theTODO(#1105)incomp.tsdescribes:So a value one library returns still cannot be passed to another library that imports the same type.
In case it helps with that later version: we have been running an approach downstream that tags a constructor with its name in its own file, as the loader's header promises (
{$: "Name", field: value}), so the tag no longer depends on which file is the root of the book.bend.tsrecords each constructor's namespace, as aDefalready does (we knowbend.tsis human-maintained, so this is only a suggestion):comp.tsspells every JS-lane tag through one function: where the lane builds a constructor, matches one, converts one at the host boundary, and resolvesCID(Name)in a.jseffect source.main's printed value keeps the full key, as the C lane does. Dispatch is per type and a file's constructor names are unique, so dropping the namespace from the tag cannot make two arms of one match collide.Evidence from when we introduced it (on 2.0.31; the same approach is carried on 2.0.34): the repro returns
4nboth for the value from the other library and for a host value with the short tag; and the 1,343 tests undertests/that definemain, built with-o t.jsand run under bun, print identical output with and without the change. Ourcomp.tsside is a 46-line change against 2.0.34; happy to rebase it ontomainand share it if that is useful.A Nat crosses to a JS host as a plain number