## Summary Implemented fail-fast validation for PHI ordering and value resolution in strict mode. ## Changes ### P1-1: Strict mode for "PHI after terminator" - File: `src/llvm_py/phi_wiring/wiring.py::ensure_phi` - Behavior: `NYASH_LLVM_PHI_STRICT=1` → RuntimeError if PHI created after terminator - Default: Warning only (no regression) ### P1-2: Strict mode for "fallback 0" - File: `src/llvm_py/phi_wiring/wiring.py::wire_incomings` - Behavior: Strict mode forbids silent fallback to 0 (2 locations) - Location 1: Unresolvable incoming value - Location 2: Type coercion failure - Error messages point to next debug file: `llvm_builder.py::_value_at_end_i64` ### P1-3: Connect verify_phi_ordering() to execution path - File: `src/llvm_py/builders/function_lower.py` - Behavior: Verify PHI ordering after all instructions emitted - Debug mode: Shows "✅ All N blocks have correct PHI ordering" - Strict mode: Raises RuntimeError with block list if violations found ## Testing ✅ Test 1: strict=OFF - passes without errors ✅ Test 2: strict=ON - passes without errors (no violations in test fixtures) ✅ Test 3: debug mode - verify_phi_ordering() connected and running ## Scope - LLVM harness (Python) changes only - No new environment variables (uses existing 3 from Phase 277 P2) - No JoinIR/Rust changes (root fix is Phase 279) - Default behavior unchanged (strict mode opt-in) ## Next Steps - Phase 278: Remove deprecated env var support - Phase 279: Root fix - unify "2本のコンパイラ" pipelines 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
4.5 KiB
4.5 KiB
Codex向け質問 - Phase 15.5後のテスト戦略
📋 背景
Phase 15.5でCore Box完全削除を実施し、すべてのBoxをプラグイン化しました。その結果:
- ✅ nyash.tomlのパス修正完了(13箇所)
- ✅ プラグインは正常にロード(.soファイル20個存在)
- ✅ 基本的な算術演算・制御構文は動作
- ❌ StringBox/IntegerBoxのメソッドが動作しない
🔍 現在の問題
StringBoxプラグインの状況
local s = new StringBox("Hello") # ← オブジェクト生成OK(ハンドル返却)
print(s) # ← 空文字列(toString失敗)
s.length() # ← 0を返す(内部データなし)
s.toString() # ← 空文字列を返す
s.get() # ← 空文字列を返す
調査済み事項
- プラグインは正常にロード(plugin-testerで確認)
- nyash_plugin_invokeは実装済み(legacy v1 ABI)
- method_id衝突を修正済み(0-3 → 4+に変更)
- 通常の文字列リテラルは動作する
- 算術演算は問題なし
🔬 根本原因(Codex調査結果 - 2025-09-24)
実装レベルの具体的問題箇所を特定済み:
-
string_invoke_idにM_BIRTH分岐がないplugins/nyash-string-plugin/src/lib.rsのstring_invoke_idにM_BIRTH分岐が無くnew StringBox("test")で生成されたIDがINSTマップに登録されない.length()呼び出しでE_HANDLEが返る
-
string_resolveがtoStringを未マッピング- 同ファイルの
string_resolveが"toString"をM_TO_UTF8にマッピングしていない .toString()は未知メソッド扱いになり空文字列/エラーでフォールバック
- 同ファイルの
-
IntegerBoxも同様の問題
plugins/nyash-integer-plugin/src/lib.rsでもM_BIRTH/M_FINIが未実装- 値を保持できず
.get()/.set()が失敗
🎯 質問
1. 実装修正の優先度は?
string_invoke_idとinteger_invoke_idにM_BIRTH/M_FINI分岐を復元するのが最優先か?- それともTypeBox共通レイヤーでフォールバック処理を追加すべきか?
2. toStringメソッドの実装方針
.toString()はtoUtf8のエイリアスにすべきか?- 新たなメソッドIDを
nyash_box.tomlへ追加してVMに通知すべきか?
3. テスト戦略の方向性
現状でStringBox/IntegerBoxが動作しない中で:
- A案: プラグインメソッド修正を優先(M_BIRTH実装)
- B案: 基本機能(算術・制御)のテストを先に充実
- C案: 別のBoxプラグイン(FileBox等)でテスト
どの方向性が効率的でしょうか?
4. 既存テストの扱い
tools/smokes/v2/profiles/quick/boxesのStringBoxケースを一時的に外すか?- 失敗を許容したまま調査用に残すか?
🔄 再現手順
最小再現コード
# test_stringbox.hako
local s = new StringBox("Hello World")
print("StringBox created")
print(s) # 期待: "Hello World", 実際: ""
local len = s.length()
print("Length: " + len) # 期待: 11, 実際: 0
実行コマンド
# プラグインロード確認
./tools/plugin-tester/target/release/plugin-tester check --config nyash.toml
# テスト実行
NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1 ./target/release/hakorune test_stringbox.hako
デバッグ情報収集
# 詳細ログ
NYASH_CLI_VERBOSE=1 ./target/release/hakorune test_stringbox.hako
# MIRダンプ確認
NYASH_VM_DUMP_MIR=1 ./target/release/hakorune --backend vm test_stringbox.hako
# 具体的な問題箇所の確認
rg "M_BIRTH" plugins/nyash-string-plugin/src/lib.rs # 該当箇所を特定
📁 関連ファイル
nyash.toml- プラグイン設定(method_id修正済み)plugins/nyash-string-plugin/src/lib.rs- StringBoxプラグイン実装(L23-L113, L205-L280)plugins/nyash-integer-plugin/src/lib.rs- IntegerBoxプラグイン実装tools/smokes/v2/- 新スモークテストシステムsrc/box_factory/plugin.rs- プラグインロード実装src/runtime/plugin_loader_v2/enabled/loader.rs- create_box → nyash_plugin_invoke_v2_shimsrc/mir/builder/builder_calls.rs- TypeBox v2 resolve実装(問題箇所)
🚀 期待する回答
- M_BIRTH/M_FINI実装の具体的な修正方法
- 効率的なテスト戦略の提案
- プラグインメソッド呼び出しのデバッグ手法
よろしくお願いします!