Skip to content

Language: record field projection, match on a local binder, or Data-shared records #2146

Open

Description

@adeerkhan

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:

  1. 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.

  2. 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.

  3. 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.

Activity

  1. adeerkhan commented on Nov 22, 2026

    @adeerkhan
    ContributorAuthor

    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.

  2. oxura commented on Nov 25, 2026

    @oxura
    Contributor

    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.

  3. adeerkhan commented on Dec 2, 2026

    @adeerkhan
    ContributorAuthor

    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.

    1. Field projection:
    def use() -> F32:
      r : R = R{1.0, 2.0}
      r.a
    

    → - expected : a defined name - observed : r.a

    1. 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)

    1. +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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions