Issue #2417: yaml: events and nodes refer to their scalars in the input instead of copying each into a String

Open and answer this issue on GitHub.

blocked, yaml · opened 2026-11-20 · updated 2026-11-23 · 18 comments

Filed by the supervisor (owner’s goal, 2026-11-20: yaml faster than saphyr-parser).

Part of #1548.

Goal

An event and a tree node hold their text as a view of the input instead of an owned String. Then a scalar costs no allocation and no copy between the parse and the walk.

Today

To build

Done when


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-20

Brief queued: issue-2417


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

Issue #2417

Your work order is issue #2417, 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/2417/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-2417.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-20

Run: issue-2417, Result: blocked

Tokens: input 60, cache read 1522200, cache write 61502, output 14290 Cost: 1.13 USD, time 6 min 2 s, turns 30

Report

Result: blocked Files: none Commit: none Body: Measured events.off (checks off, HEAD e8872d32, callgrind): deep 121,469,613, large 4,395,210,241, scalars 209,873,823 instructions. malloc+free inclusive: deep 15.6 %, large 17.1 %, scalars 15.0 %; memcpy 5.2 / 4.6 / 3.0 %. The scalar strings are the event’s: on large walk calls malloc for 4.87 % and fold (text() of a plain or single scalar, a new String) for 2.85 %; walk is 16.5 % inclusive on large, 9.6 % on deep, 10.1 % on scalars. On deep, malloc comes from the tree’s one-element lists (task_block::List<Node>::from_iter_in, 3.5 %) and Place::deallocate (6.7 %), not from scalars. The tree already holds views: the lowered Node has raw: &'a2 str and anchor: Option<&'a str>, and Scalar.value is an EitherText. Only Event owns (value: String, text, anchor, tag). Nothing was built. Fixes: none Pushed: none Tests: none run; nothing committed. Probes on target/fast/nikaia (built from HEAD’s sources) below and in Found Gate: green Deviation: none Found: A function that pushes, onto a mut list parameter, a struct holding a view of another lent parameter gets that parameter inferred as keep (NK1102), and no form says “out’s elements view n” (ADR-views-v4 D8 and D14 give from to results only), so yaml’s walk(n, ds, mut out) cannot put views of the input into its events; probe struct N {\n\traw: String,\n}\nstruct E {\n\tv: String,\n}\nfn walk(n: N, mut out: Vec[E]) {\n\tout.push(E { v: n.raw })\n}\nfn events(ns: Vec[N]) -> Vec[E] {\n\tlet mut out: Vec[E] = []\n\tfor n in ns {\n\t\twalk(n, out)\n\t}\n\treturn out\n}\nfn make() -> String {\n\tlet mut g = String()\n\tg.push_str("abc def")\n\treturn g\n}\nfn main() throws {\n\tlet input = make()\n\tlet parts: Vec[String] = input.split(" ").collect()\n\tlet ns = [N { raw: parts[0] }, N { raw: parts[1] }]\n\tfor e in events(ns) {\n\t\tprintln(e.v)\n\t}\n} gives error[NK1102]: walk expects n to be an N of its own ... It's declared as walk(keep n: N, mut out: Vec[E]). The same push written inline in events prints abc/def. Returning a list per node instead (D16) is the per-level copy #1548 removed. In the package, value: n.raw in walk draws NK1106 Event.value holds a String of its own, with or without the @stream entry. no decision yet Found: Event is the item type of both yaml::events(docs) and the @stream entry Yaml::events, and ADR-grammar-typed-read-v1 D7 says a @stream item does not borrow from the input (“yaml’s Event owns its text”). So even with the first gap closed, a view-holding Event needs either a second, owned event type for the stream (a public API change) or a change to D7; the issue’s “Where the language allows neither, stop” did not cover “the function may, the stream may not”. no decision yet Needs: supervisor decision: (1) whether a mut list parameter may receive views of another lent parameter (inferred, or written as from), (2) whether yaml::events and Yaml::events get separate event types, or D7 changes Changelog: none Issue: wrong I7: “Today” says the Node tree holds its own String per scalar and the bench README says “a String per scalar in the tree and again in its event”, but the lowered Node holds &str views; on deep, malloc comes from the tree’s one-element lists, not from scalars; only Event’s strings and fold()’s result allocate per scalar; broke I5: To build asked “can a pub struct returned from a package hold a view” without naming that Event is also the @stream item type, which ADR-grammar-typed-read-v1 D7 makes owned Owner: none Comment: #2417 Measured at e8872d32 (events.off, checks off): deep 121.5 M, large 4,395.2 M, scalars 209.9 M instructions; malloc+free 15.6 / 17.1 / 15.0 %. The tree already views the input (Node.raw is &str); per scalar only Event’s value/text/anchor/tag strings and fold()’s result allocate (walk’s malloc 4.87 %, fold’s 2.85 % of large). Blocked on two decisions: a mut out-list cannot receive views of another parameter (NK1102 infers keep), and @stream items must own (ADR-grammar-typed-read-v1 D7) while Event is shared by events() and Yaml::events. Friction: none Disk freed: scratch bench build target deleted (about 1 GB); target/nikaia-project-tests 3.7G, / 12G free, no new cache entry over 100 MB Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwSpspVvrTQMgwWNUS

