Repository navigation
[AUTOMATED] Print a function-tail if wrapped or as a guard clause by the size of its tail (option tailform) - #1902
Merged
Merged
Conversation
…ion tailform)
At the end of a function `if (c) { S } return K;` and
`if (!c) return K; S; return K;` are the same program, and kuna printed
whichever one the binary's return layout implied. The new P8 print-tree
pass kuna_tailform wraps a guard whose remaining tail prints at most 4
lines, turns a one-arm if before the final return whose body prints more
into a guard clause, and drops an arm's return that repeats the
function's final return. Returns must be void, equal constants or one
SSA value; conditions are negated in place; no op is cloned, reordered
or removed. Option `tailform off|on|<n>|<void>,<value>`, default on (4).
Vendored datatests and stage tests that pin the binary's own return
layout set `option tailform off`.
[AUTOMATED]
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
…keep the source helpers The printed record() indexes the int array as bytes, a typing defect outside this feature, so the round trip links the re-spelled functions against the source's note() and record(). [AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
…ng call's if tailform wraps the one-statement tail, so the test prints negated. [AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
The looptest plan prints a rotated loop top-tested and drops the guard in
front of it. tailform now computes that plan on the tree it edits and
does not merge, wrap or guard a claimed if, nor move a tail or body that
holds one, so while (p) { ... } is not turned back into
if (!p) return; do { ... } while (p);. The stage test gains a list walk
that pins both plans, and the counters are re-derived after the merge.
[AUTOMATED]
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
…urn layout compact_switch_cli checks the switch's nesting, rettriangle_round_trip the split it compares against, and the warning-style test the line each warning lands on; all three print the binary's own function-tail form. [AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
…ing main The looptest plan now takes the printer's declared counter types; the pass plans before they exist and passes none, so counters keep their high's own type. kuna-looptest-order pins the binary's return layout like kuna-looptest, and the corpus count is re-derived. [AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
mahaloz
added a commit
to sjkim1127/kuna
that referenced
this pull request
Nov 23, 2026
Resolve the stage-corpus count (885 on main after Noelo-Lab#1902, +1 here = 886) and synthesize docs/baseline-stages.json from both sides (main 5198 + 5 = 5203). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
mahaloz
added a commit
that referenced
this pull request
Nov 23, 2026
The stage corpus file count is 886 with #1902's stage file. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
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.
At the end of a function,
if (c) { S } return K;andif (!c) return K; S; return K;are the same program. kuna printed whichever one the compiler's return layout implied, and that layout usually points the other way from the source: a short body ending in a call gets its own exit (a tail jump), so it prints as a guard clause, while a long body shares the epilogue and prints wrapped.Before:
After:
A long body goes the other way: six statements wrapped in
if (p) { ... }before a shared epilogue now print behindif (!p) return;.kuna_tailform, optiontailform off|on|<n>|<void>,<value>(default on,<n>= 4). It works on the function's top-level statements. A guardif (c) return K;whose remaining tail prints at most<n>lines becomesif (!c) { tail } return K;. A one-armifbefore the final bare return whose body prints more than<n>lines becomes a guard clause. In a valued function, an arm of that lastifthat ends in the function's ownreturn K;drops it.FlowBlock::negateConditiondoes it. Statements only move, and no op is cloned, reordered or removed. Tails that end in a decode-failure orhalttruncation are left alone.return K;shares a basic block with the last statement (shrink-wrappedcall; xor eax,eax; ret), the leaf prints without its return inside theif, and a return-only copy of the leaf prints after it. Two leaf flags and three small hooks inprintc.rsdo this.kuna_tailform::decideholds the whole policy (current form, void or valued, printed lines), so another decision function can replace it.looptestdrops in front of a loop stayslooptest's: the pass computes that plan on the tree it edits and leaves such anif(and any tail or body holding one) alone.rettrianglestays as it is. It decides before structuring and still matters for joins nested inside other constructs.On the decbench O2 (no inlining) corpus, 549 more functions match the source's control flow exactly (gained 755, lost 206), and 461 more at O0 (gained 717, lost 256). The threshold was fitted on half the projects and checked on the other half. The lost functions are sources that wrote the other form.
Tests:
tests/stages/kuna-tailform.xmldecompiles a gcc -O2 fixture with the option off and on (11 assertions, two of them on a looplooptestowns).kuna-cli/tests/tailform_round_trip.rscompiles the printed C of the -O2 and -O0 builds beside the source with gcc and clang at -O0/-O2, and checks every function returns, counts and stores what the source does. There are also unit tests fordecideand the option value. Five vendored datatests, thirteen stage tests and threekuna-clitests that pin the binary's return layout now setoption tailform off, and one CLI probe accepts either polarity of a re-spelledif.docs/baseline.jsonis unchanged.Model:
anthropic/claude-opus-5-5🤖 Generated with Claude Code
https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU