Skip to content

Module statics cannot hold string or struct types, which is the real limit on stateful handlers #562

Closed

Description

@godofecht

Split out from the "capabilities are stateless" note in docs/effects-showcase.md. That note is broader than the actual limitation, and the two examples it gives both work today.

What works

A metrics counter:

let mut call_count: i32 = 0

effect Log { info(msg: string) -> void, }

capability CountingLogger {
    effect Log,
    function info(msg: string) -> void {
        call_count = call_count + 1
    },
}

function main() -> i32 {
    handle Log with CountingLogger {
        Log.info("one")  Log.info("two")  Log.info("three")
    }
    printf("handler ran %d times\n", call_count)
    return 0
}
handler ran 3 times

A collecting test spy:

let mut seen: array<i32, 8> = [0, 0, 0, 0, 0, 0, 0, 0]
let mut n_seen: i32 = 0
collected 3: 10 20 30

Capability methods have no self, which is true, but Flow does have module statics and they are mutable from inside a handler. "A real collecting test-spy or a metrics counter" — the two cases the note names as impossible — are both straightforward.

What actually does not work

Module statics are restricted by type:

✗ Module static 'v' has unsupported type 'string': module statics must be a
  primitive (i32/i64/u8/u32/f32/f64/c64/c128/bool), a fixed array of
  primitives, or ptr<T>

Struct statics are rejected the same way. So a handler that accumulates strings or structs has nowhere to put them, and that is the real boundary. A spy collecting numbers is fine; a spy collecting log lines is not.

Suggested resolution

Either widen module statics to cover string and struct types, or keep the restriction and fix the documentation to describe it accurately. The current wording sends people to a more awkward pattern than they need for the common cases.

The documentation half is worth doing regardless of whether the restriction changes, since a stated limitation that is not real costs readers real work.

Activity

  1. godofecht commented on Oct 21, 2026

    @godofecht
    ContributorAuthor

    Reopening this with a concrete application use case. In EmbryoMaker Flow, batch execution state in src/model.flow is held in six module-level scalar globals. Grouping those related values into a ModelBatch record is rejected by flowc because module statics currently exclude struct types.

    The batch API is used by the long-lived Studio server. A record would keep its token, target, mode, and elapsed progress together while preserving the existing API functions.

    Could the Flow repo agent implement struct-typed module statics and open a follow-up patch PR against godofecht/embryo-maker-flow that groups this batch state into a record? Please preserve the current flowc build and simulation parity.

  2. added 13 commits that reference this issue on Oct 23, 2026
    c30d2ed
    472e6b2
    c1fb54b
    1ae5eef
    914901d
    290623e
    1a2e4f3
    22ac5ab
    4645211
    bad5c6d
    0f6edba
    c338030
    51dc323
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