Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
cfe76be
Add goto-free structurer (restructure::structured) and decompiler qua…
Oct 12, 2026
dc96f9a
structured: fix compile error and mark loop headers as emitted
Oct 12, 2026
67f430a
decompiler-quality: surface unit test failures as annotations
Oct 12, 2026
fbc29ef
decompiler-quality: keep annotation step running when cargo test fails
Oct 12, 2026
c6edccc
decompiler-quality: run corpus first, publish results as annotations
Oct 12, 2026
02facf2
structured: TOPAZ_STRUCTURED_DEBUG diagnostics; publish reasons in CI
Oct 12, 2026
13976d8
decompiler-quality: publish decompiled output samples as annotations …
Oct 12, 2026
14f10ba
structured: accept loops with early returns; check runtime output equ…
Oct 12, 2026
50efd67
decompiler-quality: one annotation per block (per-step notice cap), n…
Oct 12, 2026
b8cb38f
Add files via upload
TouseefX Oct 12, 2026
50bb4ec
ci: bounded ClientRenderer bytecode decompile with PASS/FAIL verdict
Oct 12, 2026
7c73ca1
ci(clientrenderer): publish incomplete reason, goto/block markers and…
Oct 12, 2026
3a9d0c1
structured: tag debug lines with source line; clientrenderer: separat…
Oct 12, 2026
3b3d4b3
structured: for loops with several exits (break to other blocks) disp…
Oct 12, 2026
a89d01d
structured: multi-exit for loops accept a return-block header exit; b…
Oct 12, 2026
3ef5d0f
structured: when arms have no post-dominator, stop them at the neares…
Oct 12, 2026
92b394b
structured: loop exit dispatch uses the join of its exits when no pos…
Oct 12, 2026
f95a203
structured: for loops whose header exit is a return block still dispa…
Oct 12, 2026
0364ca4
remove Lua 5.1 support: lua51-lifter, lua51-deserializer, CLI/server/…
Oct 12, 2026
658493d
spill excess top-level locals into a table to stay under Luau's 200-l…
Oct 12, 2026
845955a
spill: measure peak active locals per function; move top-level tail, …
Oct 12, 2026
8c7641d
structured: diagnostics for duplicate node emits and two-way branches…
Oct 12, 2026
bbbff93
structured: join walk cap 4096 -> 16384 and report truncation (duplic…
Oct 12, 2026
0fef792
structured: correct join cap comment after CI showed no truncation
Oct 12, 2026
096ac4e
Add files via upload
TouseefX Oct 12, 2026
f0bf412
structured: reject branch merges past the enclosing stop (tail duplic…
Oct 12, 2026
5d88d62
structured: raise nesting depth limit 1000 -> 3000 (long elseif chain…
Oct 12, 2026
c203e82
structured: revert depth limit to 1000; 3000 exposed exponential dupl…
Oct 12, 2026
43b0b27
copy_fold: inline single-use values across pure local declarations
TouseefX Oct 12, 2026
7c5858c
structurer: escape flag for branches whose merge lies past the enclos…
TouseefX Oct 12, 2026
b9b1d04
structurer: diagnostics for escape tails (count per target, reported …
TouseefX Oct 12, 2026
c966be5
structurer: CFG dump of escape sites (diagnostics only)
TouseefX Oct 12, 2026
aa0c4d7
ClientRenderer workflow: notice with the first escape-site dumps for …
TouseefX Oct 12, 2026
f393c55
restructure: goto-free dispatch fallback (state machine) when the str…
TouseefX Oct 12, 2026
7b85dc1
dispatch fallback: lower numeric and generic for-loop headers to expl…
TouseefX Oct 12, 2026
c503f52
dispatch: diagnostics for each reason the fallback gives up
TouseefX Oct 12, 2026
8804a25
dispatch: sign-aware test for non-literal for-loop steps; notes for h…
TouseefX Oct 12, 2026
14a8c9a
dispatch: balanced if-tree instead of a flat elseif chain (Luau parse…
TouseefX Oct 12, 2026
45381fb
dispatch: declare hoisted locals in chunks of 50 (register limit afte…
TouseefX Oct 12, 2026
86d07c3
dispatch: merge straight-line node chains into one arm
TouseefX Oct 12, 2026
7170855
restructure: node splitting makes irreducible flow graphs reducible b…
TouseefX Oct 12, 2026
162a852
structurer: escape scopes share one dispatch variable; each target is…
TouseefX Oct 12, 2026
1d48e88
structurer: always emit escape targets; unused scopes were dropping b…
TouseefX Oct 12, 2026
eb0b34c
gui: drop stale Lua 5.1 wording from the header labels
TouseefX Oct 12, 2026
aae7188
diagnostics: CFG and two-way decision dump for the 4836 function (deb…
TouseefX Oct 12, 2026
7000347
structurer: early-return dead ends no longer count as exits for the p…
TouseefX Oct 12, 2026
5ab9f9c
diagnostics: drop the CFG dumps; print the 4836 outcome as one notice
TouseefX Oct 12, 2026
362eb09
diagnostics: 4836 notice shows the outcome lines, not the no-merge notes
TouseefX Oct 12, 2026
ba52004
diagnostics: 4836 notice shows counts and the last lines
TouseefX Oct 12, 2026
c65f9dd
structurer: post-dominators ignore every return block (shared ones to…
TouseefX Oct 12, 2026
26e6a7d
Revert "structurer: post-dominators ignore every return block (shared…
TouseefX Oct 12, 2026
5c86840
structurer: post-dominators ignore every return block (shared ones to…
TouseefX Oct 12, 2026
028be10
structurer: escape tails stop at the innermost enclosing stop they re…
TouseefX Oct 12, 2026
739f58b
diagnostics: count and sample the Request == checks in the ClientRend…
TouseefX Oct 12, 2026
78b7b57
diagnostics: count every string comparison in the ClientRenderer output
TouseefX Oct 12, 2026
751ac6c
spill: only spill functions over Luau's real 200-local limit (was 150…
TouseefX Oct 13, 2026
9f2d565
spill: leave room for the _spilled table itself (it is a live local t…
TouseefX Oct 13, 2026
2e85f75
spill: debug stats for oversized bodies (TOPAZ_DEBUG_SPILL) to see wh…
TouseefX Oct 13, 2026
b8316b3
spill debug: match the string literal as bytes (Literal::String is Ve…
TouseefX Oct 13, 2026
508016f
spill debug: distance between a single-read declaration and its read;…
TouseefX Oct 13, 2026
aede2cd
spill debug: sample adjacent single-read declarations
TouseefX Oct 13, 2026
f8cc9b1
copy_fold debug: count why single-read declarations are not inlined i…
TouseefX Oct 13, 2026
f4b56b8
copy_fold: inline single-value calls (Select) into their reader when …
TouseefX Oct 13, 2026
4433591
copy_fold: inline plain local copies past unrelated calls; inline bar…
TouseefX Oct 15, 2026
f3a0e8c
copy_fold debug: tally candidates by value kind and outcome
TouseefX Oct 15, 2026
7c80f97
copy_fold: a single-use closure may move into its reader (creating a …
TouseefX Oct 15, 2026
8c9ea7b
copy_fold: rename a captured local copy (a = b) to its source when ne…
TouseefX Oct 15, 2026
7d2a8b7
scope top-level locals in do-blocks after their last use before spill…
TouseefX Oct 15, 2026
0bb0f00
spill debug: live-range and ideal-nesting peaks for the scoping plan
TouseefX Oct 15, 2026
915763f
Revert "spill debug: live-range and ideal-nesting peaks for the scopi…
TouseefX Oct 15, 2026
8f1fb9b
Revert "scope top-level locals in do-blocks after their last use befo…
TouseefX Oct 15, 2026
a6a5314
sink top-level declarations to their first use before spilling (only …
TouseefX Oct 15, 2026
fd3a91b
scope top-level locals in do-blocks after sinking, only for what is s…
TouseefX Oct 15, 2026
ca1dfca
sink calls too, only past statements that cannot observe or change them
TouseefX Oct 15, 2026
76ddef3
revert sink and scope experiments: neither lowers the active-local pe…
TouseefX Oct 15, 2026
9edd27d
compare the decompiled ClientRenderer with the cleaned reference in C…
TouseefX Oct 15, 2026
d239a6a
compare_decompile: list unknown globals, duplicated shapes and functi…
TouseefX Oct 15, 2026
137aaaa
compare_decompile: list every use of a name that nothing declares, wi…
TouseefX Oct 15, 2026
e77d9eb
Debug scope check (TOPAZ_SCOPE_CHECK): count reads of undeclared loca…
TouseefX Oct 15, 2026
c301f60
Scope check: per-function stages (lift, fold, declare) and example lines
TouseefX Oct 15, 2026
363d749
Scope check: show the offending statement text, check only the declar…
TouseefX Oct 15, 2026
7c88a8c
Scope check: classify unresolved reads as never declared or declared …
TouseefX Oct 15, 2026
3a054d7
Scope check: read the expression tree, not closure upvalue lists
TouseefX Oct 15, 2026
1bfbe4f
Scope check: per-function count after post passes, summed in the report
TouseefX Oct 15, 2026
25e5306
A/B switches for the suspect copy passes, [ab] counters, and an A/B s…
TouseefX Oct 15, 2026
98fdbc2
Scope check: attribute out-of-scope reads to each post pass, one line…
TouseefX Oct 15, 2026
a01ba70
Scope check: subtree check at the declare stage, entering the closure…
TouseefX Oct 15, 2026
157bc17
Scope check: declare stages report unresolved, never-declared and ski…
TouseefX Oct 15, 2026
2136bdc
Scope check: count LocalDeclarer's silent skips (blocks not locked, d…
TouseefX Oct 16, 2026
7669619
Scope check: out-of-scope uses get their own examples, so they are no…
TouseefX Oct 16, 2026
c16a8e2
Compare: list every out-of-scope example and its declare-stage statem…
TouseefX Oct 16, 2026
aba3128
Scope check: name out-of-scope uses as the statements print them, and…
TouseefX Oct 16, 2026
c42204e
Compare: out-of-scope examples and statements first, so the annotatio…
TouseefX Oct 16, 2026
c73426e
LocalDeclarer: check each chosen declaration point against its uses (…
TouseefX Oct 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
243 changes: 243 additions & 0 deletions .github/workflows/clientrenderer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
name: ClientRenderer bytecode

# Decompiles the large Roblox ClientRenderer LocalScript dump with the
# topaz CLI, bounded by an outer `timeout -s KILL` (the output must never
# be left unbounded, see CODEBASE.md) and an internal --time-budget.
#
# A run is a PASS only when all of these hold (exit 0 alone is not enough):
# - topaz exited 0 (no timeout, no panic)
# - no TOPAZ_INCOMPLETE marker in the output
# - no goto / ::label:: in the output
# - the decompiled output still compiles with luau-compile
#
# The verdict is published as an annotation and as a step summary. The
# decompiled file, the topaz log and the verdict are uploaded as an artifact.

on:
workflow_dispatch:
push:
branches:
- 'arena/**'
paths:
- 'ClientRenderer_LocalScript_88615311464962_Bytecode.txt'
- '.github/workflows/clientrenderer.yaml'
- 'topaz/**'
- 'luau-lifter/**'
- 'restructure/**'
- 'cfg/**'
- 'ast/**'
- 'reference/**'
- 'scripts/compare_decompile.py'

env:
BYTECODE: ClientRenderer_LocalScript_88615311464962_Bytecode.txt
BUDGET_SECS: '600'
KILL_SECS: '900'

jobs:
decompile:
name: ClientRenderer (${{ matrix.label }})
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
include:
- label: new
src: .
- label: baseline
src: baseline
steps:
- name: Checkout this branch
uses: actions/checkout@v4

- name: Checkout main as baseline
if: matrix.label == 'baseline'
uses: actions/checkout@v4
with:
ref: main
path: baseline

- name: Install Rust nightly
uses: dtolnay/rust-toolchain@nightly

- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: ${{ matrix.src }}

- name: Build topaz CLI
working-directory: ${{ matrix.src }}
run: cargo build --release -p topaz

- name: Build luau-compile
run: |
git clone --depth 1 https://github.com/luau-lang/luau.git /tmp/luau
cmake -S /tmp/luau -B /tmp/luau/build -DCMAKE_BUILD_TYPE=Release
cmake --build /tmp/luau/build --target Luau.Compile.CLI Luau.Analyze.CLI --parallel 4
LUAU_COMPILE="$(find /tmp/luau/build -type f -name 'luau-compile' | head -n 1)"
test -x "$LUAU_COMPILE"
echo "LUAU_COMPILE=$LUAU_COMPILE" >> "$GITHUB_ENV"
LUAU_ANALYZE="$(find /tmp/luau/build -type f -name 'luau-analyze' | head -n 1)"
test -x "$LUAU_ANALYZE"
echo "LUAU_ANALYZE=$LUAU_ANALYZE" >> "$GITHUB_ENV"

- name: Decompile ClientRenderer (bounded)
env:
TOPAZ_STRUCTURED_DEBUG: '1'
TOPAZ_SCOPE_CHECK: '1'
TOPAZ_DEBUG_CYCLES: '1'
TOPAZ_DEBUG_SPILL: '1'
TOPAZ_DEBUG_INLINE: '1'
run: |
mkdir -p out
start=$(date +%s)
rc=0
timeout -s KILL "$KILL_SECS" "${{ matrix.src }}/target/release/topaz" decompile \
--time-budget "$BUDGET_SECS" \
--input "$GITHUB_WORKSPACE/$BYTECODE" \
--output "out/ClientRenderer.luau" > out/topaz.log 2>&1 || rc=$?
echo "$rc" > out/exit.txt
echo "$(( $(date +%s) - start ))" > out/elapsed.txt
echo "topaz exit=$rc elapsed=$(cat out/elapsed.txt)s"

- name: Score output and publish verdict
if: always()
id: score
run: |
esc() { sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/$/%0A/' | tr -d '\n'; }
label="${{ matrix.label }}"
out=out/ClientRenderer.luau
rc="$(cat out/exit.txt 2>/dev/null || echo missing)"
elapsed="$(cat out/elapsed.txt 2>/dev/null || echo ?)"
if [ -f "$out" ]; then
lines=$(wc -l < "$out")
bytes=$(wc -c < "$out")
gotos=$(grep -c -E '^[[:space:]]*(goto[[:space:]]|::[A-Za-z_][A-Za-z0-9_]*::)' "$out" || true)
commented=$(grep -c -E '^[[:space:]]*--[[:space:]]*(goto[[:space:]]|::[A-Za-z_][A-Za-z0-9_]*::)' "$out" || true)
blocks=$(grep -c -- '-- block' "$out" || true)
incomplete=$(grep -c 'TOPAZ_INCOMPLETE' "$out" || true)
else
lines=0; bytes=0; gotos=0; commented=0; blocks=0; incomplete=0
fi
compile="not-run"
if [ -f "$out" ]; then
if "$LUAU_COMPILE" "$out" > /dev/null 2> out/compile.err; then
compile=ok
else
compile=fail
fi
fi
reasons=""
[ "$rc" = "0" ] || reasons="$reasons topaz-exit-$rc;"
[ "$incomplete" = "0" ] || reasons="$reasons incomplete-marker;"
[ "$gotos" = "0" ] || reasons="$reasons gotos=$gotos;"
[ "$compile" = "ok" ] || reasons="$reasons compile=$compile;"
if [ -z "$reasons" ]; then verdict=PASS; else verdict="FAIL ($reasons)"; fi
{
echo "## ClientRenderer ($label)"
echo ""
echo "| metric | value |"
echo "| --- | --- |"
echo "| topaz exit | $rc |"
echo "| elapsed | ${elapsed}s (budget ${BUDGET_SECS}s, kill ${KILL_SECS}s) |"
echo "| output lines | $lines |"
echo "| output bytes | $bytes |"
echo "| live goto / ::label:: | $gotos |"
echo "| commented-out goto / label | $commented |"
echo "| -- block | $blocks |"
echo "| TOPAZ_INCOMPLETE | $incomplete |"
echo "| luau-compile | $compile |"
echo "| **verdict** | **$verdict** |"
} > out/verdict.md
cat out/verdict.md >> "$GITHUB_STEP_SUMMARY"
printf '::notice title=ClientRenderer verdict (%s)::%s\n' "$label" "$(cat out/verdict.md | esc)"
s0="$(grep -h '^structured' out/topaz.log 2>/dev/null | sed -E 's/^structured\[[^]]*\]: //; s/[0-9]+/N/g' | sort | uniq -c | sort -rn | head -n 10 || true)"
s1="$(grep -h '^structured\[' out/topaz.log 2>/dev/null | grep -v ': ok (' | grep -v ': built:' | head -n 40 | cut -c1-200 || true)"
printf '::notice title=structured fallbacks (%s)::%s\n' "$label" "$(printf '%s\n%s\n' "$s0" "$s1" | esc)"
esc_sites="$(grep -h 'Some(4836)\]: ESC site' out/topaz.log 2>/dev/null | head -n 60 | cut -c1-400 || true)"
printf '::notice title=escape sites 4836 (%s)::%s\n' "$label" "$(printf '%s\n' "$esc_sites" | esc)"
res4836_all="$(grep -h 'Some(4836)\]' out/topaz.log 2>/dev/null || true)"
res4836="$(printf '%s\n' "$res4836_all" | sed -E 's/^structured\[[^]]*\]: //; s/[0-9]+/N/g' | sort | uniq -c | sort -rn | head -n 25 | cut -c1-200)"
res4836_tail="$(printf '%s\n' "$res4836_all" | tail -n 8 | cut -c1-240)"
printf '::notice title=result 4836 (%s)::%s\n' "$label" "$(printf 'counts:\n%s\nlast:\n%s\n' "$res4836" "$res4836_tail" | esc)"
req_count=$(grep -c ' == "' "$out" 2>/dev/null || true)
req_sample="$(grep -n ' == "' "$out" 2>/dev/null | head -n 12 | cut -c1-160 || true)"
printf '::notice title=string checks (%s)::%s\n' "$label" "$(printf 'string == "X" lines: %s\n%s\n' "$req_count" "$req_sample" | esc)"
tail_log="$(tail -n 40 out/topaz.log 2>/dev/null | cut -c1-300 || true)"
printf '::notice title=topaz log tail (%s)::%s\n' "$label" "$(printf '%s\n' "$tail_log" | esc)"
# Where the output is incomplete: the reason line and the first
# markers, with line numbers and the enclosing function header.
if [ -f "$out" ]; then
reason="$(grep -h -E '^-- ERROR' "$out" | head -n 5 | cut -c1-300 || true)"
printf '::notice title=incomplete reason (%s)::%s\n' "$label" "$(printf '%s\n' "$reason" | esc)"
marks="$(grep -n -E 'goto |::[A-Za-z_][A-Za-z0-9_]*::|-- block|internal control|GenericFor|NumFor|failed to|formatter stopped' "$out" | head -n 40 | cut -c1-220 || true)"
printf '::notice title=goto and block markers (%s)::%s\n' "$label" "$(printf '%s\n' "$marks" | esc)"
fnctx="$(awk '/function/ {f=$0; fn=NR} /-- block|goto / {c++; if (c<=20) print NR": in fn@"fn": "substr(f,1,150)}' "$out" || true)"
printf '::notice title=enclosing functions (%s)::%s\n' "$label" "$(printf '%s\n' "$fnctx" | esc)"
fi
cerr="$(head -n 20 out/compile.err 2>/dev/null | cut -c1-300 || true)"
if [ -n "$cerr" ]; then
printf '::notice title=luau-compile errors (%s)::%s\n' "$label" "$(printf '%s\n' "$cerr" | esc)"
fi
spill=$(grep -h '^\[spill\|^\[inline' out/topaz.log 2>/dev/null | head -n 40 | cut -c1-1200 || true)
printf '::notice title=spilled locals (%s)::%s\n' "$label" "$(printf '%s\n' "$spill" | esc)"
errline=$(sed -n 's/.*ClientRenderer\.luau(\([0-9]*\),.*/\1/p' out/compile.err 2>/dev/null | head -n 1 || true)
if [ -n "$errline" ] && [ -f "$out" ]; then
ectx=$(awk -v L="$errline" '/function/ {fn=NR; f=$0; n=0} NR==L {print "error line " L " in fn@" fn ": " substr(f,1,160) " (local lines before it in fn: " n ")"; exit} /^[ \t]*local / {n++}' "$out" || true)
printf '::notice title=compile error context (%s)::%s\n' "$label" "$(printf '%s\n' "$ectx" | esc)"
fi
echo "verdict=$verdict" >> "$GITHUB_OUTPUT"

- name: Compare with the cleaned reference
if: always() && matrix.label == 'new'
run: |
esc() { sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/$/%0A/' | tr -d '\n'; }
python3 scripts/compare_decompile.py reference/ClientRenderer.cleaned.luau out/ClientRenderer.luau "$LUAU_COMPILE" "$LUAU_ANALYZE" > out/compare.txt 2>&1 || echo "compare script exit=$?" >> out/compare.txt
cat out/compare.txt >> "$GITHUB_STEP_SUMMARY"
split -C 2800 -d -a 2 out/compare.txt out/cmp_
n=0
for part in out/cmp_*; do
n=$((n+1))
[ "$n" -le 40 ] || break
printf '::notice title=compare with cleaned reference %s::%s\n' "$n" "$(cat "$part" | esc)"
done

- name: A/B each suspect pass switched off
if: matrix.label == 'new'
run: |
esc() { sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/$/%0A/' | tr -d '\n'; }
topaz="${{ matrix.src }}/target/release/topaz"
for variant in BASELINE NO_CAPTURED_RENAME NO_POST_COPY_FOLD NO_FOLD_COPIES; do
switch=""
[ "$variant" = BASELINE ] || switch="TOPAZ_AB_${variant}=1"
rc=0
# shellcheck disable=SC2086
env TOPAZ_AB_REPORT=1 $switch timeout -s KILL 300 "$topaz" decompile \
--time-budget 200 \
--input "$GITHUB_WORKSPACE/$BYTECODE" \
--output "out/ab_$variant.luau" > "out/ab_$variant.log" 2>&1 || rc=$?
ab_line="$(grep -h '^\[ab\]' "out/ab_$variant.log" | tail -n 1 || true)"
summary=""
if [ "$variant" != BASELINE ] && [ -f "out/ab_$variant.luau" ]; then
python3 scripts/compare_decompile.py reference/ClientRenderer.cleaned.luau \
"out/ab_$variant.luau" "$LUAU_COMPILE" "$LUAU_ANALYZE" \
> "out/ab_$variant.compare" 2>&1 || true
summary="$(grep -E '^absolute, not Roblox|^functions:|^string constants' "out/ab_$variant.compare" | head -n 4 || true)"
fi
printf '::notice title=A/B %s (topaz exit %s)::%s\n' "$variant" "$rc" "$(printf '%s\n%s\n' "$ab_line" "$summary" | esc)"
done

- name: Upload ClientRenderer output
if: always()
uses: actions/upload-artifact@v4
with:
name: clientrenderer-${{ matrix.label }}
path: out
if-no-files-found: warn

- name: Fail the branch run on a FAIL verdict
if: matrix.label == 'new' && steps.score.outputs.verdict != 'PASS'
run: |
echo "ClientRenderer verdict: ${{ steps.score.outputs.verdict }}"
exit 1
145 changes: 145 additions & 0 deletions .github/workflows/decompiler-quality.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Decompiler quality

# Builds the decompiler from this branch and from main, decompiles the
# Lua corpus in decompiler-corpus/ with both, and reports goto counts,
# incomplete markers and whether each decompiled output still compiles.
#
# Results are also published as workflow annotations (readable through the
# checks API even when the raw job log is not available).

on:
workflow_dispatch:
pull_request:
push:
branches:
- 'arena/**'

jobs:
corpus:
name: Corpus (${{ matrix.label }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- label: new
src: .
- label: baseline
src: baseline
steps:
- name: Checkout this branch
uses: actions/checkout@v4

- name: Checkout main as baseline
if: matrix.label == 'baseline'
uses: actions/checkout@v4
with:
ref: main
path: baseline

- name: Install Rust nightly
uses: dtolnay/rust-toolchain@nightly

- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: ${{ matrix.src }}

- name: Build topaz CLI
working-directory: ${{ matrix.src }}
run: cargo build --release -p topaz

- name: Build luau-compile and luau (runtime)
run: |
git clone --depth 1 https://github.com/luau-lang/luau.git /tmp/luau
cmake -S /tmp/luau -B /tmp/luau/build -DCMAKE_BUILD_TYPE=Release
cmake --build /tmp/luau/build --target Luau.Compile.CLI --target Luau.Repl.CLI --parallel 4
LUAU_COMPILE="$(find /tmp/luau/build -type f -name 'luau-compile' | head -n 1)"
LUAU_REPL="$(find /tmp/luau/build -type f -name 'luau' -perm -u+x | head -n 1)"
test -x "$LUAU_COMPILE"
test -x "$LUAU_REPL"
echo "LUAU_COMPILE=$LUAU_COMPILE" >> "$GITHUB_ENV"
echo "LUAU_REPL=$LUAU_REPL" >> "$GITHUB_ENV"

- name: Decompile corpus
env:
TOPAZ_STRUCTURED_DEBUG: '1'
run: |
bash scripts/decompile_corpus.sh \
"${{ matrix.src }}/target/release/topaz" \
"$LUAU_COMPILE" \
decompiler-corpus \
"corpus-out/${{ matrix.label }}" \
"$LUAU_REPL"
cat "corpus-out/${{ matrix.label }}/SUMMARY.md" >> "$GITHUB_STEP_SUMMARY"

- name: Publish corpus summary as annotations
if: always()
run: |
# Each block is ONE annotation with %0A line breaks: GitHub caps the
# number of notices per step, so one-line-per-annotation loses data.
label="${{ matrix.label }}"
esc() { sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/$/%0A/' | tr -d '\n'; }
f="corpus-out/$label/SUMMARY.md"
if [ -f "$f" ]; then
printf '::notice title=corpus summary (%s)::%s\n' "$label" "$(sed 's/|/ /g' "$f" | esc)"
else
echo "::warning title=corpus::no SUMMARY.md produced"
fi
logs=(corpus-out/$label/*.topaz.log)
if [ -f "${logs[0]}" ]; then
# Why the goto-free structurer gave up (or succeeded), aggregated.
s1="$(cat "${logs[@]}" | grep -h '^structured:' | sort | uniq -c | sort -rn | head -40)"
printf '::notice title=structured reasons (%s)::%s\n' "$label" "$(printf '%s\n' "$s1" | esc)"
# Panics and errors from the decompiler itself, aggregated.
s2="$(cat "${logs[@]}" | grep -h -E 'panicked|error' | sort | uniq -c | sort -rn | head -15)"
printf '::notice title=topaz errors (%s)::%s\n' "$label" "$(printf '%s\n' "$s2" | esc)"
fi

- name: Publish output samples (debug)
if: always()
run: |
label="${{ matrix.label }}"
esc() { sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/$/%0A/' | tr -d '\n'; }
for f in corpus-out/$label/01_loops_break_continue.topaz.log corpus-out/$label/07_cutscene_like.decompiled.lua corpus-out/$label/07_cutscene_like.topaz.log; do
[ -f "$f" ] || { echo "::notice title=sample::missing $f"; continue; }
printf '::notice title=sample %s (%s, %s bytes)::%s\n' "$(basename "$f")" "$label" "$(wc -c < "$f")" "$(head -n 150 "$f" | esc)"
done
: > /tmp/diffs.txt
for f in corpus-out/$label/*.diff; do
[ -f "$f" ] || continue
{ printf '== %s ==\n' "$(basename "$f")"; head -n 25 "$f"; } >> /tmp/diffs.txt
done
diffs="$(cat /tmp/diffs.txt)"
if [ -n "$diffs" ]; then
printf '::notice title=output diffs (%s)::%s\n' "$label" "$(printf '%s' "$diffs" | esc)"
fi

- name: Unit tests (ast, cfg, restructure) - informational
continue-on-error: true
working-directory: ${{ matrix.src }}
env:
RUST_BACKTRACE: '1'
run: |
# Every test binary runs (--no-fail-fast). Failure lines become
# annotations so the cause is visible without the raw job log.
rc=0
cargo test -p ast -p cfg -p restructure --lib --no-fail-fast > unit-test.log 2>&1 || rc=$?
esc() { sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/$/%0A/' | tr -d '\n'; }
summary="$(grep -E '^error|^ +--> |panicked at|^test .* FAILED|test result' unit-test.log | head -80)"
printf '::error title=unit test results (%s, exit %s)::%s\n' "${{ matrix.label }}" "$rc" "$(printf '%s\n' "$summary" | esc)"
exit $rc

- name: Restructure unit tests (gate, new only)
if: matrix.label == 'new'
env:
RUST_BACKTRACE: '1'
run: cargo test -p restructure --lib

- name: Upload corpus output
if: always()
uses: actions/upload-artifact@v4
with:
name: decompile-corpus-${{ matrix.label }}
path: corpus-out/${{ matrix.label }}
if-no-files-found: warn
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ result.lua
# But explicitly allow the stress-test source files used by the
# compile-and-decompile stress test (tests/opcode_stress_compile.rs).
!luau-lifter/tests/stress_sources/*.luau
!reference/ClientRenderer.cleaned.luau
Loading
Loading