Commit Graph

2487 Commits

Author SHA1 Message Date
a2c5fd90fe feat(joinir): Phase 188.3 - Pattern6 (NestedLoopMinimal) 選択ロジック実装
## Phase 188.3 進捗: Phase 2 完了 (6/13 tasks)

### 実装完了 

**Phase 1: Fixture作成**
- apps/tests/phase1883_nested_minimal.hako 追加
  - Add/Compare のみ(乗算なし)
  - 期待 exit code: 9 (3×3 nested loops)
- 既存 lowering で fallback 動作確認

**Phase 2: 選択ロジック (SSOT)**
- LoopPatternContext に step_tree_max_loop_depth フィールド追加
- choose_pattern_kind() に Pattern6 選択ロジック実装:
  1. Cheap check (has_inner_loop)
  2. StepTree 構築 (max_loop_depth 取得)
  3. AST validation (is_pattern6_lowerable)
- pattern6_nested_minimal.rs モジュール作成 (stub)
- LOOP_PATTERNS に Pattern6 entry 追加
- **検証**: Pattern6 が正しく選択される 

### 設計原則 (確認済み)

1. **Fail-Fast**: Pattern6 選択後は Ok(None) で逃げない
2. **outer 変数 write-back 検出 → validation false** (Phase 188.4+)
3. **最小実装**: inner local だけ、Pattern1 モデル二重化
4. **cfg! 依存なし**: production で動作

### 検証結果

```
[choose_pattern_kind] has_inner_loop=true
[choose_pattern_kind] max_loop_depth=2
[choose_pattern_kind] is_pattern6_lowerable=true
 Pattern6 SELECTED!
```

Stub からの期待エラー:
```
[ERROR]  [Pattern6] Nested loop lowering not yet implemented
```

### 次: Phase 3 (Lowering 実装 - 推定4時間)

残りタスク:
- Phase 3-1: AST 抽出ヘルパー
- Phase 3-2: Validation ヘルパー
- Phase 3-3: Continuation 生成 (outer_step, inner_step, k_inner_exit)
- Phase 3-4: fixture が exit=9 を返すことを検証

### 変更ファイル

**新規**:
- apps/tests/phase1883_nested_minimal.hako
- src/mir/builder/control_flow/joinir/patterns/pattern6_nested_minimal.rs
- docs/development/current/main/phases/phase-188.{1,2,3}/README.md

**変更**:
- src/mir/builder/control_flow/joinir/routing.rs (Pattern6 選択)
- src/mir/builder/control_flow/joinir/patterns/router.rs (Context 拡張)
- src/mir/builder/control_flow/joinir/patterns/mod.rs (module 宣言)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 05:45:12 +09:00
229553f7a4 refactor(nyrt): consolidate ny_release_strong into lifecycle module
Phase 29y.1 cleanup: Eliminate duplicate ny_release_strong implementation.

Changes:
- Remove duplicate ny_release_strong from lib.rs (11 lines)
- Consolidate into ffi/lifecycle.rs (rename shim → legacy name)
- Maintain backward compatibility with existing LLVM lowering

Verification:
- quick: 154/154 PASS
- integration phase29y: 2/2 PASS

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 02:15:13 +09:00
26a739189d docs(phase-29y): note pilot plumbing completion in Now/Backlog 2025-12-27 02:07:54 +09:00
2e99b14e24 phase-29y.1: add lifecycle pilot plumbing (ABI shim, rc pass skeleton, root summary) 2025-12-27 02:07:10 +09:00
8a5218a9ad docs(phase-29y): add ABI/RC-insertion/observability SSOT stubs 2025-12-27 01:11:36 +09:00
47493b95ce docs(mir): document KeepAlive/ReleaseStrong lifecycle directives 2025-12-27 01:07:46 +09:00
348b19f42d docs(phase-29y): self-contained consult packet + entry 2025-12-27 01:03:24 +09:00
ba1fc21375 docs(phase-29y): tighten lifecycle vocab consult packet 2025-12-27 00:38:21 +09:00
64bc2746df docs(phase-285): add ret.py boxification appendix 2025-12-27 00:36:32 +09:00
bd0783fa85 docs(phase-285): Complete P4 Post-Completion documentation
Phase 285 P4 Post-Completion activities (2025-12-27):

1. Phase 284 P2 Integration Fix (commit 225600b5f)
   - Fixed phase284_p2_return_in_loop_llvm (unreachable instruction)
   - Integration LLVM tests: 3/3 PASS (no FAIL remaining)

2. ret.py Box-First Refactoring (commits 32aa0ddf6, 5a88c4eb2)
   - Phase 1-2: UnreachableReturnHandlerBox + ReturnTypeAdjusterBox
   - Phase 3: StringBoxerBox + ReturnPhiSynthesizerBox
   - Reduced lower_return(): 166→117 lines (-29%)

3. Code Quality Improvements (4 commits)
   - LLVM exit code SSOT (d7c6df367)
   - nyash_kernel FFI split (798c193cb)
   - LLVM detection consolidation (1869396fd)
   - auto_detect.conf clarity (095213c58)

Final status:
- Integration LLVM tests: 3/3 PASS
- Quick profile: 154/154 PASS
- Current Focus: Phase 29y (post self-host, docs-first)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 00:31:29 +09:00
095213c580 refactor(smoke): Clarify auto_detect.conf responsibilities with profile parameter
**Problem**:
- detect_optimal_config() took no arguments (line 11)
- Quick profile SSOT forcing scattered outside function (line 134-137)
- Profile-specific logic split between detect_optimal_config() and auto_configure()
- Hard to understand flow: "why is this logic duplicated?"

**Solution** (Task 4 - Low Priority):
- Accept profile parameter: `detect_optimal_config(profile)`
- Move quick profile SSOT forcing inside function (top priority)
- Eliminate duplicate logic in auto_configure()
- Update show_auto_config() to pass profile parameter

**Changes**:
- detect_optimal_config(): Add `local profile="${1:-quick}"`
- Quick SSOT check: Move to function top (early return)
- auto_configure(): Pass `"$profile"` to detect_optimal_config
- show_auto_config(): Pass `"${SMOKES_CURRENT_PROFILE:-quick}"`
- Remove 6 lines of duplicate quick forcing logic

**Benefits**:
- Single responsibility: Profile logic inside detect_optimal_config
- Clearer flow: All detection in one function
- Maintainability: One place to modify profile behavior
- Readability: Intent is explicit (profile parameter)

**Verification**:
-  detect_optimal_config "quick": returns rust_vm_dynamic (SSOT)
-  detect_optimal_config "integration": returns llvm_static
-  Quick profile: 154/154 PASS

**Note**: This is a low-impact refactoring (code organization only)
- Behavior unchanged (same logic, better location)
- No performance impact
- Future-proof for profile-specific detection

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 17:32:48 +09:00
1869396fd7 refactor(smoke): Consolidate LLVM detection to can_run_llvm() SSOT
**Problem**:
- LLVM availability check scattered across 9+ test files
- Duplicate grep patterns: `--version | grep -q "features.*llvm"`
- Hard to maintain when detection logic changes
- Potential SKIP hell when conditions diverge

**Solution** (Task 3 - Medium Priority):
- Create `can_run_llvm()` function in test_runner.sh (SSOT)
- Consolidate both detection methods:
  1. Primary: `--version | grep features.*llvm`
  2. Fallback: `strings | grep ny-llvmc|NYASH_LLVM_USE_HARNESS`
- Replace all inline checks with function call

**Files Changed**:
- test_runner.sh: Add can_run_llvm() + update run_nyash_llvm()
- 9 test files: Replace inline grep with can_run_llvm()
  - quick: phase285_weak_basic_llvm.sh
  - integration: phase284/285, json_{lint,pp,query}, parity tests

**Benefits**:
- Single point of maintenance (SSOT)
- Consistent LLVM detection across all tests
- Easy to extend (e.g., add Python llvmlite check)
- Prevents future SKIP divergence

**Verification**:
-  phase284_p2_return_in_loop_llvm: PASS
-  phase285_weak_basic_llvm: PASS
-  Quick profile: 154/154 PASS

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 17:31:19 +09:00
798c193cbe refactor(kernel): Extract weak reference FFI to ffi/weak.rs module
**Problem**:
- nyash_kernel/src/lib.rs is 1295 lines (monolithic FFI functions)
- Hard to navigate and maintain
- No clear module boundaries

**Solution** (Task 2 - Medium Priority):
- Create `ffi/` module structure
- Extract weak reference functions to `ffi/weak.rs` (74 lines)
  - nyrt_weak_new
  - nyrt_weak_to_strong
  - nyrt_weak_drop
- lib.rs: 1295 → 1221 lines (-74 lines, -5.7%)
- Re-export via `pub use ffi::weak::*` for ABI compatibility

**Architecture**:
- Box-First: Clear module boundaries (SSOT for weak refs)
- Reversible: Can merge back if needed (small, safe step)
- ABI stable: #[no_mangle] exports preserved

**Verification**:
-  Build successful (cargo build -p nyash_kernel)
-  phase285_p2_weak_upgrade_success_llvm: PASS
-  phase285_p2_weak_upgrade_fail_llvm: PASS
-  Quick profile: 154/154 PASS

**Next steps** (deferred to future):
- Extract string FFI (~11 functions)
- Extract memory management FFI
- Extract box operations FFI

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 17:29:15 +09:00
d7c6df3675 refactor(smoke): Phase 284 P2 - LLVM harness exit code SSOT
**Problem**:
- phase284_p2_return_in_loop_llvm.sh used fallback: exit code OR output grep
- Inconsistent with exit code SSOT policy for LLVM harness tests
- Output pollution from harness logs makes grep unreliable

**Solution** (Task 1 - High Priority):
- Remove `|| echo "$OUTPUT" | grep -qE "(^7$|RC: 7$)"` fallback
- Pure exit code validation: `if [ "$EXIT_CODE" -eq 7 ]`
- OUTPUT kept for error debugging only (line 40)
- Align with phase285_p2 tests (already using exit code SSOT)

**Verification**:
-  phase284_p2_return_in_loop_llvm: PASS (exit 7)
-  phase285_p2_weak_upgrade_success_llvm: PASS (exit 2)
-  phase285_p2_weak_upgrade_fail_llvm: PASS (exit 1)
-  Quick profile: 154/154 PASS

**Impact**:
- 1 file changed, 5 lines modified
- More reliable LLVM test validation
- No regression in existing tests

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 17:25:25 +09:00
5a88c4eb23 refactor(llvm-py): Phase 3 boxification - Strategic extraction
Extract complex logic while keeping simple parts inline:

1. StringBoxerBox (15 lines)
   - Box string pointers (i8*) to handles (i64)
   - Eliminate function declaration boilerplate
   - Clear single responsibility

2. ReturnPhiSynthesizerBox (101 lines)
   - Synthesize PHI nodes for return values
   - should_synthesize_phi(): Zero-like detection
   - synthesize_phi(): PHI creation with predecessors
   - Respects _disable_phi_synthesis flag

