Issue #2444: fn first(site: (int, String, int)) -> int sync { return site.0 } then `let…

Open and answer this issue on GitHub.

ready, bugs · opened 2026-11-20 · updated 2026-11-22 · 2 comments

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

Found

fn first(site: (int, String, int)) -> int sync { return site.0 } then let mut t: Vec[(int, String, int)] = [(5, "a", 1)]; t.sort_by_key(first); let at = t.binary_search_by_key(5, first) lowers to |a0| first(*a0), rustc E0507 (cannot move out of a shared reference), should compile as the lambda fn(s) { s.0 } does; suspected emit_arg_lent_params case 2 (#1504) in emit_core_args.nika, which emits *a0 assuming a Copy parameter type (check: a Copy-typed fn(x: int) in the same place compiles)

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-2444


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

Issue #2444

Your work order is issue #2444, 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/2444/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-2444.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-2444, Result: partial: the issue’s exact probe (string literals in a list literal) still fails, through a separate text-tier defect filed as the Found below; the copied-part shape with owned text is fixed

Tokens: input 108, cache read 3197671, cache write 69604, output 20311 Cost: 1.65 USD, time 5 min 14 s, turns 54

Report

Result: partial: the issue’s exact probe (string literals in a list literal) still fails, through a separate text-tier defect filed as the Found below; the copied-part shape with owned text is fixed Files: crates/nikaia-std/src/compiler/keeps.nika crates/nikaia-std/src/compiler/lowered/keeps.rs crates/nikaia-std/src/compiler/lowered.rs tests/compiler/tests/a_copied_part_of_a_tuple_parameter_keeps_nothing.nika tests/compiler/tests/a_copied_part_of_a_tuple_parameter_keeps_nothing.stdout Commit: A tuple parameter’s parts are its fields in the keep pass: handing back a part that copies (return site.0) keeps nothing of the tuple Body: keeps.nika keeps_uses_of gave only struct parameters a field table, so a_field_that_copies read a tuple parameter’s site.0 as unknown and kept site. So fn first(site: (int, String, int)) -> int { return site.0 } lowered by value: first(t); first(t) drew NK2105, and xs.sort_by_key(first) was rustc NK1343 (fn((_, Text, _)) where fn(&(_, Text, _)) is wanted). Now each part gets a field by position, so the parameter is lent (first(site: &(i64, String, i64))), as return site.n of a struct already was. Before: the new test drew NK2105 twice on $NIKAIA_OLD; after: it prints 5 5 a / b true. Part: #2444 Pushed: local f290348a4b0b3b8fc831b3e01578d29e1620ad8e Tests: new test a_copied_part_of_a_tuple_parameter_keeps_nothing green –both-settings, failed on $NIKAIA_OLD (NK2105 x2); tests/compiler –filter tuple 68 ok, –filter keep 132 ok; it keeps:: 33 ok; lower-std fixpoint (2nd run changed nothing besides my keeps.rs/lowered.rs); clippy nikaia-std –features compiler clean; pre-push green Gate: green Deviation: none Found: fn first(site: (int, String, int)) -> int sync { return site.0 } + fn main() throws { let mut t: Vec[(int, String, int)] = [(5, "a", 1), (2, "b", 3)]; t.sort_by_key(first); let at = t.binary_search_by_key(5, first); println(f"{t.len()} {at ?? -1}") } on HEAD+this fix gives NK1343 “Expected reference &(_, nikaia_std::block::Text, _) found reference &&(_, &'static str, _)” (the lowering is let mut t: Vec<(i64, &'static str, i64)> = vec[...]; t.sort_by_key(|__nikaia_a0| first(&__nikaia_a0))), should print 2 1 as the same program with the strings made by a fn make with push_str does; suspected text_tiers.nika: the list literal’s text parts are tiered to &'static str although the list is handed to a named function value whose parameter holds an owned String (check: nikaia check --tethers on the probe, then trace where the tier pass reads named fn values) Found: fn klen(x: String) -> int sync { return x.len() } + fn make(s: String) -> String { let mut g = String(); g.push_str(s); return g } + fn main() throws { let mut t: Vec[String] = []; t.push(make("abc")); t.push(make("b")); t.sort_by_key(klen); println(f"{t[0]}") } gives NK1343 “Expected function signature for<'a> fn(&'a nikaia_std::block::Text) -> _ found function signature fn(&str) -> _” (lowered t.sort_by_key(klen) bare), should print b as t.sort_by_key(fn(s) { s.len() }) does; suspected emit_core_args.nika emit_arg_lent_params: a text parameter lent as &str at a fn(ref T) slot with T = String counts as matching (both lend), so no closure is written around the name (check: the same with xs: Vec[Site] of a struct passes bare and compiles) Needs: none Changelog: A function that hands back a number out of its tuple parameter (return site.0) now only borrows the tuple: the caller can use the tuple again, and the function can be handed to sort_by_key and binary_search_by_key. Issue: wrong I7: the suspected emit_arg_lent_params case 2 (*a0) was not the cause; HEAD wrote no closure at all, because keeps.nika keeps_uses_of built no field table for a tuple parameter, so return site.0 kept the tuple and first was lowered by value; the issue’s probe with literal strings also hits a separate text-tier defect Owner: none Comment: none Friction: none Disk freed: none (target/nikaia-project-tests 2.9G, / 9.0G free, no new entry over 100 MB) Reviewed: 615bc000c524d28c912ea2795f4a5d68fb6c93842280bfe57e549ed83ac51c44 Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDutPTwP5Xj5HkGuidk

Debrief

  1. What cost the most. The single build cycle, about 10 minutes, since a keeps.nika change re-lowers std. The second biggest cost was following the issue’s suspected cause (emit_arg_lent_params). Varying the shape (struct parameter, return 0, return site.1.len()) moved it to keeps.nika in a few probes.
  2. What I looked up. That a tuple index is Expr::Field with the name "0". Where KeepsBody.fields is built (keeps_uses_of). That block::Text is what String lowers to under the block setting.
  3. Checks.
    • Run: the probes on $NIKAIA_OLD, one cycle, the new test with --both-settings, tests/compiler --filter tuple and --filter keep, it keeps::, clippy on nikaia-std, pre-push.
    • Wasted: none really. The grep for a Deref for Text led nowhere.
  4. One change. builder.md could say: “when the issue’s quoted lowering (|a0| first(*a0)) is not what nikaia lower shows today, distrust the suspected function and vary the shape first”.
  5. What the issue lacked.
    • wrong I7: it suspected emit_arg_lent_params case 2, but no closure was written at all. The cause was in keeps.nika keeps_uses_of: a tuple parameter had no field table, so return site.0 kept the tuple.
    • wrong I5: the quoted output (first(*a0), E0507) did not match today’s lowering. The probe mixed two defects: the keep pass, and how the literal strings get their text type.
    • rules-gap: no rule asks a probe to keep to one cause. Here the literal strings brought in a second, separate defect.
  6. Traps the next builder will meet:
    • Fact: Probes A probe of a named function value over a list of text should build its strings with a fn make and push_str: string literals in a list literal are lowered as &'static str and add a second, separate rustc mismatch.
    • Fact: Lowering and lower-std keeps.nika reads a parameter’s parts through context.fields (built in keeps_uses_of), and a parameter with no entry there is kept whatever is returned; tuple parts are fields named "0", "1", … since f290348a.
  7. Fact: none
    • My brief named no topic section, and I measured no figures.

Generated by Claude Code

Back to Open Issues