Skip to content

[AUTOMATED] [PROPOSAL] Embedder hooks: add a rule to a default pool and run code at phase boundaries - #1699

Closed
coleleavitt wants to merge 2 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/hook-registry
Closed

coleleavitt wants to merge 2 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/hook-registry

Conversation

@coleleavitt

@coleleavitt coleleavitt commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

[AUTOMATED]

Code that links kuna-decomp can now add one rule to the default tree and run a
callback when a phase finishes, without replacing the universal action. First
slice of #1641; draft for the design below.

arch.add_rule("analysis", RuleState::new("analysis", 0, "orandsum"), Box::new(RuleOrAndSum))?;
arch.on_phase(KunaPhase::P5, |fd| rename_stack_local(fd, "seed"))?;

cd decompiler && cargo test -p kuna-decomp --test integration hook_registry::
decompiles tests/fixtures/hook_registry.xml (x86-64, built from the .S next
to it) before and after those two calls:

uint4 mba_sum(uint4 a0,uint4 a1)            uint4 mba_sum(int4 a0,int4 a1)
{                                           {
  uint4 v1; // stack - 0xc                    uint4 seed; // stack - 0xc

  sub_100030(&v1);                            sub_100030(&seed);
  return (a0 | a1) + (a0 & a1) ^ v1;          return a0 + a1 ^ seed;
}                                           }

This slice

  • infra/kuna_hooks.rs: a HookRegistry on Architecture, read each time the
    universal tree is built. No option, no CLI surface.
  • Architecture::add_rule(after_group, RuleState, Box<dyn Rule>) puts the rule
    behind the last rule of after_group, in the first pool that holds that
    group. An unknown group is an error.
  • Architecture::on_phase(phase, callback) runs at one schedule point per
    phase: P2 after start; P3, P4, P5 together after fullloop settles (Band B
    has no boundary between them); P6 after copymarker; P7 after the final
    blockstructure; P8 before prototypewarnings. Each point is a leaf in its
    neighbours' group, so reduced roots skip the phases they do not run.
  • With nothing registered the schedule gains no row and no leaf. The listing
    snapshot test is unchanged, and decompile-all /usr/bin/ls is byte-identical
    and no slower (6.6-7.2 s against 6.9-7.9 s before, dev build).
  • A registration rebuilds the tree, so breakpoints and disabled rules set
    before it are lost; group lists are kept.

Design: what follows

  1. P1 and P9 callbacks. Neither has a point inside the action tree (P1 ends
    before the function exists, P9 is the printer), so they are driven from
    decompile_drive.rs; registering for them is an error until then.
  2. lift_override(Address, FnMut(&mut PcodeEmit) -> bool): one instruction's
    p-code replaced at lift time. It goes through FlowEnvironment in
    p2_lift/flow.rs; the passes that lift instructions on their own (callee
    contracts, call-width proofs) need the same lookup, which is why it is its
    own slice.
  3. Read access for callbacks to what the action context holds (warnings, the
    architecture's type factory), if the first users need it.

Phases touched: none change behaviour. The code is in infra/ and the spec
text in docs/spec/00-overview.md §0.6.

Tests

tests/hook_registry.rs: the rule and the P5 rename both show in the printed C
and the P2/P6/P8 callbacks fire in schedule order; the hooks sit at the stated
positions in the action listing; bad registrations are errors; an empty registry
gives the same listing and the same C. The test rule folds (x | y) + (x & y)
rather than the issue's x ^ x, which the default pool already folds.

Refs #1641

Model: anthropic/claude-fable-5-2

… at phase boundaries

First slice of the hook registry. Code that links kuna-decomp can add one
rule to the default action tree and run a callback when a phase finishes,
without replacing the universal action.

- infra/kuna_hooks.rs: HookRegistry on Architecture, read each time the
  universal tree is built. No option and no CLI surface.
- Architecture::add_rule(after_group, RuleState, Box<dyn Rule>) inserts the
  rule behind the last rule of after_group, in the first pool that holds a
  rule of that group.
- Architecture::on_phase(phase, callback) runs at one schedule point per
  phase: P2 after start; P3, P4, P5 after fullloop settles; P6 after
  copymarker; P7 after the final blockstructure; P8 before
  prototypewarnings. P1 and P9 have no point inside the action tree and
  are an error for now.
- With an empty registry the schedule gains no rule row and no leaf: the
  listing snapshot is unchanged and decompile-all output is byte-identical.

lift_override and the P1/P9 callbacks follow in later slices.

Refs Noelo-Lab#1641
sjkim1127 added a commit to sjkim1127/kuna that referenced this pull request Nov 19, 2026
[AUTOMATED] Adds how Noelo-Lab#1534's symbolic p-code emulator, the Noelo-Lab#1641/Noelo-Lab#1699
phase hooks, the Noelo-Lab#317 ghidra-sim harness, the per-PR compile-and-compare
oracles and DecBench byte_match relate to this proposal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
[AUTOMATED] Keep the P6 hook boundary and the typevote action (both sides of the typerecovery insertion).
@coleleavitt
coleleavitt deleted the fix/hook-registry branch November 22, 2026 20:13
mahaloz added a commit to sjkim1127/kuna that referenced this pull request Nov 22, 2026
…hase-hooks status

P9 and P6 carry 27 and 13 fix(pN) commits since 2026-06-01, not 24 and 12, and the
other single-phase tags total 17. Draft Noelo-Lab#1699 was closed unmerged; phase hooks are
tracked by the open issue Noelo-Lab#1641.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
mahaloz added a commit to sjkim1127/kuna that referenced this pull request Nov 23, 2026
Resolve the add/add conflicts in docs/features/diffverify/{analysis.md,proposal.md,
record.json} (the design record merged as Noelo-Lab#1714): keep this branch's newer C1-C4 status
and results text, and re-apply main's corrections from 4dc3f68 (the P9/P6 fix-tag
counts, and phase hooks tracked by the open issue Noelo-Lab#1641 since draft Noelo-Lab#1699 closed
unmerged). record.json's status line now names the C3 and decbench work the branch
holds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
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