What was NOT boxified (good decisions):
- Fast path vmap lookup (13 lines): Too simple
- Global vmap fallback (7 lines): Too small
- Default value generation (18 lines): Clear as-is

Impact:
- lower_return(): 166→117 lines (-29% reduction)
- File size: 250→352 lines (+102 for organization)
- Testable units: 2→4 (+2 new Boxes)

Tests:
- phase286_pattern5_return_min.hako: PASS (exit 7)
- phase284_p1_return_in_loop_llvm.sh: PASS
- phase284_p2_return_in_loop_llvm.sh: PASS

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 17:12:34 +09:00
32aa0ddf69 refactor(llvm-py): Box-First refactoring of ret.py (Phase 1-2)
Extract two responsibility Boxes following Box-First principle:

1. UnreachableReturnHandlerBox (Phase 1)
   - Handle unreachable block returns with Fail-Fast principle
   - Implements Phase 284-P2 unreachable semantics
   - Moved os/sys imports to file header

2. ReturnTypeAdjusterBox (Phase 2)
   - Handle ptr↔int conversion and int width adjustment
   - Isolate type coercion logic for LLVM compatibility
   - Support truncate/extend for integer width mismatches

Changes:
- File size: 205→249 lines (+21% for better organization)
- Reduced lower_return() complexity
- Preserved all Phase 284-P2 comments and semantics
- No breaking changes

Tests:
- phase286_pattern5_return_min.hako: PASS (exit 7)
- phase284_p2_return_in_loop_llvm.sh: PASS
- Quick profile: 154/154 PASS

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 17:04:42 +09:00
225600b5f9 fix(llvm): Phase 284 P2 - Use unreachable for null returns (Fail-Fast)
MIR generates unreachable blocks with null return values (e.g., after loop(true)).
LLVM type-checks ALL blocks, so we must match function signatures.

Solution: Use builder.unreachable() instead of ret void for non-void functions.
- Type-safe: Satisfies LLVM type checker without return value
- Fail-Fast: Immediate crash if "unreachable" block is executed
- No silent failures

Test results:
 phase284_p2_return_in_loop_llvm: PASS (integration)
 phase285_p2_weak_upgrade_success_llvm: PASS (already passing)
 quick 154/154: PASS (no regression)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 16:58:06 +09:00
606e236d6d fix(phase-285): restore weak_basic_llvm + complete LLVM detection/quick SSOT 2025-12-26 16:32:37 +09:00
ce2baa0d47 feat(llvm): Phase 285 P3 - KeepAlive/ReleaseStrong LLVM implementation
Phase 285 P3: LLVM One-Pass (VM/LLVM一気通貫の最小ゲート)

## 実装内容

### 1. LLVM Backend (Python)
- src/llvm_py/instructions/lifecycle.py: NEW
  - lower_keepalive(): no-op (DCE/liveness only)
  - lower_release_strong(): ny_release_strong() 呼び出し
- src/llvm_py/builders/instruction_lower.py:
  - KeepAlive/ReleaseStrong ディスパッチエントリ追加

### 2. Runtime (Rust)
- crates/nyash_kernel/src/lib.rs:
  - ny_release_strong(handle: i64): handles::drop() 呼び出し
  - Phase 287対応(変数上書きセマンティクス)

### 3. MIR JSON Serialization
- src/runner/mir_json_emit.rs:
  - KeepAlive/ReleaseStrong JSON emit 追加(両関数)
  - {"op":"keepalive","values":[...]}
  - {"op":"release_strong","values":[...]}

## テスト結果

 **phase285_p2_weak_upgrade_fail_llvm**: PASS (exit 1, weak_to_strong null)
⏸️ **phase285_p2_weak_upgrade_success_llvm**: SKIP (--version に features 表示なし)
⏸️ **phase284_p2_return_in_loop_llvm**: SKIP (同上)

## SKIP理由(--version feature表示問題)

テストスクリプトが `--version | grep "features.*llvm"` で環境チェックするが、
現在の --version は "nyash 1.0" のみ出力。LLVM feature有効でも SKIP される。

**対応方針**: Phase 285 P3 目的(KeepAlive/ReleaseStrong LLVM実装)達成。
--version feature表示は Phase 286以降で対応予定。

## 検証

- cargo build --release --features llvm: OK
- weak_upgrade_fail_llvm: PASS (VM/LLVM parity確認)
- quick gate: 154/154 PASS (退行なし)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 14:34:05 +09:00
72552cddfb docs(phase-285): add P3 LLVM one-pass instructions 2025-12-26 14:21:12 +09:00
fbd9c83b62 docs: reflect Phase 285 P2.2 completion (KeepAlive/ReleaseStrong) 2025-12-26 14:17:19 +09:00
3bb865c6b0 refactor(mir): Separate KeepAlive/ReleaseStrong instructions (Phase 287)
Phase 287: KeepAlive/ReleaseStrong 命令分離

## 変更内容(2つの側面)

### 1. 命令セマンティクスの分離
- KeepAlive { values, drop_after: bool } を2命令に分離
  - KeepAlive { values }: スコープ終了での生存維持(PURE)
  - ReleaseStrong { values }: 変数上書き時の強参照解放(WRITE)
- 効果分析の明確化: PURE vs WRITE の境界確定

### 2. VM実行サポート
- handlers/mod.rs: KeepAlive → 完全 no-op
- handlers/mod.rs: ReleaseStrong → release_strong_refs() 呼び出し
- handlers/lifecycle.rs: handle_keepalive() 削除

## 影響範囲
- 10 ファイル修正(31箇所の出現を全変換)
- instruction.rs, builder.rs, lexical_scope.rs, methods.rs,
  display.rs, printer_helpers.rs, query.rs, joinir_id_remapper.rs,
  handlers/mod.rs, handlers/lifecycle.rs

## 検証
- 154/154 quick smoke PASS
- weak テスト回帰なし(weak_upgrade_fail, weak_basic)
- rg -n drop_after src → 0 件(完全除去確認)
- MIRダンプで release_strong/keepalive 正常表示

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 14:12:58 +09:00
f74ff6116c refactor(lifecycle): Phase 285 P2.1 hygiene - lifecycle.rs 箱化完了
責務分離により KeepAlive 処理を handlers/lifecycle.rs に隔離:
- handlers/lifecycle.rs 新規作成(47行)
  - handle_keepalive() で drop_after 判定
  - release_strong_refs() で Arc 同一性探索を集約
  - HashSet による O(1) 検索最適化
- handlers/mod.rs を dispatch 専用化(49行削除→1行呼び出し)
- README.md に P2.1 完了状態を記載(SKIP→PASS)
- phase-29y 将来設計相談パケット追加(NyRT ABI/RC insertion pass)

Test: 154/154 PASS 

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 13:36:17 +09:00
3bf0dee2b0 feat(mir): Phase 285 P2.1 - KeepAlive instruction for weak ref semantics
Add KeepAlive instruction to fix hidden root problem where x = null
doesn't properly drop the strong reference.

Key changes:
- Add KeepAlive { values, drop_after } instruction to MIR
- Emit KeepAlive[drop=true] in build_assignment() before variable overwrite
- Emit KeepAlive[drop=false] in pop_lexical_scope() at scope end
- VM handler: when drop_after=true, remove ALL ValueIds pointing to
  the same Arc (handles SSA Copy chains)

Test results:
- weak_upgrade_fail: exit 1  (weak_to_strong returns null after x=null)
- weak_basic: exit 2  (weak_to_strong succeeds while x alive)
- quick smoke: 154/154 PASS 

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 13:08:32 +09:00
58ceb3de2f feat(smoke): Phase 285 P2 - weak conformance smokes (success pattern)
Phase 285 P2: weak の意味論(weak <expr> + weak_to_strong() 成功/失敗)を integration smoke で固定

実装内容:
- Fixture A(成功パターン): exit 0 → exit 2 に変更(fail=1, success=2 で明確化)
- Fixture B(失敗パターン): 明示 drop (x = null) 方式で作成
- VM smoke success: PASS
- LLVM smoke success: SKIP(backend unavailable)
- VM/LLVM smoke fail: SKIP(hidden root 問題で理由付き)

既知の問題:
- x = null で明示 drop しても weak_to_strong が成功(hidden root が strong ref を保持)
- Phase 285 P2.1 (investigation) で root 保持箇所を棚卸し予定

スコープ:
- Block scope drop conformance は別タスク(未整合の可能性あり)
- P2 では明示 drop 方式で weak の最小意味論(non-owning)のみを検証

検証:
- quick smoke 154/154 PASS 維持
- integration smoke 4本(success 2本 PASS/SKIP、fail 2本 SKIP)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 11:33:12 +09:00
b7f14e38d7 docs(lifecycle): Phase 285 P1 - Box lifecycle 実装棚卸し完了
## Rust VM 実装棚卸し(11項目)
- WeakBox 生成/観測/真実値判定: value.rs
- weak_to_strong: upgrade_weak() 失敗時 Void
- Finalizer: finalization.rs (scope レベル、InstanceBox 限定)
- Scope 追跡: scope_tracker.rs (Arc/Weak 管理)
- MIR WeakNew/WeakLoad: handlers/weak.rs

## LLVM harness 状況
- WeakNew/WeakLoad:  実装済み (llvm_py/instructions/weak.py)
- Finalizer:  未実装 (scope 管理なし)
- GC:  未実装 (RC のみ)

## P2 smoke 候補絞り込み(4本)
- weak_basic_vm/llvm: 既存+LLVM版
- weak_to_strong_fail: null 確認(新規)
- weak_cycle_report: leak report(新規)

**重要な発見**:
- WeakRef は両バックエンド完全実装(仕様通り)
- Finalizer は VM scope レベルで実装あり、LLVM 未対応

quick smoke 154/154 PASS

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 10:55:33 +09:00
5ec0056059 docs(lifecycle): Phase 285 P0 - Box lifecycle/weakref/GC SSOT 固定
## 言語 SSOT との境界明文化
- lifecycle/weak/fini: lifecycle.md
- null/void/truthiness: types.md
- Phase 285 は実装状況・差分追跡のみ(言語SSOT書き換えなし)

## 用語・禁止事項固定
- Roots/Strong/Weak/Finalizer/GC 定義
- 禁止: finalizer 再入・例外・allocation・silent fallback

## VM/LLVM 差分分類
- (A) 仕様通り: weak/weak_to_strong/leak report
- (B) 未実装: finalizer/GC cycle collection

## P1/P2 導線
- P1: 棚卸し対象ファイル一覧(value.rs, finalization.rs等)
- P2: smoke 候補(weak_basic, weak_to_strong_fail, leak_report)

quick smoke 154/154 PASS

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 10:51:17 +09:00
03f9bbe1aa feat(smoke): Phase 284 P2 - return-in-loop VM/LLVM parity smoke
- VM smoke: phase284_p2_return_in_loop_vm.sh (PASS)
- LLVM smoke: phase284_p2_return_in_loop_llvm.sh (SKIP if no LLVM feature)
- Reuse existing fixture: phase286_pattern5_return_min.hako (exit 7)
- P2-INSTRUCTIONS.md: 手順書作成
- quick smoke 154/154 PASS

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 10:45:54 +09:00
7a575e30cc refactor(joinir): Phase 286 P3.2 cleanup + normalizer modularization
## Legacy Pattern5 削除 (488行)
- pattern5_infinite_early_exit.rs 完全削除
- LOOP_PATTERNS テーブルからエントリ削除
- Plan extractor が SSOT

## Normalizer 分割 (3294行 → 12ファイル)
- helpers.rs: 共通ヘルパー関数
- pattern*.rs: 各パターン専用ファイル
- mod.rs: ディスパッチャ

## ドキュメント更新
- Phase 286 README: クリーンアップ完了・Fail-Fast方針記載
- Phase 287 README: 将来計画

quick smoke 154/154 PASS

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 10:30:08 +09:00
22945c190c feat(joinir): Phase 286 P3.2 - Pattern5 Plan line (loop(true) + early exit)
- Pattern5InfiniteEarlyExitPlan (Return/Break variants)
- extract_pattern5_plan() for loop(true) literal only
- normalize_pattern5_return(): 5 blocks CFG (header→body→found/step)
- normalize_pattern5_break(): 6 blocks CFG with carrier PHI
- NormalizationPlanBox exclusion for Pattern5-style loops
- Fixtures: phase286_pattern5_{return,break}_min.hako
- quick smoke 154/154 PASS

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 09:56:34 +09:00
ec55cce380 docs(joinir): Phase 286 P3.1 ステータス更新 (COMPLETE)
- ステータスバナーを IN PROGRESS → COMPLETE に更新
- 実装ステップ全て 
- 検証結果に実際の結果を反映
  - Fixture B: Plan line PASS (出力 11)
  - Fixture A: legacy fallback(PoC サブセット外)
  - quick smoke 154/154 PASS

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 07:56:45 +09:00
b235a5b6db feat(joinir): Phase 286 P3.1 - Pattern2 Plan line 完走(after_bb PHI)
Pattern2(Loop with Break)を Plan/Frag SSOT へ移行。

主な変更:
- Pattern2BreakPlan 追加(DomainPlan variant)
- extract_pattern2_plan() 実装(PoC サブセット厳守)
- normalize_pattern2_break() 実装(6-block CFG, 3 PHI)
- after_bb PHI が本質: carrier_out = PHI(header: carrier_current, break_then: carrier_break)
- router に Pattern2 追加(Pattern1 より前、より具体的)

テスト:
- Fixture B (break without update): PASS (出力 11)
- quick smoke: 154/154 PASS

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 05:56:30 +09:00
f76fb6cd3e refactor(joinir): Phase 286 P2.8 - Normalizer Hygiene(小箱化・重複削減)
- LoopBlocksStandard5: 5-block レイアウト(Pattern1/9 で使用)
- LoopBlocksWithIfPhi: 8-block レイアウト(Pattern3 で使用)
- create_phi_bindings(): phi_bindings 作成ヘルパー(全5パターンで使用)

リファクタ適用:
- Pattern1: LoopBlocksStandard5 + create_phi_bindings
- Pattern3: LoopBlocksWithIfPhi + create_phi_bindings
- Pattern4: create_phi_bindings(8-block は別構造のため据え置き)
- Pattern8: create_phi_bindings(6-block は別構造のため据え置き)
- Pattern9: LoopBlocksStandard5 + create_phi_bindings

意味論は完全不変。quick 154/154 PASS。

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 05:08:09 +09:00
65304ec0c4 docs(joinir): Phase 286 Pattern2調査・設計相談パケット追加
- phase286_pattern2_frag_poc.hako: Pattern2 PoC fixture
- phase286_pattern2_frag_poc.sh: integration smoke
- phase-286-plan-normalization-consult.md: Plan正規化の設計相談
- 10-Now.md, 30-Backlog.md: 進捗更新
- pattern2-deferred.md: 更新

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 04:58:38 +09:00
630ed02c48 feat(joinir): Phase 286 P2.7 - V10不変条件追加(body_bb effects契約)
- verifier.rs: V10検証追加 - body_bbのblock_effectsは空でなければならない
  - 違反時: "[V10] Loop at depth N has non-empty block_effects for body_bb"
  - テスト: test_v10_body_bb_effects_in_block_effects_fails
- joinir-plan-frag-ssot.md: V10をPlan段階の不変条件に追加
- README.md: P2.7セクション追加

Phase 286 P2.6.1で発見した「lowererはloop_plan.bodyをemitし、
block_effectsのbody_bbは無視する」問題を契約化し再発防止。

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 04:55:14 +09:00
0fca2df5be feat(joinir): Phase 286 P2.6.1 - Pattern3 Plan 完走(normalizer 実装 + Fail-Fast 統一)
## 変更内容

### Router Fail-Fast 統一
- Pattern3 stub fallback 特例を撤去
- extract 成功 → normalize/lower 失敗は即 Err(他パターンと統一)

### normalize_pattern3_if_phi() 実装
- CFG 構造: 8 blocks (preheader, header, body, then, else, merge, step, after)
- PHI 構成: 3本(header×2 + merge×1)
  - Header: loop_var_current, carrier_current
  - Merge: carrier_next (if-else 合流)
- Frag: BranchStub×2 + EdgeStub×4(Pattern1 流儀の直接構築)

### 発見・修正
- lowerer は body_bb の block_effects を無視して loop_plan.body を emit
- body_bb effects は CorePlan::Effect(...) として loop_plan.body に配置

## テスト結果
- Phase 118 smoke: PASS (出力 12)
- quick: 154/154 PASS
- Plan line 完走確認: route=plan ... Pattern3_IfPhi MATCHED

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 04:39:36 +09:00
3abca63ebe refactor(joinir): Phase 286 P2.6 コード品質 - pattern3.rs 重複削除 + 共通化
## 変更内容
- pattern3.rs: has_return_statement() 削除 → common_helpers 使用
- pattern3.rs: has_control_flow_statement() → has_forbidden_control_flow_for_pattern3() にリネーム
  - Pattern3 固有のセマンティクス(ネスト if 禁止)を明確化
- common_helpers.rs: find_if_else_statement() 追加
  - PoC subset コメント付き(最初の if-else だけ取る)

## 効果
- 重複コード削除: -34 lines net
- 関数名で意図を明確化(Pattern3 固有の制約)
- common_helpers の再利用性向上

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 04:13:13 +09:00
4d17e3d812 feat(joinir): Phase 286 P2.6 - Pattern3 Plan 基盤 + Pattern1 退行修正
## Pattern1 退行修正(構造的 Fail-Fast)
- Router に pattern_kind ガード追加(ctx.pattern_kind != Pattern1SimpleWhile → skip)
- has_if_else_statement() ヘルパー追加(再帰版、ScopeBox/Loop 内もチェック)
- Pattern1 extractor に if-else 拒否追加

## Pattern3 Plan 基盤
- DomainPlan: Pattern3IfPhiPlan 構造体追加
- Extractor: extract_pattern3_plan() 追加
- Normalizer: normalize_pattern3_if_phi() スタブ追加(レガシー JoinIR へフォールバック)
- Router: PLAN_EXTRACTORS に Pattern3 追加

## テスト結果
- quick 154 PASS
- Phase 118 smoke PASS(出力 12、退行解消)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 04:01:11 +09:00
21daf1b7dd refactor(joinir): Phase 286 コード品質改善 - ヘルパー共通化 + static box フィルタ
## 1. lower_*_ast ヘルパー共通化
- `lower_value_ast()` に MethodCall 対応追加
- Pattern8 normalizer も共有ヘルパーを使用
- Pattern1/8/9 で一貫した lowering ロジック

## 2. PLAN_EXTRACTORS ドキュメント追加
- `WithPostLoop` variant: 将来拡張用として残存理由を明記
- 現在は常に `&[]` を渡すが、post-loop segment analysis 用に保持

## 3. Legacy Pattern8 残存 + static box フィルタ
- Plan extractor は pure 関数(builder にアクセス不可)
- router 側で static box フィルタリングを実装
- static box コンテキストは legacy Pattern8 へ fallback
- legacy 残存理由をドキュメント化

## 検証
- Quick: 154 PASS, 0 FAILED
- Pattern8 integration: exit 7

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 03:35:02 +09:00
832d018046 feat(joinir): Phase 286 P2.4.1 - Pattern8 normalizer 実装 + Fail-Fast 化
## 概要
Pattern8 (BoolPredicateScan) を Plan line で完走させる。
stub normalizer を完全実装に置き換え、legacy fallback を禁止。

## Step 0: Fixture 簡約
- `?:` ternary → `if/else` に変更(PoC 安定化)

## Step 1: Router Fail-Fast 化
- 文字列判定 `e.contains("[normalizer/pattern8]")` を削除
- extract が Some → normalize/lower 失敗は即 Err(fallback 禁止)
- extract が None → 次の extractor へ(legacy 含む)

## Step 2: Pattern8 normalizer 実装
- CFG: preheader → header(PHI) → body → found/step → after
- found: return false(早期脱出)
- after: return true(ループ完走)
- compose::cleanup() で 2 つの Return exit をマージ

## 検証結果
- Integration: exit 7 
- Plan 完走: route=plan strategy=extract pattern=Pattern8 MATCHED
- Regression: quick 154 PASS, 0 FAILED

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 03:17:48 +09:00
064cae169e feat(joinir): Phase 286 P2.4 - Pattern8 BoolPredicateScan Plan化 PoC
## 概要
Pattern8 (BoolPredicateScan) を Plan extraction routing に追加。
static box 除外(Phase 269 決定)を尊重し、非 static box fixture で PoC。

## 実装内容
- Pattern8BoolPredicateScanPlan struct + DomainPlan variant
- extract_pattern8_plan(): 条件・predicate check・increment 抽出
- normalize_pattern8_bool_predicate_scan(): PoC stub(CoreExitPlan::Return 未統合)
- PLAN_EXTRACTORS テーブルに Pattern8 追加(3rd priority)
- エラーフォールバック: Plan normalization 失敗時 → legacy Pattern8 へ

## 動作フロー
Plan extraction MATCHED → normalization failed (PoC stub) → legacy Pattern8 MATCHED

## 検証結果
- Integration: phase286_pattern8_plan_poc_vm PASS (exit 7)
- Regression: quick 154 PASS, 0 FAILED

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 03:01:11 +09:00
1d24e9a106 feat(joinir): Phase 286 P2.3 + Phase 287 - Pattern9 Plan化 + Router table-driven
## Phase 286 P2.3: Pattern9 AccumConstLoop Plan化 PoC

- DomainPlan::Pattern9AccumConstLoop 追加
- PlanNormalizer::normalize_pattern9_accum_const_loop() 実装
  - PHI 2本(loop_var, acc_var)
  - const/var 両方 OK(sum = sum + 1 または sum = sum + i)
- Pattern9 は Pattern1 より優先(より具体的なパターン)
- Integration test: phase286_pattern9_frag_poc PASS (return: 3)
- Regression: quick 154 PASS

## Phase 287: Router table-driven Plan extraction

- PLAN_EXTRACTORS static table で Pattern6/7/4/9/1 を統一管理
- PlanExtractorEntry/PlanExtractorVariant 構造体追加
- try_plan_extractors() で ~100行 → 3行に集約
- メンテナンス性向上(新 Pattern 追加はテーブル1行追加のみ)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 02:38:09 +09:00
6656098c95 docs(phase-286): P2.2 完了 + P2.3 準備中の進捗記載
更新内容:
- Phase 286 README に P2.2  COMPLETE セクション追加
  - extractor helper化(extract_loop_increment_plan 統一)の内容
  - router helper化(lower_via_plan() 追加)の内容
  - 削減行数(~65行)と検証結果(quick 154 PASS, PoC 両方 PASS)

- 10-Now.md の Current Focus を Phase 286 P2.3 に更新
  - P2/P2.1/P2.2 の完了を時系列記載
  - Pattern9 (AccumConstLoop) を次の PoC 対象に決定

- CURRENT_TASK.md の Handoff(現状)を更新
  - P2.2 COMPLETE の記載(hygiene 内容 + 成果)
  - P2.3 準備中(Pattern9 PoC 準備)の1段落を追加

- pattern2-deferred.md 新規作成
  - Pattern2 の複雑性(break値再接続)を説明
  - 再開条件(after_bb PHI + compose::loop_ + Break wiring)を明文化
  - Phase 286 P2.2 として後続タスク化

関連 issues: Phase 286 JoinIR Line Absorption

🤖 Generated with Claude Code

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-26 02:03:34 +09:00
a824346e30 feat(joinir): Phase 286 P2/P2.1/P2.2 - JoinIR Line Absorption (Pattern1/4 Plan化 PoC + hygiene)
Phase 286 P2: Pattern4 (Loop with Continue) を Plan/Frag SSOT に移行
- DomainPlan::Pattern4Continue 追加
- PlanNormalizer::normalize_pattern4_continue() 実装(phi_bindings による PHI dst 優先参照)
- Router integration(Plan line routing → legacy fallback)
- Integration test PASS (output: 6), quick smoke 154/154 PASS

Phase 286 P2.1: Pattern1 (SimpleWhile) を Plan/Frag SSOT に移行
- DomainPlan::Pattern1SimpleWhile 追加
- PlanNormalizer::normalize_pattern1_simple_while() 実装(4ブロック、1 PHI、phi_bindings 流用)
- Router integration(Plan line routing → legacy fallback)
- Integration test PASS (return: 3), quick smoke 154/154 PASS

Phase 286 P2.2: hygiene(extractor重複排除 + router小整理)
- extractor helper化: extract_loop_increment_plan を common_helpers.rs に統一
  - Pattern1/Pattern4 が呼ぶだけに変更(重複排除 ~25行)
- router helper化: lower_via_plan() を追加し Pattern6/7/4/1 で共用
  - 3行パターン(normalize→verify→lower)を1関数に集約(ボイラープレート削減 ~40行)

成果物:
- DomainPlan 2パターン新規追加(Pattern1SimpleWhile, Pattern4Continue)
- Normalizer 2つの normalize 関数追加
- Router に Plan line ブロック追加 + lower_via_plan() helper
- Extractor に extract_pattern1_plan() 追加
- Integration fixtures 2個 + smoke tests 2個

検証:
- quick smoke: 154/154 PASS
- integration: phase286_pattern1_frag_poc PASS, phase286_pattern4_frag_poc PASS
- Plan line routing: route=plan strategy=extract で Pattern1/4 検出確認

🤖 Generated with Claude Code

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-26 02:03:22 +09:00
55d30c9845 docs(repl): record Phase 288.1 contract and results
更新内容:
- docs/reference/language/repl.md
  - Phase 288.1 完了ステータスに更新
  - Implementation Architecture セクション追加(AST rewrite 方式説明)
  - AST Rewriter の動作フロー追加(Variable/Assignment 変換ロジック)
  - ExternCall Bridge の仕組み追加(__repl.get/set → VMValue)
  - Expression Detection ロジック追加(wrapper AST 判定)
  - 動作例を完全に更新(全機能が動作済み)

- docs/development/current/main/phases/phase-288/README.md
  - Phase 288.1 完了セクション追加
  - 変更ファイル一覧(8ファイル, +592行)記録
  - 確認コマンド 4種 記録(変数永続化/式表示/_変数/リセット)
  - 回帰テスト結果記録(154/154 PASS)

- docs/development/current/main/10-Now.md
  - "Phase 288.1 完了" に更新
  - 次の候補(REPL UX 改善 / JoinIR 設計作業)を追記

- CURRENT_TASK.md
  - 1段落サマリー更新(288.1 完了、次の方向性)

Phase 288.1 成果(SSOT記録):
 変数永続化(session → eval bridge)
 式自動表示(pure expression auto-output)
 _ 変数(last displayed value)
 Fail-Fast 未定義エラー + ヒント
 セッションリセット(.reset)
 154/154 smoke tests PASS(file mode 不変)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 23:05:20 +09:00
46fbe12ce6 feat(repl): Phase 288.1 session persistence + auto-display
実装内容:
- AST Rewriter (~430行): 未宣言変数を __repl.get/set に変換
- ExternCall Bridge: VM で __repl.get/set ハンドラー実装
- Rc<RefCell<>> セッション共有: VM と REPL runner 間で永続化
- 式自動表示: pure expression の結果を自動出力
- _ 変数: 最後の表示値を保存(Void は除外)
- .reset 実装: セッション変数の完全クリア
- Fail-Fast: 未定義変数読み取りで明示的エラー + ヒント

変更ファイル (8ファイル, +592行):
- src/runner/repl/ast_rewriter.rs (NEW, +430行)
- src/runner/repl/repl_runner.rs (+84/-35行)
- src/backend/mir_interpreter/handlers/externals.rs (+54行)
- src/mir/builder/calls/build.rs (+41行)
- src/backend/mir_interpreter/mod.rs (+12行)
- src/runner/repl/repl_session.rs (+11/-9行)
- src/runner/repl/mod.rs (+2行)
- src/runner/mod.rs (+2/-1行)

REPL専用設計(src/mir/builder/calls/build.rs の特別扱い理由):
- __repl.get/set は REPL mode 専用の橋渡し機能
- try_build_repl_method_call() で早期検出・ExternCall 変換
- file mode では決して使用されない(VM で "outside REPL mode" エラー)
- 将来的にも file mode への影響ゼロを保証

検証済み:
- 変数永続化: x = 42; print(x) → 42 
- 式自動表示: 1 + 1 → 2 
- _ 変数: 10 * 2 → 20; _ → 20 
- Fail-Fast: 未定義エラー + ヒント 
- 回帰テスト: 154/154 PASS 

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 23:04:59 +09:00
e986e279b4 refactor(repl): Quiet Mode 方針整合 - REPL 専用フラグに統一
方針整合修正(commit 1cec724ce の改善):
- NYASH_QUIET_INTERNAL_LOGS 撤去(環境変数スパロー防止)
- src/runner/repl/repl_runner.rs: quiet_internal_logs フラグ追加、環境変数操作削除
- src/mir/mod.rs: set_quiet_internal_logs() 公開 API 追加
- src/mir/builder/compilation_context.rs: quiet_internal_logs フラグ追加
- src/mir/builder/decls.rs: 環境変数直読み → context フラグ参照

アーキテクチャ:
   REPL 専用フラグで制御(file mode 無影響保証)
   ReplRunnerBox → MirCompiler → CompilationContext の明確な伝播経路
   crate::config::env::cli_verbose() 既存 SSOT を活用

ルール遵守:
   環境変数スパロー防止ポリシー(AGENTS.md 5.3)
   隠しトグル禁止(新規環境変数なし)
   既存の verbose 制御(NYASH_CLI_VERBOSE)に統一

機能保持:
   REPL 通常モード: 内部ログ抑制(clean output)
   REPL verbose モード: デバッグログ表示(--verbose)
   File mode 既定挙動: 不変(quiet_internal_logs 常に false)

Test results:
   REPL quiet/verbose 動作確認
   File mode regression: 154/154 pass(既定挙動不変)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 14:42:16 +09:00
1cec724ce0 feat(repl): REPL Quiet Mode - デバッグログ自動抑制
REPL mode では内部デバッグログを自動抑制:
- src/runner/repl/repl_runner.rs: NYASH_QUIET_INTERNAL_LOGS 設定/解除
- src/mir/builder/decls.rs: NYASH_QUIET_INTERNAL_LOGS チェック追加
- NYASH_CLI_VERBOSE=1 でデバッグログ有効化可能

UX improvement:
  Before: >>> print("Hello")
          [build_static_main_box] Storing fn_body_ast...
          Hello

  After:  >>> print("Hello")
          Hello

Test results:
   通常モード: ログ抑制
   デバッグモード (NYASH_CLI_VERBOSE=1): ログ表示
   File mode regression: 154/154 pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 14:26:42 +09:00
dd1b2a22e1 docs(repl): Phase 288 final documentation polish
Updated documentation for Phase 288 completion:
- docs/reference/language/repl.md: Status clarified (P0–P3 complete)
- docs/development/current/main/phases/phase-288/README.md: Added P0-P3 summaries

Changes:
- repl.md: "partial (dev tool)" → "P0–P3 complete / Phase 288.1 next"
- README.md: Each phase now has detailed description with key deliverables
- Added Box化モジュール化 (3445ef7a7) to completion record

Documentation improvements:
-  P0-P3 completion clearly marked
-  VMValue persistence approach documented
-  Box-First modularization recorded
-  Consistent with 10-Now.md, 30-Backlog.md, P1-INSTRUCTIONS.md

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 14:21:22 +09:00
3445ef7a7d refactor(repl): Phase 288 Box化 - REPL Runner モジュール分離
箱理論モジュール化(Box-First):
- src/runner/repl/ 新規モジュール作成
- ReplRunnerBox: REPL実行器の完全隔離
- ReplSessionBox: mir/builder → runner/repl へ移動

File changes:
- src/runner/mod.rs: -118行(REPL コード削除)
- src/runner/repl/mod.rs: +22行(公開API)
- src/runner/repl/repl_runner.rs: +143行(ReplRunnerBox実装)
- src/runner/repl/repl_session.rs: moved from mir/builder/

Benefits:
- runner/mod.rs が綺麗(REPL 関連削除)
- REPL 機能が完全隔離(file mode への影響ゼロ保証)
- テスト容易性向上(Box 単体テスト可能)

Test results:
   REPL 動作確認(print/.reset/.exit)
   File mode regression: 154/154 pass

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 14:06:22 +09:00