Skip to content

chore: delete 257 lines of dead code, and the 25 allows that were hiding nothing - #422

Merged
doublegate merged 4 commits into
mainfrom
chore/v2.3.9-stale-dead-code-allows
Aug 20, 2026
Merged

chore: delete 257 lines of dead code, and the 25 allows that were hiding nothing#422
doublegate merged 4 commits into
mainfrom
chore/v2.3.9-stale-dead-code-allows

Conversation

@doublegate

Copy link
Copy Markdown
Owner

A remediation pass over the project's dead-code suppressions. 257 lines removed, nothing added.

The question, and why the method matters

The project rule is that every local #[allow] is justified. This asks the prior question — is it still doing anything? — by stripping every #[allow(dead_code)] and re-running clippy.

A single-combo probe would prove nothing. An item can be live by default and dead on wasm or under --no-default-features, which is precisely the situation that would have earned the attribute in the first place. So every combination this repo gates was run: default, debug-hooks, full, the no_std thumbv7em target, and all four wasm32 variants (default, wasm-canvas, browser-cheevos, script-wasm).

Of 29 attributes, 25 suppressed nothing in any combination. Each was a permanently-disabled dead-code check on an item that is used — the opposite of what it looks like, and a place a future regression could hide unnoticed.

The two islands that were real

Both are leftovers from the mc-r1-* staged master-clock migration, whose cargo features exist nowhere in the workspace.

The APU pair (dmc_abort_delay_for + schedule_explicit_dmc_abort_if_needed) — its own comment said it was "retained for the flag-off path", and that flag was removed in #237 (v2.0.1). 34 lines.

The four LockstepBus DMA-service methods — a closed island: each called the next and nothing outside called any. That is why grepping a single name found a caller and looked reassuring, and why removing one attribute made all four report at once. 183 lines.

What deleting the island exposed

drain_dma — called on every CPU read, every CPU write, and every bus cycle — had already been reduced to an empty body: let _ = read_addr; and forty lines of comments describing what it used to do.

Its #[allow] list was the tell: unused_self, needless_pass_by_ref_mut and missing_const_for_fn fire together exactly when a method does nothing. Its comments still claimed "the legacy service below stays active for the default build" — untrue since v2.0.0 — and at the call site it read as though DMA were being serviced there. Deleted with its three call sites.

Verification

rustynes-apu and rustynes-core both change, so the accuracy battery is VERIFIED, not asserted — and re-run after the island deletion, not only after the first commit:

AccuracyCoin (RAM): pass rate = 100.00% over 141 assigned tests

That is the authoritative decoder, quoted case-sensitively; the framebuffer decoder reports 120 and is known-buggy. nestest passes. Both with a confirmed non-zero test count, since a filter matching nothing exits 0.

Also clean: no_std cross-compile, workspace clippy, debug-hooks, full, all four wasm32 combos, rustdoc, and every crate suite.

Behaviour is unchanged by construction: the compiler proves the island was unreachable — that is what made it dead — and an empty function called three times is three no-ops.

Left alone deliberately

Fifteen comments across rustynes-core, rustynes-cpu and rustynes-apu still name the removed functions while describing the historical mechanism. Rewriting fifteen technical comments to avoid a name risks changing what they say about the hardware, which is a worse trade than a reader grepping and finding the explanation here.

Copilot AI lite review requested due to automatic review settings August 19, 2026 23:01
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4f5eac09-eba0-441a-bd10-42844741e31c


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

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes stale #[allow(dead_code)] suppressions and deletes now-unreachable code paths, tightening the project’s “every allow must be justified” rule and reducing the surface area where regressions can hide behind blanket lints.

Changes:

  • Removed 25 #[allow(dead_code)] attributes that were no longer suppressing anything across core/frontend/PPU code.
  • Deleted an unreachable “LockstepBus DMA service” island in rustynes-core (including an already-empty drain_dma and its call sites).
  • Deleted an unreachable DMC-abort scheduling island in rustynes-apu.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/rustynes-ppu/src/ppu.rs Removes an unnecessary dead_code allow on a live PPU struct field.
