Skip to content

chore: flag fakematches without a Fakematch: comment - #207

Merged
mateuszklysz merged 5 commits into
mainfrom
decomp/fakematch-check
Oct 16, 2026
Merged

mateuszklysz merged 5 commits into
mainfrom
decomp/fakematch-check

Conversation

@mateuszklysz

@mateuszklysz mateuszklysz commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Before: CI accepted code that only steers the compiler (x++; x--;, x = x;, a do { } while (0) outside a macro, if (0)) without any note, so readers could not tell a fakematch from real code.

After: the cleanup job fails a pull request that adds one of these shapes unless a comment that starts with Fakematch: ends at most three lines above it. Every existing case in src is now either marked or removed.

How:

  • scripts/check-cleanup.py: new [fakematch] rule. It skips macro bodies and NON_MATCHING drafts, and only new cases fail, like the other rules. It comes with a test and a short section in docs/code-cleanup.md.
  • Each existing case was compiled with and without the trick (game cc1 or SN, depending on the unit):
    • 57 if (0) branches in the hero files and setup_menu_display_text gave identical output, so they were dead code and are removed.
    • Four written-out library macros now use their names: EXTRACT_WORDS ×2, CHECK_INIT and DO_GLOBAL_CTORS_BODY.
    • The other 24 cases change the code, so they keep the trick and get a Fakematch: comment.
  • Assembly for all 28 changed C files is identical to main.

check-cleanup.py reports x++; x--, x = x, a do { } while (0) outside a macro and if (0) when no Fakematch: comment ends at most three lines above them. NON_MATCHING drafts and macro bodies are skipped.
EXTRACT_WORDS, CHECK_INIT and DO_GLOBAL_CTORS_BODY; the compiler output is unchanged.
Removing each branch leaves the compiler output byte-identical, so they are dead code, not fakematches.
@mateuszklysz mateuszklysz added the enhancement New feature or request label Oct 16, 2026 — with Claude
@mateuszklysz mateuszklysz self-assigned this Oct 16, 2026
@github-actions

Copy link
Copy Markdown

Decompilation progress

C_EXACT Change Matched bytes Functions C_FUZZY
All code 90.09 % — 3,196,488 / 3,548,100 B (—) 4,026 / 4,246 (—) 91.33 %
Boot executable 85.82 % — 304,388 / 354,672 B (—) 1,179 / 1,232 (—) 98.24 %
Game 84.60 % — 231,508 / 273,636 B (—) 874 / 912 (—) 98.46 %
SDK 89.94 % — 72,880 / 81,036 B (—) 305 / 320 (—) 97.49 %
Level overlays 90.56 % — 2,892,100 / 3,193,428 B (—) 2,847 / 3,014 (—) 90.56 %
Shared level code 83.19 % — 940,484 / 1,130,492 B (—) 1,458 / 1,583 (—) 83.19 %
Per-level code 94.60 % — 1,951,616 / 2,062,936 B (—) 1,389 / 1,431 (—) 94.60 %
Data in C Change Matched bytes
All data 42.81 % — 5,322,477 / 12,433,372 B (—)
Boot executable 2.29 % — 16,042 / 699,136 B (—)
Level overlays 45.22 % — 5,306,435 / 11,734,236 B (—)

No function changed its match state compared with main (606bc76).

Compared with main (606bc76). C_FUZZY uses main's last measurement.

@mateuszklysz
mateuszklysz merged commit 88f3bf7 into main Oct 16, 2026
4 checks passed
@mateuszklysz
mateuszklysz deleted the decomp/fakematch-check branch October 16, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant