feat(control_tree): Phase 131 P1.5-P2 DirectValue exit reconnection

Implement DirectValue mode for Normalized shadow exit handling:

**P1.5 Changes**:
- Add ExitReconnectMode::DirectValue (skip exit PHI generation)
- Carry remapped_exit_values through merge result
- Update host variable_map directly with exit values
- Fix loop(true) { x = 1; break }; return x to return 1 correctly

**P2 Changes**:
- Normalize k_exit continuation entry/exit edges
- Rewrite TailCall(k_exit) → Jump(exit_block) for proper merge
- Add verify_all_terminator_targets_exist contract check
- Extend ExitLineReconnector to handle DirectValue mode

**Infrastructure**:
- tools/build_llvm.sh: Force TMPDIR under target/ (EXDEV mitigation)
- llvm_exe_runner.sh: Add exit_code verification support
- Phase 131 smokes: Update for dev-only + exit code validation

**Contracts**:
- PHI-free: Normalized path uses continuations only
- Exit values reconnect via remapped ValueIds
- Existing patterns unaffected (既定挙動不変)

Related: Phase 131 loop(true) break-once Normalized support

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-18 17:48:05 +09:00
parent bfac188732
commit 02c4c313e5
19 changed files with 973 additions and 93 deletions

View File

@ -191,3 +191,62 @@ llvm_exe_build_and_run_numeric_smoke() {
printf "%s\n" "$EXPECTED"
return 1
}
llvm_exe_build_and_run_expect_exit_code() {
# Required globals:
# - INPUT_HAKO
# - OUTPUT_EXE
# - EXPECTED_EXIT_CODE
#
# Optional:
# - LLVM_BUILD_LOG
# - RUN_TIMEOUT_SECS
if [ -z "${INPUT_HAKO:-}" ] || [ -z "${OUTPUT_EXE:-}" ] || [ -z "${EXPECTED_EXIT_CODE:-}" ]; then
echo "[FAIL] llvm_exe_build_and_run_expect_exit_code: missing INPUT_HAKO/OUTPUT_EXE/EXPECTED_EXIT_CODE"
return 1
fi
mkdir -p "$(dirname "$OUTPUT_EXE")"
echo "[INFO] Building: $INPUT_HAKO$OUTPUT_EXE"
local cargo_target_dir
cargo_target_dir="$(llvm_exe_cargo_target_dir)"
# Ensure we use the compiler binary built in that target dir.
local nyash_bin="$cargo_target_dir/release/hakorune"
local obj_out="$cargo_target_dir/aot_objects/$(basename "$INPUT_HAKO").o"
mkdir -p "$(dirname "$obj_out")"
local build_log="${LLVM_BUILD_LOG:-/tmp/llvm_exe_build.log}"
if ! env CARGO_TARGET_DIR="$cargo_target_dir" NYASH_BIN="$nyash_bin" NYASH_LLVM_OBJ_OUT="$obj_out" NYASH_DISABLE_PLUGINS=0 \
"$NYASH_ROOT/tools/build_llvm.sh" "$INPUT_HAKO" -o "$OUTPUT_EXE" 2>&1 | tee "$build_log"; then
echo "[FAIL] build_llvm.sh failed"
tail -n 80 "$build_log"
return 1
fi
if [ ! -x "$OUTPUT_EXE" ]; then
echo "[FAIL] Executable not created or not executable: $OUTPUT_EXE"
ls -la "$OUTPUT_EXE" 2>/dev/null || echo "File does not exist"
return 1
fi
echo "[INFO] Executing: $OUTPUT_EXE"
set +e
local output
output=$(timeout "${RUN_TIMEOUT_SECS:-10}" env NYASH_DISABLE_PLUGINS=0 "$OUTPUT_EXE" 2>&1)
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
fi
return 0
}