Commit Graph

34 Commits

Author SHA1 Message Date
923a442326 refactor(edgecfg): add Frag/ExitKind API entrypoint (Phase 264 design-first)
Phase 264 P0: EdgeCFG Fragment 入口API作成(実装置換なし)

- 入口フォルダ作成: src/mir/builder/control_flow/edgecfg/api/
- コア型定義: ExitKind, EdgeStub, Frag
- 合成関数シグネチャ: seq, if_, loop_, cleanup(中身TODO、pub(crate))
- 最小テスト: 3個のユニットテスト追加(frag.rs)
- ドキュメント連動: edgecfg-fragments.md に実装入口追記

制約遵守:
- 既存 pattern6/7/8 未改変
- merge/EdgeCFG 未改変
- 既存LoopId使用(control_form.rs に PartialOrd, Ord 追加)
- MIR側EdgeArgs使用(JoinIRと混線回避)
- BTreeMap採用(決定的順序保証、Phase 69-3 教訓)

次フェーズ: Phase 265 で Pattern8 適用時に compose::loop_ を実装

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-21 12:49:53 +09:00
e3dd1bbecb docs: Phase 263 P0 完了記録(Pattern2 fallback 修正)
- 10-Now.md: Phase 263 P0 完了記録を追加(最上部に配置)
- phase-263/README.md: 詳細な実装記録・検証結果を作成
- 30-Backlog.md: Phase 263+ planned 項目を追加
  - Pattern2 LoopBodyLocal promotion(seg)
  - PromoteDecision API hardening(構造で迷子防止)
- phase263_p0_pattern2_seg_vm.sh: smoke test スクリプト改善

検証結果:
- cargo test --lib: 1368/1368 PASS 
- quick smoke: 45/46 PASS  (大幅改善)
- Pattern2 が正しく abort することを確認
2025-12-21 10:39:48 +09:00
1fe5be347d refactor(mir): phase260 p0.1 strangler hardening + smoke fixtures 2025-12-21 05:47:37 +09:00
9336785680 feat(anf): Phase 146/147 - Loop/If Condition ANF with Compare support
## Phase 146 P0: ANF Routing SSOT Unified

**Goal**: Unify ANF routing in `lower_expr_with_scope()` L54-84, remove legacy lowering

**Changes**:
- expr_lowerer_box.rs: Added scope check (PureOnly → skip ANF, WithImpure → try ANF)
- post_if_post_k.rs: Removed legacy inline lowering (L271-285), added `lower_condition_legacy()` helper
- contract.rs: Already had `CondLoweringFailed` out-of-scope reason

**Test Results**:  Phase 146 P0 smoke (exit 7), 0 regressions

## Phase 146 P1: Compare Operator Support

**Goal**: Enable ANF for condition expressions with Compare operators

**Changes**:
- joinir_dev.rs: Added `anf_allow_pure_enabled()` (HAKO_ANF_ALLOW_PURE=1)
- expr_lowerer_box.rs: PureOnly scope ANF support (L56-66)
- execute_box.rs: Compare operator support (+122 lines)
  - `execute_compare_hoist()`, `execute_compare_recursive()`, `ast_compare_to_joinir()`
  - Extended `normalize_and_lower()` for Compare

**Test Results**:  Phase 146 P1 smoke (exit 7 with flags), 0 regressions

## Phase 147 P0: Recursive Comparison ANF

**Goal**: Extend recursive ANF to Compare operators

**Changes**:
- contract.rs: Added `AnfParentKind::Compare` variant
- plan_box.rs: Compare case in BinaryOp routing (L68-79, L134-139)
  - Distinguishes Compare vs arithmetic BinaryOp

**Benefits**: Enables recursive ANF for comparisons
- `s.length() == 3` → `t = s.length(); if (t == 3)` 
- `s1.length() < s2.length()` → `t1 = s1.length(); t2 = s2.length(); if (t1 < t2)` 

## Implementation Summary

**Files Modified** (9 files, +253 lines, -25 lines = +228 net):
1. src/config/env/joinir_dev.rs (+28 lines)
2. src/mir/control_tree/normalized_shadow/anf/contract.rs (+2 lines)
3. src/mir/control_tree/normalized_shadow/anf/execute_box.rs (+122 lines)
4. src/mir/control_tree/normalized_shadow/anf/plan_box.rs (+18 lines)
5. src/mir/control_tree/normalized_shadow/common/expr_lowerer_box.rs (+18 lines, -0 lines)
6. src/mir/control_tree/normalized_shadow/post_if_post_k.rs (+44 lines, -25 lines)
7. CURRENT_TASK.md
8. docs/development/current/main/10-Now.md
9. docs/development/current/main/30-Backlog.md

**Files Created** (7 files):
- apps/tests/phase146_p0_if_cond_unified_min.hako
- apps/tests/phase146_p1_if_cond_intrinsic_min.hako
- tools/smokes/.../phase146_p0_if_cond_unified_vm.sh
- tools/smokes/.../phase146_p0_if_cond_unified_llvm_exe.sh
- tools/smokes/.../phase146_p1_if_cond_intrinsic_vm.sh
- tools/smokes/.../phase146_p1_if_cond_intrinsic_llvm_exe.sh
- docs/development/current/main/phases/phase-146/README.md

**Acceptance Criteria**:  All met
- cargo build --release: PASS (0 errors, 0 warnings)
- Phase 145 regressions: PASS (exit 12, 18, 5)
- Phase 146 P0: PASS (exit 7)
- Phase 146 P1: PASS (exit 7 with HAKO_ANF_ALLOW_PURE=1)

**Architecture**:
- SSOT: ANF routing only in `lower_expr_with_scope()` L54-84
- Box-First: Phase 145 `anf/` module extended
- Legacy removed: post_if_post_k.rs unified with SSOT

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-19 17:03:56 +09:00
6a3b6deb20 feat(anf): Phase 145 P0/P1/P2 - ANF (A-Normal Form) transformation
Implement ANF transformation for impure expressions to fix evaluation order:

Phase 145 P0 (Skeleton):
- Add anf/ module with contract/plan/execute 3-layer separation
- AnfDiagnosticTag, AnfOutOfScopeReason, AnfPlan enums
- Stub execute_box (always returns Ok(None))
- 11 unit tests pass

Phase 145 P1 (Minimal success):
- String.length() whitelist implementation
- BinaryOp + MethodCall pattern: x + s.length() → t = s.length(); result = x + t
- Exit code 12 verification (VM + LLVM EXE)
- 17 unit tests pass

