Add environment variable controls and debug logging for JoinIR lowering rollout.
Changes:
- Add HAKO_JOINIR_STAGE1 env var for Stage-1 function rollout control
- Add HAKO_JOINIR_DEBUG (0-3) for granular debug logging
- Level 0: Silent (default)
- Level 1: Basic lowering info
- Level 2: Pattern matching details
- Level 3: Full variable/instruction dump
- Implement 3-tier whitelist system:
- Tier 1: Test functions (always enabled)
- Tier 2: Stage-1 rollout (env-controlled)
- Tier 3: Explicit approvals (validated in Phase 33-4)
- Add A/B test automation script (tools/joinir_ab_test.sh)
- Update if_merge.rs and if_select.rs with debug_level support
Environment variables (with NYASH_* fallback for compatibility):
- HAKO_JOINIR_IF_SELECT: Enable JoinIR lowering
- HAKO_JOINIR_STAGE1: Enable Stage-1 function rollout
- HAKO_JOINIR_DEBUG: Debug log level (0-3)
A/B test verification: PASSED on joinir_if_merge_{simple,multiple}.hako
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
73 lines
1.7 KiB
Bash
73 lines
1.7 KiB
Bash
#!/bin/bash
|
|
# Phase 33-8: A/B test automation for JoinIR lowering
|
|
#
|
|
# Usage:
|
|
# tools/joinir_ab_test.sh <test_file.hako>
|
|
#
|
|
# Example:
|
|
# tools/joinir_ab_test.sh apps/tests/joinir_if_merge_simple.hako
|
|
|
|
set -euo pipefail
|
|
|
|
test_case=$1 # e.g., "apps/tests/joinir_if_merge_simple.hako"
|
|
|
|
if [ ! -f "$test_case" ]; then
|
|
echo "❌ Test file not found: $test_case"
|
|
exit 1
|
|
fi
|
|
|
|
echo "🧪 Testing: $test_case"
|
|
echo ""
|
|
|
|
# Route A: Traditional if_phi
|
|
echo "=== Route A (if_phi) ==="
|
|
HAKO_JOINIR_IF_SELECT=0 \
|
|
NYASH_PARSER_STAGE3=1 \
|
|
HAKO_PARSER_STAGE3=1 \
|
|
./target/release/hakorune "$test_case" \
|
|
> /tmp/route_a.out 2>&1
|
|
route_a_rc=$?
|
|
echo "Route A RC: $route_a_rc"
|
|
echo ""
|
|
|
|
# Route B: JoinIR Select/IfMerge
|
|
echo "=== Route B (JoinIR) ==="
|
|
HAKO_JOINIR_IF_SELECT=1 \
|
|
HAKO_JOINIR_STAGE1=1 \
|
|
HAKO_JOINIR_DEBUG=1 \
|
|
NYASH_PARSER_STAGE3=1 \
|
|
HAKO_PARSER_STAGE3=1 \
|
|
./target/release/hakorune "$test_case" \
|
|
> /tmp/route_b.out 2>&1
|
|
route_b_rc=$?
|
|
echo "Route B RC: $route_b_rc"
|
|
echo ""
|
|
|
|
# Comparison
|
|
echo "=== 📊 Comparison ==="
|
|
|
|
# RC check
|
|
if [ $route_a_rc -eq $route_b_rc ]; then
|
|
echo "✅ RC matched: $route_a_rc"
|
|
else
|
|
echo "❌ RC mismatch: A=$route_a_rc, B=$route_b_rc"
|
|
exit 1
|
|
fi
|
|
|
|
# Output check (ignore debug logs starting with '[')
|
|
if diff <(grep -v '^\[' /tmp/route_a.out) <(grep -v '^\[' /tmp/route_b.out); then
|
|
echo "✅ Output matched"
|
|
else
|
|
echo "❌ Output differs:"
|
|
diff <(grep -v '^\[' /tmp/route_a.out) <(grep -v '^\[' /tmp/route_b.out) || true
|
|
exit 1
|
|
fi
|
|
|
|
# Extract lowering info from Route B
|
|
echo ""
|
|
echo "=== 🔍 Lowering Info ==="
|
|
grep -E "IfMerge|IfSelect|if_phi" /tmp/route_b.out || echo "⚠️ No lowering info found"
|
|
|
|
echo ""
|
|
echo "🎉 A/B test PASSED for $test_case"
|