tools: add LLVM IR empty-PHI smoke checker; ensures every 'phi i64' has incoming list; used with NYASH_LLVM_DUMP_IR

This commit is contained in:
Selfhosting Dev
2025-09-19 12:01:13 +09:00
parent 4f82edf901
commit ef1f5206da
2 changed files with 50 additions and 0 deletions

View File

@ -32,6 +32,18 @@ P0/P1 Safety Fixes (2025-09-19)
- Updated to_http_string and Display/to_string to read via locks; manual Clone implemented. - Updated to_http_string and Display/to_string to read via locks; manual Clone implemented.
- Removes RefCell TODOs at http_message_box.rs:292330 without violating BoxCore Send+Sync. - Removes RefCell TODOs at http_message_box.rs:292330 without violating BoxCore Send+Sync.
LLVM Harness Gate (2025-09-19)
- Added env gate `NYASH_LLVM_SANITIZE_EMPTY_PHI=1` to optionally drop malformed empty PHI lines before llvmlite parse.
- Default OFF; dev-only safety valve while finalizing PHI wiring.
- Code: src/llvm_py/llvm_builder.py (compile_to_object).
Clone() Reduction — Phase 1 (Arc/str)
- TypeBox internals
- `TypeBox.name: String``Arc<str>`.
- `TypeBox.type_parameters: Vec<String>``Vec<Arc<str>>`.
- Adjusted builder/registry and `full_name()` accordingly; public behavior unchanged.
- Rationale: share-on-clone for frequently copied identifiers, reduce String allocations.
Refactor Plan (next 12 weeks) Refactor Plan (next 12 weeks)
1) Split parse_box_declaration (667 lines) in src/parser/declarations/box_definition.rs 1) Split parse_box_declaration (667 lines) in src/parser/declarations/box_definition.rs
- Targets (line ranges are indicative): - Targets (line ranges are indicative):

View File

@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -euo pipefail
# Small smoke: ensure no empty PHI appears in IR
# Usage: tools/test/smoke/llvm/ir_phi_empty_check.sh [nyash_script]
SCRIPT=${1:-apps/tests/loop_if_phi.nyash}
echo "[phi-empty-check] building nyash (llvm features)" >&2
LLVM_PREFIX=${LLVM_SYS_180_PREFIX:-$(command -v llvm-config-18 >/dev/null 2>&1 && llvm-config-18 --prefix || true)}
if [[ -n "${LLVM_PREFIX}" ]]; then
LLVM_SYS_180_PREFIX="${LLVM_PREFIX}" cargo build --release --features llvm >/dev/null
else
cargo build --release --features llvm >/dev/null
fi
IR_OUT=tmp/nyash_harness.ll
mkdir -p tmp
echo "[phi-empty-check] running harness on ${SCRIPT}" >&2
NYASH_LLVM_USE_HARNESS=1 \
NYASH_LLVM_DUMP_IR="${IR_OUT}" \
./target/release/nyash --backend llvm "${SCRIPT}" >/dev/null || true
if [[ ! -s "${IR_OUT}" ]]; then
echo "[phi-empty-check] WARN: IR dump not found; harness may have short-circuited" >&2
exit 0
fi
# Check: any phi i64 line must include '[' (incoming pairs)
if rg -n "= phi i64( |$)" "${IR_OUT}" | rg -v "\\[" -n >/dev/null; then
echo "[phi-empty-check] FAIL: empty PHI found (no incoming list)" >&2
rg -n "\\= phi i64( |$)" "${IR_OUT}" | rg -v "\\[" -n || true
exit 1
fi
echo "[phi-empty-check] OK: no empty PHI detected in ${IR_OUT}" >&2
exit 0