935d475882
docs: Phase 103 plan (if-only parity baseline)
2025-12-17 17:39:12 +09:00
733b4fa950
docs: Phase 102 entry (real-app regression smokes)
2025-12-17 16:57:15 +09:00
bad8ee1571
docs: Phase 100 P3 string accumulator contract
...
- Add P3 section to phases/phase-100/README.md
- Document allowed form: out = out + ch (Variable RHS only)
- List Fail-Fast cases (Literal RHS, MethodCall RHS, non-string-ish)
- Add example with length-based output
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-17 16:33:03 +09:00
0ea2b7d2cb
fix(llvm_py): stabilize PHI incoming selection (no overwrite by failed candidate)
2025-12-17 16:12:16 +09:00
61c9d7929c
docs: Phase 100 P2.1 - LLVM EXE parity for mutable accumulator
...
- Update phases/phase-100/README.md with LLVM EXE smoke note
- Update 10-Now.md with P2.1 short report
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-17 06:31:21 +09:00
b45035597d
docs: Phase 100 P2 mutable accumulator contract
...
- Add P2 section to phases/phase-100/README.md
- Document allowed form: s = s + x (x must be read-only)
- List Fail-Fast cases (reversed ops, complex RHS, multiple updates)
- Add example with numeric output
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-17 06:10:26 +09:00
682fc11f7c
docs: Phase 100 P1 pinned receiver integration tests complete
...
- Update docs/development/current/main/phases/phase-100/README.md
* Document P1 implementation and pinned receiver example
- Update docs/development/current/main/10-Now.md
* Add Phase 100 P1 completion short report
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-17 05:43:54 +09:00
692d44da62
docs: Phase 100 rollout plan (Pinned then mutable carrier)
2025-12-17 05:18:09 +09:00
8ab95666c8
docs: Phase 100 pinned read-only captures plan
2025-12-17 05:03:07 +09:00
90a8f1650d
docs: Phase 99 notes and indices
...
Trim/escape実コード寄り強化の記録:
- phase-96: 3ケース追記
- phase-95: 末尾バックスラッシュ扱い追記
- phase-99: 新規README作成
- 10-Now.md: Phase 99短報追加
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-17 04:26:23 +09:00
6d73fc3404
feat(llvm): Phase 97 Box/Policy refactoring complete
...
Box化完了:
- CallRoutePolicyBox: Call routing SSoT
- PrintArgMarshallerBox: Print marshalling SSoT
- TypeFactsBox: Type propagation SSoT
- PhiSnapshotPolicyBox: PHI contract SSoT
- PluginErrorContext: Structured error reporting
📋 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-17 04:14:26 +09:00
1a0d9ce8a0
docs: add Phase 97 LLVM EXE parity entry
2025-12-17 02:26:42 +09:00
bc1a09f2c3
fix(joinir): Phase 96 next_non_ws break condition SSOT
2025-12-17 01:59:21 +09:00
db4453eb3c
test: strengthen phase96 next_non_ws fixture
2025-12-17 01:35:43 +09:00
ba87afd35c
test: add phase96 trim loop fixture and smoke
2025-12-17 01:25:06 +09:00
5b4de7b495
docs: add phase95 json_loader escape entry
2025-12-17 01:01:16 +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
d2972c1437
feat(joinir): Phase 92完了 - ConditionalStep + body-local変数サポート
...
## Phase 92全体の成果
**Phase 92 P0-P2**: ConditionalStep JoinIR生成とbody-local変数サポート
- ConditionalStep(条件付きキャリア更新)のJoinIR生成実装
- Body-local変数(ch等)の条件式での参照サポート
- 変数解決優先度: ConditionEnv → LoopBodyLocalEnv
**Phase 92 P3**: BodyLocalPolicyBox + 安全ガード
- BodyLocalPolicyDecision実装(Accept/Reject判定)
- BodyLocalSlot + DualValueRewriter(JoinIR/MIR二重書き込み)
- Fail-Fast契約(Cannot promote LoopBodyLocal検出)
**Phase 92 P4**: E2E固定+回帰最小化 (本コミット)
- Unit test 3本追加(body-local変数解決検証)
- Integration smoke追加(phase92_pattern2_baseline.sh、2ケースPASS)
- P4-E2E-PLAN.md、P4-COMPLETION.md作成
## 主要な実装
### ConditionalStep(条件付きキャリア更新)
- `conditional_step_emitter.rs`: JoinIR Select命令生成
- `loop_with_break_minimal.rs`: ConditionalStep検出と統合
- `loop_with_continue_minimal.rs`: Pattern4対応
### Body-local変数サポート
- `condition_lowerer.rs`: body-local変数解決機能
- `lower_condition_to_joinir`: body_local_env パラメータ追加
- 変数解決優先度実装(ConditionEnv優先)
- Unit test 3本追加: 変数解決/優先度/エラー
- `header_break_lowering.rs`: break条件でbody-local変数参照
- 7ファイルで後方互換ラッパー(lower_condition_to_joinir_no_body_locals)
### Body-local Policy & Safety
- `body_local_policy.rs`: BodyLocalPolicyDecision(Accept/Reject)
- `body_local_slot.rs`: JoinIR/MIR二重書き込み
- `dual_value_rewriter.rs`: ValueId書き換えヘルパー
## テスト体制
### Unit Tests (+3)
- `test_body_local_variable_resolution`: body-local変数解決
- `test_variable_resolution_priority`: 変数解決優先度(ConditionEnv優先)
- `test_undefined_variable_error`: 未定義変数エラー
- 全7テストPASS(cargo test --release condition_lowerer::tests)
### Integration Smoke (+1)
- `phase92_pattern2_baseline.sh`:
- Case A: loop_min_while.hako (Pattern2 baseline)
- Case B: phase92_conditional_step_minimal.hako (条件付きインクリメント)
- 両ケースPASS、integration profileで発見可能
### 退行確認
- ✅ 既存Pattern2Breakテスト正常(退行なし)
- ✅ Phase 135 smoke正常(MIR検証PASS)
## アーキテクチャ設計
### 変数解決メカニズム
```rust
// Priority 1: ConditionEnv (loop params, captured)
if let Some(value_id) = env.get(name) { return Ok(value_id); }
// Priority 2: LoopBodyLocalEnv (body-local like `ch`)
if let Some(body_env) = body_local_env {
if let Some(value_id) = body_env.get(name) { return Ok(value_id); }
}
```
### Fail-Fast契約
- Delta equality check (conditional_step_emitter.rs)
- Variable resolution error messages (ConditionEnv)
- Body-local promotion rejection (BodyLocalPolicyDecision::Reject)
## ドキュメント
- `P4-E2E-PLAN.md`: 3レベルテスト戦略(Level 1-2完了、Level 3延期)
- `P4-COMPLETION.md`: Phase 92完了報告
- `README.md`: Phase 92全体のまとめ
## 将来の拡張(Phase 92スコープ外)
- Body-local promotionシステム拡張
- P5bパターン認識の汎化(flagベース条件サポート)
- 完全なP5b E2Eテスト(body-local promotion実装後)
🎯 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-16 21:37:07 +09:00
568619df89
feat(mir): Phase 92 P2-2 - Body-local variable support for ConditionalStep
...
Phase 92 P2-2完了:ConditionalStepのcondition(ch == '\\'など)でbody-local変数をサポート
## 主要変更
### 1. condition_lowerer.rs拡張
- `lower_condition_to_joinir`に`body_local_env`パラメータ追加
- 変数解決優先度:ConditionEnv → LoopBodyLocalEnv
- すべての再帰ヘルパー(comparison, logical_and, logical_or, not, value_expression)対応
### 2. conditional_step_emitter.rs修正
- `emit_conditional_step_update`に`body_local_env`パラメータ追加
- condition loweringにbody-local環境を渡す
### 3. loop_with_break_minimal.rs修正
- break condition loweringをbody-local init の**後**に移動(line 411)
- header_break_lowering::lower_break_conditionにbody_local_env渡す
- emit_conditional_step_updateにbody_local_env渡す(line 620)
### 4. header_break_lowering.rs修正
- `lower_break_condition`に`body_local_env`パラメータ追加
- scope_managerにbody-local環境を渡す
### 5. 全呼び出し箇所修正
- expr_lowerer.rs (2箇所)
- method_call_lowerer.rs (2箇所)
- loop_with_if_phi_if_sum.rs (3箇所)
- loop_with_continue_minimal.rs (1箇所)
- carrier_update_emitter.rs (1箇所・legacy)
## アーキテクチャ改善
### Break Condition Lowering順序修正
旧: Header → **Break Cond** → Body-local Init
新: Header → **Body-local Init** → Break Cond
理由:break conditionが`ch == '\"'`のようにbody-local変数を参照する場合、body-local initが先に必要
### 変数解決優先度(Phase 92 P2-2)
1. ConditionEnv(ループパラメータ、captured変数)
2. LoopBodyLocalEnv(body-local変数like `ch`)
## テスト
### ビルド
✅ cargo build --release成功(30 warnings、0 errors)
### E2E
⚠️ body-local promotion問題でブロック(Phase 92範囲外)
- Pattern2はbody-local変数をcarrier promotionする必要あり
- 既存パターン(A-3 Trim, A-4 DigitPos)に`ch = get_char(i)`が該当しない
- **Phase 92 P2-2目標(condition loweringでbody-local変数サポート)は達成**
## 次タスク(Phase 92 P3以降)
- body-local variable promotion拡張(Pattern2で`ch`のような変数を扱う)
- P5b E2Eテスト完全動作確認
## Phase 92 P2-2完了
✅ Body-local変数のcondition lowering対応完了
✅ ConditionalStepでbody-local変数参照可能
✅ Break condition lowering順序修正
2025-12-16 17:08:15 +09:00
51017a0f9a
feat(joinir): Phase 92 P0-2 - Skeleton to LoopPatternContext (Option A)
...
SSOT principle: Pass canonicalizer-derived ConditionalStep info to Pattern2 lowerer
without re-detecting from AST.
Changes:
- router.rs: Add skeleton: Option<&'a LoopSkeleton> to LoopPatternContext
- parity_checker.rs: Return (Result, Option<LoopSkeleton>) to reuse skeleton
- routing.rs: Pass skeleton to context when joinir_dev_enabled()
- pattern2_with_break.rs: Detect ConditionalStep in can_lower()
Next: P0-3 implements actual JoinIR generation for ConditionalStep.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-16 15:22:29 +09:00
7e03cb6425
docs(phase-91): Update Phase 91 README with Step 2 completion status
...
### Updates
#### 1. Status Section
- Updated Status to reflect all completed steps (1, 2-A/B/D, 2-E)
- Documented parity verification success
#### 2. Completion Status Section (NEW)
- Added dedicated section for Phase 91 Step 2 completion
- Listed all deliverables with checkmarks
- Documented test results: 1062/1062 PASS
#### 3. Next Steps
- Clarified Phase 92 lowering requirements
- Updated timeline expectations
#### 4. Test Fixture Fix
- Fixed syntax error in test_pattern5b_escape_minimal.hako
(field declarations: changed `console: ConsoleBox` to `console ConsoleBox`)
### Context
Phase 91 Step 2 is now fully complete:
- ✅ AST recognizer (detect_escape_skip_pattern)
- ✅ Canonicalizer integration (UpdateKind::ConditionalStep)
- ✅ Unit tests (test_escape_skip_pattern_recognition)
- ✅ Parity verification (strict mode green)
Ready for Phase 92 lowering implementation.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-16 14:55:40 +09:00
9e3b258046
feat(phase-91): JoinIR Selfhost depth-2 advancement - Pattern P5b design & planning
...
## Overview
Analyzed 34 loops across selfhost codebase to identify JoinIR coverage gaps.
Current readiness: 47% (16/30 loops). Next frontier: Pattern P5b (Escape Handling).
## Current Status
- Phase 91 planning document: Complete
- Loop inventory across 6 key files
- Priority ranking: P5b (escape) > P5 (guard) > P6 (nested)
- Effort estimates and ROI analysis
- Pattern P5b Design: Complete
- Problem statement (variable-step carriers)
- Pattern definition with Skeleton layout
- Recognition algorithm (8-step detection)
- Capability taxonomy (P5b-specific guards)
- Lowering strategy (Phase 92 preview)
- Test fixture: Created
- Minimal escape sequence parser
- JSON string with backslash escape
- Loop Canonicalizer extended
- Capability table updated with P5b entries
- Fail-Fast criteria documented
- Implementation checklist added
## Key Findings
### Loop Readiness Matrix
| Category | Count | JoinIR Status |
|----------|-------|--------------|
| Pattern 1 (simple bounded) | 16 | ✅ Ready |
| Pattern 2 (with break) | 1 | ⚠️ Partial |
| **Pattern P5b (escape seq)** | ~3 | ❌ NEW |
| Pattern P5 (guard-bounded) | ~2 | ❌ Deferred |
| Pattern P6 (nested loops) | ~8 | ❌ Deferred |
### Top Candidates
1. **P5b**: json_loader.hako:30 (8 lines, high reuse)
- Effort: 2-3 days (recognition)
- Impact: Unlocks all escape parsers
2. **P5**: mini_vm_core.hako:541 (204 lines, monolithic)
- Effort: 1-2 weeks
- Impact: Major JSON optimization
3. **P6**: seam_inspector.hako:76 (7+ nesting)
- Effort: 2-3 weeks
- Impact: Demonstrates nested composition
## Phase 91 Strategy
**Recognition-only phase** (no lowering in P1):
- Step 1: Design & planning ✅
- Step 2: Canonicalizer implementation (detect_escape_pattern)
- Step 3: Unit tests + parity verification
- Step 4: Lowering deferred to Phase 92
## Files Added
- docs/development/current/main/phases/phase-91/README.md - Full analysis & planning
- docs/development/current/main/design/pattern-p5b-escape-design.md - Technical design
- tools/selfhost/test_pattern5b_escape_minimal.hako - Test fixture
## Files Modified
- docs/development/current/main/design/loop-canonicalizer.md
- Capability table extended with P5b entries
- Pattern P5b full section added
- Implementation checklist updated
## Acceptance Criteria (Phase 91 Step 1)
- ✅ Loop inventory complete (34 loops across 6 files)
- ✅ Pattern P5b design document ready
- ✅ Test fixture created
- ✅ Capability taxonomy extended
- ⏳ Implementation deferred (Step 2+)
## References
- JoinIR Architecture: joinir-architecture-overview.md
- Phase 91 Plan: phases/phase-91/README.md
- P5b Design: design/pattern-p5b-escape-design.md
Next: Implement detect_escape_pattern() recognition in Phase 91 Step 2
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-16 14:22:36 +09:00
26077186aa
docs: Phase 142 P2 Step 3-B design decisions fixed
...
- Pattern5 handles return (not Pattern4) - prevents bloat as parse_*/continue family expands
- ExitMeta expansion NOT needed initially - return ends function, no carrier reconnect needed
- Return payload self-contained within Pattern5 (temporary/direct return, no phi merge)
- ContinueReturn asset reuse: extract consistency checks only (not exit_line machinery)
- Implementation checklist prepared for next session
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-16 14:18:42 +09:00
2674e074b6
feat(joinir): Phase 142 P2 Step 3-A - Pattern4 early return fail-fast
2025-12-16 13:48:30 +09:00
42339ca77f
feat(mir): Phase 143 P1 - Add parse_string pattern to canonicalizer
...
Expand loop canonicalizer to recognize parse_string patterns with both
continue (escape handling) and return (quote found) statements.
## Implementation
### New Pattern Detection (ast_feature_extractor.rs)
- Add `detect_parse_string_pattern()` function
- Support nested continue detection using `has_continue_node()` helper
- Recognize both return and continue in same loop body
- Return ParseStringInfo { carrier_name, delta, body_stmts }
- ~120 lines added
### Canonicalizer Integration (canonicalizer.rs)
- Try parse_string pattern first (most specific)
- Build LoopSkeleton with HeaderCond, Body, Update steps
- Set ExitContract: has_continue=true, has_return=true
- Route to Pattern4Continue (both exits present)
- ~45 lines modified
### Export Chain
- Add re-exports through 7 module levels:
ast_feature_extractor → patterns → joinir → control_flow → builder → mir
- 10 lines total across 7 files
### Unit Test
- Add `test_parse_string_pattern_recognized()` in canonicalizer.rs
- Verify skeleton structure (3+ steps)
- Verify carrier (name="p", delta=1, role=Counter)
- Verify exit contract (continue=true, return=true, break=false)
- Verify routing decision (Pattern4Continue, no missing_caps)
- ~180 lines added
## Target Pattern
`tools/selfhost/test_pattern4_parse_string.hako`
Pattern structure:
- Check for closing quote → return
- Check for escape sequence → continue (nested inside another if)
- Regular character processing → p++
## Results
- ✅ Strict parity green: Pattern4Continue
- ✅ All 19 unit tests pass
- ✅ Nested continue detection working
- ✅ ExitContract correctly set (first pattern with both continue+return)
- ✅ Default behavior unchanged
## Technical Challenges
1. Nested continue detection required recursive search
2. First pattern with both has_continue=true AND has_return=true
3. Variable step updates (p++ vs p+=2) handled with base delta
## Statistics
- New patterns: 1 (parse_string)
- Total patterns: 4 (skip_whitespace, parse_number, continue, parse_string)
- New capabilities: 0 (uses existing ConstStep)
- Lines added: ~300
- Files modified: 9
- Parity status: Green ✅
Phase 143 P1: Complete
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-16 12:37:47 +09:00
d605611a16
feat(canonicalizer): Phase 143-P0 - parse_number pattern support
...
Add parse_number pattern recognition to canonicalizer, expanding adaptation
range for digit collection loops with break in THEN clause.
## Changes
### New Recognizer (ast_feature_extractor.rs)
- `detect_parse_number_pattern()`: Detects `if invalid { break }` pattern
- `ParseNumberInfo`: Struct for extracted pattern info
- ~150 lines added
### Canonicalizer Integration (canonicalizer.rs)
- Parse_number pattern detection before skip_whitespace
- LoopSkeleton construction with 4 steps (Header + Body x2 + Update)
- Routes to Pattern2Break (has_break=true)
- ~60 lines modified
### Export Chain (6 files)
- patterns/mod.rs → joinir/mod.rs → control_flow/mod.rs
- builder.rs → mir/mod.rs
- 8 lines total
### Tests
- `test_parse_number_pattern_recognized()`: Unit test for recognition
- Strict parity verification: GREEN (canonical and router agree)
- ~130 lines added
## Pattern Comparison
| Aspect | Skip Whitespace | Parse Number |
|--------|----------------|--------------|
| Break location | ELSE clause | THEN clause |
| Pattern | `if cond { update } else { break }` | `if invalid { break } rest... update` |
| Body after if | None | Required (result append) |
## Results
- ✅ Skeleton creation successful
- ✅ RoutingDecision matches router (Pattern2Break)
- ✅ Strict parity OK (canonicalizer ↔ router agreement)
- ✅ Unit test PASS
- ✅ Manual test: test_pattern2_parse_number.hako executes correctly
## Statistics
- New patterns: 1 (parse_number)
- Total patterns: 3 (skip_whitespace, parse_number, continue)
- Lines added: ~280
- Files modified: 8
- Parity status: Green ✅
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-16 09:08:37 +09:00
521e58d061
docs: mark loop canonicalizer Phase 137-141 complete
2025-12-16 07:54:33 +09:00
632e495e51
docs(mir): Phase 137-6-S3 - Router委譲の準備コメント追加
...
## 目的
将来の Router → Canonicalizer 委譲に備えた TODO コメント拡充
## 変更内容
### routing.rs の TODO コメント拡充
- 有効化条件を明記(新フラグ or 既存フラグ)
- 注意事項追加(全 Pattern の parity green 必須)
- コード例を追加(将来実装時の参考)
### Phase 137 README 更新
- Phase 137-6(完了)セクション追加
- S1/S2/S3 の実装内容を記録
- 効果と受け入れ基準達成を記録
## 効果
- ✅ 将来の委譲に備えた明確なガイド
- ✅ Phase 137-6 完了記録
- ✅ 既定挙動不変(フラグOFF時)
## Phase 137-6 完了サマリー
### 実装完了内容
- **S1**: choose_pattern_kind SSOT 入口(61行追加)
- **S2**: dev-only parity check 統合(52行追加)
- **S3**: Router 委譲準備コメント(ドキュメント拡充)
### 受け入れ基準
- ✅ strict parity green(skip_whitespace)
- ✅ 既定挙動不変(フラグOFF時)
- ✅ 新 env 追加なし
- ✅ choose_pattern_kind が SSOT 入口として機能
- ✅ 全テスト PASS(退行なし)
### テスト結果
- ✅ `cargo build --release`: 成功
- ✅ スモークテスト(simple_*): 5/5 PASS
- ✅ parity check 動作確認:
```
NYASH_JOINIR_DEV=1 HAKO_JOINIR_STRICT=1 ./target/release/hakorune \
tools/selfhost/test_pattern3_skip_whitespace.hako
→ [choose_pattern_kind/PARITY] OK
```
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-16 07:44:57 +09:00
3026251323
docs(mir): Phase 141-P7-C - Phase 138-141 完了記録
...
## 変更内容
### 追加セクション
- Phase 138(完了): 基盤整備
- Phase 139(完了): 型安全化
- Phase 140(完了): 共通化と統合
- Phase 141(完了): ドキュメント & Cleanup
### 最終成果サマリー
- **コード品質メトリクス表**: 5 つの指標で改善率を明示
- 最大ファイルサイズ: 931行 → 414行(-55%)
- モジュール数: 1個 → 4個(+300%)
- 重複コード: 100行 → 29行(-71%)
- 型安全性: string → enum(✅ )
- 環境変数: 直呼び出し → SSOT(✅ )
- **アーキテクチャ改善リスト**: 5 つの達成項目
- 単一責任の原則
- Capability Guard 型安全化
- Pattern Detection SSOT 化
- Context 統合
- ドキュメント充実
## 効果
- Phase 137-141 の成果を一覧可能
- メトリクスで定量的な改善を可視化
- 次 Phase 着手時の基準点として活用可能
Status: Phase 138-141 完全完了 ✅
2025-12-16 07:24:51 +09:00
5edd81e373
refactor(mir): Phase 138-P1-A - loop_canonicalizer を4モジュール分割
...
## 概要
- 931行の mod.rs を 4モジュール + 161行 mod.rs に分割
- 全14テスト PASS、退行なし
## モジュール構成
- skeleton_types.rs (213行) - LoopSkeleton/SkeletonStep/UpdateKind/CarrierSlot/ExitContract
- capability_guard.rs (104行) - RoutingDecision/capability_tags
- pattern_recognizer.rs (249行) - try_extract_skip_whitespace_pattern
- canonicalizer.rs (414行) - canonicalize_loop_expr + 統合テスト
- mod.rs (161行) - 型定義と re-export
## ファイルサイズ達成
- 最大ファイル: canonicalizer.rs 414行(目標250行を一部超過するが許容範囲)
- mod.rs: 931行 → 161行 (83%削減)
- 合計: 1141行(元の931行 + tests分離で増加)
## テスト結果
- 14 tests passed
- loop_canonicalizer::* 全テスト green
2025-12-16 06:41:46 +09:00
58f66e3fa2
feat(mir): Phase 137-5 - Decision Policy SSOT化完了
...
## 目的
Canonicalizer の RoutingDecision.chosen を「lowerer 選択の最終結果」にする
(構造クラス名ではなく ExitContract ベースの決定)
## 実装内容
### 1. Canonicalizer の決定ロジック修正
- `src/mir/loop_canonicalizer/mod.rs`
- `skip_whitespace` パターン認識で ExitContract (has_break=true) を考慮
- Pattern3IfPhi → Pattern2Break に修正(構造は似ているが break あり)
- 単体テスト更新(Pattern2Break 期待に変更)
### 2. Parity 検証テスト修正
- `src/mir/builder/control_flow/joinir/routing.rs`
- `test_parity_check_mismatch_detected` → `test_parity_check_skip_whitespace_match`
- Canonicalizer と Router の一致を検証(ミスマッチ検出からマッチ検証へ)
- Phase 137-5 の SSOT 原則を反映
### 3. ドキュメント更新
- `docs/development/current/main/design/loop-canonicalizer.md`
- Phase 137-5: Decision Policy SSOT セクション追加
- ExitContract 優先の原則を明記
- skip_whitespace の例を追加
- `docs/development/current/main/phases/phase-137/README.md`
- Phase 4 完了マーク追加
- Phase 5 完了セクション追加(実装・検証・効果)
## 検証結果
- ✅ 単体テスト: `cargo test --release --lib loop_canonicalizer::tests` (11/11 passed)
- ✅ Parity テスト: `cargo test --release --lib 'routing::tests::test_parity'` (2/2 passed)
- ✅ Strict モード: `HAKO_JOINIR_STRICT=1` で skip_whitespace parity OK
## 効果
- Router と Canonicalizer の pattern 選択が一致
- ExitContract が pattern 決定の SSOT として明確化
- 構造的特徴(if-else 等)は notes に記録(将来拡張に備える)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-16 06:17:03 +09:00
9ea15e8417
feat(mir): Loop Canonicalizer Phase 4 - router parity verification
...
## Summary
既存 Router と Canonicalizer の選択が一致することを dev-only で検証。
不一致は理由付き Fail-Fast(strict mode)。
## Changes
- src/mir/builder/control_flow/joinir/routing.rs:
- verify_router_parity() 実装
- cf_loop_joinir_impl でパリティチェック呼び出し
- 2つのユニットテスト追加
- test_parity_check_mismatch_detected
- test_parity_check_match_simple_while
- docs/development/current/main/phases/phase-137/phase-137-4-parity-verification.md:
- Phase 4 完全ドキュメント
## Verification Modes
- Debug mode (HAKO_JOINIR_DEBUG=1): ログのみ
- Strict mode (HAKO_JOINIR_STRICT=1): 不一致でエラー
## Known Mismatch
- skip_whitespace pattern:
- Canonicalizer: Pattern3IfPhi (構造認識)
- Router: Pattern2Break (has_break優先)
- Phase 5+ で分類ルール改善予定
## Tests
- Unit tests: 2 tests PASS
- Integration: skip_whitespace parity mismatch 検出確認
- cargo test --release --lib: 1046/1046 PASS
Phase 137-4 complete
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-16 05:51:57 +09:00
a0009d474d
feat(mir): Loop Canonicalizer Phase 3 - skip_whitespace pattern recognition
...
## Summary
skip_whitespace パターンを Skeleton→Decision で認識可能に。
dev-only 観測で chosen=Pattern3IfPhi / missing_caps=[] を固定。
## Changes
- src/mir/loop_canonicalizer/mod.rs:
- try_extract_skip_whitespace_pattern() 追加
- loop(cond) { ... if check { p = p + 1 } else { break } } パターン認識
- carrier name, delta, body statements を抽出
- canonicalize_loop_expr() 拡張(skip_whitespace 対応)
- Pattern3IfPhi 成功時は RoutingDecision::success 返却
- Skeleton に HeaderCond, Body, Update ステップ追加
- CarrierSlot に Counter role 設定
- ExitContract に has_break=true 設定
- Phase 3 unit tests 追加
- test_skip_whitespace_pattern_recognition: 基本パターン
- test_skip_whitespace_with_body_statements: body 付きパターン
- test_skip_whitespace_fails_without_else: else なし失敗
- test_skip_whitespace_fails_with_wrong_delta: 減算パターン失敗
- Phase 2 obsolete tests 削除
- src/mir/builder/control_flow/joinir/routing.rs:
- Debug 出力拡張(chosen pattern 表示)
## Tests
- cargo test --release --lib loop_canonicalizer::tests: PASS(11 tests)
- cargo test --release --lib: PASS(1044 tests, 退行なし)
- HAKO_JOINIR_DEBUG=1 test_pattern3_skip_whitespace.hako:
- chosen=Pattern3IfPhi ✅
- missing_caps=[] ✅
## Validation
- ✅ dev-only 観測(HAKO_JOINIR_DEBUG=1)のときだけログ出力
- ✅ フラグ OFF 時は完全不変
- ✅ skip_whitespace パターンで SUCCESS 固定
- ✅ unit tests で全パターン固定
Phase 137-3 complete
2025-12-16 05:38:18 +09:00
ec1ff5b766
docs: update Phase 137-1 completion status and Phase 2 roadmap
...
## Summary
Loop Canonicalizer Phase 1(型定義)の完了と、Phase 2(dev-only 観測)への
ロードマップを記録。
## Changes
### loop-canonicalizer.md
- Status: Design (P0) → Phase 1 done(型定義まで)
- 実装の入口を明記(src/mir/loop_canonicalizer/mod.rs)
- NYASH_LOOP_ROUTING_TRACE → joinir_dev_enabled() に変更
(新 ENV を増やさず、既存のスイッチに寄せる)
### CURRENT_TASK.md
- Phase 137-1 完了を追記
- P0 を「設計」→「Phase 2(dev-only 観測)」へ更新
### phases/README.md
- Phase 137 を追加
### phases/phase-137/README.md (NEW)
- Phase 1 完了サマリ
- Phase 2 予定を最小で記録
### joinir-design-map.md / 01-JoinIR-Selfhost-INDEX.md
- loop-canonicalizer への導線を追加
## Next Steps
Phase 2: dev-only 観測の導入
- canonicalize_loop_expr() の薄い入口を追加
- joinir_dev_enabled() 配下でログ出し
- 既定挙動は完全不変
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-16 05:10:29 +09:00
84ded8ca6c
docs: add loop canonicalizer SSOT + MirBuilder entrypoint
2025-12-16 04:37:47 +09:00
905a2b97fe
refactor(mir): Extract CompilationContext from MirBuilder (Phase 136 follow-up 7/7)
...
## Summary
Extracted compilation-related fields into dedicated CompilationContext struct,
completing all 7 steps of the Context Box refactoring plan. This is the final
major context extraction, consolidating 15 compilation-specific fields.
## Changes
- NEW: src/mir/builder/compilation_context.rs (435 lines, 15 fields)
- Modified: src/mir/builder.rs (added compilation_ctx field + sync helpers)
- Updated: phase-136-context-box-progress.md (7/7 complete)
- Created: step-7-compilation-context-summary.md (detailed documentation)
## Extracted Fields (15 total)
- compilation_context - Box compilation context
- current_static_box - Currently compiling static box name
- user_defined_boxes - User-defined box registry
- reserved_value_ids - Reserved ValueIds (for PHI nodes)
- fn_body_ast - Function body AST (for capture analysis)
- weak_fields_by_box - Weak field registry
- property_getters_by_box - Property getter registry
- field_origin_class - Field origin tracking
- field_origin_by_box - Class-level origin
- static_method_index - Static method index
- method_tail_index - Method tail fast lookup
- method_tail_index_source_len - Source size snapshot
- type_registry - Unified type information
- current_slot_registry - Function-scope SlotRegistry
- plugin_method_sigs - Plugin method signatures
## Tests
- cargo test --release --lib: 1029/1033 passed (4 pre-existing failures)
- phase135_trim_mir_verify.sh: PASS
- Backward compatibility: 100% maintained (deprecated fields synced)
## Phase 136 Context Extraction: Complete! ✅
Total: 7 contexts, 36 fields extracted, 1086 lines of new modules
- ✅ Step 1: TypeContext (3 fields, 130 lines)
- ✅ Step 2: CoreContext (5 fields, 112 lines)
- ✅ Step 3: ScopeContext (7 fields, 141 lines)
- ✅ Step 4: BindingContext (1 field, 63 lines)
- ✅ Step 5: VariableContext (1 field, 85 lines)
- ✅ Step 6: MetadataContext (4 fields, 120 lines)
- ✅ Step 7: CompilationContext (15 fields, 435 lines)
## Next Phase: Legacy Field Removal
Phase 2 will remove all 36 deprecated fields from MirBuilder,
eliminating 469 deprecation warnings and reducing builder.rs from
1472 → ~800-900 lines (500-600 line reduction).
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-15 22:17:38 +09:00
1adf57ec54
refactor(mir): Extract BindingContext from MirBuilder (Phase 136 follow-up 4/7)
...
## Summary
Extracted binding management into dedicated BindingContext struct,
completing step 4 of 7 in the Context Box refactoring plan.
## Changes
- NEW: src/mir/builder/binding_context.rs (BindingContext struct + helpers)
- Modified 7 files to use binding_ctx (SSOT pattern with legacy sync)
- Added comprehensive unit tests for BindingContext
## Extracted Fields
- binding_map: BTreeMap<String, BindingId> → binding_ctx.binding_map
## Benefits
- Clear separation: BindingId mapping isolated from MirBuilder
- Better testability: BindingContext can be tested independently
- Consistent pattern: Same SSOT + legacy sync approach as previous steps
## Tests
- cargo test --release --lib: 1008/1008 passed
- phase135_trim_mir_verify.sh: PASS
- Backward compatibility: 100% maintained (deprecated fields synced)
## Progress
Phase 136 Context Extraction: 4/7 complete (57%)
- ✅ Step 1: TypeContext
- ✅ Step 2: CoreContext
- ✅ Step 3: ScopeContext
- ✅ Step 4: BindingContext (this commit)
- ⏳ Step 5: VariableContext
- ⏳ Step 6: MetadataContext
- ⏳ Step 7: RegionContext
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-15 20:40:23 +09:00
455d511187
feat(mir): Phase 136 P0 - ValueId allocator SSOT 徹底(関数内経路から value_gen.next() 掃討)
...
## Summary
Eliminates remaining `value_gen.next()` calls from function-context code paths,
unifying all ValueId allocation through `MirBuilder::next_value_id()` SSOT allocator.
## Changes
### 1. Fixed `new_typed_value()` (src/mir/builder.rs:1068)
**Before**: `let id = self.value_gen.next();` (bypasses function context)
**After**: `let id = self.next_value_id();` (respects function context)
This is a public API used in function context, so must use SSOT allocator
to avoid collisions with reserved PHI dsts and function params.
### 2. Fixed test code (src/mir/builder.rs)
**test_shadowing_binding_restore** (lines 1161, 1171):
- Simulates function scope with `push_lexical_scope()`
- Changed to `builder.next_value_id()` for function scope simulation
**test_valueid_binding_parallel_allocation** (lines 1196-1216):
- Tests ValueId/BindingId independence
- Changed to `builder.next_value_id()` with note that Module context fallback preserves test intent
### 3. Verified Module context fallbacks (OK, no change needed)
These already check `current_function.is_some()` and use `value_gen.next()` only as Module context fallback:
- `src/mir/builder/utils.rs:43` - next_value_id() SSOT implementation
- `src/mir/builder/utils.rs:436` - pin_to_slot()
- `src/mir/builder/utils.rs:467` - materialize_local()
- `src/mir/utils/phi_helpers.rs:69` - insert_phi_unified()
## Verification
```bash
rg -n "value_gen\.next\(" src/mir --type rust | grep -v "Module context" | grep -v "//"
# Result: Only comments/docs remain
```
## Acceptance
✅ cargo test --release --lib - 997 passed
✅ phase135_trim_mir_verify.sh - PASS
✅ phase132_exit_phi_parity.sh - 3/3 PASS
✅ All function-context `value_gen.next()` eliminated
## Effect
- **Collision prevention**: No more ValueId collisions between function-level allocations and reserved PHI dsts
- **SSOT compliance**: All ValueId allocation flows through single allocator
- **Contract enforcement**: Phase 135 P1 contract_checks will catch violations immediately
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-15 19:37:30 +09:00
22b0c14adb
feat(joinir): Phase 135 P1 - Contract checks Fail-Fast (二度と破れない設計)
...
## Summary
Adds early Fail-Fast contract verification to prevent Phase 135 P0 issues from recurring.
Two new verifiers catch allocator SSOT violations and boundary inconsistencies before --verify.
## Changes
### Step 1: verify_condition_bindings_consistent
**Location**: `src/mir/builder/control_flow/joinir/merge/contract_checks.rs`
**Contract**: condition_bindings can have aliases (multiple names for same join_value),
but same join_value with different host_value is a violation.
**Example Error**:
```
[JoinIRVerifier/Phase135-P1] condition_bindings conflict:
join_value ValueId(104) mapped to both ValueId(12) and ValueId(18)
```
**Catches**: ConditionLoweringBox bypassing SSOT allocator before BoundaryInjector
### Step 2: verify_header_phi_dsts_not_redefined
**Location**: `src/mir/builder/control_flow/joinir/merge/contract_checks.rs`
**Contract**: Loop header PHI dst ValueIds must not be reused as dst in non-PHI instructions.
Violation breaks MIR SSA (PHI dst overwrite).
**Example Error**:
```
[JoinIRVerifier/Phase135-P1] Header PHI dst ValueId(14) redefined by non-PHI instruction in block 3:
Instruction: Call { dst: Some(ValueId(14)), ... }
```
**Catches**: ValueId collisions between header PHI dsts and lowered instructions
### Integration
**Location**: `src/mir/builder/control_flow/joinir/merge/mod.rs`
Added to `verify_joinir_contracts()`:
1. Step 1 runs before merge (validates boundary)
2. Step 2 runs after merge (validates func with PHI dst set)
### Documentation
- Updated `phase135_trim_mir_verify.sh` - Added P1 contract_checks description
- Updated `phase-135/README.md` - Added P1 section with contract details and effects
## Acceptance
✅ Build: SUCCESS
✅ Smoke: phase135_trim_mir_verify.sh - PASS
✅ Regression: phase132_exit_phi_parity.sh - 3/3 PASS
✅ Regression: phase133_json_skip_whitespace_llvm_exe.sh - PASS
## Effect
- **Prevention**: Future Box implementations catch SSOT violations immediately
- **Explicit Errors**: Phase 135-specific messages instead of generic --verify failures
- **Unbreakable**: Debug builds always detect violations, enforced by CI/CD
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-15 19:25:33 +09:00
d82c332a40
feat(joinir): Phase 135 P0 - ConditionLoweringBox allocator SSOT (ValueId collision fix)
...
## Summary
Root cause: ConditionLoweringBox was bypassing ConditionContext.alloc_value (SSOT allocator),
causing ValueId collisions between JoinIR condition params and lowered instructions.
## Changes
1. **ConditionLoweringBox (expr_lowerer.rs)**: Must use ConditionContext.alloc_value
- Pass &mut ConditionContext to lower_condition (SSOT allocator)
- Eliminates internal counter usage
2. **Allocator unification (condition_lowerer.rs, method_call_lowerer.rs)**:
- Accept &mut dyn FnMut() -> ValueId as allocator parameter
- Ensures all lowering paths use same SSOT allocator
3. **Boundary Copy deduplication (joinir_inline_boundary_injector.rs)**:
- Deduplicate condition_bindings by dst
- Fail-Fast if different sources target same dst (MIR SSA violation)
4. **Trim pattern fixes (trim_loop_lowering.rs, trim_pattern_validator.rs, stmts.rs)**:
- Use builder.next_value_id() instead of value_gen.next() in function context
- Ensures function-level ValueId allocation respects reserved PHI dsts
## Acceptance
✅ ./target/release/hakorune --verify apps/tests/phase133_json_skip_whitespace_min.hako
✅ Smoke: phase135_trim_mir_verify.sh - MIR SSA validation PASS
✅ Regression: phase132_exit_phi_parity.sh - 3/3 PASS
✅ Regression: phase133_json_skip_whitespace_llvm_exe.sh - compile-only PASS
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-15 18:49:08 +09:00
e8e4779942
feat(plugin): Phase 134 P1 - Core box strict guard (SSOT in plugin_guard.rs)
2025-12-15 17:49:08 +09:00
06bfb1eb31
test(docs): Phase 133 smoke is compile-only (--dump-mir)
2025-12-15 16:57:28 +09:00
f5c1694d44
docs: Phase 133 P1 - Mark as Done (Trim promoted_pairs SSOT fix complete)
2025-12-15 13:03:44 +09:00
7b675a6a27
docs: Phase 133 P0 - Promoted carrier join_id summary (JsonParser pattern)
2025-12-15 12:36:46 +09:00
aad01a1079
feat(llvm): Phase 132-P2 - Dict ctx removal (FunctionLowerContext SSOT completion)
...
Completed SSOT unification for FunctionLowerContext by removing the manual
dict ctx creation and assignment in function_lower.py.
Changes:
- Removed builder.ctx = dict(...) creation (18 lines, lines 313-330)
- Removed builder.resolver.ctx assignment (no longer needed)
- Confirmed instruction_lower.py uses context=owner.context throughout
- Added phase132_multifunc_isolation_min.hako test for multi-function isolation
- Extended phase132_exit_phi_parity.sh with Case C (Rust VM context test)
Testing:
- Phase 132 smoke test: All 3 cases PASS
- Phase 87 LLVM exe test: PASS (Result: 42)
- STRICT mode: PASS
- No regressions: Behavior identical before/after (RC:6 maintained)
Impact:
- Reduced manual context management complexity
- FunctionLowerContext now sole source of truth (SSOT)
- Per-function state properly isolated, no cross-function collisions
- Cleaner architecture: context parameter passed explicitly vs manual dict
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-15 12:12:54 +09:00
a15d1e97e6
refactor(llvm): Phase 132-P1 follow-up - bind block_end_values and clear predeclared PHIs
2025-12-15 11:47:58 +09:00
c8970bd4d4
docs: Phase 132-P3 verifier note
2025-12-15 06:08:19 +09:00
771bf6b0d1
feat(joinir): Phase 132-P3 - Exit PHI collision early detection
...
Added verify_exit_phi_no_collision() to contract_checks.rs for early detection
of ValueId collisions between exit PHIs and other instructions.
Problem detected:
- If exit_phi_builder uses builder.value_gen.next() (module-level) instead of
func.next_value_id() (function-level), ValueIds can collide:
Example:
- bb0: %1 = const 0 (counter init)
- bb3: %1 = phi ... (exit PHI - collision!)
Previous behavior:
- Error only detected at LLVM backend runtime
- Cryptic error: "Cannot overwrite PHI dst=1"
New behavior:
- Panic at Rust compile time (debug build)
- Clear error message with fix suggestion:
"Exit PHI dst %1 collides with instruction in block 0
Fix: Use func.next_value_id() in exit_phi_builder.rs"
Benefits:
- 🔥 Fail-Fast: Catch errors during Rust compilation, not LLVM execution
- 📋 Clear messages: Exact collision point + fix suggestion
- 🧪 Testable: verify_exit_phi_no_collision() can be unit tested
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-15 06:00:48 +09:00
447d4ea246
feat(llvm): Phase 132 - Pattern 1 exit value parity fix + Box-First refactoring
...
## Phase 132: Exit PHI Value Parity Fix
### Problem
Pattern 1 (Simple While) returned 0 instead of final loop variable value (3)
- VM: RC: 3 ✅ (correct)
- LLVM: Result: 0 ❌ (wrong)
### Root Cause (Two Layers)
1. **JoinIR/Boundary**: Missing exit_bindings → ExitLineReconnector not firing
2. **LLVM Python**: block_end_values snapshot dropping PHI values
### Fix
**JoinIR** (simple_while_minimal.rs):
- Jump(k_exit, [i_param]) passes exit value
**Boundary** (pattern1_minimal.rs):
- Added LoopExitBinding with carrier_name="i", role=LoopState
- Enables ExitLineReconnector to update variable_map
**LLVM** (block_lower.py):
- Use predeclared_ret_phis for reliable PHI filtering
- Protect builder.vmap PHIs from overwrites (SSOT principle)
### Result
- ✅ VM: RC: 3
- ✅ LLVM: Result: 3
- ✅ VM/LLVM parity achieved
## Phase 132-Post: Box-First Refactoring
### Rust Side
**JoinModule::require_function()** (mod.rs):
- Encapsulate function search logic
- 10 lines → 1 line (90% reduction)
- Reusable for Pattern 2-5
### Python Side
**PhiManager Box** (phi_manager.py - new):
- Centralized PHI lifecycle management
- 47 lines → 8 lines (83% reduction)
- SSOT: builder.vmap owns PHIs
- Fail-Fast: No silent overwrites
**Integration**:
- LLVMBuilder: Added phi_manager
- block_lower.py: Delegated to PhiManager
- tagging.py: Register PHIs with manager
### Documentation
**New Files**:
- docs/development/architecture/exit-phi-design.md
- docs/development/current/main/investigations/phase132-llvm-exit-phi-wrong-result.md
- docs/development/current/main/phases/phase-132/
**Updated**:
- docs/development/current/main/10-Now.md
- docs/development/current/main/phase131-3-llvm-lowering-inventory.md
### Design Principles
- Box-First: Logic encapsulated in classes/methods
- SSOT: Single Source of Truth (builder.vmap for PHIs)
- Fail-Fast: Early explicit failures, no fallbacks
- Separation of Concerns: 3-layer architecture
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-15 03:17:31 +09:00