crates/rustynes-frontend/src/save_states_ui.rs Removes an unnecessary dead_code allow from a public save-state slot path helper.
crates/rustynes-frontend/src/save_state.rs Removes stale dead_code allows from save-state helper APIs.
crates/rustynes-frontend/src/input.rs Removes an unnecessary dead_code allow from a test-used defaults constructor.
crates/rustynes-frontend/src/gfx.rs Removes unnecessary dead_code allows from post-processing disable helpers.
crates/rustynes-frontend/src/debugger/mod.rs Removes unnecessary dead_code allows from retained overlay state fields.
crates/rustynes-frontend/src/config.rs Removes unnecessary dead_code allows from config save APIs.
crates/rustynes-frontend/src/audio.rs Removes unnecessary dead_code allows from audio queue/output inspection helpers.
crates/rustynes-core/src/bus.rs Deletes unreachable DMA-service code and removes drain_dma call sites that were no-ops.
crates/rustynes-apu/src/apu.rs Deletes unreachable DMC-abort scheduling helpers and removes a stale dead_code allow.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/rustynes-frontend/src/save_state.rs
Comment thread crates/rustynes-frontend/src/save_states_ui.rs Outdated
@doublegate
doublegate force-pushed the chore/v2.3.9-stale-dead-code-allows branch from 9bee157 to 2a05ded Compare August 19, 2026 23:14
@doublegate

Copy link
Copy Markdown
Owner Author

The blocking finding is declined as not reproducible, and the quote it rests on is the false comment this PR removes.

drain_dma is not dead code; it is actively called in cpu_read and cpu_write. Its internal comments note it "stays active for the default build". Deleting it and its invocations will break DMA timing and synchronization.

drain_dma was called — and its entire body was this:

fn drain_dma(&mut self, read_addr: Option<u16>) {
    let _ = read_addr;
}

Nothing else. Forty lines of comments describing what it used to do, and one statement discarding its argument. Deleting an empty function and its three call sites is three no-ops removed; there is no timing to break because there was no work being done.

The sentence you quote is the evidence, not the counter-evidence. "The legacy service below stays active for the default build" refers to the mc-r1-* staged migration's bus-side DMA service. Those cargo features exist nowhere in the workspace and the master-clock scheduler has been the only path since v2.0.0, so the claim has been false for five releases. A comment asserting a behaviour the code does not have is exactly what this pass is removing — reading it as authority inverts the finding.

The #[allow] list on that function was the tell: unused_self, needless_pass_by_ref_mut and missing_const_for_fn fire together precisely when a method does nothing.

The suggestion is also measured, not assumed

Removing #[allow(dead_code)] from private struct fields … will likely trigger compiler warnings. If the project enforces #![deny(warnings)] in CI, this will break the build.

That was the first thing checked, and it is why only 25 of 29 attributes were removed rather than all of them. Every gated combination was run with -D warnings: workspace, debug-hooks, full, no_std thumbv7em, and all four wasm32 variants. Zero errors. The four attributes that were still doing work are the two islands, and they are the reason the sweep took the shape it did.

And the accuracy battery, after the deletion

AccuracyCoin (RAM): pass rate = 100.00% over 141 assigned tests

Re-run after the island and drain_dma were removed, not only after the first commit — plus nestest, with a confirmed non-zero test count.

Both Copilot findings on this PR were real and are fixed in 9374bf60; they were comments that outlived what they described, which is the same class as the one quoted above.

@doublegate
doublegate force-pushed the chore/v2.3.9-stale-dead-code-allows branch from 9374bf6 to 9bb00fd Compare August 20, 2026 00:00
@doublegate

Copy link
Copy Markdown
Owner Author

The blocking finding is not reproducibletry_default was never touched.

