feat(lifecycle): Phase 83 P3-D MethodReturnHintBox implementation

ChatGPT Pro設計に基づき、既知メソッド戻り値型推論箱(P3-D)を実装。

## 変更内容

- method_return_hint.rs: MethodReturnHintBox 新規作成
  - BoxCall/Call のメソッド名から戻り値型を推論
  - TypeAnnotationBox と同等のマッピングを適用
  - length/size/len → Integer, push → Void, str/substring → String
- lifecycle.rs: P3-D 経路を P3-C の前に挿入
- mod.rs: method_return_hint モジュール登録

## 成果

- Case D 削減: 20 → 16 (4件削減, 20%)
- Unit tests: 5/5 passed

## 設計原則

- 単一責務: P3-D 推論のみ
- TypeAnnotationBox 薄ラップ: 型マッピングの SSOT は TypeAnnotationBox
- 将来移行性: MethodRegistry 導入時も API 不変

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-02 18:09:04 +09:00
parent ce60ebc439
commit 8ae1eabcfa
3 changed files with 243 additions and 0 deletions

View File

@ -41,6 +41,8 @@ fn has_main_static(ast: &ASTNode) -> bool {
use crate::mir::join_ir::lowering::type_hint_policy::TypeHintPolicy;
// Phase 67: P3-C ジェネリック型推論箱
use crate::mir::join_ir::lowering::generic_type_resolver::GenericTypeResolver;
// Phase 83: P3-D 既知メソッド戻り値型推論箱
use crate::mir::join_ir::lowering::method_return_hint::MethodReturnHintBox;
// Phase 82: dev ガード用ヘルパー - Case 分類ロジック統一化
//
@ -323,6 +325,24 @@ impl super::MirBuilder {
} else {
None
};
// Phase 83: P3-D 既知メソッド戻り値型推論P3-C より先に試行)
//
// P3-D は「既知メソッドの戻り値型」を直接推論する。
// BoxCall の method 名から TypeAnnotationBox と同じマッピングで型を取得。
if hint.is_none() {
if let Some(mt) =
MethodReturnHintBox::resolve_for_return(&function, *v, &self.value_types)
{
if std::env::var("NYASH_P3D_DEBUG").is_ok() {
eprintln!(
"[lifecycle/p3d] {} type inferred via MethodReturnHintBox: {:?}",
function.signature.name, mt
);
}
inferred = Some(mt);
break;
}
}
// Phase 67: P3-C 対象なら GenericTypeResolver を優先使用
if hint.is_none() && TypeHintPolicy::is_p3c_target(&function.signature.name) {
if let Some(mt) =