Skip to content

Feature request: make @rt_safe/@lifetime sound across imported calls #765

Closed

Description

@godofecht

flow-audio needs hard real-time contracts to remain valid when a callback calls helpers imported from other Flow modules/packages.

Current lifetime-domain documentation explicitly says cross-module domains are not consulted. That prevents a library from making an end-to-end guarantee: an @lifetime(callback) function in one module can call an imported helper whose implementation allocates or blocks without the caller's checker necessarily seeing the imported domain/call graph.

Requested capability: emit/import a compact effect/lifetime summary for public functions and use it during type checking. At minimum the summary should say whether a callable is callback-safe, frame-safe, may allocate/free, may block/lock, may do device/file/network I/O, and its declared lifetime domain. Transitive diagnostics should preserve the useful call-chain explanation.

This should not require runtime metadata and should erase before codegen, like the current annotations.

Why this matters beyond audio: any reusable hard-deadline library, game callback, embedded interrupt-ish path, or low-latency service boundary needs contracts to compose across packages.

flow-audio will avoid depending on this until implemented; its RT core will use direct named calls with locally visible implementations.

Activity

  1. godofecht commented on Aug 27, 2026

    @godofecht
    ContributorAuthor

    Worked through the cross-module contract and archived the full derivation + Flow semantic model in godofecht/OpenProjects as compilers/modular-rt-safety-effect-summaries.md / .flow.

    The minimal exported contract is a transitive may-effect bitset plus declared lifetime domain for each public callable. Local summaries are the least fixed point

    E_f = L_f ∪ ⋃ E_callee

    with imported summaries treated as leaves. Because the effect lattice is finite, a worklist terminates after at most |Effects| * |Functions| successful bit insertions, including recursive SCCs. If imported summaries are sound upper bounds, the client's computed summary is a sound upper bound across module boundaries.

    There is also a useful incremental result. If a new dependency contract refines the old one (effects_new ⊆ effects_old and domain_new <= domain_old), every caller previously accepted under the old contract remains accepted and sound. Only effect growth / movement to a longer-lived domain can invalidate prior accepted clients. So RT/lifetime cache invalidation can key on public semantic summaries rather than full dependency source hashes.

    An unprovable imported/extern callable should carry an explicit unknown effect bit rather than silently getting an empty summary. Diagnostics can preserve one provenance edge per newly introduced forbidden bit to retain transitive call-chain explanations.

    Local validation: randomized recursive call graphs up to 11 functions matched direct reachability union; the five-bit worklist never exceeded the 5|F| insertion bound. The refinement theorem was exhaustively checked over 9,720 valid effect/domain combinations. No hosted CI was used.

  2. added a commit that references this issue on Oct 4, 2026
  3. added a commit that references this issue on Oct 5, 2026
  4. godofecht commented on Oct 7, 2026

    @godofecht
    ContributorAuthor

    2026-10-07: Extended draft PR #1355 with a cache-correctness hardening. An empty/truncated prior RT-summary snapshot previously refined trivially, which could set rt_cache_hit=1 and skip imported RT/lifetime checks. The branch now validates serialized framing, RT bit/domain ranges and loaded snapshots; rejects empty old/new summaries and non-hex/traversal-like cache keys; bounds malformed entry walking; and adds self-tests for zero-length/truncated snapshots. 10/10 source invariants pass. Native flowc/bootstrap fixed-point verification is still required.

  5. 2 remaining items

  6. godofecht commented on Oct 8, 2026

    @godofecht
    ContributorAuthor

    2026-10-08 hardening supplement: serialized imported RT/lifetime summaries now fail closed before refinement. flowc_rt_summary_buffer_valid validates complete kind/name/value NUL framing and bounds RT bit/domain fields; truncated/empty/malformed prior state can no longer count as a reusable/refining contract. Added tests/lang/test_rt_summary_cache_validation.flow and wired it into tests/scripts/rt_summary.flow; docs now reflect the current six-domain lattice (callback < frame < request < session < application < persistent). 10/10 committed-source invariants pass. Native ./flow test-lang / script-suite execution is still required before merge; no claim that this closes all #765 gaps.

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions