Repository navigation
regionstructure: loop-successor refinement infrastructure (convergence; goto-win is documented follow-up) - #95
Merged
Conversation
…refine, default-off)
Add the `regionlooprefine` opt-in (default-OFF) that extends the region
structurer (`regionstructure`) with cyclic loop-successor refinement — the read
side of angr `RegionIdentifier`'s omitted
`_refine_loop_successors_to_guarded_successors` / `_ensure_jump_at_loop_exit_ends`
(the `force_loop_single_exit` path).
What it does:
* `KunaRegionIdentifier::cyclic_loops()` projects each identified cyclic region
onto basic-block start addresses: (head, refined loop body, exit/successor
frontier). This exposes the region identifier's correct loop-body analysis
(which absorbs the dominated switch-case successors a structural natural-loop
walk on the sblocks graph misses).
* `region_structurer::refine_loop_edges` (re-enabled, RI-grounded): for a
multi-exit / multi-latch / mid-entry loop the base cyclic schemas could not
fold, virtualize the SECONDARY exits and latches (keeping one normal exit +
one primary latch) so the loop folds into a structured while/do-while/inf-loop;
the existing scopeBreak / loop-construction passes then lower the virtualized
loop-exit/back-edge gotos to break;/continue;. Only loops the base schemas
declined to fold are touched, so reducible code stays byte-identical.
Gating + parity: the refinement only fires when BOTH `regionstructure` and
`regionlooprefine` are on; OFF (default) it is dead code, so `make test` stays
PARITY OK 675/675 (docs/baseline.json untouched). Wired end-to-end:
Architecture/seam field `region_loop_refine`, option `regionlooprefine`,
KUNA_OPTION_NAMES, stages.toml, docs/assertions.md regenerated, catalog --check OK.
Gates: make test 675/675 PARITY OK; make test-stages 203/203 PARITY OK (kuna-catalog
counts bumped for the +1 settable); make rust-test green (settable_count 49->50 and
the catalog-shape tests updated).
NOTE: this is the infrastructure increment. A goto win on tr_O2.o::parse_str is
NOT yet realized — see the follow-up analysis commit: the region structurer's
ACYCLIC convergence (its limited sequence/ITE schemas + virtualize fallback
fragment the graph and fall back to CollapseStructure) blocks any loop-refinement
win, on small and large functions alike, before the loop schemas can matter.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
Brings in the analysis-tier features that landed on main since this branch was cut (eh_frame_full / operand_refs / funcstart_patterns settables, +3) plus the catalog-fixture refresh for regionstructure default-on. Merged the +1 regionlooprefine settable on top: settable count 49 -> 53, stage_catalog.json fixture regenerated, kuna-catalog.xml angr/structure-recovery counts kept at 15/9. Gates green: make test 675/675 PARITY OK, make test-stages 203/203 PARITY OK, make rust-test green, kuna catalog --check OK. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
…in deferred) Land the parity-safe portion of the loop-successor refinement increment on top of the regionlooprefine infrastructure (commit 55764be, now merged with main): a convergence stage test proving the new machinery is byte-safe and active, and the roadmap section documenting the remaining goto-win path as a future increment. What this adds: * tests/stages/regionstructure-loop-refine.xml — a multi-exit `for` loop (mexit: early `return -1` + `break`, x86-64 GCC -O1) where the new RI loop projection (`KunaRegionIdentifier::cyclic_loops`) is consumed and `refine_loop_edges` FIRES (verified `[rs] RI loop head=…` + `[rs] refined loop head#N` under KUNA_RS_DEBUG). Asserts the emitted C is byte-identical with `regionlooprefine off` and `on` across both passes (same do-while body, both early returns, ZERO gotos) — the increment's parity invariant: the refinement is wired in and active at zero output risk. * docs/region-structurer-roadmap.md — Inc 5b section: what landed (RI projection + force_loop_single_exit refinement, default-OFF, parity-safe convergence that fires-but-falls-back) and the REMAINING goto-win path as the deferred Inc 6 — complete the acyclic schema set (false-clause if-then, no-exit if-then) + SAILR-style continuation hoisting, so a refined multi-exit loop folds to a structured root (ok=true) instead of falling back to CollapseStructure. Status header updated to LANDED & DEFAULT-ON. * docs/baseline-stages.json — +5 keys for the new stage test (203 -> 208). * kuna-base xml corpus-count test bumped 145 -> 146 (the +1 stage file). Gates (regionstructure default-ON, regionlooprefine default-OFF): make test 675/675 PARITY OK make test-stages 208/208 PARITY OK make rust-test green kuna catalog --check OK The goto win itself (a measurable goto reduction on parse_str-class functions) is NOT in this increment — it needs the acyclic-schema completion + continuation hoisting documented as Inc 6. This lands the parity-safe infrastructure + a clear roadmap for the rest. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
…loop-refine # Conflicts: # decompiler/crates/kuna-base/src/xml.rs # decompiler/crates/kuna-decomp/src/p0_knowledge/kuna_stages/tests.rs # decompiler/crates/kuna-decomp/tests/catalog_bytecompat.rs # docs/baseline-stages.json # tests/stages/kuna-catalog.xml
This was referenced Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lands the parity-safe portion of the region structurer's loop-successor refinement work as a focused increment, and documents the remaining path to the goto win as a future increment (Inc 6). This is the infrastructure + roadmap, not the goto win — by design.
Builds on the committed
regionlooprefineinfrastructure (default-OFF opt-in) and merges currentmain.What this lands (parity-safe)
KunaRegionIdentifier::cyclic_loops()projects each identified cyclic region onto basic-block start addresses(head, refined body, exit frontier)— the read side of angrRegionIdentifier._refine_loop_successors_to_guarded_successors/_ensure_jump_at_loop_exit_ends(force_loop_single_exit), which kuna's RI port had omitted.refine_loop_edges(re-enabled, RI-grounded) — for a multi-exit / multi-latch / mid-entry loop the base cyclic schemas declined, virtualize the secondary exits and latches to gotos so the body collapses toward the clean single-exit/single-latch shapetry_fold_loopaccepts (lowered tobreak;/continue;by the existingscopeBreak/loop-construction passes). Only loops the base schemas already declined are touched.regionlooprefineopt-in (default-OFF, settable [PROPOSAL] angr-true-1804-x86-64-8a690c: condition-aware if/else tail dedup (S8 structuring) #53). Wired end-to-end: Architecture/seam field, option,KUNA_OPTION_NAMES,stages.toml,docs/assertions.md,kuna catalog --checkOK.Parity invariant (the honest result)
The refinement is wired in and actively fires on multi-exit loops (
KUNA_RS_DEBUG=1shows[rs] RI loop head=…+[rs] refined loop head#N). But after it fires, the structurer still reportsok=falseand the function falls back toCollapseStructurefor the final collapse — because the acyclic convergence around the refined loop is incomplete. The net effect on emitted C is therefore zero:regionlooprefine offandonproduce byte-identical output. Somake teststays PARITY OK 675/675 withregionstructuredefault-ON.Convergence stage test
tests/stages/regionstructure-loop-refine.xml— a multi-exitforloop (mexit: earlyreturn -1+break, x86-64 GCC -O1) where the new RI projection is consumed andrefine_loop_edgesfires. Asserts the emitted C is byte-identical across both passes (offandon): samedo { … } while (…)body, both early returns, ZERO gotos — the increment's parity invariant proved end-to-end.Remaining path to the goto win (documented as Inc 6 — NOT in this PR)
The refinement firing without a structuring win localizes the goto-reduction blocker precisely: it is not the loop schemas (complete, Inc 3) and not the refinement wiring (it fires — this PR). It is the acyclic convergence around the refined loop. Closing it (a genuinely deep, multi-increment effort) needs:
negateConditionorientation flip in the structurer) and the no-exit if-then (an if-then region with no fall-through successor). kuna's structural ITE handles only the symmetric two-arm shape today. Until these collapse, the body the refinement frees stays multi-component andtry_fold_loopnever sees the single-block loop it needs.ok=true) instead of fragmenting back toCollapseStructure.Only then does a refined loop fold to a structured root and the virtualized secondary-exit gotos become
break;/continue;— a measurable goto reduction over Ghidra on theparse_str-class functions that motivated the work. Seedocs/region-structurer-roadmap.md→ Inc 5b section for the full write-up.Gates (regionstructure default-ON, regionlooprefine default-OFF)
make testmake test-stagesmake rust-testkuna catalog --checkNotes
origin/main(brought in eh_frame_full/operand_refs/funcstart_patterns settables + the catalog-fixture refresh for regionstructure default-on); resolved the settable-count bookkeeping conflicts (49 → 53 settables, fixture regenerated, kuna-catalog counts at angr=15 / structure-recovery=9).docs/baseline.jsonuntouched.🤖 Generated with Claude Code
https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac