Skip to content

Check that a drained service is drained once, at compile time and at run time - #62

Merged
SandroMaglione merged 1 commit into
mainfrom
feat/consume-once
Oct 23, 2026
Merged

SandroMaglione merged 1 commit into
mainfrom
feat/consume-once

Conversation

@SandroMaglione

Copy link
Copy Markdown
Member

Why

snapshot() takes the presses since the previous call. A second caller gets only what the first left, so a press reaches one of them. consumeService made draining visible to describe(), but two gaps remained:

  • a system could call snapshot() through a plain Game.System.service without declaring it;
  • the lint only saw named schedules.

What

  • Compile time: System.Consumes<"snapshot"> marks the methods of a service type that drain it. Through Game.System.service those methods are an error naming the fix:
    snapshot() drains Game/Controls: declare it with Game.System.consumeService, or read the resource its capture writes.
    consumeService calls them. Other methods (rebind) stay available through service.
  • Every input source is marked:
    • Keyboard.Actions and Keyboard.Presses
    • Gamepad.Actions
    • Touch.Touch
    • Pointer.Pointer
    • Controls.Device and Controls.Controls
    • InputCapture.Source
  • Run time: a debug runtime records the placements (schedule and step) where consuming systems ran. service-consumed-twice then also reports a source consumed at two placements in unnamed schedules. Named schedules are still reported once, by the static lint.
  • service returns ServiceRead<D, false>, and consumeService returns ServiceRead<D, true>.

Checks

  • pnpm run check, pnpm pack:check
  • pnpm bench --compare against origin/main on the same machine: no regressions, all within noise.
  • bench:check against the committed baseline flags query/iterate-write-10k on this machine; it was −3% against main. Types +0.2% against main.

🤖 Generated with Claude Code

…run time

System.Consumes marks the methods of a service type that drain it; with a
plain Game.System.service those methods are a compile error naming
consumeService. Every input source is marked. Debug runtimes also record
where consuming systems ran, so service-consumed-twice covers unnamed
schedules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SandroMaglione
SandroMaglione merged commit a119607 into main Oct 23, 2026
2 checks passed
@SandroMaglione
SandroMaglione deleted the feat/consume-once branch October 23, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant