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).
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).'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).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.#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.
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
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:
for whose body does not pause is the parser’s each, with no thread.So:
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
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.
Reading::counting):
None (default): reused in place, no count.Cursor: ring order.Plain: Rc.Shared: Arc, one count per batch.D8’s cut token is kept, and a full pool is an error.
TypeId sink and the 'static rewrite are gone.
each, an emitted item borrows its buffer or the in-memory input for the turn.BufView beside the item through parse_<rule>_reader_each_held. A Rust item type with views cannot itself become 'static without unsafe or a self-referential holder, so Nikaia’s tether pairs them.Measured (callgrind, 200 000 rows), step None against a310181:
| Case | a310181 | None |
Change |
|---|---|---|---|
_reader_each |
91.52 M | 81.91 M | −10.5 % |
| one emit per item | 113.32 M | 85.71 M | −24.4 % |
| other cases | within 0.3 % |
No case is slower.
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):
main.emit_grammar.nika binds _state as &mut ::winnow_grammar::Act(&mut input.state) in a grammar with an emitting @stream entry.Reading literals get counting.The checker accepts an emitted item that views its input. It refuses that today:
struct Item { word: String, at: u32, }
grammar Counted { rule WS = "" -> { } @stream entry rule items -> Item = group* rule group = w:text(letter+) ";" -> { emit Item { word: w, at: 0 } } rule letter = x:any if(x >= 'a' && x <= 'z') -> { } }
fn main() throws { let input = "ab;cd;efg;" for it in Counted::items(input) { println(f"{it.word} {it.at}") } }
This gives NK1106: Item.word holds a String of its own, but you're giving it a view of a String. By ADR-grammar-typed-read-v2 D7 and ADR-views-v4 D5 it should check, because the item lives for one turn.
Generated by Claude Code