Issue #2708: A for over a @stream call runs its body as the parser’s each, and the items view the input (ADR-grammar-typed-read-v1 D7)

Open and answer this issue on GitHub.

blocked, yaml · opened 2026-11-22 · updated 2026-11-22 · 10 comments

Part of #1548 Found while #2426

What it is

ADR-grammar-typed-read-v1 D7, as rewritten after the owner’s decision on #2426 (2026-11-22): an item of a @stream entry views the input it is parsed from (ADR-views-v4 D5), and the compiler chooses how each walk runs. This issue builds the first method, the one the yaml benchmark and part 6 of the yaml goal need: a for over a @stream call runs its body as the parser’s each, with no thread and no channel.

Today __nikaia_walk_<book>__<rule> (emit_stream_walk and the batched handoff in crates/nikaia-std/src/compiler/emit_grammar.nika, lines 379 and 970) takes the input by move, parses on a spawned thread and hands owned items over a channel. So yaml’s Event cannot hold views: the stream needs its fields owned, and the ledger lists a field tethered or owned per type. That blocks “yaml: events and nodes refer to their scalars in the input instead of copying each into a String” (#2417). On yaml-deep the stream counts 188.7M against 157.6M in memory (callgrind, checks off).

To build

  1. Push at a direct for. A for whose iterable is a @stream call, or a local bound to one that this for alone walks, once, in the same function, lowers to parse_<rule>_slice_each with the input lent and the body as the each closure.
    • The input is lent, not moved; a temporary (Yaml::events(Bytes(...))) lives for the for.
  2. Control flow out of the body.
    • continue returns ControlFlow::Continue; break returns ControlFlow::Break, as today.
    • return, throw, a labelled break or continue to an outer loop, and a parse error are carried out of the closure as the break’s reason and acted on after the call.
  3. Items view the input. An item’s text fields are views of the input (ADR-views-v4 D5), listed tethered in the ledger; an item kept beyond the input is refused as any view is, with .clone() named.
  4. The other uses, until the general method is built. A @stream call held and passed on, handed back, stored, given to a task, combined or walked twice keeps today’s thread where its item type holds no view. Where it does, the use is refused with NK1355 (reserved here), naming the use and the build issue of the general method.
  5. Tests in packages/yaml/tests/: the existing events_stream, events_break and events_stream_whole_input pass unchanged. New tests for:
    • an item kept past the loop with .clone();
    • return and throw from inside the loop;
    • a labelled break to an outer loop;
    • NK1355 on a stream handed back from a function whose item holds a view, with its .stderr.
  6. Count yaml-deep’s stream against the in-memory path with callgrind (docs/measuring.md) before and after, and give both counts in the commit message.

Done when

for e in yaml::Yaml::events(input) lowers to the parser’s each with no thread, as the generated Rust shows. The tests of item 5 are green. The commit message gives the stream’s count on yaml-deep before and after, beside the in-memory count.

Comments

keywan-ghadami, 2026-11-22

Brief queued: issue-2708


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #2708

Your work order is issue #2708, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/2708/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/yaml/issue-2708.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Run: issue-2708, Result: partial

Tokens: input 306, cache read 23929797, cache write 225163, output 86242 Cost: 8.40 USD, time 1 min 37 s, turns 153

Report

Result: partial Files: crates/nikaia-std/src/compiler/emit_core_calls.nika crates/nikaia-std/src/compiler/emit_core_flow.nika crates/nikaia-std/src/compiler/emit_core_leaves.nika crates/nikaia-std/src/compiler/emit_grammar.nika crates/nikaia-std/src/compiler/emit_kinds.nika crates/nikaia-std/src/compiler/emit_state.nika crates/nikaia-std/src/compiler/emit_stmt.nika crates/nikaia-std/src/compiler/emit_sums.nika crates/nikaia-std/src/compiler/lowered.rs crates/nikaia-std/src/compiler/lowered/emit_core_calls.rs crates/nikaia-std/src/compiler/lowered/emit_core_flow.rs crates/nikaia-std/src/compiler/lowered/emit_core_leaves.rs crates/nikaia-std/src/compiler/lowered/emit_grammar.rs crates/nikaia-std/src/compiler/lowered/emit_kinds.rs crates/nikaia-std/src/compiler/lowered/emit_state.rs crates/nikaia-std/src/compiler/lowered/emit_stmt.rs crates/nikaia-std/src/compiler/lowered/emit_sums.rs packages/yaml/tests/events_kept.nika packages/yaml/tests/events_kept.stdout packages/yaml/tests/events_return_throw.nika packages/yaml/tests/events_return_throw.stdout tests/compiler/tests/a_narrower_error_sum_widens_into_the_callers.nika tests/compiler/tests/a_narrower_error_sum_widens_into_the_callers.stdout Commit: A for over a @stream call runs its body as the parser’s each, with no thread (ADR-grammar-typed-read-v1 D7) Part: #2708 Body: A for whose iterable is the call of a @stream entry (this file’s grammar, or a package’s through a new hidden __nikaia_each_<G>__<rule> beside __nikaia_walk_) in a function that throws, outside a catch, now lowers to parse_<rule>_slice_each with the input lent (a temporary lives for the walk) and the body as the each closure (emit_stmt_for_each). Inside, the body runs as a for over the one item, so break/continue stay the body’s own (a continue is seen as the one-item walk being asked for another); the body is an inner closure failing into the function’s channel, so ? and throw leave it natively and return writes Ok(Some(v)) (EmitFlow::returns_out, also nested); anything not a continue breaks the parse with that outcome, acted on after the call, and the parse error is thrown as before. A body that pauses (writes .await) keeps the thread. Callgrind, yaml-deep (target/yaml-bench/inputs/deep.yaml), bench settings (opt 3, lto, cu 1, overflow checks off), program for e in yaml::Yaml::events(input) { out.push_str(yaml::event_line(e)); out.push_str("\n") }: stream 188,758,595 before, 176,048,667 after; in-memory yaml::events(yaml::documents(input)) 157,685,200 before, 157,685,389 after; outputs identical (md5 418bb8e9). The rest of the gap is the per-item clone of Event (the item is still bound owned) and the engine’s EmitSink. Also fixed (defect met on the throw test, in this commit because commit.nika needs lowered.rs with any lowered file): a function failing in two errors called with ? from one failing in those and more (main adds io::IoError) was refused by rustc; write_error_sums now writes impl From<Narrower> for Wider member for member (test a_narrower_error_sum_widens_into_the_callers, fails on $NIKAIA_OLD with rustc ? couldn’t convert the error to __NikaiaThrows_A__B__io_IoError). Tests: yaml package whole 38/38 (events_stream, events_break, events_stream_whole_input unchanged; new events_kept, events_return_throw); tests/compiler: the 27 programs with @stream plus a_function_value_failing_in_a_sum_is_caught and the new sum test, 29/29; new sum test fails on $NIKAIA_OLD; events_return_throw fails on $NIKAIA_OLD only through the sum defect (same output otherwise, the lowering changes no behaviour); lower-std fixpoint holds; cargo fmt, clippy -D warnings, pre-push green Gate: green Deviation: item 2’s labelled break/continue and item 5’s test of it are not built: Part I 3.3 (10-nikaia-light.md, “There is no label”) refuses labels, so a body can only break/continue its own loop Deviation: item 3 not built: the item is bound owned (__wg_one.clone(), as on the thread), not as a view of the input; making it a view needs the checker to treat a @stream for binding as lent (check_core_stmt_for’s lent, today only over a place) and yaml’s Event text fields tethered to the input, and the checker’s typing of a package grammar call is not in the moved Nikaia parts Deviation: item 4 (NK1355) not built: no item type holds a view until item 3, so every other use keeps today’s thread unchanged Deviation: a for over a local bound to a @stream call (item 1’s second form) still takes the thread; only the direct call is pushed Found: none Needs: none Changelog: Changed: for e in G::entry(input) over a @stream entry runs its body inside the parser’s walk, with no thread or channel; return, throw, break and continue work in it as in any loop (yaml-deep’s stream walk 188.8M to 176.0M instructions). Fixed: a call to a function that fails in two ways, from one that fails in those and more, no longer fails to compile. Issue: wrong I3: item 2 asks for a labelled break/continue and item 5 for its test, but Part I 3.3 refuses labels; broke I5: Done-when’s “as the generated Rust shows” names no test or command that shows it Comment: #2708 Built the push for a direct for (items 1, 2 without labels, 5 partly, 6); left: item 3 (bind the item as a view: checker lent for a @stream for, Event’s fields tethered), item 4 (NK1355), and the for over a local bound to the call. Friction: commit.nika refuses a lowered file without lowered.rs (its digest names the whole set), so a defect fix and a feature that both change lowered files cannot be two commits as CLAUDE.md asks Disk freed: scratch build targets of the measurement and probe projects; target/nikaia-project-tests 4.5G, / 13G free; new cache entries over 100 MB: yaml-facade/debug 2092 MB, rust-library-user/3e3c2476… 806 MB, rust-library-user/2059b5a4… 900 MB Friction: a passing package test hides rustc warnings, and a failing one shows the dependency’s (yaml’s let mut all in its lowered grammar) mapped onto the test file’s lines, which cost turns to tell apart from the program’s own Reviewed: 4ea45c03664173ca050ae9447c66023614aabf2be9ef3ba8299f6aa51f450029 Pushed: local 642a07adfba8e6193a476468e58ad08a22a7424e Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwSpspVvrTQMgwWNUS

Debrief

  1. Most cost: three build cycles of 7–10 minutes each. One fixed an EmitOut? .clone() refusal (NK1125). One added the error-sum fix. One undid the walk.async_pausing guard: it silently sent the benchmark’s main (which pauses on fs::read) back to the thread path, and that only showed after a callgrind run. Chasing “unused mut” warnings that turned out to be yaml’s own, mapped onto the test’s lines, cost about 8 turns.
  2. Looked up: where the for, stream-call and return lowerings live (emit_stmt_for, emit_core_grammar_entry, emit_call_grammar, emit_core_return). The engine’s slice_each signature in the winnow-grammar checkout. That Part I 3.3 refuses loop labels. The benchmark settings and the stream program from issue-2433’s report.
  3. Checks: the yaml package, the 29 @stream/sum programs, the fails-before run, fmt, clippy, pre-push and the fixpoint all paid off. Wasted: the first “after” callgrind, because the program’s gen file was stale and then the async guard skipped the push. The hand cargo build to read raw rustc warnings.
  4. One change: in builder.md, “a package test hides stderr on success, and on failure shows the dependency’s rustc warnings mapped onto the test file”, plus a probe command that prints a program’s generated Rust.
  5. The issue:
    • wrong I3: item 2 and item 5 ask for labelled break/continue, but Part I 3.3 refuses labels.
    • broke I5: “as the generated Rust shows” names no command that shows it.
    • rules-gap: item 3 doesn’t say that the checker’s grammar-call typing sits outside the moved Nikaia parts, so its size was unknown.
    • knowledge: Measuring | the "stream vs in memory" program and the benchmark settings are only in docs/briefs/yaml/issue-2433 and benches/yaml/bench.nika.
  6. Facts:
    • Fact: Core | commit.nika refuses any lowered/*.rs without lowered.rs (LOWERED_DIGEST), so a defect fix and a feature that both change lowered files cannot be two commits.
    • Fact: Tests and the gate | a package test's rustc warnings from the dependency's lowered code are mapped onto the test file's lines; build target/nikaia/build with the bench/yaml Cargo.toml paths pointed at gen/*.rs to see the real source.
    • Fact: Lowering | walk.async_pausing is true for any function that pauses anywhere (fs::read in main); guard a closure on its own written text (".await"), not on the function.
  7. Facts for the next builder here:
    • Fact: Grammar streams | push lowering: emit_stmt_for_each in emit_stmt.nika, emit_core_grammar_each in emit_core_leaves.nika, __nikaia_each_ in emit_grammar.nika emit_stream_walk; return via EmitFlow::returns_out.
    • Fact: Grammar streams | measure: build a project with yaml as a path dependency and [build.x86_64-linux] opt-level 3, lto, codegen-units 1, using RUSTFLAGS='-C overflow-checks=off' nikaia build, then valgrind --tool=callgrind BIN target/yaml-bench/inputs/deep.yaml.
    • Fact: Grammar streams | 2026-11-22, commit 642a07ad: on deep.yaml the stream walk counts 176.05M after (188.76M before) against 157.69M in memory; most of what is left is the Event clone per item and the engine's EmitSink.

Generated by Claude Code

keywan-ghadami, 2026-11-22

From the report of the run of issue-2708 (#2708):

Built the push for a direct for (items 1, 2 without labels, 5 partly, 6); left: item 3 (bind the item as a view: checker lent for a @stream for, Event’s fields tethered), item 4 (NK1355), and the for over a local bound to the call.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Supervisor, 2026-11-22, for the rerun. 642a07ad built item 1 (the direct for) and item 2 (control flow). yaml-deep’s stream fell from 188.8M to 176.0M instructions; in memory it is 157.7M.

What the rerun builds:

  1. Item 3, the item as a view of the input. This is what “yaml: events and nodes refer to their scalars in the input” (#2417) and the rest of the 18M need.
    • The checker treats the binding of a for over a @stream call as lent from the input, as check_core_stmt_for does over a place (lent).
    • An item type’s text fields become tethered to the input (ADR-views-v4 D5).
    • The item is bound without __wg_one.clone().
    • Where the checker’s typing of a package grammar call sits in Rust, not in moved Nikaia: the grammar lane’s exception holds (CLAUDE.md, the specification first; the compiler’s Rust parts). Name the Rust added in the report.
  2. Item 4 (NK1355) once an item holds a view.
  3. Item 1’s second form: a local bound to a @stream call that one for alone walks.

Not built, by design: labelled break/continue (Part I 3.3 has no labels), so item 2 is complete as built.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Brief queued: issue-2708-rerun


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #2708

Your work order is issue #2708, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/2708/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/yaml/issue-2708-rerun.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Run: issue-2708-rerun, Result: partial; items left: item 4 (the refusal of a held, handed-back or stored @stream call whose item holds a view) and the second half of item 3 (an item type’s text fields tethered to the input: own_stream_items in text_tiers.nika still owns them), both waiting for a free NK code

Tokens: input 248, cache read 16880935, cache write 195241, output 74712 Cost: 6.52 USD, time 61 min 23 s, turns 124

Report

Result: partial; items left: item 4 (the refusal of a held, handed-back or stored @stream call whose item holds a view) and the second half of item 3 (an item type’s text fields tethered to the input: own_stream_items in text_tiers.nika still owns them), both waiting for a free NK code Files: crates/nikaia-std/src/compiler/check_core_stmt.nika crates/nikaia-std/src/compiler/check_facts.nika crates/nikaia-std/src/compiler/check_grammar.nika crates/nikaia-std/src/compiler/emit_state.nika crates/nikaia-std/src/compiler/emit_stmt.nika crates/nikaia-std/src/compiler/lowered/check_core_stmt.rs crates/nikaia-std/src/compiler/lowered/check_facts.rs crates/nikaia-std/src/compiler/lowered/check_grammar.rs crates/nikaia-std/src/compiler/lowered/emit_state.rs crates/nikaia-std/src/compiler/lowered/emit_stmt.rs crates/nikaia-std/src/compiler/lowered.rs tests/compiler/tests/a_stream_entry_of_another_package_is_walked.nika tests/compiler/tests/a_stream_item_is_lent_from_its_input.nika tests/compiler/tests/a_stream_item_is_lent_from_its_input.stdout tests/compiler/tests/a_stream_item_kept_past_its_turn_is_refused.nika tests/compiler/tests/a_stream_item_kept_past_its_turn_is_refused.stderr tests/compiler/tests/grammar_stream_runs.nika tests/compiler/tests/grammar_stream_walked_once.nika tests/compiler/tests/grammar_stream_walked_once.stderr Commit: The item of a for over a @stream call is lent from the input, and a let of the call one for walks runs as the parser’s each too (ADR-grammar-typed-read-v1 D7) Body: The checker lends the one binding of a for over a @stream call (grammar_a_stream_call in check_grammar.nika; fact lent_stream_loops), as a walk over a place does (ADR-views-v4 D5): the emitter binds the engine’s reference (once(__wg_one), no clone) in the each walk and &step? on the thread, and an item kept past its turn is NK1102 with .clone() named; a mut head still owns a copy. A let bound to a @stream call whose values are literals or names that cannot change, walked by one for (facts stream_lets, stream_let_loops, walked_stream_lets), writes nothing, and the for writes the call where it stands (emit_stmt_for_walked), so it runs as the parser’s each, no thread. Four tests that pushed or returned the item now write .clone() (D7 as rewritten on #2426). Callgrind, yaml-deep (target/yaml-bench/inputs/deep.yaml), bench settings (opt 3, lto, cu 1, overflow checks off), program for e in yaml::Yaml::events(input) { out.push_str(yaml::event_line(e)); out.push_str("\n") }: stream 176,057,191 before (HEAD 7d60ebab), 168,868,923 after; in memory yaml::events(yaml::documents(input)) 157,581,992 before, 157,581,909 after; outputs identical (md5 418bb8e9). No Rust added beyond lowered output. Part: #2708 Pushed: local faae3601b08e651c8a7c68d365e1ec4e1ad054fe Tests: new a_stream_item_is_lent_from_its_input (stdout) and a_stream_item_kept_past_its_turn_is_refused (stderr, NK1102; fails on $NIKAIA_OLD, which accepts the push); tests/compiler –both-settings –filter stream 21/21 (after the four .clone() edits and the re-bless of grammar_stream_walked_once.stderr, line numbers only) and –filter grammar_emit 7/7; a_narrower_error_sum_widens_into_the_callers ok; packages/yaml –filter events 6/6 (events_stream, events_break, events_stream_whole_input unchanged); cargo fmt –check, clippy –all-targets -D warnings and pre-push green; lower-std at its fixpoint Gate: green Deviation: item 4 not built: NK1355, which the issue reserves, is already Part I 5.x’s and ADR-call-spread-v1 D4’s code for a second spread in a call zone (10-nikaia-light.md line 2276, Part III’s table), so the refusal needs another code; item 3’s tethered fields not built: removing own_stream_items (text_tiers.nika) without item 4’s refusal turns today’s clean NK1106 into rustc errors for every walk that keeps the thread (inside a catch, a body that pauses, a held or handed-back call); yaml’s Event also stays owned, since its Rust facade (de.rs reads event.value.as_str()) and the Rust Yaml::events_reader need an owned item, the “owned form of the item” ADR-grammar-typed-read-v1 D7 names for the reader, which no issue builds; item 5’s NK1355 test not written, as item 4; the kept-with-clone, return and throw tests are events_kept and events_return_throw from the first run Found: none Needs: supervisor decision: a free NK code for item 4’s refusal (NK1355 is ADR-call-spread-v1’s), then item 4 and the tethered half of item 3 can be built Changelog: Changed: the item of for e in G::entry(input) over a @stream entry is lent from the input, as an element of a list walked in place is: one kept past its turn is written e.clone(); let s = G::entry(input) walked by one for also runs inside the parser’s walk, with no thread (yaml-deep’s stream walk 176.1M to 168.9M instructions). Issue: wrong I4a: item 4 reserves NK1355, which ADR-call-spread-v1 D4 and Part I already give to a call spread; rules-gap: item 3 asks for tethered item fields, but the Rust reader of a @stream entry (emit_stream_reader, rust-library) needs the owned item form D7 names, and no issue builds it Owner: none Comment: #2417 The item of a for over yaml::Yaml::events is now lent (no clone per event; yaml-deep stream 176.1M to 168.9M, in memory 157.6M). Event’s fields becoming views still waits for #2708’s item 4 (an NK code: NK1355 is taken) and for an owned item form for the Rust reader and facade (de.rs uses event.value.as_str()). Friction: a ?? panic("...") in emit_stmt_for widened the error type of the whole emitter from Thrown to Box (21 lowered files, two 10-minute cycles to find); a `match` on the optional does not Disk freed: the two scratch measurement builds (m_stream, m_mem target/); target/nikaia-project-tests 6.6G, / 6.6G free of 252G; new cache entry over 100 MB: rust-library-user/7111e61f (888 MB) Reviewed: bab6b7fbfb8f6518794e417b27e58e142fc756c2bb03331e6d5ac03c12157a49 Attribution: Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UVxJDwSpspVvrTQMgwWNUS

Debrief

  1. Most time: two 10-minute lower-std cycles spent finding why 21 lowered emitter files changed. A ?? panic(...) widened the emitter’s error type to Box<dyn Error>. I first blamed the recursion and rebuilt for nothing, then found it by comparing with HEAD’s emit_grammar. Waiting on cycles was most of the clock time. I also waited with sleep loops, which builder.md forbids.
  2. Looked up: that NK1355 is already taken (Part I 5.x, ADR-call-spread-v1); where a @stream call gets its type, since the checker has no stream predicate and I had to mirror the emitter’s emit_stmt_a_stream_entry; own_stream_items in text_tiers.nika; how the yaml bench measures (the program, inputs and settings were only in the earlier commit message).
  3. Checks: lower-std and build cycles (one wasted, on the recursion guess), the stream and grammar_emit programs under both settings, yaml events*, the fails-before run on $NIKAIA_OLD, fmt, clippy, pre-push, and callgrind before and after. The first quick probe after the item 3 cycle was useful. None wasted beyond the one cycle.
  4. One change: a facts line saying that panic(...) in a sync throws compiler function widens the lowered error type of its whole call graph to Box<dyn Error>. That would have saved a cycle and the hunt.
  5. What the issue lacked:
    • wrong I4a: item 4 “reserves” NK1355, which Part I and ADR-call-spread-v1 D4 already use.
    • rules-gap: item 3’s tethered item fields collide with the Rust _reader and yaml’s facade (de.rs), which need an owned item form that no issue builds.
    • broke I11: no file list (text_tiers.nika own_stream_items, check_core_stmt_for, emit_stmt_for_each, emit_stream_reader).
    • knowledge: Measuring | yaml-deep stream counts are taken by building a two-line program with target/yaml-bench/events/nikaia.toml's settings and RUSTFLAGS='-C overflow-checks=off'.
  6. Traps for the next builder:
    • Fact: Lowering | A \?? panic(“…”)` in an emitter or checker function widens the lowered error type of its whole call graph from Thrown to Box; use a \`match\` on the optional.`
    • Fact: Checker and views | A \for` over a @stream call (grammar_a_stream_call, check_grammar.nika) is lent like a place walk; its item kept past the turn is NK1102 and needs `.clone()`.`
    • Fact: Core | An NK code an issue "reserves" may already be in Part III's table; grep docs/specification for it before building.
  7. For the next builder here:
    • Fact: Grammar streams | Key files: text_tiers.nika own_stream_items (forces owned items), emit_stmt.nika emit_stmt_for/for_walked/for_each, emit_grammar.nika emit_stream_walk/emit_stream_reader, check_grammar.nika grammar_a_stream_call.
    • Fact: Grammar streams | Measure: build \for e in yaml::Yaml::events(fs::read(path, fs::Root::Anywhere)) { out.push_str(yaml::event_line(e)) … }` with target/yaml-bench/events/nikaia.toml, overflow checks off, then callgrind on target/yaml-bench/inputs/deep.yaml.`
    • Fact: Grammar streams | yaml-deep 2026-11-22: stream 176,057,191 at 7d60ebab, 168,868,923 at faae3601; in memory 157,581,909 (md5 418bb8e9).

Generated by Claude Code

keywan-ghadami, 2026-11-22

Supervisor, 2026-11-22, for the third run.

The code is NK1359, not NK1355. NK1355 is ADR-call-spread-v1’s; my reservation was wrong. The question asked in #2734 is answered.

What the run builds:

  1. Item 4 with NK1359: refuse a @stream call that is held and passed on, handed back, stored, given to a task, or walked where it keeps the thread (inside a catch, a body that pauses), where its item type holds a view. The message names the use and “The other methods of a @stream walk” (#2709). Add the code to Part III’s table.
  2. Item 3’s tethered half: remove own_stream_items (text_tiers.nika) for item types whose Rust side does not need an owned item. Each walk that keeps the thread now gets NK1359 instead of a rustc error.

yaml’s Event stays owned until “The owned form of a @stream item for the Rust side” (#2735) is built. That issue makes the Rust reader and the facade (de.rs) read an owned twin. This run leaves Event as it is, and the test of the tethered half uses a type of its own.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Brief queued: issue-2708-run3


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #2708

Your work order is issue #2708, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/2708/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/yaml/issue-2708-run3.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Run: issue-2708-run3, Result: partial: an item that views the input and is kept past its turn with .clone() fails in rustc (the engine’s each is higher-ranked), so item 5’s kept test uses a type whose kept copy is the text; item 6’s count waits for yaml’s Event to view its input (#2735)

Tokens: input 170, cache read 8379062, cache write 131863, output 43853 Cost: 3.67 USD, time 1 min 36 s, turns 85

Report

Result: partial: an item that views the input and is kept past its turn with .clone() fails in rustc (the engine’s each is higher-ranked), so item 5’s kept test uses a type whose kept copy is the text; item 6’s count waits for yaml’s Event to view its input (#2735) Files: crates/nikaia-std/src/compiler/text_tiers.nika crates/nikaia-std/src/compiler/emit_grammar.nika crates/nikaia-std/src/compiler/emit_core_leaves.nika crates/nikaia-std/src/compiler/emit_core_calls.nika crates/nikaia-std/src/compiler/emit_state.nika crates/nikaia-std/src/compiler/emit_stmt.nika crates/nikaia-std/src/compiler/lowered.rs crates/nikaia-std/src/compiler/lowered/text_tiers.rs crates/nikaia-std/src/compiler/lowered/emit_grammar.rs crates/nikaia-std/src/compiler/lowered/emit_core_leaves.rs crates/nikaia-std/src/compiler/lowered/emit_core_calls.rs crates/nikaia-std/src/compiler/lowered/emit_state.rs crates/nikaia-std/src/compiler/lowered/emit_stmt.rs docs/specification/30-nikaia-tooling.md tests/compiler/tests/a_stream_item_views_its_input.nika tests/compiler/tests/a_stream_item_views_its_input.stdout tests/compiler/tests/a_stream_of_viewing_items_held_and_passed_on_is_refused.nika tests/compiler/tests/a_stream_of_viewing_items_held_and_passed_on_is_refused.stderr Commit: A @stream item views its input unless a Rust reader may read it, and a walk that would carry such items to a thread is NK1359 (ADR-grammar-typed-read-v1 D7) Body: The tier pass owns a stream entry’s items (own_stream_items) only for a pub grammar entry that takes no values, the entries a package offered to Rust writes a reader for (the pass runs at parse time, before the build’s offered_to_rust is known); every other item type views the input as its action builds it (ADR-views-v4 D5) and is tethered. A walk that keeps the parser’s thread over such items (a let held and passed on, a for inside a catch, a body that pauses, a call another package walks through __nikaia_walk_) is NK1359 in the emitter (emit_stream_thread_refused, naming the use through EmitWalk.stream_use and #2709), and no __nikaia_walk_ is written beside a pub grammar whose items view the input. The fold’s closure and the __nikaia_each_ closure name the item’s lifetime '_, not the undeclared 'a. NK1359 added to Part III’s table. No Rust added beyond lowered output. yaml’s Event stays owned (#2735), so yaml-deep’s counts are unchanged from faae3601 (stream 168.9M, in memory 157.6M). Part: #2708 Pushed: local 076c31356ae3131dda40eafba6dbc122013de60b Tests: new a_stream_item_views_its_input and a_stream_of_viewing_items_held_and_passed_on_is_refused (both NK1106 on the before binary target/bins/446aad89c53d); tests/compiler –filter stream 23 passed, –filter grammar 91 passed; packages/yaml –filter events 6 passed; lower-std fixpoint holds; clippy -p nikaia-std clean Gate: green Deviation: item 4’s NK1359 test refuses a stream held and passed on (held.count()), not one handed back: no program writes Seq[T] in a signature (ADR-105 D4), fn items(text: String) -> Seq[Item] throws { return Words::items(text) } is NK1135 “There’s no type called Seq” Deviation: the tier pass keeps owned items for every pub grammar stream entry without values, not only those of a package offered to Rust: the pass runs at parse time (crates/nikaia/src/text_tiers.rs refine_with) and gets no Build settings Found: a stream item that views its input cannot be kept past its turn: struct Item { word: String } / grammar Words { @stream entry rule items -> Item = item* rule item -> Item = "[" w:until("]") "]" ";" -> { Item { word: w } } } / fn kept(text: String) -> i64 throws { let mut kept: Vec[Item] = []; for it in Words::items(text) { kept.push(it.clone()) }; return kept.len() as i64 } gives today NK1343 “Rustc output: borrowed data escapes outside of closure” at kept.push(it.clone()), and should run (ADR-grammar-typed-read-v1 D7 as rewritten on #2426: an item views the input, kept past its turn with .clone()); traced: winnow-grammar (rev e417f40) winnow-grammar-macros/src/codegen/stream.rs stream_each_fn writes parse_<rule>_slice_each(input: &[u8], ..., each: impl for<'a> FnMut(&Item<'a>) ...), whose item lifetime is fresh per call; the slice form needs input: &'i [u8] and each: impl FnMut(&Item<'i>) (the reader form keeps for<'a>), then a new rev in Cargo.toml Needs: #2735 (item 6: yaml-deep counts once Event views its input) Changelog: Added: NK1359 refuses a @stream call whose items view the input where its walk would keep the parser’s thread (held and passed on, inside a catch, a body that pauses). Changed: the items of a @stream entry view the input their action builds them from (Item { word: w }), unless the entry is a pub grammar’s that a Rust reader may read. Issue: wrong I5: item 5’s “NK1359 on a stream handed back from a function” cannot be written, no program writes Seq[T] (ADR-105 D4); rules-gap: item 3 assumed the engine’s each lends items at the input’s lifetime, it is higher-ranked (for<'a>), so a kept item cannot leave the closure Owner: none Comment: #2709 the thread walks of a @stream whose items view the input are refused with NK1359 (emit_stream_thread_refused in emit_grammar.nika); building a thread that borrows the input lifts it Comment: #2735 own_stream_items now runs only for a pub grammar @stream entry without values (text_tiers.nika walk_grammar); yaml’s Event stays owned through that rule Friction: none Disk freed: none (target/nikaia-project-tests 4.8G, disk 11G free; new entry over 100 MB: rust-library-user/1aa7007a 806 MB) Reviewed: c9005e86c990d5295149fc641a818c55db2eb66164097a0514b1b1c10ee5e272 Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwSpspVvrTQMgwWNUS

Debrief

  1. Most time. Two build cycles of 10–15 min each. The second was needed because the first probe hit rustc on the undeclared 'a in the fold closure; the engine’s for<'a> each showed up only after that build. Finding the winnow-grammar source in ~/.cargo/git/checkouts also took a few turns.
  2. Looked up. How a sequence type is written: Seq[T] can’t be written at all (ADR-105 D4, found through par_iter_to_a_function.nika). Where TierAsk is built (crates/nikaia/src/text_tiers.rs, at parse time, no Build settings). Where the thread walk is emitted (emit_core_leaves.nika emit_core_grammar_entry, emit_core_calls.nika). That the emitter’s view-holding test is borrowing/tethered. That emitter refusals carry a code as "[NK1227] …".
  3. Checks. Ran: the probe matrix, lower-std plus a fixpoint check twice, stream/grammar/yaml events tests, clippy on nikaia-std, pre-push, and the fails-before run on target/bins. Wasted: none, though the first cycle’s fixpoint rebuild repeated what the second cycle did anyway.
  4. One change. Have the brief state the engine’s slice_each signature, impl for<'a> FnMut(&Item<'a>). A builder would then know before the first build that a view item can’t leave the closure.
  5. What the issue lacked.
    • wrong I5: item 5 asks for NK1359 “on a stream handed back from a function”, which can’t be written: no Seq[T] in signatures (ADR-105 D4).
    • rules-gap: item 3 assumed items are lent at the input’s lifetime. The engine’s each is higher-ranked, and no rule asks an issue to check an external crate’s signature.
    • knowledge: Core | the tier pass runs at parse time (refine_with) and gets no Build settings, so offered_to_rust is not known there.
  6. Traps.
    • Fact: Core | No program can write Seq[T] or Par[T] in a signature (ADR-105 D4), so a stream can never be handed back or passed to a function.
    • Fact: Checker and views | winnow-grammar's parse_<rule>_slice_each takes each: impl for<'a> FnMut(&Item<'a>) (winnow-grammar-macros/src/codegen/stream.rs, rev e417f40), so an item that holds a view cannot be kept outside the closure.
    • Fact: Checker and views | A grammar emit that writes an item type inside a closure must rename 'a to '_ (emit_renamed_lifetime); a stream rule that hands back a count declares no 'a.
  7. Next builder (grammar streams, a new topic).
    • Fact: Grammar streams | Thread walks: emit_core_grammar_entry (emit_core_leaves.nika), emit_call_grammar (emit_core_calls.nika) and emit_stream_walk (emit_grammar.nika). NK1359 is emit_stream_thread_refused; owned items are own_stream_items (text_tiers.nika).
    • Fact: Grammar streams | yaml-deep stream walk 168.9M instructions, in memory 157.6M (callgrind, faae3601, 2026-11-22); unchanged by 076c3135 because Event stays owned until #2735.

Generated by Claude Code

keywan-ghadami, 2026-11-22

Driver: not queued, this issue waits for #2735, which is still open (#1819). Set ready again when it is closed.


Generated by Claude Code

Back to Open Issues