Files
hakorune/CODEX_QUESTION.md
tomoaki 757193891f feat(llvm/phi): Phase 277 P1 - fail-fast validation for PHI strict mode
## 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>
2025-12-22 14:48:37 +09:00

4.5 KiB
Raw Blame History

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()                          # ← 空文字列を返す

調査済み事項

  1. プラグインは正常にロードplugin-testerで確認
  2. nyash_plugin_invokeは実装済みlegacy v1 ABI
  3. method_id衝突を修正済み0-3 → 4+に変更)
  4. 通常の文字列リテラルは動作する
  5. 算術演算は問題なし

🔬 根本原因Codex調査結果 - 2025-09-24

実装レベルの具体的問題箇所を特定済み:

  1. string_invoke_idM_BIRTH分岐がない

    • plugins/nyash-string-plugin/src/lib.rsstring_invoke_idにM_BIRTH分岐が無く
    • new StringBox("test")で生成されたIDがINSTマップに登録されない
    • .length()呼び出しでE_HANDLEが返る
  2. string_resolveがtoStringを未マッピング

    • 同ファイルのstring_resolve"toString"M_TO_UTF8にマッピングしていない
    • .toString()は未知メソッド扱いになり空文字列/エラーでフォールバック
  3. IntegerBoxも同様の問題

    • plugins/nyash-integer-plugin/src/lib.rsでもM_BIRTH/M_FINIが未実装
    • 値を保持できず.get()/.set()が失敗

🎯 質問

1. 実装修正の優先度は?

  • string_invoke_idinteger_invoke_idM_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_shim
  • src/mir/builder/builder_calls.rs - TypeBox v2 resolve実装問題箇所

🚀 期待する回答

  1. M_BIRTH/M_FINI実装の具体的な修正方法
  2. 効率的なテスト戦略の提案
  3. プラグインメソッド呼び出しのデバッグ手法

よろしくお願いします!