Skip to content

fix(xtask): R6 by liveness, test regions in all their forms, refuse a stale gate binary (audit T, U, X) - #249

Merged
dc0sk merged 2 commits into
mainfrom
fix/r6-liveness
Oct 16, 2026
Merged

dc0sk merged 2 commits into
mainfrom
fix/r6-liveness

Conversation

@dc0sk

@dc0sk dc0sk commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Closes the R6/R7 class from the audit (issue #242: T, U, X; V documented).

R6 used to count a name's occurrences. A definition counted as a use, and so did a same-named function, a call from a dead function, and a use line. Now it runs a liveness pass over a name-level call graph:

  • Live contexts: code outside functions, main, methods of an impl Trait for Type block, and attribute strings (deserialize_with = "…").
  • A function is live when its name occurs in a live context, and its own body then counts.
  • Self-references: recursion of a uniquely named function doesn't keep it alive. A same-named call counts, because it may be delegation: Primitive::prepare calls Gpu::prepare. My first version got that wrong; the fix came before commit.

Test regions (U) are now recognised in all their forms, which feeds R3, R5 and R6:

  • cfg(all(test, …)), and any(…) whose every part is test-only. any(test, feature) and not(test) stay live code.
  • An inner #![cfg(test)] covers the whole file.
  • An item's generics no longer end it at a comma.
  • Out-of-line test modules (#[cfg(test)] mod tests;) are excluded from R6.

A stale gate binary is refused. With one target directory shared between checkouts, target/debug/xtask is re-linked only on a rebuild. cargo run -p xtask in main ran the worktree's binary and reported the worktree's baseline as main's. xtask now exits 2 when cargo starts a binary built for another checkout (reproduced). CI was never affected, because each job has a fresh target directory.

Evidence:

  • Fixtures: 11 functions that must be flagged and 7 that must stay live. The old gate, run on the same fixtures in a scratch copy, flagged only chain_top, and wrongly flagged by_attribute.

  • Region sabotages, run under hold-checkout.sh, each a single-line change:

    • S1, all() requiring every argument;
    • S2, the inner attribute ignored;
    • S3, a comma ending a generic item.

    Each turned its tests red and was restored green.

  • On main, four real orphans, now in the baseline (26 → 30):

    • encode_kz and encode_kzl: only the dormant send_cw and set_cw_delay call them;
    • luminance: only the baselined contrast calls it;
    • poll_cat: a test convenience, hidden until now by the trait default's name.
  • R3, R4, R5 and R7 are unchanged on main, compared with a separate target directory per checkout.

  • Workspace: 616 passed (+4 xtask tests), clippy clean, gate OK, all with --locked.

Ledger 4.55. The audit status table is updated: T, U, X fixed; V documented; W fixed by #248.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ma4bQKqGNFTYyVSEKPcXRk

Simon Keimer and others added 2 commits October 16, 2026 17:47
… in all their forms; refuse a stale gate binary (audit T, U, X)

R6 counted a name's occurrences: a definition counted as a use, so did a
same-named function, a call from a dead function and a `use` line. Orphan
chains, same-named functions with no caller and attribute-prefixed or
split definitions all got through (audit T, X). Now a liveness pass: live
contexts are code outside functions, main, trait-impl methods and attribute
strings; a function is live when its name occurs in a live context, and its
body then counts. Recursion of a uniquely named function does not keep it
alive; a same-named call may be delegation and counts.

Test regions (audit U): cfg(all(test, ..)) and any(..) of test-only parts
are test code, any(test, feature) and not(test) are not; an inner
#![cfg(test)] covers the file; an item's end ignores commas in its generics;
out-of-line test modules (`#[cfg(test)] mod tests;`) are excluded from R6.

Fixtures: 11 functions that must be flagged and 7 that must stay live. The
old gate, run on the same fixtures, flagged only chain_top (and wrongly the
attribute-string function by_attribute). On main the new R6 finds four real
orphans, now baselined with reasons: encode_kz and encode_kzl (only the
dormant send_cw / set_cw_delay call them), luminance (only the baselined
contrast), poll_cat (test convenience; hidden by the trait default's name).
R3, R4, R5 and R7 are unchanged on main.

xtask now refuses to run when cargo starts a binary built for another
checkout: with a shared target dir, target/debug/xtask is re-linked only on
rebuild, and main's gate silently checked a worktree (2026-10-16).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ma4bQKqGNFTYyVSEKPcXRk
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ma4bQKqGNFTYyVSEKPcXRk
@dc0sk
dc0sk merged commit 413cede into main Oct 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant