Issue #2454: lower-std writes Ty::Named { name: item, args: inner, .. } without ref…

Open and answer this issue on GitHub.

ready, bugs · opened 2026-11-21 · updated 2026-11-23 · 3 comments

Filed by the driver from the Found: of the run of issue-743-run6 (#743) (owner, 2026-11-06).

Found

lower-std writes Ty::Named { name: item, args: inner, .. } without ref in check_core_index_of (lowered/check_core_places.rs; rustc E0308 is_whole_number(item) expected &str, found Text) when another function of check_core_places.nika has the arm Expr::Variable(name, _) => { let local: CheckLocal = state.binding(world.words.resolve(name)) ?? return null; return state.facts.pos_texts.get(local.id)?.clone() }; written let kept = state.facts.pos_texts[local.id] ?? return null; return kept.clone() it lowers with ref item again (my commit uses that form); a standalone program with the same match and ?.clone() shapes does not show it; renaming item or my args binding changes nothing; one function’s lowering must not depend on another’s body; suspected check_core_flow_lent_parts / CheckState::parts_lent (check_compare.nika, the handed/changed indices from, changed_from), cause unknown

To build

Done when

The probe or check gives the expected output the first item names from its ADR or Part I-III section, and a tests/compiler/tests/ test (or the named check) that failed on the unfixed tree is green; or the probe already passes on develop and a test pins it, naming the commit that fixed it; or the issue is closed as by design, naming the function or ADR.


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-22

Brief queued: issue-2454


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

Issue #2454

Your work order is issue #2454, 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/2454/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/bugs/issue-2454.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-23

Run: issue-2454, Result: partial

Tokens: input 114, cache read 3342245, cache write 100571, output 23283 Cost: 2.11 USD, time 0 min 26 s, turns 57

Report

Result: partial Files: none Commit: none Body: Reproduced on develop f846e4420 with an uncached lower-std (NIKAIA_LOWER_CACHE_SALT fresh, –sysroot of a git archive copy): with the issue’s form of the Expr::Variable arm in check_core_places.nika (~1325), lowered check_core_index_of’s Ty::Named { name: item, args: inner, .. } arm loses ref (name: ref item becomes name: item); with HEAD’s form (let kept = state.facts.pos_texts[local.id] ?? return null; return kept.clone()) it keeps it. Narrowed: only the .get(local.id)?.clone() part triggers it (variant with just the : CheckLocal annotation keeps ref; let kept = ...get(local.id) ?? return null; return kept.clone() keeps ref; return state.facts.pos_texts.get(local.id)?.clone() drops it, each with the same 1-node shift). Ruled out: a node-id shift alone (HEAD’s file plus a 1-node dummy fn keeps ref; the issue’s form plus a 3, 4 or 5-node dummy fn stays bare); package-level id-keyed facts (PackageFacts/CheckPackage hold none); cross-file walks (instantiations_beside, unroll and field_copies walk only this file). Not fixed, nothing committed. Fixes: Pushed: none Tests: uncached lower-std of copies only (HEAD form: ref; issue form: bare; K-node shift copies as above); no test added, since no fix was made Gate: green Deviation: no fix and no test: no cause found within the 40-turn time box Found: lower-std drops ref in lowered check_core_index_of’s Ty::Named { name: item, args: inner, .. } arm (match subject args[0], lowered as *unsafe { nikaia_std::proven::read(&args, 0) }) when check_core_places.nika’s Expr::Variable arm (~1325) reads let local: CheckLocal = state.binding(world.words.resolve(name)) ?? return null; return state.facts.pos_texts.get(local.id)?.clone() instead of let kept = state.facts.pos_texts[local.id] ?? return null; return kept.clone(); it should keep name: ref item, as the HEAD form does, and rustc otherwise gives E0308; probe: replace the arm in a git archive copy, run NIKAIA_LOWER_CACHE_SALT=x target/fast/nikaia lower-std --sysroot COPY/crates, grep Named { name: in lowered/check_core_places.rs; suspected: check_core_flow.nika check_core_flow_lent_parts / check_compare.nika parts_lent (lent_bindings keyed by id_of(arm.body), so per-file ids collide) or a per-file fact the SafeMethod ?.clone() on a Vec::get result sets (std_gets/copied_walks keyed by id_of(expr)), since only that shape flips it (.get() ?? return null then .clone() keeps ref); cause unknown Needs: Changelog: Issue: fits I1-I13; its probe reproduces Owner: Comment: #2454 Reproduced on f846e4420 with an uncached lower-std of an archive copy; a node-id shift of 1, 3, 4 or 5 nodes does not flip it, so it is not a plain id collision from the arm’s size; only return state.facts.pos_texts.get(local.id)?.clone() flips it (the annotation alone and .get() ?? return null then .clone() keep ref); suspects are lent_bindings via parts_lent and the facts the SafeMethod ?.clone() sets Friction: each uncached lower-std of a copy takes several minutes, and a traced compiler build was not possible (8.6G free, a second target/ is forbidden), so bisecting the checker fact cost most of the turns Disk freed: none; target/nikaia-project-tests 2.9G, / 8.6G free of 252G, no new cache entry over 100 MB, scratch dir 110M Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDutPTwP5Xj5HkGuidk

Debrief

  1. Most cost: each uncached lower-std of an archive copy takes several minutes. Narrowing the trigger meant one copy per variant: the node-shift runs with K=1, 3, 4 and 5, then variants a, b and c. Reading the checker’s flow code to guess at a cause also took turns: check_core_flow_arm, parts_lent, lent_bindings.
  2. Looked up: that parsed node ids restart from 0 in every file (parser/mod.rs, ADR-340/383). That a match arm’s ref comes from facts.lent_bindings[id_of(arm.body)], written in emit_core_match.nika. The NIKAIA_LOWER_CACHE_SALT plus --sysroot recipe for an uncached reference run. Which per-file sets are keyed by id_of(expr).
  3. Checks: the HEAD copy against the issue-form copy (needed). The K-node shift copies: four runs that only ruled out a plain id shift, where one or two would have done. The a/b/c variants: the most useful, and they should have come first. No compiler build, no tests.
  4. Change: for a lowering defect that comes from moving source around, the brief should say to bisect the source form first: split the triggering edit into its parts, one uncached copy each, in one background batch. Only then read the checker. A short recipe in builder.md for the uncached copy run would also help.
  5. What the issue lacked:
    • rules-gap: the issue gives the whole triggering arm, not the smallest shape. The single shape is return state.facts.pos_texts.get(local.id)?.clone().
    • knowledge: Lowering | a match arm is lowered with ref only when lent_bindings holds that name under id_of(arm.body), and these ids are unique only within one file.
    • rules-gap: the issue names no command for the uncached reproduction, so I had to work out the salt-and-sysroot recipe.
  6. Traps:
    • Fact: Lowering | lower-std caches per file, so a reference run of an edited copy needs NIKAIA_LOWER_CACHE_SALT=<fresh> and --sysroot COPY/crates, else it reports the cached result
    • Fact: Core | a traced second compiler build doesn't fit: target/fast is 7.6G with about 8.6G free (2026-11-22, f846e4420), so bisect with uncached lower-std copies instead
  7. Same work area:
    • Fact: Lowering | an uncached lower-std of one edited check_core_places.nika copy took several minutes per run (2026-11-22, f846e4420, binary target/fast/nikaia)
    • Fact: Lowering | #2454 trigger, measured 2026-11-22 on f846e4420: \return state.facts.pos_texts.get(local.id)?.clone()` drops ref in check_core_index_of; `.get() ?? return null` then `.clone()` keeps it`

Generated by Claude Code

keywan-ghadami, 2026-11-23

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

Reproduced on f846e4420 with an uncached lower-std of an archive copy; a node-id shift of 1, 3, 4 or 5 nodes does not flip it, so it is not a plain id collision from the arm’s size; only return state.facts.pos_texts.get(local.id)?.clone() flips it (the annotation alone and .get() ?? return null then .clone() keep ref); suspects are lent_bindings via parts_lent and the facts the SafeMethod ?.clone() sets


Generated by Claude Code

Back to Open Issues