Skip to content

Goto-free structurer for the Luau decompiler (restructure::structured) - #3

Draft
TouseefX wants to merge 94 commits into
mainfrom
arena/1e866726-topaz
Draft

TouseefX wants to merge 94 commits into
mainfrom
arena/1e866726-topaz

Conversation

@TouseefX

@TouseefX TouseefX commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • restructure/src/structured.rs: goto-free, region-based structurer. Emits if, while, for, generic for, with break / continue. Loops with several real exits use a flag and dispatch after the loop (for both while and for forms).
  • Branches whose arms have no post-dominator now stop at the nearest shared node (join_all), so tails are not copied into each arm. Loop exits use the same join when there is no post-dominator.
  • lift() tries the structurer first and falls back to the legacy GraphStructurer when a shape is not proven. Every fallback is logged with its source line when TOPAZ_STRUCTURED_DEBUG=1.
  • .github/workflows/decompiler-quality.yaml: corpus check, new vs main.
  • .github/workflows/clientrenderer.yaml: bounded decompile of ClientRenderer_LocalScript_88615311464962_Bytecode.txt (timeout -s KILL 900, --time-budget 600), with a PASS/FAIL verdict. The branch run fails on FAIL. The baseline run never fails.

Verified in CI (commit f95a203)

  • Corpus (decompiler-quality): same files pass and fail as before. goto 0 and -- block 0 everywhere. 01 53→67 lines and 05 45→54 lines because of flag dispatch; both still produce the same output.
  • restructure unit tests (gate): pass.
  • ClientRenderer (clientrenderer, branch run):
    • topaz exits 1 with TOPAZ_INCOMPLETE after ~5s (not a timeout).
    • live gotos 0, -- block 5, commented-out gotos/labels 104. All 104 come from one function (the 422-loop function at line 4836).
    • luau-compile fails with cFrame652: exceeded limit 200 (Luau's 200-local register limit). This is the known open item in CODEBASE.md, and the structurer does not change it.
    • structurer: 1609 of 1610 functions structured. The one fallback is line 4836, which exceeds the statement budget (206612 > 206600). Nodes 7540–7562 are each emitted 29 times, so there is still tail duplication there.

Not solved yet

  1. The duplicated chain in the 422-loop function (line 4836). It forces the legacy fallback, which is where the -- block and commented-out gotos come from.
  2. The 200-local limit. Luau refuses the output, so ClientRenderer does not compile. This needs an output pass that moves excess locals into a table (or splits scopes).
  3. Readability (not measured by the corpus): extra local temporaries from SSA copies, and generic for loops print internal result locals.
  4. Pre-existing on main, unrelated to this branch: 03 loses state naming, 07 renames self (runtime error). cfg destruct and ast inline_gotos unit tests fail on main as well.
  5. The ClientRenderer dump in the repo is 1.8 MB / 10,314 lines. CODEBASE.md describes the large dump as about 22 MB / 60k+ lines. Confirm this is the file you intended.

arena-agent and others added 30 commits October 12, 2026 06:06
…lity CI

- structured.rs: region-based structuring over the final CFG. Natural loops
  from dominator back edges, post-dominator merges on region views (return
  blocks with one predecessor are early exits), while/for/generic-for with
  break/continue, dispatch flags for multi-exit loops. Falls back to the
  legacy GraphStructurer on any unproven shape, budget overrun or deadline.
- lift() tries the structured path first; output is validated for no
  goto/labels/leftover for-loop IR.
- decompiler-quality.yaml: compares this branch against main on a corpus
  (goto count, -- block count, incomplete markers, recompile check).
- scripts/decompile_corpus.sh and decompiler-corpus/ (8 Luau sources).

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
- StableGraph::node_bound is a NodeIndexable trait method, not inherent; compute the index bound directly. This was the compile error breaking cargo check (Android) and the restructure unit tests.
- emit_loop now marks the header emitted for while/for forms; emit() requires every reachable node to be emitted, so without this every while/for loop fell back to the legacy structurer.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Run all test binaries with --no-fail-fast, keep the full output, and emit
error annotations for panics, compile errors and failed tests so the cause
can be read through the API without the raw job log.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
- Corpus runs before unit tests so a test failure cannot hide the output.
- ast/cfg/restructure unit tests run for both new and baseline as
  informational (continue-on-error) so pre-existing failures are visible as
  a comparison; restructure tests stay a hard gate on new.
- SUMMARY.md rows and topaz log hits are published as notice annotations.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
The corpus shows goto counts unchanged from main, so the structurer is
falling back to the legacy path. Each bail-out now records its reason when
TOPAZ_STRUCTURED_DEBUG is set, and the corpus job publishes the aggregated
reasons as annotations.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…(debug)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ivalence

- for/while forms looked at every exit, so a 'return' inside a loop (copied
  inline by classify) rejected the loop. Only real exits count now.
- Build the luau REPL alongside luau-compile and compare original vs
  decompiled stdout and exit code per corpus file (same output column).
- Corpus 07 is self-contained and deterministic (no math.random, has a
  driver that prints).

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ormalize error line numbers

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
… enclosing functions

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…e live vs commented gotos, list fallbacks

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…atch by flag after the loop; log every fallback

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…udget note lists the most emitted nodes

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…t shared node (no tail copies); nested arms keep the enclosing stop

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…t-dominator; richer for-shape note

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…tch the other exit by flag

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…GUI/Android routes and samples

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ocal limit

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…then nested locals, when above 150

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
… with no merge (debug output only)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ate-emit experiment)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ation); spill the minimal set of locals

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…s hit it at line 4836)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ication (node emitted 9856x)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ing stop

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
TouseefX and others added 30 commits October 15, 2026 08:37
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…closure has no effects)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ither is rewritten; the closure's upvalue follows

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ing; spill only what is still over the limit

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…re spilling; spill only what is still over the limit"

This reverts commit 7d2a8b7.
…for functions over the limit)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…till over the limit

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ak of the large body (see notes); spill stays as before

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…I (constants, opcodes, analyzer errors)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ons without a counterpart

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…th its line and function

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ls after each post pass

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…e stage per function

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…elsewhere, add start step

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…tep in the ClientRenderer workflow

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
… per function

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…s of each function

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…pped counts

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ropped declarations, read-never-written locals)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…t crowded out

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ents

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
… record the statements that contain one

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…ns keep them

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…debug), count placements with no block

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
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