Skip to content

[AUTOMATED] feat(p5): structsynth shares one layout across functions by subsumption - #675

Merged
mahaloz merged 13 commits into
mainfrom
feat/structdedup
Sep 19, 2026
Merged

mahaloz merged 13 commits into
mainfrom
feat/structdedup

Conversation

@mahaloz

@mahaloz mahaloz commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

The problem

structsynth mints one struct_N per exact layout, so two functions that read different parts of one record get a name each:

$ cat rec.c
struct rec { char *name; long len; int a; unsigned b; };
__attribute__((noinline)) long head(struct rec *r) { return *r->name + r->len; }
__attribute__((noinline)) long all(struct rec *r) { return *r->name + r->len + r->a + r->b; }
int main(int c, char **v) { struct rec r = { v[0], c, c, c }; return head(&r) + all(&r); }
$ gcc -O2 -o rec rec.c && strip rec
$ kuna decompile-all rec --option structdefs on
struct struct_0 { char *field_0x0; long field_0x8; };
long sub_11b0(struct_0 *a0)
struct struct_1 { char *field_0x0; long field_0x8; int field_0x10; unsigned int field_0x14; };
long sub_11c0(struct_1 *a0)

(Struct bodies joined onto one line here.) With this change both functions take struct_1. Across twelve coreutils, findutils and tar builds the name count goes from 515 to 471.

The fix

  • A measured layout reuses the smallest minted structure that contains it: every field it measured, at the same offset, width and type.
  • A larger container also needs evidence. It may claim at most 2× the fields and be at most 4× the size. The reader must have measured two fields, one of them a typed pointer, or three fields. A table of code * / void * slots is answered only by its own shape.
  • A container may not put a member in the alignment padding between two of the reader's fields, and a reader with no typed pointer is answered only by a same-size structure with nothing past its last field. Records that begin alike keep separate names: stat and cycle_check_state, rsyslogd's *_if_s interfaces, bash's if_com and for_com (int line sits where if_com pads), dpkg's pkg_queue and pkg_spec.
  • A container must lay the reader's own members over any bytes the reader read or wrote without a field of its own (an unaligned word, a 16-byte copy). Otherwise a 4-byte load at offset 7 was spelled through the container's char at 7 and printed after the reader's byte store at 8.
  • A structure is never widened. A larger layout mints a new name and the smaller one is superseded. After decompile-all, the functions that name a superseded structure are decompiled once more. If that second pass fails, the first body is kept.
  • structsynth is on by default since [AUTOMATED] feat(p5): structsynth on by default #682, so all of this is default output and was measured as such.

The tests

🤖 Generated with Claude Code

https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG

@mahaloz mahaloz added the full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) label Sep 17, 2026
@mahaloz
mahaloz force-pushed the feat/structdedup branch 2 times, most recently from bec33fc to 5cd7d4b Compare September 18, 2026 20:08
@mahaloz
mahaloz force-pushed the feat/structdedup branch 5 times, most recently from a879669 to f4b2e52 Compare September 19, 2026 14:28
mahaloz and others added 13 commits September 19, 2026 15:19
…by subsumption

The layout ledger answers a measured layout with the smallest minted
struct_N that contains it, under growth bounds and evidence rules (typed
pointer, table, integer same-size, unclaimed-bytes); a larger layout
supersedes a smaller one and decompile-all re-decides the functions that
named it. Squashed from the review rounds (backup/structdedup-r6-prerebase).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…too; re-record stages on 6e4f6fa

Since structsynth on by default (#682), a field read both as a float and as
an integer is raw-byte filler in the reader's own layout. A container's typed
field there would print the float read as a value conversion again, so the
ledger's unclaimed-bytes veto covers those bytes as well. Stage baseline
re-recorded on 6e4f6fa (+12 structsynth keys, 1156 -> 1168); options.md and
the phase_catalog fixture regenerated.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…f6fa (structsynth default on)

Pooled held-out claimed-field precision 0.8735 -> 0.8750, 30 builds gain and
4 lose, 1 of 178 absorbed parameters given a different record; census
516 -> 472; sweep rename-only, --option structsynth off byte-identical;
typesweep identical. options.md and the phase_catalog fixture regenerated.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…ment padding

A structure no longer answers for a reader when it claims a member inside
the alignment padding the reader's own claims leave between two of them,
and a reader with no typed pointer is no longer answered by a structure
that claims anything past its last field. bash's if_com and for_com, the
ITEMLIST readers and case_com, and dpkg's pkg_queue and pkg_spec each
shared one struct_N before.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…with the padding rule

Eight sets, 177 builds: the second reviewer's 24 and 18 builds and 34
chosen before any result under the padding rule. Records the remaining
e2fsck false unifications and the container-larger address spelling as
known limits.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
@mahaloz
mahaloz merged commit bcfe628 into main Sep 19, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/structdedup branch September 19, 2026 16:04
mahaloz added a commit that referenced this pull request Sep 19, 2026
…s convergence sweep

decompile-all's callee-first path decompiled each target with decompile_entry
and never reached the batch's converge_synthesized_structs (#675), so under the
protoorder default a function kept a structure a later, larger one had
superseded (tests/cli/structsynth-sweep-mints-no-third-name failed). The sweep
now runs at the end of the callee-first path, in plan order with each target's
own park decision; not under lock, where a parked prototype is declared.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
mahaloz added a commit that referenced this pull request Sep 19, 2026
…s convergence sweep

decompile-all's callee-first path decompiled each target with decompile_entry
and never reached the batch's converge_synthesized_structs (#675), so under the
protoorder default a function kept a structure a later, larger one had
superseded (tests/cli/structsynth-sweep-mints-no-third-name failed). The sweep
now runs at the end of the callee-first path, in plan order with each target's
own park decision; not under lock, where a parked prototype is declared.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant