Skip to content

[AUTOMATED] feat(p5): structsynth nests a record pointer loaded from a field - #705

Merged
mahaloz merged 2 commits into
mainfrom
feat/structnest
Sep 21, 2026
Merged

mahaloz merged 2 commits into
mainfrom
feat/structnest

Conversation

@mahaloz

@mahaloz mahaloz commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

The problem

structsynth gives a pointer parameter a record, but a pointer field of that record stays a scalar, so every read through the loaded field is raw offset arithmetic again.

cat > t.c <<'X'
struct inner { long a; int b; int c; };
struct outer { struct inner *in; long x; int y; };
__attribute__((noinline)) long use_outer(struct outer *o) { return o->in->a + o->in->b + o->in->c + o->x + o->y; }
int main(int argc, char **argv) { return (int)use_outer((struct outer *)argv); }
X
gcc -O2 -fcf-protection=none -o t t.c && strip t
kuna decompile-all t --option structdefs on        # add --option structsynth nest for the fix
struct struct_0 {
    long *field_0x0;
    long field_0x8;
    int field_0x10;
    char field_0x14[4];
};

long sub_1140(struct_0 *a0)
{
  long *v1;

  v1 = a0->field_0x0;
  return (long)(int)v1[1] + *v1 + (long)*(int *)((long)v1 + 0xc) + a0->field_0x8 + (long)a0->field_0x10;
}

The fix

  • New structsynth value nest. The loads of one pointer field are measured as one record under the rules a parameter already follows (already a pointer, no phi, index or integer use, two offsets including 0). The field then becomes struct_0 *field_0x0 over {long; int; int}, and the body reads (long)v1->field_0x8 + v1->field_0x0 + (long)v1->field_0xc.
  • When a loaded record reads nothing its holder doesn't hold, the field points at the holder itself. grep's kwset tree comes out as struct_19 { struct_19 *field_0x0; struct_19 *field_0x8; long field_0x10; unsigned char field_0x18; ... }. That struct is minted around its incomplete shell, and a load through the self pointer takes the completed type, so three links down still reads v3->field_0x18 and not *(uint1 *)&v3[3].
  • scripts/decbench/structscore ignored a pointer to a struct defined later in the header (or to its own struct) when counting nested fields. That is fixed too.
  • param stays the default. With nest, a structure whose field points at another synthesized structure or at itself cannot be rebuilt in another process, so --jobs names every structure-bearing function in one worker (26.0 s against 15.9 s for decompile-all --jobs 8 on tar O2, with the same output). docs/features/structnest/default-on-evaluation.md has the numbers and the protocol change that would lift this.

Tests

  • tests/stages/structsynth-nest.xml: pass 1 (param) pins the raw reads; pass 2 (nest) pins the nested record and the self-pointing tree node. There are also unit tests for the evidence merge, self minting, shell resolution and shard portability.
  • Comparing nest with param on one build: the 444-slice typesweep stays at 1,353 perfect, with 0 functions better and 0 worse. Over 15 binaries (three of them ARM32), 93 of 7,819 functions change: 86 only in struct_N numbering, 7 with reads respelled through the nested record, and no control flow or arity moves. Serial decompile-all is 1.7% to 5.0% faster (min-of-15; fmt, ls, sort and bash at O2). All 487 exported structs compile with exact offsetof.

🤖 Generated with Claude Code

https://claude.ai/code/session_017ei9zqc7XHgZdMAzrk8jAL

@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 21, 2026
mahaloz and others added 2 commits September 21, 2026 20:00
…a field

New structsynth value nest (opt-in): the loads of a pointer field of an
accepted record are measured as one record under the parameter rules, and the
field becomes a pointer to it, or to its own record when the loaded record
reads nothing the holder does not hold. Self-pointing records are minted around
their shell and a load through the self pointer resolves to the completed
record. structscore now counts a pointer to a later or enclosing struct as a
pointee. param stays the default: see docs/features/structnest/default-on-evaluation.md.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_017ei9zqc7XHgZdMAzrk8jAL
@mahaloz
mahaloz merged commit a26b99d into main Sep 21, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/structnest branch September 21, 2026 20:59
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