Debrief

  1. What cost the most: the baseline. The bench binaries were older than HEAD, so I rebuilt events.off in the scratchpad (about 2 minutes), then ran callgrind on three inputs. My first awk script for listing malloc’s callers also printed noise and took two rewrites.
  2. What I had to look up:
    • ADR-grammar-typed-read-v1 D7: @stream items are owned, and it names yaml’s Event as the example.
    • ADR-views-v4 D5, D8 and D16: when a struct field becomes a view, and that from exists only for return values.
    • The package’s generated Rust, under the bench project’s target/nikaia/gen/yaml/yaml.rs, which showed that Node already holds &str.
    • How to rebuild the bench binary outside bench.nika.
  3. Checks run:
    • Useful: the baseline build and callgrind (deep/large/scalars), nikaia check on a scratch copy of the package with the clone removed (with and without the stream entry), and two small probes.
    • Wasted: the first nikaia check without a file argument, the first probe (NK1245 on an untyped split()[0]), and the syntax.nika -- 'field view' lookup, which found nothing.
  4. One change that would save the most: for a yaml performance issue, the brief should give the command that rebuilds events.off at HEAD and the path of the package’s generated Rust.
  5. What the issue lacked:
    • wrong I7: “the Node tree holds its own String per scalar”. The generated Node already holds &str; on deep, malloc comes from the tree’s one-element lists.
    • broke I5: it doesn’t say that Event is also the @stream item type, which ADR-grammar-typed-read-v1 D7 makes owned. So its “stop when the language allows neither” didn’t fit a case where events() could hold views but the stream could not.
    • rules-gap: no rule asks a performance issue to run its own settling probe first. Here that would be dropping the .clone() in walk, which draws NK1106 at once.
  6. Traps the next builder will meet:
    • Fact: Lowering A function that pushes, onto a mut list parameter, a value holding a view of another parameter gets that parameter inferred as keep (NK1102), because from exists only for return values.
    • Fact: Measuring target/yaml-bench/bin/* may predate HEAD: rebuild with RUSTFLAGS='-C overflow-checks=off' nikaia build in a scratch copy of target/yaml-bench/events (about 2 minutes); the package’s generated Rust is then in its target/nikaia/gen/yaml/yaml.rs.
    • Fact: Probes nikaia check needs a file argument even inside a package (nikaia check src/main.nika).

Generated by Claude Code

keywan-ghadami, 2026-11-20

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

Measured at e8872d32 (events.off, checks off): deep 121.5 M, large 4,395.2 M, scalars 209.9 M instructions; malloc+free 15.6 / 17.1 / 15.0 %. The tree already views the input (Node.raw is &str); per scalar only Event’s value/text/anchor/tag strings and fold()’s result allocate (walk’s malloc 4.87 %, fold’s 2.85 % of large). Blocked on two decisions: a mut out-list cannot receive views of another parameter (NK1102 infers keep), and @stream items must own (ADR-grammar-typed-read-v1 D7) while Event is shared by events() and Yaml::events.


Generated by Claude Code

keywan-ghadami, 2026-11-20

The report of the run of issue-2417 (#2417) judged this issue against docs/issues.md; the author fixes the issue by the rule it names (How a run judges its issue):


Generated by Claude Code

keywan-ghadami, 2026-11-20

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


Generated by Claude Code

keywan-ghadami, 2026-11-20

Open questions moved here from the closed improve issue #2427 (Founds: #2425, #2426): (1) may a mut list parameter take views of another lent parameter — inferred, or written with from? (2) separate event types for yaml::events and Yaml::events, or a change to D7?


Generated by Claude Code

keywan-ghadami, 2026-11-22

Needs #2708

The second gap is decided (“Event is the item type of both…”, #2426, option 9; ADR-grammar-typed-read-v1 D7 rewritten). A stream item views its input, so one Event with view fields serves both yaml::events(docs) and Yaml::events. The first gap (“A function that pushes, onto a mut list parameter, a struct holding a view…”, #2425) is built. This waits for “A for over a @stream call runs its body as the parser’s each” (#2708), after which the stream’s Event may hold views.


Generated by Claude Code

keywan-ghadami, 2026-11-22

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

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()).


Generated by Claude Code

keywan-ghadami, 2026-11-22

Needs #2708, #2735

The second run of “A for over a @stream call runs its body as the parser’s each” (#2708) lends the item in Nikaia. yaml’s Event must stay owned for now, because the Rust reader and the serde facade (de.rs) need an owned item. That is “The owned form of a @stream item for the Rust side” (#2735), queued in the yaml lane behind #2708’s third run.


Generated by Claude Code

keywan-ghadami, 2026-11-22

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

After #2735 nothing forces yaml’s Event owned but its own clones. Dropping them (anchor: n.anchor?.clone() -> n.anchor, value: a.clone() -> a, value: n.raw.clone() -> n.raw in opening/walk) draws, with nikaia check src/main.nika: NK1127 “limits can’t be computed while the program is built” at the limits: Limits = default_limits() options of documents, read, parse, load (lines 1911, 1937, 2044, 2084) for the anchor change, and NK1106 “Event.value holds a String of its own” at 2627/2639 for the raw change; cause unknown. de.rs already reads event text either way (text_of).


Generated by Claude Code

keywan-ghadami, 2026-11-22

Supervisor, 2026-11-22: unblocked, ready.

The run measures yaml::events(yaml::documents(input)) and the load path on deep, large and scalars against saphyr-parser (benches/yaml/bench.nika) before and after.


Generated by Claude Code

keywan-ghadami, 2026-11-22

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


Generated by Claude Code

keywan-ghadami, 2026-11-22

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


Generated by Claude Code

keywan-ghadami, 2026-11-22

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


Generated by Claude Code

keywan-ghadami, 2026-11-23

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


Generated by Claude Code

keywan-ghadami, 2026-11-23

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


Generated by Claude Code

keywan-ghadami, 2026-11-23

Run: issue-2417, Result: blocked

Tokens: input 90, cache read 2480898, cache write 67837, output 19583 Cost: 1.48 USD, time 7 min 11 s, turns 45

Report

Result: blocked Pushed: none Tests: none run (blocked before the first edit was kept); dependency #2425 closed (commit “Pin #2425’s probe …” carries Fixes #2425); probe = drop the clones in opening/walk of packages/yaml/src/main.nika (anchor: n.anchor?.clone() -> n.anchor, value: a.clone() -> a, value: n.raw.clone() -> n.raw), target/fast/nikaia check src/main.nika in packages/yaml at 0b2c28b84: 4x NK1127 “limits can’t be computed while the program is built” (default_limits() at lines 1911/1937/2044/2084), file restored unchanged Gate: green Deviation: none Found: An emitted @stream item cannot view its input, though ADR-grammar-typed-read-v1 D7 says “An item views the input it is parsed from” and “An item may be emitted”: winnow-grammar a310181 emitted_type (winnow-grammar-macros/src/codegen/stream.rs) rewrites every lifetime of an emitted item to 'static (its ADR 28: the sink tells values apart by TypeId, “An item that borrows the input can be emitted only as one that borrows nothing”). Probe: with yaml’s Event clones dropped as above, the comptime program for limits: Limits = default_limits() fails in rustc (seen with RUSTC set to a logging wrapper) with “lifetime may not live long enough … 'a defined here, returning this value requires that 'a must outlive 'static” at both grammar! { grammar Yaml and grammar YamlOverBytes, from the actions for ev in all.drain() { emit ev } of FirstEvents/NextEvents; the user only sees NK1127 “this compiler’s fault”. Should: compile, by D7. Needs an engine change (a non-TypeId or lifetime-erased sink for in-memory input) or a D7 change; no decision yet Found: An emitting @stream entry whose item type views the input writes its item rule rule __wg_<entry>_item(...) -> ::std::option::Option<Event<'_, '_>> (rustc E0106 “missing lifetime specifiers”; Event<'a, 'a> compiles, checked by hand on the generated main.rs), traced: crates/nikaia-std/src/compiler/emit_grammar.nika emit_stream_rule uses folded (built from unnamed, 'a renamed to '_ for the entry’s fold closure) also for the item rule, which has 'a; it should use item there. Only shows once the defect above lets such an item be emitted Found: A function with two ref parameters returning a struct that may hold views, here holding none, refuses with NK1343 “Rustc output: missing lifetime specifiers … borrowed from n or ds” on target/fast/nikaia at 0b2c28b84 (nikaia run p.nika); should print abc -. Probe whole: struct N {\n\traw: String,\n\ttag: String?,\n}\nstruct E {\n\tvalue: String,\n\ttag: String?,\n}\nfn view(n: ref N) -> E sync {\n\treturn E { value: n.raw, tag: null }\n}\nfn opening(n: ref N, ds: ref Vec[N]) -> E sync {\n\treturn E { value: "", tag: null }\n}\nfn main() throws {\n\tlet mut src = String()\n\tsrc.push_str("abc")\n\tlet n = N { raw: src, tag: "t" }\n\tlet ds: Vec[N] = []\n\tlet a = view(n)\n\tlet b = opening(n, ds)\n\tprintln(f"{a.value} {b.tag ?? "-"}")\n}; a function with no ref parameter gets E<'static> (yaml’s bare), this one E<'_>; suspected: the emitter’s signature writer, which should write 'static for a result that views no parameter (cause unknown, check: nikaia lower the probe and read opening’s signature) Needs: supervisor decision: how an emitted @stream item views its input under winnow-grammar ADR 28’s 'static emit sink (engine change in winnow-grammar, or D7 amended so emitted items own), no decision yet Changelog: none Issue: broke I5: To build asked whether the language lets a @stream item hold views, but not whether the grammar engine does; winnow-grammar ADR 28 makes every emitted item 'static, and yaml’s stream emits all its events Owner: none Comment: #2426 D7 (rewritten) lets an emitted @stream item view its input, but winnow-grammar’s emit sink (its ADR 28, emitted_type) forces emitted items to 'static; yaml’s Event with view fields fails in rustc at both grammars ('a must outlive 'static), so option 9 cannot be built on the engine as pinned (a310181) Friction: the real error behind NK1127 “this compiler’s fault” (a rustc failure of the comptime program) is printed nowhere; finding it took a RUSTC wrapper that logs rustc’s stderr and arguments Disk freed: removed my scratch copy’s target/ and packages/yaml/target/nikaia/build-time/comptime; target/nikaia-project-tests 2.4G, / 11G free (74 %); entries over 100 MB newer than the brief (rlib/df8bcfe6 451M, yaml-facade/debug 1015M, rust-library-user/bff714c0 895M) are not from this run, which ran no test Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwSpspVvrTQMgwWNUS

Debrief

  1. What cost the most: finding the real error behind NK1127 (“this compiler’s fault”). The compiler never prints the rustc failure of the build-time program. I needed a RUSTC wrapper that logs stderr and arguments, plus a script to run rustc again on a patched main.rs. That took about 10 turns. Getting rerun.sh right cost 2 more.
  2. What I had to look up: where the build-time program is written (target/nikaia/build-time/comptime/<key>/main.rs), and that RUSTC is read in comptime_bundle.nika. Also winnow-grammar’s ADR 28 and its emitted_type, found in ~/.cargo/git/checkouts/winnow-grammar-*/a310181, and D7’s wording on emitted items.
  3. Checks run: the dependency check through git log --grep, which was useful. nikaia check with each clone change on its own, also useful: it showed that one change alone gives a different error than the full set. The rustc reruns, useful. The probe of opening’s '_, useful, it became a Found:. Wasted: the first probe.nika --file call (it refuses scratchpad paths) and an as_str slip in a probe.
  4. One change to builder.md: “NK1127 or NK1178 saying ‘this compiler’s fault’: run with RUSTC set to a wrapper that logs stderr. The program is at target/nikaia/build-time/comptime/*/main.rs.”
  5. What the issue lacked:
    • broke I5: it asked whether the language lets an emitted @stream item hold views, but not whether the engine does. winnow-grammar ADR 28 forces emitted items to 'static.
    • wrong I7: the last comment says the NK1106 at value: n.raw has an unknown cause. After #2425 it is gone, and the NK1127 is rustc’s 'static emit error plus '_ lifetimes.
    • knowledge: Lowering | a non-lowering NK1127 or NK1178 hides a rustc error of the build-time program, which the RUSTC wrapper shows.
  6. Traps the next builder will meet:
    • Fact: Core scripts/probe.nika --file refuses a path outside the working directory, so run a scratchpad probe with cd $S && target/fast/nikaia run p.nika.
    • Fact: Lowering a @stream item that is emitted (an emit in an action) is made 'static by winnow-grammar (emitted_type, its ADR 28), so it cannot view the input.
  7. For the next builder in this area:
    • Fact: yaml Event’s view fields come from removing the .clone()s in opening and walk (packages/yaml/src/main.nika, about lines 2578-2640); with all of them removed, walk and opening lower to Event<'a, 'a> cleanly (2026-11-23, 0b2c28b84).
    • Fact: yaml what blocks them is emit ev in FirstEvents and NextEvents (lines 362-383) under winnow-grammar a310181’s 'static emit sink (2026-11-23, 0b2c28b84).

Generated by Claude Code

keywan-ghadami, 2026-11-23

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


Generated by Claude Code

Back to Open Issues