Phase 145 P2 (Generalization):
- Recursive ANF for compound expressions
- Left-to-right, depth-first evaluation order
- Patterns: x + s.length() + z, s1.length() + s2.length()
- ANF strict mode (HAKO_ANF_STRICT=1)
- Diagnostic tags (joinir/anf/*)
- 21 unit tests pass, 0 regression

Also includes Phase 143 P2 (else symmetry) completion.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-19 16:19:49 +09:00
845ae70cb7 chore: Remove unused imports in normalized_shadow modules
Cleaned up unused imports after Phase 143 execution fix (5e662eaaf).

**Priority files (Phase 143)**:
- if_as_last_join_k.rs: removed ValueId, BTreeMap
- loop_true_break_once.rs: added #[cfg(test)] for test-only imports
- post_if_post_k.rs: removed ValueId, BTreeMap
- normalized_helpers.rs: added #[cfg(test)] for Span

**Additional cleanup**:
- contract_checks.rs: removed BasicBlockId
- joinir/mod.rs: removed Info struct re-exports (functions kept)
- patterns/mod.rs: removed Info struct re-exports (functions kept)
- ast_feature_extractor.rs: removed EscapeSkipPatternInfo
- plan_box.rs: added #[cfg(test)] for PlanKind

**Verification**:
- 0 unused import warnings (was 20+)
- All 69 normalized_shadow tests pass
- Clean build with --release

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-19 08:36:45 +09:00
7030b110cb feat(phase143/r0): Contract SSOT extraction - loop-if-exit pattern refactoring
Phase 143 R0: Refactor P0 to prevent if-branch explosion in P1/P2

**Key Changes**:
- New: loop_if_exit_contract.rs (LoopIfExitShape, LoopIfExitThen, OutOfScopeReason)
- Contract SSOT for pattern shape detection and exit action discrimination
- Separated unit tests to tests/phase143_loop_if_exit_contract.rs (8 tests)
- Removed embedded tests from implementation file
- Updated module declarations for contract and test modules

**Benefits**:
- Enum-driven pattern discrimination (no if-branch explosion)
- P1 extension: Add Continue via 1 enum variant + 1 match arm
- P2 extension: Add else via contract fields (linear growth, not exponential)
- Improved maintainability and code discoverability

**Verification**:
- cargo check:  0 errors
- Unit tests:  8/8 passed
- Documentation:  Updated 10-Now.md and 30-Backlog.md

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

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-19 06:33:56 +09:00
af2a5e27d6 feat(normalization): Phase 142 P1 - LLVM EXE parity for loop normalization
Some checks failed
fast-smoke / fast (push) Has been cancelled
Phase 142-loopstmt P1: LLVM EXE smoke test for statement-level loop normalization

- Added: tools/smokes/v2/profiles/integration/apps/phase142_loop_stmt_only_then_return_length_min_llvm_exe.sh
- Verification: Exit code 3 parity with VM test
- Status:  PASS (exit code 3, string length computed correctly)

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

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-19 05:42:11 +09:00
4082abb30c feat(normalization): Phase 142 P0 - Loop statement-level normalization
Phase 142-loopstmt P0: Statement-level normalization

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

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-19 05:28:49 +09:00
b5d628d8bf docs: Phase 130 DONE (if-only normalized small expr/assign) 2025-12-18 09:13:19 +09:00
05fccce09a docs: add Phase 130 plan and set Now to Phase 130 2025-12-18 08:36:38 +09:00
80df1cccd4 feat(control_tree): Phase 129-C post-if via post_k continuation 2025-12-18 08:33:56 +09:00
36717cad4f docs: update Now/INDEX for Phase 129-B join_k as-last 2025-12-18 07:54:16 +09:00
088122df71 docs: update Now/INDEX for Phase 127 DONE and Phase 129 next 2025-12-18 07:28:30 +09:00
9aedc19413 docs: add Phase 127 entry (planned) 2025-12-18 06:55:29 +09:00
7eeeb588e4 docs: add Phase 125 entry (planned) 2025-12-18 06:28:39 +09:00
51ed137339 docs: Phase 123 plan (if-only normalized semantics) 2025-12-18 05:29:34 +09:00
c92154966c docs: add Phase 122 entry (planned) 2025-12-18 04:48:53 +09:00
5091cda9cb docs: Phase 118 DONE (loop+if merge parity) 2025-12-18 03:43:16 +09:00
f63b5c3c64 docs: fix INDEX numbering + refresh backlog after Phase 116
- Fixed INDEX numbering: 24/25 → 28/29 (was duplicated after Phase 116 additions)
- Updated Backlog: next candidate Phase 114 → Phase 117 (nested if + call merge)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-18 02:52:01 +09:00
97675b4035 docs: Phase 114 DONE
Phase 114完了に伴うドキュメント更新:
- 30-Backlog.md: Phase 114の次候補から完了済みに移行
- design/control-tree.md: Phase 110-112の進捗反映
- design/README.md, joinir-design-map.md, phases/README.md: マイナー更新

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-18 02:19:41 +09:00
46c924ac6d docs: add Phase 108 entry 2025-12-17 23:30:13 +09:00
6a21382d44 docs: add Phase 107 to Now/INDEX and backlog 2025-12-17 23:15:57 +09:00
af3b851984 docs: add Phase 107 prep for find_balanced 2025-12-17 22:01:23 +09:00
712e1ad755 docs: update Phase104 status and JoinIR map 2025-12-17 21:47:37 +09:00
a5cec824c2 docs: Phase 103 DONE (if-only parity smokes) 2025-12-17 17:41:10 +09:00
935d475882 docs: Phase 103 plan (if-only parity baseline) 2025-12-17 17:39:12 +09:00
692d44da62 docs: Phase 100 rollout plan (Pinned then mutable carrier) 2025-12-17 05:18:09 +09:00
7ab459503b feat(joinir): Phase 94 - P5b escape full E2E (derived ch + +1/+2) 2025-12-17 00:59:33 +09:00
93e62b1433 docs(phase93): Phase 93 P0完了記録 & ドキュメント整理
## 追加
- docs/development/current/main/phases/phase-93/README.md
  - Phase 93 P0 (ConditionOnly Derived Slot) 完了記録
  - 実装内容・テスト結果の詳細

## 更新
- CURRENT_TASK.md: Phase 93 P0完了に伴う更新
- 10-Now.md: 現在の進捗状況更新
- 30-Backlog.md: Phase 92/93関連タスク整理
- phase-91/92関連ドキュメント: historical化・要約化

## 削減
- 735行削減(historical化により詳細をREADMEに集約)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-16 23:30:39 +09:00
05c5021147 docs(phase131): LLVM SSOT強化 + ConsoleBox調査完了 + Phase86-90要約
Phase 131-1 完了: LLVM exe line SSOT 強化
- phase87-selfhost-llvm-exe-line.md に 4セクション追加(+300行)
  - 環境変数リファレンス(14変数)
  - 成功/失敗基準(exit code 0/1/2/3)
  - コンパイラモード説明(harness vs crate)
  - デバッグセクション拡張
- "1コマンドで再現" 可能な状態を確立

Phase 131-2 完了: ConsoleBox 問題調査
- VM の 3重登録経路を特定(BoxFactoryRegistry/UnifiedRegistry/Builtin)
- LLVM backend は Phase 133 で解決済み
- 3つのドキュメント作成:
  - phase131-2-consolebox-investigation.md(詳細調査)
  - phase131-2-summary.md(エグゼクティブサマリ)
  - phase131-2-box-resolution-map.md(Box 解決マップ)

Phase 86-90 完了: Loop frontends 要約
- phase86-90-loop-frontends-summary.md 追加
- Pattern4/ContinueReturn/ParseStringComposite の経緯を1枚に集約
- INDEX から導線追加

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 05:24:31 +09:00
43d5911051 docs(phase130): JoinIR→LLVM ベースライン確立
Phase 130完了: JoinIR → LLVM 経路の現状を観測・記録

実施内容:
- 代表ケース7本選定(selfhost/hako_check/JoinIR各系統)
- Rust VM / LLVM harness 両経路でテスト実行
- 実行結果を表形式で記録(観測専用、修正なし)
- Phase 131への引き継ぎ事項を整理

テスト結果:
- Rust VM: 6/7 PASS (85.7%)
  - peek_expr_block, loop_min_while, phase123_simple_if,
    phase123_while_loop, joinir_if_select_simple, joinir_min_loop
  - FAIL: esc_dirname_smoke (ConsoleBox未登録)
- LLVM harness: 0/7実行 (Mock backend、要--features llvm)
  - MIRコンパイルは全て成功
  - 実LLVM実行は未対応

検出された問題点:
1. LLVM Backend未対応(最重要)
   - --features llvm ビルドが必要
   - Mock backend実行中
2. ConsoleBox未登録問題
   - Rust VM環境での登録不備
   - Phase 15.5方針との衝突
3. JoinIR → LLVM経路の不明確性
   - MIR → LLVM IR lowering未検証

成果物:
- docs/development/current/main/phase130_joinir_llvm_baseline.md
  - 代表ケース選定理由・実行コマンド整理
  - 実行結果詳細・問題点分析
  - Phase 131引き継ぎ事項
- CURRENT_TASK.md: Phase 130セクション追加
- 30-Backlog.md: Phase 131予告追加

次フェーズ: Phase 131 - JoinIR→LLVM 個別修正ライン
2025-12-04 10:52:10 +09:00
ac14f94578 refactor(phase115): FileHandleBox 箱化・モジュール化実装完成
「Everything is Box」原則に基づいて FileHandleBox を整理し、
コード重複を削減して保守性を大幅向上。

【Task 1】テストヘルパー外出し
- tests/common/file_box_helpers.rs を新規作成
- setup_test_file / cleanup_test_file / init_test_provider を共有化
- FileBox と FileHandleBox 両方で統一的なテストヘルパーを使用可能に

【Task 2】ny_* メソッド統一化(マクロ化)
- 4つのマクロを新規定義:
  - ny_wrap_void!(open, write, close)
  - ny_wrap_string!(read)
  - ny_wrap_bool!(exists, is_file, is_dir)
  - ny_wrap_integer!(size)
- 8個のny_*メソッドをマクロ呼び出しに置き換え
- 削減効果: 52行 → 8行(85%削減!)

【Task 3】ドキュメント & テスト確認
- FileHandleBox ドキュメントに "Code Organization" セクション追加
- Phase 115 実装内容を明記(モジュール化・箱化・マクロ統一化)
- CURRENT_TASK.md に Phase 115 セクション追加

【効果】
- 保守性向上: ny_* メソッドの重複パターンをマクロで一元管理
- テスト共有化: 共通ヘルパーで FileBox/FileHandleBox 間の一貫性確保
- 可読性向上: 実装の意図が明確に
- 拡張性: 新しいny_*メソッド追加時はマクロ呼び出し1行で完了

【統計】
- 新規作成: 2ファイル(+40行)
- 修正: 2ファイル(+72行, -62行)
- 実質: +50行(マクロ・ヘルパー・ドキュメント追加)
- テスト: 27個全PASS(1個は環境依存で ignore)

【技術的工夫】
- マクロ展開後の動作が既存と同一(互換性維持)
- エラーハンドリング一元化(unwrap_or_default / unwrap_or(false))
- allow(unused_mut) で警告抑制

【Phase 106-115 全体成果】
Ring0/FileBox I/O パイプライン第1章完全クローズ
- 10フェーズ完成
- 60ファイル修正
- +2,500行実装
- 59テスト全PASS
- Ring0 / Ring1 / FileBox / FileHandleBox 完全統一設計

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 04:13:15 +09:00
d99b941218 docs: add MIR13 mode doc and set PHI-off as default; bridge lowering split (if/loop/try); llvmlite resolver stabilization; curated runner default PHI-off; refresh CURRENT_TASK.md 2025-09-17 10:58:12 +09:00