Issue #2852: winnow-grammar’s reader reads into counted buffers and its emit sink holds counted handles, so an emitted item views its input

Open and answer this issue on GitHub.

wip, queued · opened 2026-11-28 · updated 2026-11-30 · 2 comments

Part of #2834

The engine half of ADR-stream-buffers-v1 D7 and ADR-grammar-typed-read-v2 D7 (owner, 2026-11-28, #2834). This is the defect #2834 was filed for: winnow-grammar’s emit sink (EmitSink, its ADR 28; emitted_type in winnow-grammar-macros/src/codegen/stream.rs) rewrites every lifetime of an emitted item to 'static, so an emitted item cannot view its input; and its reader (G::<rule>_reader) reads into windows that move, so it hands out owned items (#2735, superseded).

To build

  1. The reader reads into counted buffers. winnow-grammar’s reader path reads into buffers from a pool whose size the caller gives, each buffer behind a count (the tether crate’s Keep/Place, or the engine’s own; the builder chooses and says why), and a token cut by a buffer’s end moves to the next buffer’s start (ADR-stream-buffers-v1 D8).
  2. The sink holds counted handles. An emitted item carries a handle on its buffer, so it is 'static as a type with its text a view; emitted_type’s rewrite to 'static goes; no unsafe is added for it. Test: winnow-grammar’s own tests, and in this repository the probe of #2834 (yaml’s Event with its clones dropped compiles and packages/yaml’s tests pass).
  3. The pin moves. This repository’s winnow-grammar pin (Cargo.toml) names the commit; packages/yaml’s events view their input. Test: packages/yaml’s tests and its events benchmark (benches/yaml/events), Ir before and after in the commit message.

Done when

#2834’s probe compiles and runs, packages/yaml’s tests pass with Event viewing its input, the pin is moved; the last commit in this repository carries Fixes #2834.

Files and limits

winnow-grammar (keywan-ghadami/winnow-grammar; the session needs it added to push there), this repository’s pin, packages/yaml/src. The emitter defects “The item rule written with '_” (#2835) and “Two ref parameters and a result that may hold views” (#2836) are their own issues.

Supervisor: add winnow-grammar to the builder’s session (or build items 1-2 there) and push its commit before item 3.

Facts: Grammar, Packages

Comments

keywan-ghadami, 2026-11-30

Correction of items 1 and 2 (supervisor, 2026-11-30). As written, the issue asks for “each buffer behind a count” and “an emitted item carries a handle on its buffer”. That wording follows a line in ADR-stream-buffers-v1’s Consequences (“The engine’s emit sink holds counted handles, so an emitted item is 'static on every path”), not the decisions. The decisions are what count:

So:

  1. The reader’s pool takes the D5 step it is given, by default none. A counter exists only at steps 3 and 4, and an atomic one only at step 4. Until “A stream’s views handed to a task over a bounded channel, counted with the cheapest of four steps” (#2854) is built, the caller passes the step; after that, the compiler chooses it.
  2. The emit sink is generic over the item type with its lifetime (no TypeId, no rewrite to 'static). On each, an emitted item borrows its buffer or the in-memory input for the turn, with no count. A handle, atomic, exists only on the walks where the item crosses a thread.

The first run’s ee6771c (an Arc per buffer) is being reworked to this. The Consequences line in ADR-stream-buffers-v1 will be corrected to match D5 and the walk table.


Generated by Claude Code

keywan-ghadami, 2026-11-30

Items 1 and 2 are built in winnow-grammar, branch stream-buffers (ee6771c, d64d8a6, a9f6aa4, c06d356), PR keywan-ghadami/winnow-grammar#48. They wait for the owner’s review; the pin moves to main after the merge.

The two ADR lines that said every emitted item carries a counted handle are corrected to D2 and D5: ADR-stream-buffers-v1 Consequences, and ADR-grammar-typed-read-v2 D7’s emit bullet. Both are editorial fixes; no decision changes.

Item 3 (in this repository, after the merge):


Generated by Claude Code

Back to Open Issues