feat(joinir): Phase 34-6 MethodCall 構造と本物の substring 意味論

**Phase 34-6 実装完了**: MethodCall 構造を JoinIR に追加し、本物の substring
呼び出しを通すことに成功。

## 主要変更

### 1. MethodCall 構造追加 (34-6.1)
- `src/mir/join_ir/mod.rs`: JoinInst::MethodCall バリアント (+8 lines)
  - 構造: `{ dst, receiver, method, args }`
  - 設計原則: JoinIR は構造のみ、意味論は MIR レベル

### 2. extract_value 更新 (34-6.2)
- `src/mir/join_ir/frontend/ast_lowerer.rs`: Method 処理本物化 (+37 lines)
  - receiver/args を extract_value で再帰処理
  - ダミー Const(0) 削除 → 本物の MethodCall 生成
  - cond 処理修正: ValueId(0) ハードコード → extract_value で取得

### 3. JoinIR→MIR 変換実装 (34-6.3)
- `src/mir/join_ir_vm_bridge.rs`: MethodCall → BoxCall 変換 (+12 lines)
- `src/mir/join_ir/json.rs`: MethodCall JSON シリアライゼーション (+16 lines)
- `src/mir/join_ir_runner.rs`: MethodCall 未対応エラー (+7 lines)

### 4. テスト更新 (34-6.4)
- `docs/.../fixtures/json_shape_read_value.program.json`: 本物の substring 構造
- `src/tests/joinir_frontend_if_select.rs`: run_joinir_via_vm 使用
- テスト成功: v="hello", at=3 → "hel" 

## 成果

-  テスト全通過(1 passed; 0 failed)
-  設計原則確立: JoinIR = 構造 SSOT、意味論 = MIR レベル
-  Phase 33-10 原則との整合性: Method でも同じ原則適用

**ドキュメント更新**: CURRENT_TASK.md + TASKS.md(Phase 34-6 完了記録)

🤖 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-27 17:05:46 +09:00
parent 6a5701ead9
commit 588129db65
15 changed files with 1891 additions and 69 deletions

View File

@ -5,6 +5,7 @@
use crate::mir::join_ir::frontend::AstToJoinIrLowerer;
use crate::mir::join_ir_runner::{run_joinir_function, JoinValue};
use crate::mir::join_ir_vm_bridge::run_joinir_via_vm;
/// Phase 34-2: IfSelect simple pattern の A/B テスト
///
@ -138,11 +139,11 @@ fn joinir_frontend_if_select_local_ab_test() {
// 「値としての if」の本質が Select であることを確認
}
/// Phase 34-4: JsonShapeToMap._read_value_from_pair/1 の A/B テスト
/// Phase 34-6: JsonShapeToMap._read_value_from_pair/1 の完全実装テスト
///
/// 入力: `fixtures/json_shape_read_value.program.json`
/// パターン: `if at { return 10 } else { return 20 }` (簡略版・構造確認)
/// 期待: Phase 34-2/34-3 と同じ JoinIR 出力Select ベース)
/// パターン: `if at { return v.substring(0, at) } else { return v }`
/// 期待: 本物の substring 呼び出しが JoinIR MethodCall → MIR BoxCall で実行される
#[test]
fn joinir_frontend_json_shape_read_value_ab_test() {
// フィクスチャ読み込み
@ -157,7 +158,7 @@ fn joinir_frontend_json_shape_read_value_ab_test() {
let join_module = lowerer.lower_program_json(&program_json);
// デバッグ: JoinIR Module の内容を確認
eprintln!("=== JoinIR Module (json_shape_read_value) ===");
eprintln!("=== JoinIR Module (json_shape_read_value - Phase 34-6) ===");
eprintln!("Entry: {:?}", join_module.entry);
for (func_id, func) in &join_module.functions {
eprintln!("\nFunction {:?}: {}", func_id, func.name);
@ -168,38 +169,35 @@ fn joinir_frontend_json_shape_read_value_ab_test() {
}
}
// JoinIR Runner で実行
let mut vm = crate::backend::mir_interpreter::MirInterpreter::new();
// Phase 34-6: JoinIR→MIR→VM ブリッジ経由で実行MethodCall サポート)
// at = 1 (truthy) の場合
let result_true = run_joinir_function(
&mut vm,
// テストケース 1: v="hello", at=3 → "hel" (substring)
let result_substring = run_joinir_via_vm(
&join_module,
join_module.entry.unwrap(),
&[JoinValue::Int(1)],
&[JoinValue::Str("hello".to_string()), JoinValue::Int(3)],
)
.expect("Failed to run JoinIR function (at=1)");
.expect("Failed to run JoinIR function (v=\"hello\", at=3)");
// at = 0 (falsy) の場合
let result_false = run_joinir_function(
&mut vm,
// テストケース 2: v="world", at=0 → "world" (v そのまま)
let result_original = run_joinir_via_vm(
&join_module,
join_module.entry.unwrap(),
&[JoinValue::Int(0)],
&[JoinValue::Str("world".to_string()), JoinValue::Int(0)],
)
.expect("Failed to run JoinIR function (at=0)");
.expect("Failed to run JoinIR function (v=\"world\", at=0)");
// 検証: at=1 → 10, at=0 → 20 (簡略版・構造確認)
match result_true {
JoinValue::Int(v) => assert_eq!(v, 10, "at=1 should return 10"),
_ => panic!("Expected Int, got {:?}", result_true),
// 検証: substring 呼び出し結果
match result_substring {
JoinValue::Str(s) => assert_eq!(s, "hel", "v.substring(0, 3) should return \"hel\""),
_ => panic!("Expected Str, got {:?}", result_substring),
}
match result_false {
JoinValue::Int(v) => assert_eq!(v, 20, "at=0 should return 20"),
_ => panic!("Expected Int, got {:?}", result_false),
// 検証: 元の文字列そのまま
match result_original {
JoinValue::Str(s) => assert_eq!(s, "world", "v should return \"world\""),
_ => panic!("Expected Str, got {:?}", result_original),
}
// Phase 34-4: Stage-1/meta 実用関数でも simple pattern が Select JoinIR に正規化されることを実証
// 構造確認フェーズMethod 呼び出し意味論は Phase 34-5 で対応)
// Phase 34-6: 本物の Method 呼び出し意味論が JoinIR MethodCall → MIR BoxCall で実行されることを実証
}