Skip to content

Rust: inventory trait default bodies once and recover default-body calls - #1287

Draft
tt-a1i wants to merge 3 commits into
codex/rust-trait-change-investigationfrom
codex/rust-trait-default-body-calls
Draft

tt-a1i wants to merge 3 commits into
codex/rust-trait-change-investigationfrom
codex/rust-trait-default-body-calls

Conversation

@tt-a1i

@tt-a1i tt-a1i commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

A maintainer investigating the BytesMut::put change at bytes@c08f876 needs src/buf/buf_impl.rs:2374 back from the normal CLI, with the enclosing trait default method and the target implementation visible.

Rust rust-source-direct-v6 / adapter revision 6 inventories each trait default method body once per source declaration. Calls in that body carry defaultMethod context (file, name, qualname, line, column, trait) and reuse the existing receiver typing:

  • A local receiver with a captured nominal type resolves to the unique trait impl; 2374 resolves to src/bytes_mut.rs:1300:5.
  • Calls that depend on the concrete Self remain unresolved.
  • A trait declaration without a body adds no calls.
  • Multiple implementing types do not duplicate the default body's calls.

Baseline reproduction at 7d228fb5c (rust-source-direct-v5) is 2/3. Candidate v6 is 3/3.

Results

Result Call range Target declaration Owning trait Default method Impl type Status
bytes ret.put(&mut self.a) src/buf/chain.rs:184:13-184:33 src/bytes_mut.rs:1300:5 BufMut none BytesMut correct
bytes ret.put((&mut self.b).take(...)) src/buf/chain.rs:185:13-185:53 src/bytes_mut.rs:1300:5 BufMut none BytesMut correct
bytes ret.put(self.take(len)) src/buf/buf_impl.rs:2374:9-2374:32 src/bytes_mut.rs:1300:5 BufMut Buf::copy_to_bytes (src/buf/buf_impl.rs:2363:8) BytesMut correct
log kvs.into_kvs() src/__private_api.rs:101:9-101:23 src/__private_api.rs:17:12 KVs none unverified correct

Bytes fixed-sample improvement: 2/3 -> 3/3. The log candidate remains 1/1 and does not claim an implementation. Per-call target ends remain unverified because the CLI does not expose them.

Boundaries and retained sample

  • A second, previously unused default body, Buf::copy_to_slice (src/buf/buf_impl.rs:299), was frozen in source-first.json before the candidate run.
  • self.try_copy_to_slice(dst) at 300:9-300:36 is captured once with defaultMethod context and stays unresolved (rust-trait-or-method-dispatch) because Self is concrete-only.
  • panic_advance(&error) at 301:37-301:58 is captured once with the same context and resolves to src/lib.rs:206.
  • Two impl Buf types do not duplicate either call.
  • Fixture and real-result negative controls still pass: same-named wrong target, same-line different call, target-column-only, and the ambiguous two-trait fixture.

Verification

  • npm --prefix archify run test:code-analysis: 418 pass, 0 fail.
  • Source run: run.py exits 0; bytes 3/3, log candidate 1/1, retained default body correct.
  • Unpacked archify.zip (43e22e75…, 405 files) produces the identical normalized result.
  • Canonical ZIP built with Node 22.23.3 / bundled zlib 1.3.1-e00f703.

Reproduction

python3 benchmarks/code-analysis-rust-trait-change/run.py \
  --cli archify/bin/archify.mjs \
  --samples <path-to>/rust-trait-samples-20261108 \
  --out /tmp/rust-default-candidate

evidence/baseline-summary.json is the v5 2/3 run; evidence/summary.json is the v6 3/3 source run; evidence/zip.json is the unpacked-ZIP run.

New-repository default-body evaluation

A separate, previously unused Rust case evaluates a real change to a trait default body:

  • Repository: marshallpierce/rust-base64; base 1e8246a, head d021c39 (Optimize generic functions); modified method Engine::decode (src/engine/mod.rs:246).
  • Source answer: eight call positions in the default body, including two trait-method targets and six intentional unknowns (external methods, macro, constructor, nested local function).
  • v5 baseline: 0/8 calls and 0 target declarations. All eight are outside its call inventory and are counted as misses.
  • v6 candidate: 8/8 calls, 2 target declarations verified (Engine::internal_decoded_len_estimate:66, Engine::internal_decode:91), 6 unknowns retained, 0 wrong targets, 0 missed.
  • The nested inner target remains an explicit target-identity gap, not a wrong implementation.
  • This uses neither the older --baseline-cli path nor its zero-reference assumption. v5 is scored by source-range containment; v6 by defaultMethod context. See benchmarks/code-analysis-rust-default-body-eval/run.py.
python3 benchmarks/code-analysis-rust-default-body-eval/run.py \
  --baseline-cli <checkout-7d228fb5c>/archify/bin/archify.mjs \
  --candidate-cli <checkout-77cecd0ca>/archify/bin/archify.mjs \
  --samples <base64-base-and-head-worktrees> \
  --out /tmp/base64-default-body-eval

Final commit and CI

Final head: ba24b046d7e36ed25337fa0ea114daf83de49c9d (test(code-analysis): evaluate Rust default-body calls on base64), branched from 7d228fb5c849c370b09ae2d1a2d315b1c9e01ee4.

  • Validation commit a4c0e6721 (feat(rust): inventory trait default method bodies once): run 42475803613, attempt 1 success, 19 successful jobs; deploy-pages and deploy-cloudflare skipped by policy.
  • Documentation commit 77cecd0ca: run 42476406957, attempt 1 success, 19 successful jobs; the same two deploy jobs skipped by policy.
  • Evaluation commit ba24b046d: run 42477760230, attempt 1 success, 19 successful jobs; the same two deploy jobs skipped by policy.

Limits

Local captured traits and impls only; external, blanket, supertrait and macro-generated impls remain unknown. Calls in default bodies that require the concrete Self, fields or chained receivers remain unresolved. No compiler, runtime or complete-impact proof is claimed.

Draft only. Base is the #1286 source branch codex/rust-trait-change-investigation. No merge, no labs/code-analysis update, no installation.

Scan each trait default body as one source body with defaultMethod context,
reuse receiver typing, and leave Self-dependent dispatch unresolved. This
retrieves bytes@c08f876 src/buf/buf_impl.rs:2374 and raises the fixed sample
from 2/3 to 3/3 without duplicating calls per implementing type.
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Record a source-first case from rust-base64 d021c39 where the modified
Engine::decode default body has eight calls. Score v5 with its source-range
flow and v6 with defaultMethod context; the candidate recovers all eight
calls, verifies two trait targets, and retains six unknowns without a wrong
target.

This branch has not been deployed

No deployments
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