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: intended encoding for evolving state across an online loop #2150
Environment: Bend 2.0.38. Context: porting an online greedy decoder for the two weight-tied layers of a Mamba-3 SISO LM. The work is done and gated (tokens equal the full-prefix golden exactly at 16 tokens); this issue is a question about the intended encoding, not a bug report.
The shape that works today:
per-layer state as a record of a 2048-float Array<F32> (the SSM), a List<&2, F32> (angle, 16 floats) and a pending previous-row record (x 128, roped k 64, DT 4, trap 4) — records with Array fields work as parameters, matched at the top of their def;
the whole decoder state carried unmatched through the single self-recursive def's parameter (so nothing needs +), and every intermediate record (LOUT, SR, SA) consumed by a parameter-match helper;
arrays threaded by value, never +-bound.
Two spellings the compiler rejects today (both verified on this lane):
def use(+a: Array<F32>) -> F32:
0.0
bend → expected : Data, observed : Type (a can be used many times, so its type must be Data).
A record carrying an Array<F32> as a parameter matches fine (type St is Type: St{arr: Array<F32>, step: Nat}), so the record+Array combination is expressible — the missing part is any way to share it or to look through a def boundary at the values it contains without a helper per access.
The question: is unmatched threading of state records through one recursive def the intended encoding for an online loop (streaming decode, incremental scan), or is there a blessed pattern (explicit mutable state, a Scan-like law, a State-ish helper in Base) that we should target instead? A pointer to the intended direction is enough; no implementation ask.
Related asks already filed: #2146 (record field projection / local-binder match / Data-shared records), #2147 (forward references, mutual recursion, unrolling loops).
I got this working on current main without sharing the array: pass the state record unchanged into the loop, and unpack/update it in an affine feed helper. Put the structurally decreasing argument before the state. run(feed(s, x), xs) failed the termination check here; run(xs, feed(s, x)) passed.
This example writes three samples and reads the last one. Both the interpreter and a native build printed 13.
Activity
oxura commentedon Nov 24, 2026
I got this working on current main without sharing the array: pass the state record unchanged into the loop, and unpack/update it in an affine
feedhelper. Put the structurally decreasing argument before the state.run(feed(s, x), xs)failed the termination check here;run(xs, feed(s, x))passed.This example writes three samples and reads the last one. Both the interpreter and a native build printed
13.