$ grep -n "try_default" crates/rustynes-frontend/src/audio.rs
616:    pub fn try_default() -> Result<Self, AudioError> {

$ git diff origin/main...HEAD -- crates/rustynes-frontend/src/audio.rs | grep -E '^[+-]' | grep -vE '^(\+\+\+|---)'
-    #[allow(dead_code)] // read in tests + as a UI mirror.
-    #[allow(dead_code)] // Used by tests + the Performance panel.
-    #[allow(dead_code)] // Used by tests + the Performance panel.
-    #[allow(dead_code)] // wasm builds render the panel without native audio.
-    #[allow(dead_code)] // wasm builds render the panel without native audio.
-    #[allow(dead_code)]
-    #[allow(dead_code)]
-    #[allow(dead_code)]

Eight attribute lines removed from that file and nothing else — no function deleted, in audio.rs or anywhere. Removing those lines shifted everything below them upward, which is the likeliest way pub fn try_default() came to sit next to a - line in a diff view.

Worth noting the finding's own internal check would have caught it: it says the deletion "directly contradicts the rationale you used to keep pub fn slot_path_for". That rationale is applied consistently here — pub items in a lib target are exempt from dead-code analysis, which is exactly why neither try_default nor slot_path_for needed an attribute and why neither was removed. The code this PR deletes is private and provably unreachable; the compiler said so, and that is what made it safe to cut.

The suggestion is taken (9582fcf9)

You are right that my rewrite of those two notes kept more history than a docstring needs. What a reader must know is the mechanismpub items are exempt from dead-code analysis, so neither item needs an attribute — not how many attributes this pass removed or which review prompted the wording. Both notes now carry the former and drop the latter.

@doublegate
doublegate force-pushed the chore/v2.3.9-stale-dead-code-allows branch from 9582fcf to 7c8b4fb Compare August 20, 2026 00:57
The project rule is that every local `#[allow]` is justified. This asks
the prior question -- is it still doing anything? -- and the answer for
almost all of them was no.

Method matters here, because a single-combo probe proves nothing. An item
can be live by default and dead on wasm or under `--no-default-features`,
which is precisely the situation that would have earned the attribute. So
every `#[allow(dead_code)]` in the four crates carrying them was stripped
and clippy re-run across EVERY gated combination: default, `debug-hooks`,
`full`, the `no_std` thumbv7em target, and the four wasm32 variants
(default, `wasm-canvas`, `browser-cheevos`, `script-wasm`).

Of 29 attributes, 25 suppressed nothing in any combination. Each was a
permanently-disabled dead-code check on an item that is used -- the
opposite of what it looks like, and a place a future regression could
hide.

Two genuinely-dead islands remain, both leftovers from the `mc-r1-*`
staged master-clock migration whose cargo features no longer exist
anywhere in the workspace.

The APU pair (`dmc_abort_delay_for` +
`schedule_explicit_dmc_abort_if_needed`) is DELETED. Its own comment said
it was "retained for the flag-off path", and that flag was removed in
#237 (v2.0.1); the master-clock scheduler has been the only path since
v2.0.0, so the path it was retained for cannot be taken. Thirty-four
self-contained lines, and git keeps them.

The four `LockstepBus` DMA-service methods are KEPT, with a corrected
justification. They form a CLOSED ISLAND -- they call each other and
nothing outside calls any of them, which is why removing one attribute
makes all four report at once and why grepping a single name finds a
caller and looks reassuring. Cutting four methods out of `bus.rs` is a
larger and riskier edit than the sweep that found them justifies, and
unreferenced code cannot change behaviour, so this is a maintenance
question rather than a correctness one. The note also corrects a nearby
comment claiming "the legacy service below stays active for the default
build", which has been false since v2.0.0.

`rustynes-apu` changes, so the accuracy battery is VERIFIED rather than
asserted: AccuracyCoin (RAM) 100.00% over 141 assigned tests -- the
authoritative decoder, quoted case-sensitively, since the framebuffer
decoder reports 120 and is known-buggy -- and nestest passes. Both run
with a confirmed non-zero test count.
… behind

Maintainer call: take the dead code out rather than annotate it.

The four `LockstepBus` methods -- `clock_oam_dma_cycle`,
`service_dmc_dma`, `service_dmc_abort` and `service_dmc_dma_during_oam`
-- are the legacy bus-side DMA service from the `mc-r1-*` staged
master-clock migration. Those cargo features exist nowhere in the
workspace and the master-clock scheduler has been the only path since
v2.0.0, so nothing can reach them. They formed a closed island: each
called the next and nothing outside called any, which is why grepping a
single name found a caller and looked reassuring, and why removing one
`#[allow(dead_code)]` made all four report at once. 183 lines.

Removing them exposed the more interesting half. `drain_dma` -- called
on every CPU read, every CPU write, and every bus cycle -- had already
been reduced to an empty body: `let _ = read_addr;` and forty lines of
comments describing what it used to do. Its `#[allow]` list
(`unused_self`, `needless_pass_by_ref_mut`, `missing_const_for_fn`) was
the tell: those three fire together exactly when a method does nothing.
Its comments still claimed "the legacy service below stays active for
the default build", which had not been true since v2.0.0, and it read at
the call site as though DMA were being serviced there.

Deleted with its three call sites. Behaviour is unchanged by
construction -- an empty function called three times is three no-ops --
and the compiler proves the island was unreachable, which is what made
it dead in the first place.

`rustynes-core` changes, so the accuracy battery is VERIFIED rather than
asserted: AccuracyCoin (RAM) 100.00% over 141 assigned tests, the
authoritative decoder, plus nestest; `no_std` cross-compile, workspace
clippy and every crate suite clean.

Fifteen comments across `rustynes-core`, `rustynes-cpu` and
`rustynes-apu` still name the removed functions while describing the
historical mechanism. They are left as-is deliberately: rewriting
fifteen technical comments to avoid a name risks changing what they say
about the hardware, which is a worse trade than a reader grepping and
finding the explanation in this commit.
Both found by review, and both are the same class this sweep exists to
find -- prose describing a state that no longer holds.

`slot_exists`'s note said "we allow `dead_code` rather than wait to land
it", referring to an attribute this change removes. It also had the
reason backwards: the item is `pub` in a lib target, and `pub` items are
exempt from dead-code analysis, so it never needed the attribute at all.
The anticipated Sprint 5-3 "recently used slots" indicator was never
built; the comment now says that plainly and points at the test that does
exercise it.

`slot_path_for`'s doc claimed it was "re-exported for the app to log /
inspect". There is no in-repo call site. Reworded to what is true -- a
thin wrapper available to external and diagnostic callers -- and kept
rather than deleted, because unlike the dead code this change removes it
is `pub` and part of the module's surface, not an unreachable island.
Review is right that the rewrite kept more history than a docstring
needs. What a reader has to know is the mechanism -- `pub` items in a
lib target are exempt from dead-code analysis, so neither item needs an
attribute -- not how many attributes this pass removed or which review
prompted the wording. Both notes now say the former and drop the latter.
@doublegate
doublegate force-pushed the chore/v2.3.9-stale-dead-code-allows branch from 7c8b4fb to 7985ad3 Compare August 20, 2026 01:23
@github-actions

Copy link
Copy Markdown

Antigravity review (Gemini via Ultra)

This PR removes 257 lines of unused legacy DMA/scheduling logic and drops 25 #[allow(dead_code)] attributes across the codebase.

Blocking issues

None found.

Suggestions

  • crates/rustynes-frontend/src/debugger/mod.rs (lines 837, 844): You removed #[allow(dead_code)] from the private fps and movie fields. As your new comment on slot_exists correctly points out, pub items in a library are exempt from dead-code analysis, but private and pub(crate) fields are not. If these fields are set but never read, removing the attribute will introduce dead_code compiler warnings.
  • crates/rustynes-core/src/bus.rs (line 329), crates/rustynes-ppu/src/ppu.rs (line 594), and crates/rustynes-apu/src/apu.rs (line 179): The same compiler warning risk applies here. Removing #[allow(dead_code)] from the pub(crate) fields (cart, secondary_oam, subpos_arm_countdown) will trigger lints if they lack in-crate readers. Consider restoring the allows for these internal fields if they are genuinely unread.

Nitpicks

  • The PR title states the allows "were hiding nothing," but they were likely actively suppressing warnings for the internal and private fields.

Automated first-pass review by agy on a self-hosted runner -- not a human review.

@doublegate
doublegate merged commit 6340bb7 into main Aug 20, 2026
27 checks passed
@doublegate
doublegate deleted the chore/v2.3.9-stale-dead-code-allows branch August 20, 2026 02:01
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.

2 participants