refactor(joinir,smokes): Task 2,3,4 - instruction_rewriter boxification + OutputContract unification
Task 2: instruction_rewriter 分箱化 - Extract k_exit special case logic into TailCallLoweringPolicyBox - Separate detect/collect/transform concerns into dedicated policy box - Rewriter becomes pure transformation engine - Added 5 unit tests for exit edge normalization - New file: src/mir/builder/control_flow/joinir/merge/tail_call_lowering_policy.rs (212 lines) Changes: - instruction_rewriter.rs: Delegate k_exit detection to policy box (-50 lines) - merge_result.rs: Add MirMergeResult struct for intermediate results - Single responsibility principle: each box handles one concern Task 3 & 4: smokes runner 改善 - Unify exit_code and numeric output verification into check_output_contract() - Add require_joinir_dev() helper for dev-only fixture setup - Reduce boilerplate in phase131_loop_true_break_once_*.sh scripts - Consistent error message format across verification types Changes: - tools/smokes/v2/lib/llvm_exe_runner.sh: Add OutputContract interface (+90 lines) - tools/smokes/v2/lib/test_runner.sh: Add require_joinir_dev() helper - Phase 131 smoke scripts: Use new helpers (cleaner, less repetition) - Build script: Improve TMPDIR configuration for EXDEV mitigation Benefits: - Single responsibility: policy box handles one concern - Code reuse: OutputContract eliminates duplication - Clarity: Smoke scripts are more concise and readable - Maintainability: Easier to add new verification types Test Results: - Policy box unit tests: 5 PASS - Smoke tests: 2/2 PASS - No regression in existing functionality Related: Phase 131 refactoring for improved code organization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -11,6 +11,98 @@
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
# Source centralized environment configuration (SSOT)
|
||||
LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
if [ -f "$LIB_DIR/env.sh" ]; then
|
||||
source "$LIB_DIR/env.sh"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Helper: require_joinir_dev
|
||||
# ============================================================================
|
||||
# Sets dev-only environment variables for JoinIR normalized shadow testing.
|
||||
# Must be called BEFORE build/run operations if the fixture requires dev-only features.
|
||||
#
|
||||
# Usage:
|
||||
# require_joinir_dev
|
||||
#
|
||||
# NOTE: This now validates that env.sh has been sourced correctly.
|
||||
#
|
||||
require_joinir_dev() {
|
||||
# Verify env.sh provided the defaults
|
||||
if [ "${NYASH_JOINIR_DEV:-0}" != "1" ]; then
|
||||
export NYASH_JOINIR_DEV=1
|
||||
fi
|
||||
if [ "${HAKO_JOINIR_STRICT:-0}" != "1" ]; then
|
||||
export HAKO_JOINIR_STRICT=1
|
||||
fi
|
||||
echo "[INFO] JoinIR dev mode enabled (NYASH_JOINIR_DEV=1, HAKO_JOINIR_STRICT=1)"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Helper: check_output_contract
|
||||
# ============================================================================
|
||||
# Unified output validation interface for exit_code, numeric, and substring checks.
|
||||
#
|
||||
# Args:
|
||||
# $1: contract_type - "exit_code" / "numeric" / "substring"
|
||||
# $2: expected - Expected value (string/number)
|
||||
# $3: actual - Actual value to compare
|
||||
# $4: context - (optional) Context description for error messages
|
||||
#
|
||||
# Returns:
|
||||
# 0 if contract satisfied, 1 otherwise
|
||||
#
|
||||
check_output_contract() {
|
||||
local contract_type="${1:-}"
|
||||
local expected="${2:-}"
|
||||
local actual="${3:-}"
|
||||
local context="${4:-output}"
|
||||
|
||||
if [ -z "$contract_type" ] || [ -z "$expected" ]; then
|
||||
echo "[FAIL] check_output_contract: missing contract_type or expected value"
|
||||
return 1
|
||||
fi
|
||||
|
||||
case "$contract_type" in
|
||||
exit_code)
|
||||
if [ "$actual" -ne "$expected" ] 2>/dev/null; then
|
||||
echo "[FAIL] OutputContract(exit_code): got $actual, expected $expected"
|
||||
return 1
|
||||
fi
|
||||
echo "[PASS] OutputContract(exit_code): $actual == $expected"
|
||||
return 0
|
||||
;;
|
||||
|
||||
numeric)
|
||||
if [ "$actual" != "$expected" ]; then
|
||||
echo "[FAIL] OutputContract(numeric): got '$actual', expected '$expected'"
|
||||
echo "[INFO] Context: $context"
|
||||
return 1
|
||||
fi
|
||||
echo "[PASS] OutputContract(numeric): $actual == $expected"
|
||||
return 0
|
||||
;;
|
||||
|
||||
substring)
|
||||
if ! printf "%s" "$actual" | grep -qF "$expected"; then
|
||||
echo "[FAIL] OutputContract(substring): '$expected' not found in $context"
|
||||
echo "[INFO] Actual output (first 200 chars):"
|
||||
printf "%s" "$actual" | head -c 200
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
echo "[PASS] OutputContract(substring): '$expected' found in $context"
|
||||
return 0
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "[FAIL] check_output_contract: unknown contract_type '$contract_type'"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
llvm_exe_cargo_target_dir() {
|
||||
# Use the workspace target dir by default so `NYASH_BIN` and plugin artifacts match local dev expectations.
|
||||
local target_dir="${LLVM_EXE_CARGO_TARGET_DIR:-$NYASH_ROOT/target}"
|
||||
@ -180,15 +272,12 @@ llvm_exe_build_and_run_numeric_smoke() {
|
||||
echo "[INFO] CLEAN output:"
|
||||
echo "$clean"
|
||||
|
||||
if [ "$clean" = "$EXPECTED" ]; then
|
||||
if check_output_contract "numeric" "$EXPECTED" "$clean" "numeric stdout (first $EXPECTED_LINES lines)"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "[FAIL] Output mismatch"
|
||||
echo "[INFO] Raw output (tail):"
|
||||
echo "$output" | tail -n 80
|
||||
echo "[INFO] Expected:"
|
||||
printf "%s\n" "$EXPECTED"
|
||||
return 1
|
||||
}
|
||||
|
||||
@ -241,12 +330,11 @@ llvm_exe_build_and_run_expect_exit_code() {
|
||||
local exit_code=$?
|
||||
set -e
|
||||
|
||||
if [ "$exit_code" -ne "$EXPECTED_EXIT_CODE" ]; then
|
||||
echo "[FAIL] Execution exit code mismatch: got $exit_code, expected $EXPECTED_EXIT_CODE"
|
||||
echo "[INFO] Raw output (tail):"
|
||||
echo "$output" | tail -n 80
|
||||
return 1
|
||||
if check_output_contract "exit_code" "$EXPECTED_EXIT_CODE" "$exit_code" "executable exit code"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 0
|
||||
echo "[INFO] Raw output (tail):"
|
||||
echo "$output" | tail -n 80
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user