Files
hakorune/tools/test_phase132_phi_ordering.sh
nyash-codex e4eedef34f feat(llvm): Phase 132 - Fix PHI instruction ordering bug
Structural fix for LLVM backend PHI placement issue discovered in Phase 131.

Changes:
- Modified ensure_phi() to position PHI before existing instructions
- Enhanced setup_phi_placeholders() with debug mode
- Created phi_placement.py utility for validation
- Added test script for representative cases

Technical approach:
- PHI creation during setup (before block lowering)
- Explicit positioning with position_before(instrs[0])
- Debug infrastructure via NYASH_PHI_ORDERING_DEBUG=1

Design principles:
- PHI must be created when blocks are empty
- finalize_phis only wires, never creates
- llvmlite API constraints respected

Phase 132 complete. Ready for Phase 133 (ConsoleBox integration).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 11:28:55 +09:00

97 lines
2.5 KiB
Bash

#!/bin/bash
# Phase 132: Test PHI ordering fix
# This script tests representative cases that had PHI ordering issues
set -e
cd "$(dirname "$0")/.."
echo "=== Phase 132: PHI Ordering Test ==="
echo ""
# Enable debug mode for PHI ordering
export NYASH_PHI_ORDERING_DEBUG=1
export NYASH_CLI_VERBOSE=0
# Test cases
TEST_CASES=(
"local_tests/phase123_simple_if.hako"
"local_tests/phase123_while_loop.hako"
"apps/tests/loop_min_while.hako"
"apps/tests/joinir_if_select_simple.hako"
)
PASS=0
FAIL=0
RESULTS=()
for test_case in "${TEST_CASES[@]}"; do
if [ ! -f "$test_case" ]; then
echo "⚠️ Skipping $test_case (not found)"
continue
fi
echo "---"
echo "Testing: $test_case"
echo ""
# Test with VM backend first (baseline)
echo " VM backend..."
if ./target/release/hakorune --backend vm "$test_case" > /tmp/vm_out.txt 2>&1; then
VM_EXIT=$?
VM_OUTPUT=$(cat /tmp/vm_out.txt | grep -E "RC:|Exit code:" | tail -1)
echo " ✅ VM: $VM_OUTPUT"
else
VM_EXIT=$?
echo " ❌ VM failed with exit code $VM_EXIT"
fi
# Test with LLVM backend
echo " LLVM backend..."
if NYASH_LLVM_USE_HARNESS=1 NYASH_LLVM_OBJ_OUT=/tmp/test_$$.o \
./target/release/hakorune --backend llvm "$test_case" > /tmp/llvm_out.txt 2>&1; then
LLVM_EXIT=$?
LLVM_OUTPUT=$(cat /tmp/llvm_out.txt | grep -E "RC:|Exit code:" | tail -1)
echo " ✅ LLVM: $LLVM_OUTPUT"
# Check for PHI ordering warnings
if grep -q "WARNING.*terminator" /tmp/llvm_out.txt; then
echo " ⚠️ PHI ordering warning detected!"
RESULTS+=("⚠️ $test_case: PHI ordering warning")
else
RESULTS+=("$test_case: PASS")
((PASS++))
fi
else
LLVM_EXIT=$?
echo " ❌ LLVM failed with exit code $LLVM_EXIT"
# Check error type
if grep -q "PHI" /tmp/llvm_out.txt; then
echo " 💥 PHI-related error!"
fi
RESULTS+=("$test_case: FAIL (exit $LLVM_EXIT)")
((FAIL++))
fi
echo ""
done
echo "==================================="
echo "Phase 132 Test Results"
echo "==================================="
for result in "${RESULTS[@]}"; do
echo "$result"
done
echo ""
echo "Summary: $PASS passed, $FAIL failed out of $((PASS + FAIL)) tests"
echo ""
if [ $FAIL -eq 0 ]; then
echo "🎉 All tests passed!"
exit 0
else
echo "❌ Some tests failed"
exit 1
fi