Phase 21.7 normalization: optimization pre-work + bench harness expansion

- Add opt-in optimizations (defaults OFF)
  - Ret purity verifier: NYASH_VERIFY_RET_PURITY=1
  - strlen FAST enhancement for const handles
  - FAST_INT gate for same-BB SSA optimization
  - length cache for string literals in llvmlite
- Expand bench harness (tools/perf/microbench.sh)
  - Add branch/call/stringchain/arraymap/chip8/kilo cases
  - Auto-calculate ratio vs C reference
  - Document in benchmarks/README.md
- Compiler health improvements
  - Unify PHI insertion to insert_phi_at_head()
  - Add NYASH_LLVM_SKIP_BUILD=1 for build reuse
- Runtime & safety enhancements
  - Clarify Rust/Hako ownership boundaries
  - Strengthen receiver localization (LocalSSA/pin/after-PHIs)
  - Stop excessive PluginInvoke→BoxCall rewrites
- Update CURRENT_TASK.md, docs, and canaries

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-13 16:40:58 +09:00
parent 9e2fa1e36e
commit dda65b94b7
160 changed files with 6773 additions and 1692 deletions

View File

@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)
cd "$ROOT"
TMP_SRC=$(mktemp --suffix .hako)
cat >"$TMP_SRC" <<'HAKO'
static box Main {
method add(a,b){ return a + b }
method main(){ return add(2,3) }
}
HAKO
TMP_JSON=$(mktemp --suffix .json)
# Emit MIR(JSON) with defs + call resolution + methodize (dev)
HAKO_SELFHOST_BUILDER_FIRST=1 \
HAKO_STAGEB_FUNC_SCAN=1 \
HAKO_MIR_BUILDER_FUNCS=1 \
HAKO_MIR_BUILDER_CALL_RESOLVE=1 \
HAKO_MIR_BUILDER_METHODIZE=1 \
NYASH_USE_NY_COMPILER=0 HAKO_DISABLE_NY_COMPILER=1 \
NYASH_PARSER_STAGE3=1 HAKO_PARSER_STAGE3=1 NYASH_PARSER_ALLOW_SEMICOLON=1 \
NYASH_ENABLE_USING=1 HAKO_ENABLE_USING=1 \
bash "$ROOT/tools/hakorune_emit_mir.sh" "$TMP_SRC" "$TMP_JSON" >/dev/null
# Observability: prefer mir_call(Method), but tolerate delegate(Global) during bring-up
if ! rg -q '"op"\s*:\s*"mir_call"' "$TMP_JSON" || ! rg -q '"callee"\s*:\s*\{[^}]*"type"\s*:\s*"Method"' "$TMP_JSON"; then
echo "[NOTE] methodize: mir_call(Method) not observed (delegate Global path likely). Proceeding with VM check." >&2
cp "$TMP_JSON" /tmp/phase217_methodize_last.json || true
fi
# Execute semantics via standard .hako compile pathJSON実行はv1検討中
BIN=${NY_BIN:-${NY_BIN:-$ROOT/target/release/hakorune}}
set +e
"$BIN" --backend vm "$TMP_SRC" >/dev/null 2>&1; rc=$?
set -e
if [[ "$rc" == "5" ]]; then
echo "[PASS] phase217_methodize (compile-run rc=5)"
else
echo "[FAIL] phase217_methodize — compile-run rc=$rc" >&2
exit 1
fi
rm -f "$TMP_SRC" "$TMP_JSON" 2>/dev/null || true
exit 0