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
Language: record field projection, match on a local binder, or Data-shared records #2146
Environment: Bend 2.0.38, bend examples/language/mamba3/mamba3_siso.bend lane.
While porting a Mamba-3 SISO block into Bend (two weight-tied layers, ~1500 LOC, a 27-field FWD record threaded through the forward), three record ergonomics gaps kept recurring:
No field projection: r.a is not a term.
import Base
type R is Type:
R{a: F32, b: F32}
def use() -> F32:
r : R = R{1.0, 2.0}
r.a
def main() -> IO(Unit):
do IO<Unit>:
IO.print(F32.show(use()))
return Unit{}
bend → expected a defined name: r.a.
No match on a local binder: match r: where r is a local fails, so a record must be a function parameter destructured at the top of the function, before any local statement:
def use() -> F32:
r : R = R{1.0, 2.0}
match r:
case R{a, b}: a
bend → cannot scrutinize a local binder.
A record cannot be marked reusable: +r: R is rejected (+r can be used many times, so its type must be Data; a record is Type), so each use needs a fresh reconstruction from the list fields.
Context: the FWD record travels through forward_pre, forward_qb, forward_sc and their matches instead of being read where it is used, and the training/generation code rebuilds PRE, QB, SC, TP to work around (3).
Question: is record field projection (or match-on-local-binder) planned for any 2.x release? Even one of the three would remove a large amount of definition plumbing without changing semantics.
Re-confirming on Bend 2.0.38, now from the HiT diffusion-port work in bend-lab (we filed this issue during the Mamba-3 port).
I re-ran the three original repros today against the pinned 2.0.38 binary; all three still fail with the same messages:
r.a → expected a defined name / observed r.a
match r on a local → a match cannot scrutinize a local binder: give it its own def
+r: R → expected Data / observed Type
The new work hits the same plumbing again: a HiT router record carrying its hard assignment, counts, DFS order and intervals has to be destructured at the top of each function and rebuilt by hand at every return, because a local record cannot be read or matched. The ungroup path then needs the same record threaded through several defs. One of field projection, match-on-local-binder, or a Data-kind record would remove the plumbing without changing semantics.
Repros are in bend-lab/.local/mamba3-repro/ (local-only ledger directory, not a published file), and the exact error text is recorded in bend-lab/docs/NOTES.md.
For the scalar-only repro in (3), type R is Data: works today. I tried a record with two F32 fields, two accessor defs that match their parameter, and def sum(+r: R) -> F32: F32.add(left(r), right(r)); it printed 3 for R{1.0, 2.0}.
That stops working once a field is affine: changing one field to Array<F32> makes the Data declaration itself fail (expected Data, observed Type). So this avoids reconstruction for the scalar-only records, but not for the array-carrying ones. It doesn’t add r.a or matching on local binders.
Re-ran the three repros from this issue on both the pinned 2.0.38 and current 2.0.40, and checked oxura's note about type R is Data. Everything below is a fresh run on this machine (Linux x86_64).
The three gaps are still there on both versions.
Field projection:
def use() -> F32:
r : R = R{1.0, 2.0}
r.a
→ - expected : a defined name - observed : r.a
Match on a local binder:
r : R = R{1.0, 2.0}
match r:
case R{a, b}: a
→ a parameter or field scrutinee (a match cannot scrutinize a local binder: give it its own def)
+r: R on a plain type R is Type: → +r can be used many times, so its type must be Data.
oxura's correction is confirmed, with its boundary. A scalar-only record declared type R is Data: with two F32 fields, two accessor defs that match their parameter, and
def sum(+r: R) -> F32:
F32.add(left(r), right(r))
compiles and prints 3 for R{1.0, 2.0} on both versions — so a Data-kind record can be reused without reconstruction when every field is Data.
Changing one field to Array<F32>:
type R is Data:
R{a: Array<F32>, b: F32}
is refused at the declaration: - expected : Data - observed : Type. So the Data workaround covers scalar-only records and stops at any affine field, which is exactly the array-carrying router/state record this issue is about.
Net: the issue stands on both versions; the Data-kind route removes reconstruction for scalar records only, and neither projection nor local-binder match exists.
Activity
docs: pitfalls and oss-needs; record the decode-step session
adeerkhan commentedon Nov 22, 2026
Re-confirming on Bend 2.0.38, now from the HiT diffusion-port work in bend-lab (we filed this issue during the Mamba-3 port).
I re-ran the three original repros today against the pinned 2.0.38 binary; all three still fail with the same messages:
r.a→expected a defined name / observed r.amatch ron a local →a match cannot scrutinize a local binder: give it its own def+r: R→expected Data / observed TypeThe new work hits the same plumbing again: a HiT router record carrying its hard assignment, counts, DFS order and intervals has to be destructured at the top of each function and rebuilt by hand at every return, because a local record cannot be read or matched. The ungroup path then needs the same record threaded through several defs. One of field projection, match-on-local-binder, or a Data-kind record would remove the plumbing without changing semantics.
Repros are in
bend-lab/.local/mamba3-repro/(local-only ledger directory, not a published file), and the exact error text is recorded inbend-lab/docs/NOTES.md.oxura commentedon Nov 25, 2026
For the scalar-only repro in (3),
type R is Data:works today. I tried a record with twoF32fields, two accessor defs that match their parameter, anddef sum(+r: R) -> F32: F32.add(left(r), right(r)); it printed3forR{1.0, 2.0}.That stops working once a field is affine: changing one field to
Array<F32>makes theDatadeclaration itself fail (expected Data, observed Type). So this avoids reconstruction for the scalar-only records, but not for the array-carrying ones. It doesn’t addr.aor matching on local binders.adeerkhan commentedon Dec 2, 2026
Re-ran the three repros from this issue on both the pinned 2.0.38 and current 2.0.40, and checked oxura's note about
type R is Data. Everything below is a fresh run on this machine (Linux x86_64).The three gaps are still there on both versions.
→
- expected : a defined name - observed : r.a→
a parameter or field scrutinee (a match cannot scrutinize a local binder: give it its own def)+r: Ron a plaintype R is Type:→+r can be used many times, so its type must be Data.oxura's correction is confirmed, with its boundary. A scalar-only record declared
type R is Data:with twoF32fields, two accessor defs that match their parameter, andcompiles and prints
3forR{1.0, 2.0}on both versions — so aData-kind record can be reused without reconstruction when every field isData.Changing one field to
Array<F32>:is refused at the declaration:
- expected : Data - observed : Type. So theDataworkaround covers scalar-only records and stops at any affine field, which is exactly the array-carrying router/state record this issue is about.Net: the issue stands on both versions; the
Data-kind route removes reconstruction for scalar records only, and neither projection nor local-binder match exists.