feat(control_tree): Phase 133 P0 - Multiple post-loop assigns support
Extend Phase 132's loop(true) + post-loop to accept multiple assignments:
Goal: `x=0; loop(true){ x=1; break }; x=x+2; x=x+3; return x` → exit code 6
Implementation:
- Extended loop_true_break_once.rs pattern detection (len() == 2 → len() >= 2)
- Added iterative assignment lowering (for loop over post_nodes)
- Reused Phase 130's lower_assign_stmt for each assignment
- Maintained ExitMeta DirectValue mode (PHI-free)
Changes:
- apps/tests/phase133_loop_true_break_once_post_multi_add_min.hako (new fixture)
- tools/smokes/v2/profiles/integration/apps/phase133_*_multi_add_*.sh (new smokes)
- src/mir/control_tree/normalized_shadow/loop_true_break_once.rs (+30 lines)
- docs/development/current/main/phases/phase-133/README.md (new documentation)
- docs/development/current/main/10-Now.md (Phase 133 entry added)
Scope (Phase 130 baseline):
- ✅ x = <int literal>
- ✅ x = y (variable copy)
- ✅ x = x + <int literal> (increment)
- ❌ Function calls / general expressions (future phases)
Design principles:
- Minimal change: ~30 lines added
- SSOT preservation: env_post_k remains single source of truth
- Reuse: Leveraged existing lower_assign_stmt
- Fail-Fast: Contract violations trigger freeze_with_hint
Test results:
- cargo test --lib: 1176 PASS
- Phase 133 VM: PASS (exit code 6)
- Phase 133 LLVM EXE: PASS (exit code 6)
- Phase 132 regression: PASS (exit code 3)
- Phase 131 regression: PASS (exit code 1)
- Phase 97 regression: PASS
Architecture maintained:
- 5-function structure unchanged (main/loop_step/loop_body/k_exit/post_k)
- PHI-free DirectValue mode
- Zero changes to ExitMeta, merge logic, or JoinIR contracts
Related: Phase 133 loop(true) + multiple post-loop assignments
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
# Phase 133-P0: loop(true) break-once with multiple post-loop assignments (LLVM EXE parity)
|
||||
# Pattern: loop(true) { x = 1; break }; x = x + 2; x = x + 3; return x (should be 6)
|
||||
|
||||
source "$(dirname "$0")/../../../lib/test_runner.sh"
|
||||
source "$(dirname "$0")/../../../lib/llvm_exe_runner.sh"
|
||||
export SMOKES_USE_PYVM=0
|
||||
require_env || exit 2
|
||||
|
||||
llvm_exe_preflight_or_skip || exit 0
|
||||
|
||||
# Phase 133-P0 is a dev-only Normalized shadow loop + multi-post case.
|
||||
# LLVM EXE emission must run with JoinIR dev/strict enabled, otherwise it will freeze.
|
||||
require_joinir_dev
|
||||
|
||||
# Phase 133-P0: minimal plugin set (StringBox, ConsoleBox, IntegerBox only)
|
||||
STRINGBOX_SO="$NYASH_ROOT/plugins/nyash-string-plugin/libnyash_string_plugin.so"
|
||||
CONSOLEBOX_SO="$NYASH_ROOT/plugins/nyash-console-plugin/libnyash_console_plugin.so"
|
||||
INTEGERBOX_SO="$NYASH_ROOT/plugins/nyash-integer-plugin/libnyash_integer_plugin.so"
|
||||
|
||||
LLVM_REQUIRED_PLUGINS=(
|
||||
"StringBox|$STRINGBOX_SO|nyash-string-plugin"
|
||||
"ConsoleBox|$CONSOLEBOX_SO|nyash-console-plugin"
|
||||
"IntegerBox|$INTEGERBOX_SO|nyash-integer-plugin"
|
||||
)
|
||||
LLVM_PLUGIN_BUILD_LOG="/tmp/phase133_loop_true_break_once_post_multi_add_plugin_build.log"
|
||||
llvm_exe_ensure_plugins_or_fail || exit 1
|
||||
|
||||
INPUT_HAKO="$NYASH_ROOT/apps/tests/phase133_loop_true_break_once_post_multi_add_min.hako"
|
||||
OUTPUT_EXE="$NYASH_ROOT/tmp/phase133_loop_true_break_once_post_multi_add_llvm_exe"
|
||||
|
||||
EXPECTED_EXIT_CODE=6
|
||||
LLVM_BUILD_LOG="/tmp/phase133_loop_true_break_once_post_multi_add_build.log"
|
||||
if llvm_exe_build_and_run_expect_exit_code; then
|
||||
test_pass "phase133_loop_true_break_once_post_multi_add_llvm_exe: exit code matches expected (6)"
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
# Phase 133-P0: loop(true) break-once with multiple post-loop assignments (Normalized shadow, VM)
|
||||
#
|
||||
# Verifies that loop(true) { <assign>* ; break }; <assign>*; return works in Normalized:
|
||||
# - x = 0 → loop(true) { x = 1; break } → x = x + 2 → x = x + 3 → return x → 6
|
||||
# - Dev-only: NYASH_JOINIR_DEV=1 HAKO_JOINIR_STRICT=1
|
||||
|
||||
source "$(dirname "$0")/../../../lib/test_runner.sh"
|
||||
export SMOKES_USE_PYVM=0
|
||||
require_env || exit 2
|
||||
|
||||
# Phase 133-P0 is a dev-only Normalized shadow loop + multi-post case.
|
||||
require_joinir_dev
|
||||
|
||||
PASS_COUNT=0
|
||||
FAIL_COUNT=0
|
||||
RUN_TIMEOUT_SECS=${RUN_TIMEOUT_SECS:-10}
|
||||
|
||||
echo "[INFO] Phase 133-P0: loop(true) break-once with multiple post-loop assignments (Normalized shadow, VM)"
|
||||
|
||||
# Test 1: phase133_loop_true_break_once_post_multi_add_min.hako
|
||||
echo "[INFO] Test 1: phase133_loop_true_break_once_post_multi_add_min.hako"
|
||||
INPUT="$NYASH_ROOT/apps/tests/phase133_loop_true_break_once_post_multi_add_min.hako"
|
||||
|
||||
set +e
|
||||
OUTPUT=$(timeout "$RUN_TIMEOUT_SECS" env \
|
||||
NYASH_DISABLE_PLUGINS=1 \
|
||||
"$NYASH_BIN" --backend vm "$INPUT" 2>&1)
|
||||
EXIT_CODE=$?
|
||||
set -e
|
||||
|
||||
if [ "$EXIT_CODE" -eq 124 ]; then
|
||||
echo "[FAIL] hakorune timed out (>${RUN_TIMEOUT_SECS}s)"
|
||||
FAIL_COUNT=$((FAIL_COUNT + 1))
|
||||
elif [ "$EXIT_CODE" -eq 6 ]; then
|
||||
# Phase 133-P0: expected output is exit code 6 (1 + 2 + 3)
|
||||
echo "[PASS] exit code verified: 6"
|
||||
PASS_COUNT=$((PASS_COUNT + 1))
|
||||
else
|
||||
echo "[FAIL] hakorune failed with exit code $EXIT_CODE (expected 6)"
|
||||
echo "[INFO] output (tail):"
|
||||
echo "$OUTPUT" | tail -n 50 || true
|
||||
FAIL_COUNT=$((FAIL_COUNT + 1))
|
||||
fi
|
||||
|
||||
echo "[INFO] PASS: $PASS_COUNT, FAIL: $FAIL_COUNT"
|
||||
|
||||
if [ "$FAIL_COUNT" -eq 0 ]; then
|
||||
test_pass "phase133_loop_true_break_once_post_multi_add_vm: All tests passed"
|
||||
exit 0
|
||||
else
|
||||
test_fail "phase133_loop_true_break_once_post_multi_add_vm: $FAIL_COUNT test(s) failed"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user