Files
hakorune/docs/development/current/main/phases/phase-287/README.md

175 lines
5.5 KiB
Markdown
Raw Normal View History

# Phase 287: Normalizer Hygiene正規化器整理
**Status**: Planning
**Date**: 2025-12-26
**Previous**: Phase 286 (Plan Line完全運用化)
## 概要
Phase 286 でPlan lineへの移行が完了したため、legacy Pattern5 削除とnormalizer.rs の整理を実施。
## Phase 286 完了作業(本セッション)
### ✅ Legacy Pattern5 削除488行
**削除理由**: Plan line 完全運用化により、legacy Pattern5 は完全にデッドコード化
**削除ファイル**:
- `src/mir/builder/control_flow/joinir/patterns/pattern5_infinite_early_exit.rs` (488行)
**関連削除**:
- `router.rs``LOOP_PATTERNS` テーブルから Pattern5 エントリ削除
- `mod.rs` から `pub mod pattern5_infinite_early_exit;` 削除
- `router.rs` のドキュメント更新Pattern5 → Pattern4 優先順位へ)
**影響範囲**:
- Pattern5 は Plan line の `extract_pattern5_plan()` 経由で処理されるため、機能退行なし
- `LOOP_PATTERNS` テーブルの優先順位: Pattern5 → Pattern4 → Pattern8... から Pattern4 → Pattern8... に変更
### ✅ Warning クリーンアップ
**実行コマンド**:
```bash
cargo fix --lib -p nyash-rust --allow-dirty
```
**修正内容**:
- 1件の自動修正`normalizer.rs`
- 未使用 import などを自動修正
### ✅ ビルド&テスト確認
**ビルド結果**:
```bash
cargo build --release
# → 成功130 warnings、エラーなし
```
**テスト結果**:
```bash
tools/smokes/v2/run.sh --profile quick
# → 154/154 PASS ✅
```
**退行なし**: quick smoke 154/154 PASS を維持
## 削除前後の統計
### コード削減
| 項目 | 削減数 |
|------|--------|
| ソースファイル | 1ファイル (pattern5_infinite_early_exit.rs) |
| 総削減行数 | 488行 |
| router.rs エントリ | 5行Pattern5 エントリ) |
| mod.rs 宣言 | 1行 |
### Pattern優先順位の変更
**削除前**Phase 131-11+:
```
Pattern5 (most specific) → Pattern4 → Pattern3 → Pattern1 → Pattern2
```
**削除後**Phase 286+:
```
Pattern4 → Pattern8 → Pattern9 → Pattern3 → Pattern1 → Pattern2
```
**注**: Pattern5/6/7 は Plan line 経由で処理(`PLAN_EXTRACTORS` テーブル)
## Phase 287 計画(後回し)
### P0: normalizer.rs 分割計画
**現状**: `src/mir/builder/control_flow/plan/normalizer.rs` が大きすぎる(推定 1,500+ 行)
**分割案**:
#### 1. Pattern5 正規化ロジック分離430行
- `normalizer/pattern5.rs` - Pattern5 専用正規化
- Pattern5 の複雑な構造展開ロジックを独立モジュール化
#### 2. Helper 関数共通化700行
- `normalizer/helpers.rs` - 共通ヘルパー関数
- 複数パターンで使用される変換ロジック
#### 3. コアロジック残存300行
- `normalizer.rs` - PlanNormalizer struct & normalize() エントリーポイント
- パターン横断的な正規化インターフェース
**期待効果**:
- メンテナンス性向上
- テスト分離Pattern5 正規化のみをユニットテスト)
- 責任分離SRP原則
### P1: LOOP_PATTERNS テーブル完全削除
**背景**: 全Pattern が Plan line 経由になれば、`LOOP_PATTERNS` テーブルは不要
**前提条件**:
- Pattern1-4 の Plan line 移行完了Phase 286 でPattern1-4はPlan line化済み
- Pattern8-9 の Plan line 移行完了Phase 286 でPlan line化済み
**削除対象**:
- `router.rs``LOOP_PATTERNS` static テーブル40行程度
- `LoopPatternEntry` struct不要化
**残存**:
- `PLAN_EXTRACTORS` テーブルのみSSOT
**期待効果**:
- 二重管理解消LOOP_PATTERNS vs PLAN_EXTRACTORS
- ルーティングロジック一本化
## 実装方針
### フェーズ分割
1. **Phase 286完了**: Legacy Pattern5 削除 + Warning クリーンアップ
2. **Phase 287-P0保留**: normalizer.rs 分割P0優先度は低い
3. **Phase 287-P1将来**: LOOP_PATTERNS テーブル削除全Pattern Plan line化後
### 段階的移行
- 急がないnormalizer.rs 分割は緊急度低(機能的に問題なし)
- 機会を待つP1 はPattern1-4完全移行のタイミングで実施
## 関連ドキュメント
- [Phase 286 計画](../phase-286/README.md) - Plan Line完全運用化
- [Plan Line アーキテクチャ](../../design/plan-line-architecture.md) - Extractor → Normalizer → Verifier → Lowerer
- [Pattern移行ログ](../phase-273/README.md) - Pattern6/7 Plan line移行Phase 273
## 検証項目
### ✅ Phase 286 完了検証
- [x] Pattern5 ファイル削除488行
- [x] router.rs の LOOP_PATTERNS から Pattern5 エントリ削除
- [x] mod.rs から Pattern5 宣言削除
- [x] `cargo fix` 実行Warning クリーンアップ)
- [x] `cargo build --release` 成功0エラー
- [x] quick smoke 154/154 PASS
- [x] Phase 287 ドキュメント作成
### 📋 Phase 287-P0/P1 検証(将来)
fix(rewrite): toString normalization to BoxCall(slot #0) - Phase 287 P4 Root cause: toString/stringify/str were being rewritten to Global/Method calls with class inference, causing Main.toString/0 to be called for primitives. Fix (Box-First + Legacy Deletion): 1. ✅ MIR Builder - toString normalization (special.rs) - ALWAYS emit BoxCall with method_id=0 for toString/stringify/str - Do NOT rewrite to Global(Class.str/0) or Method calls - DELETED 70+ lines of complex class inference logic - Primitive guard with method name filter (known.rs) 2. ✅ JSON Serializer - method_id output (mir_json_emit.rs) - Include method_id field in BoxCall JSON for LLVM 3. ✅ LLVM Backend - universal slot #0 support - Extract method_id from JSON (instruction_lower.py) - Box primitives via nyash.box.from_i64 (boxcall.py) - Invoke toString via plugin system with method_id=0 - ⚠️ TODO: Add nyash.integer.tostring_h to kernel Test Results: ✅ VM: local x = 1; print(x.toString()) → "1" (PASS) ✅ VM: array_length test (boxed Integer) → PASS ⚠️ LLVM: Compiles successfully, needs kernel function SSOT: slot_registry - toString is ALWAYS universal slot #0 Legacy Deleted: - special.rs: Complex class inference rewrite (~70 lines) - special.rs: Unique suffix fallback for toString - special.rs: Main box special handling Files changed: - src/mir/builder/rewrite/special.rs (try_early_str_like_to_dst) - src/mir/builder/rewrite/known.rs (primitive guards x4) - src/runner/mir_json_emit.rs (method_id serialization x2) - src/llvm_py/builders/instruction_lower.py (method_id extraction) - src/llvm_py/instructions/boxcall.py (slot #0 handler) - docs/reference/language/quick-reference.md (toString SSOT) 🎊 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 11:38:05 +09:00
- [ ] normalizer.rs 分割完了P0
- [ ] pattern5.rs 独立430行
- [ ] helpers.rs 共通化700行
- [ ] normalizer.rs 縮小300行
- [ ] LOOP_PATTERNS テーブル削除P1
- [ ] 全Pattern Plan line経由確認
- [ ] `LOOP_PATTERNS` static削除
- [ ] `LoopPatternEntry` struct削除
fix(rewrite): toString normalization to BoxCall(slot #0) - Phase 287 P4 Root cause: toString/stringify/str were being rewritten to Global/Method calls with class inference, causing Main.toString/0 to be called for primitives. Fix (Box-First + Legacy Deletion): 1. ✅ MIR Builder - toString normalization (special.rs) - ALWAYS emit BoxCall with method_id=0 for toString/stringify/str - Do NOT rewrite to Global(Class.str/0) or Method calls - DELETED 70+ lines of complex class inference logic - Primitive guard with method name filter (known.rs) 2. ✅ JSON Serializer - method_id output (mir_json_emit.rs) - Include method_id field in BoxCall JSON for LLVM 3. ✅ LLVM Backend - universal slot #0 support - Extract method_id from JSON (instruction_lower.py) - Box primitives via nyash.box.from_i64 (boxcall.py) - Invoke toString via plugin system with method_id=0 - ⚠️ TODO: Add nyash.integer.tostring_h to kernel Test Results: ✅ VM: local x = 1; print(x.toString()) → "1" (PASS) ✅ VM: array_length test (boxed Integer) → PASS ⚠️ LLVM: Compiles successfully, needs kernel function SSOT: slot_registry - toString is ALWAYS universal slot #0 Legacy Deleted: - special.rs: Complex class inference rewrite (~70 lines) - special.rs: Unique suffix fallback for toString - special.rs: Main box special handling Files changed: - src/mir/builder/rewrite/special.rs (try_early_str_like_to_dst) - src/mir/builder/rewrite/known.rs (primitive guards x4) - src/runner/mir_json_emit.rs (method_id serialization x2) - src/llvm_py/builders/instruction_lower.py (method_id extraction) - src/llvm_py/instructions/boxcall.py (slot #0 handler) - docs/reference/language/quick-reference.md (toString SSOT) 🎊 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 11:38:05 +09:00
## 備考
fix(rewrite): toString normalization to BoxCall(slot #0) - Phase 287 P4 Root cause: toString/stringify/str were being rewritten to Global/Method calls with class inference, causing Main.toString/0 to be called for primitives. Fix (Box-First + Legacy Deletion): 1. ✅ MIR Builder - toString normalization (special.rs) - ALWAYS emit BoxCall with method_id=0 for toString/stringify/str - Do NOT rewrite to Global(Class.str/0) or Method calls - DELETED 70+ lines of complex class inference logic - Primitive guard with method name filter (known.rs) 2. ✅ JSON Serializer - method_id output (mir_json_emit.rs) - Include method_id field in BoxCall JSON for LLVM 3. ✅ LLVM Backend - universal slot #0 support - Extract method_id from JSON (instruction_lower.py) - Box primitives via nyash.box.from_i64 (boxcall.py) - Invoke toString via plugin system with method_id=0 - ⚠️ TODO: Add nyash.integer.tostring_h to kernel Test Results: ✅ VM: local x = 1; print(x.toString()) → "1" (PASS) ✅ VM: array_length test (boxed Integer) → PASS ⚠️ LLVM: Compiles successfully, needs kernel function SSOT: slot_registry - toString is ALWAYS universal slot #0 Legacy Deleted: - special.rs: Complex class inference rewrite (~70 lines) - special.rs: Unique suffix fallback for toString - special.rs: Main box special handling Files changed: - src/mir/builder/rewrite/special.rs (try_early_str_like_to_dst) - src/mir/builder/rewrite/known.rs (primitive guards x4) - src/runner/mir_json_emit.rs (method_id serialization x2) - src/llvm_py/builders/instruction_lower.py (method_id extraction) - src/llvm_py/instructions/boxcall.py (slot #0 handler) - docs/reference/language/quick-reference.md (toString SSOT) 🎊 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 11:38:05 +09:00
**注意**: normalizer.rs の分割は行わない本Phase完了時点では保留
fix(rewrite): toString normalization to BoxCall(slot #0) - Phase 287 P4 Root cause: toString/stringify/str were being rewritten to Global/Method calls with class inference, causing Main.toString/0 to be called for primitives. Fix (Box-First + Legacy Deletion): 1. ✅ MIR Builder - toString normalization (special.rs) - ALWAYS emit BoxCall with method_id=0 for toString/stringify/str - Do NOT rewrite to Global(Class.str/0) or Method calls - DELETED 70+ lines of complex class inference logic - Primitive guard with method name filter (known.rs) 2. ✅ JSON Serializer - method_id output (mir_json_emit.rs) - Include method_id field in BoxCall JSON for LLVM 3. ✅ LLVM Backend - universal slot #0 support - Extract method_id from JSON (instruction_lower.py) - Box primitives via nyash.box.from_i64 (boxcall.py) - Invoke toString via plugin system with method_id=0 - ⚠️ TODO: Add nyash.integer.tostring_h to kernel Test Results: ✅ VM: local x = 1; print(x.toString()) → "1" (PASS) ✅ VM: array_length test (boxed Integer) → PASS ⚠️ LLVM: Compiles successfully, needs kernel function SSOT: slot_registry - toString is ALWAYS universal slot #0 Legacy Deleted: - special.rs: Complex class inference rewrite (~70 lines) - special.rs: Unique suffix fallback for toString - special.rs: Main box special handling Files changed: - src/mir/builder/rewrite/special.rs (try_early_str_like_to_dst) - src/mir/builder/rewrite/known.rs (primitive guards x4) - src/runner/mir_json_emit.rs (method_id serialization x2) - src/llvm_py/builders/instruction_lower.py (method_id extraction) - src/llvm_py/instructions/boxcall.py (slot #0 handler) - docs/reference/language/quick-reference.md (toString SSOT) 🎊 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 11:38:05 +09:00
**理由**:
- 機能的に問題なし(現在の構造で動作)
- 緊急度低(開発速度への影響なし)
- 別Phase対応が適切Phase 287-P0として計画のみ