Files
hakorune/docs/development/normalization/ownership.md
nyash-codex dda65b94b7 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>
2025-11-13 16:40:58 +09:00

2.1 KiB
Raw Blame History

Normalization Ownership — Rust vs Hakorune

Goal

  • Prevent double-normalization and keep a clear Single Source of Truth (SSOT) for where each rewrite lives.

Ownership

  • Hakorune layer (Hako scripts)

    • Methodization: Global("Box.m/N") → mir_call(Method) への変換。
    • Name/arity canonicalizationBox.method/N
    • Function defs scan/injectHAKO_STAGEB_FUNC_SCAN, HAKO_MIR_BUILDER_FUNCS
    • Emit JSON v1 + unified mir_callNYASH_JSON_SCHEMA_V1=1, NYASH_MIR_UNIFIED_CALL=1
    • 可視化タグ/診断の出力dev のみ)
  • Rust layer

    • Structural/correctness: SSA/PHI、受信側ローカライズLocalSSA/Copy/pin
    • Legacy JSON v0 → minimal bridgingjson_v0_bridge 内での Callee 補完など)。
    • 互換/安全弁: 未定義受信の構造的回復同一BB直近 NewBoxなど、dev ガード付きの最小範囲。
    • Optimizer は構造・副作用ベースの最適化に限定(意味論の再書換えはしない)。

Guards and Toggles

  • Hakodev 推奨セット)

    • HAKO_STAGEB_FUNC_SCAN=1
    • HAKO_MIR_BUILDER_FUNCS=1
    • HAKO_MIR_BUILDER_CALL_RESOLVE=1
    • HAKO_MIR_BUILDER_METHODIZE=1methodize が v1+unified 出力へ寄与)
    • NYASH_JSON_SCHEMA_V1=1, NYASH_MIR_UNIFIED_CALL=1
  • Rustbridge/診断)

    • HAKO_BRIDGE_METHODIZE=1 は bring-up 用の補助。Hako 既定化後は OFF撤去予定
    • mir_plugin_invoke/plugin_only は A/B 評価・診断用途。既定 OFF。

Rules of Engagement

  • v1 + unified を Hako で生成した場合、Rust 側での methodize/再書換えは行わない(構造のみ)。
  • json_v0_bridge は v0 入力に対する互換のために限定運用。v1 既定化が進めば縮退する。
  • dev の安全弁(未定義受信の構造回復など)は、テストが十分になり次第 OFF/撤去する。

Testing

  • Canary
    • tools/dev/phase217_methodize_canary.shrc=5
    • tools/dev/phase217_methodize_json_canary.shschema_version + mir_call present、Method優先
    • tools/dev/phase216_chain_canary_call.shrc=5
  • 失敗時は Hako 側methodize→ Rust 側(構造) の順で原因を特定する。