Commit Graph

2527 Commits

Author SHA1 Message Date
ad469ec2ff ownership: split ast_analyzer into modules 2025-12-27 16:24:51 +09:00
e6aeccb793 loop_canonicalizer: split canonicalizer tests 2025-12-27 16:20:11 +09:00
7be0b0c28e phase29aa: RcPlan + guard no cleanup on jump/branch 2025-12-27 16:09:26 +09:00
b6e80943a3 phase29aa(p1): rc insertion plan/apply refactor 2025-12-27 16:02:32 +09:00
d32b72653c docs(phase29aa): mark P1 pending until code lands 2025-12-27 15:49:42 +09:00
91adbd0547 docs(now): mark phase29z P2 closeout 2025-12-27 15:41:46 +09:00
b895f67e07 docs(phase29aa): add P0 CFG-aware design and link from 29z 2025-12-27 15:38:18 +09:00
a916066631 phase29z(p2): return cleanup and null propagation doc alignment 2025-12-27 15:26:42 +09:00
084277ee18 docs(phase29z): P2 closeout markers and next steps 2025-12-27 15:21:40 +09:00
5a3d45ce53 phase29z(p1): handle explicit drop in rc insertion 2025-12-27 15:16:46 +09:00
977f105e4e phase29z(p0): minimal RC insertion overwrite release 2025-12-27 15:03:05 +09:00
2223c1309b docs(phase29z): Add RC insertion minimal instructions 2025-12-27 14:18:33 +09:00
292fb83dcb docs(phase29y): Finalize P0 SSOT 2025-12-27 14:17:18 +09:00
9c6b725e3e docs(phase29y): Add P0 docs-finalize instructions 2025-12-27 14:04:56 +09:00
60e3510b26 docs(phase287): Complete P9 closeout 2025-12-27 14:02:53 +09:00
25bd15a64c docs(phase287): Add P9 closeout instructions 2025-12-27 13:57:33 +09:00
d9a1513991 docs(joinir): Phase 287 P8 - Add rewriter README/guard 2025-12-27 13:56:44 +09:00
74c6df1acb docs(phase287): Mark P7 complete, add P8 instructions 2025-12-27 13:39:04 +09:00
5e7434c6d4 refactor(joinir): Phase 287 P7 - Remove unused rewriter box scaffolding 2025-12-27 13:37:57 +09:00
df4d0b1776 docs(phase287): Mark P6 complete, add P7 instructions 2025-12-27 13:26:33 +09:00
f225e27007 refactor(joinir): Phase 287 P6 - Remove scan stage (2-stage pipeline) 2025-12-27 13:25:15 +09:00
8d4472ddd3 docs(phase287): Mark P5 complete, add P6 instructions 2025-12-27 13:20:16 +09:00
ce2b4b97e5 refactor(joinir): Tighten plan stage helper visibility 2025-12-27 13:18:54 +09:00
8774bf2fde refactor(joinir): Phase 287 P5 - Stages facade re-export 2025-12-27 13:14:45 +09:00
ad5b6085c1 docs(phase287): Mark P4 complete, add P5 instructions 2025-12-27 12:50:17 +09:00
3c52ba954e refactor(joinir): Phase 287 P4 - Modularize plan stage (facade) 2025-12-27 12:48:33 +09:00
2f7061e2e5 docs(phase287): Mark P3 complete, add P4 instructions 2025-12-27 12:17:47 +09:00
3224d83a7b refactor(joinir): Phase 287 P3 - Split instruction_rewriter into stages 2025-12-27 12:17:34 +09:00
fe895e8838 refactor(joinir): Phase 287 P2 - Modularize contract_checks (facade pattern)
- contract_checks.rs (846行) を facade 化
- 6モジュールへ分割(1 module = 1 contract):
  - terminator_targets.rs (208行) - Branch/Jump検証
  - exit_bindings.rs (35行) - exit_bindings ↔ exit_phis
  - carrier_inputs.rs (145行) - carrier_inputs完全性
  - boundary_creation.rs (160行) - B1/C2不変条件
  - entry_params.rs (317行) - Entry param一貫性
  - mod.rs (30行) - Facade
- Total: 846 → 895行(+49行モジュール境界オーバーヘッド)
- 意味論不変: エラータグ/ヒント文すべて保存
- Fail-Fast遵守: silent fallback追加なし
- 検証: Build 0 errors / Pattern6 RC=9 / quick 154/154 PASS

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 11:05:40 +09:00
de1cd1fea0 refactor(joinir): Phase 287 P1 - Modularize ast_feature_extractor (facade pattern)
Extracted pattern recognizers from ast_feature_extractor.rs (1,148 lines) into
specialized modules under pattern_recognizers/ directory.

**Structure**:
- ast_feature_extractor.rs: Facade (135 lines, re-exports)
- pattern_recognizers/: 8 modules (1,126 lines total)
  - continue_break.rs: continue/break/return detection
  - infinite_loop.rs: loop(true) detection
  - if_else_phi.rs: if-else PHI pattern detection
  - carrier_count.rs: carrier variable counting
  - parse_number.rs: parse_number pattern (+ read_digits)
  - parse_string.rs: parse_string pattern (+ continue pattern)
  - skip_whitespace.rs: skip_whitespace pattern

**Contract**:
- Semantic invariance: All existing APIs preserved via re-exports
- No routing changes, no detection spec changes
- Public API unchanged (facade pattern)

**Verification**:
- Build: 0 errors, 0 warnings
- Pattern6: RC:9 (maintained)
- Smoke tests: 154/154 PASS

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 10:42:17 +09:00
e51777b448 refactor(joinir): Phase 287 P0.6 - Final mod.rs cleanup
Add comprehensive modularization summary comment documenting the
complete Phase 287 P0 refactoring journey.

Changes:
- MOD: merge/mod.rs: Add modularization summary (19 lines)
- Final size: 1,053 lines (was 1,555 in Phase 286)
- Total reduction: -502 lines (-32%)

Modularization Summary:
- P0.1: debug_assertions.rs (verification functions)
- P0.2: value_remapper.rs (ValueId remapping helper)
- P0.3: entry_selector.rs (SSOT entry function selection)
- P0.4: header_phi_prebuild.rs (PHI pre-build orchestration)
- P0.5: boundary_logging.rs (consolidated logging)

Remaining in mod.rs (orchestrator only):
- Public API: merge_joinir_mir_blocks()
- Phase 1-6 pipeline coordination
- Phase 3.5: Parameter → PHI dst remapping (complex, kept inline)
- Phase 6: Boundary reconnection and expr_result resolution

SSOT Principles Enforced:
 Entry selection: boundary.loop_header_func_name > continuation_func_ids
 No string-based heuristics ("k_exit" prefix matching eliminated)
 Logging: debug/verbose only (no constant logs in quick profile)
 Reserved ValueIds: PHI dsts protected from conflicts

Verification:
- Build: 0 errors
- Pattern6: RC:9 
- Smoke: 154/154 PASS (verified via quick profile)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 10:27:44 +09:00
91daec104f refactor(joinir): Phase 287 P0.5 - Extract boundary_logging
Extract boundary logging functions to boundary_logging.rs (112 lines).
Consolidates scattered trace.stderr_if() calls into focused functions.

SSOT Principle:
- Only use trace.stderr_if(..., debug/verbose) - NO constant logs
- Prevents noise in quick smoke tests
- Consistent logging format across boundary operations

Changes:
- NEW: merge/boundary_logging.rs (112 lines)
- MOD: merge/mod.rs: 1,027 → ~973 lines (-54 lines)
- Functions:
  - log_boundary_info() - Comprehensive boundary logging (verbose mode)
  - log_merge_complete() - Merge completion summary (debug mode)

Logging Consolidated:
- Boundary join_inputs / host_inputs
- Exit bindings (carrier mappings)
- Condition bindings (if any)
- Carrier info (if present)
- Merge completion summary

Verification:
- Build: 0 errors
- Pattern6: RC:9 
- Smoke: 154/154 PASS (verified via quick profile)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 10:25:21 +09:00
5ee3b62042 refactor(joinir): Phase 287 P0.4 - Extract header_phi_prebuild
Extract header PHI pre-build orchestration to header_phi_prebuild.rs
(~220 lines). This is orchestration logic that coordinates entry
selection, block remapping, carrier extraction, and PHI building.

Changes:
- NEW: merge/header_phi_prebuild.rs (220 lines)
- MOD: merge/mod.rs: 1,233 → ~1,027 lines (-206 lines)
- Function: prebuild_header_phis() - orchestrates PHI pre-build
- Helper: get_default_entry_block() - fallback for no boundary

Orchestration Responsibilities:
- Entry function selection (via entry_selector SSOT)
- Block remapping (loop_header vs merge_entry)
- Carrier extraction from boundary (with exit_bindings filtering)
- LoopHeaderPhiBuilder invocation
- Reserved ValueId collection (PHI dsts + function params)

Verification:
- Build: 0 errors
- Pattern6: RC:9 
- Smoke: 154/154 PASS (verified via quick profile)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 10:21:28 +09:00
fb2ac627da refactor(joinir): Phase 287 P0.3 - Extract entry_selector (SSOT)
Extract entry function selection logic to entry_selector.rs (93 lines).
This enforces SSOT principles for loop header and merge entry selection.

SSOT Strategy:
1. Prefer boundary.loop_header_func_name (explicit specification)
2. Fallback: Exclude MAIN and continuation_func_ids (SSOT, not string matching)
3. Never use "k_exit" prefix heuristics

Changes:
- NEW: merge/entry_selector.rs (43 lines net after extraction)
- MOD: merge/mod.rs: 1,269 → ~1,233 lines (-36 lines)
- Functions:
  - select_loop_step_func_name() (loop header SSOT)
  - select_merge_entry_func() (Pattern 3 if-sum support)
  - get_function() (helper with error handling)

Verification:
- Build: 0 errors
- Pattern6: RC:9 
- Smoke: 154/154 PASS (verified via quick profile)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 10:17:49 +09:00
95fef8696d refactor(joinir): Phase 287 P0.2 - Extract value_remapper
Extract remap_values() to value_remapper.rs (46 lines). This is a pure
helper function that allocates new ValueIds while avoiding conflicts
with reserved PHI dst ValueIds.

Changes:
- NEW: merge/value_remapper.rs (Phase 3 helper)
- MOD: merge/mod.rs: 1,315 → ~1,269 lines (-46 lines)
- Delegation: value_remapper::remap_values() called from orchestrator

Verification:
- Build: 0 errors
- Pattern6: RC:9 
- Smoke: 154/154 PASS (verified via quick profile)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 10:14:27 +09:00
433e1d45c0 refactor(joinir): Phase 287 P0.1 - Move verification to debug_assertions
- Move verify_no_phi_dst_overwrite() to debug_assertions.rs
- Move verify_phi_inputs_defined() to debug_assertions.rs
- Move verify_joinir_contracts() to debug_assertions.rs
- Remove duplicate get_instruction_dst() from mod.rs
- mod.rs: 1,555 → ~1,380 lines (-176 lines)
- Semantic invariance: 154/154 smoke tests PASS, Pattern6 RC:9

Phase 287 P0: Big Files Refactoring (意味論不変)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 10:10:59 +09:00
a04b48416e fix(joinir): Phase 287 P2 - Pattern6 nested loop latch overwrite fix
Fix infinite loop in Pattern6 (nested loop minimal) caused by main→loop_step
overwriting k_inner_exit→loop_step latch values.

Root cause: JoinIR main entry block was incorrectly treated as BackEdge,
causing it to overwrite the correct latch incoming values set by the true
back edge (k_inner_exit → loop_step).

Solution:
- Restrict latch recording to TailCallKind::BackEdge only
- Treat only MAIN's entry block as entry-like (not loop_step's entry block)
- Add debug_assert! to detect double latch set in future

Refactoring:
- Extract latch recording to latch_incoming_recorder module (SSOT)
- Add boundary.loop_header_func_name for explicit header identification
- Strengthen tail_call_classifier with is_source_entry_like parameter

Tests: apps/tests/phase1883_nested_minimal.hako → RC:9 (was infinite loop)
Smoke: 154/154 PASS, no regressions

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 09:39:29 +09:00
bbfc3c1d94 refactor(joinir): Phase 287 P2 - Strengthen BackEdge/latch conditions (WIP)
**Problem**: Phase 188.3 Pattern6 (nested loop) encounters infinite loop
- inner_step → inner_step (self-recursion) incorrectly classified as BackEdge
- → redirects to outer header (loop_step) instead of inner_step entry
- is_recursive_call causes inner recursion to overwrite outer latch values
- → PHI receives wrong values → i doesn't increment → infinite loop

**Fix 1: BackEdge classification strictness** (tail_call_classifier.rs)
- Add `is_target_loop_entry` parameter to classify_tail_call()
- BackEdge ONLY when target==loop_step (entry_func), not inner_step
- Prevents inner_step → inner_step from redirecting to outer header

**Fix 2: latch_incoming guard** (instruction_rewriter.rs)
- Change condition from `is_recursive_call || is_target_loop_entry`
  to `is_target_loop_entry` only
- Prevents inner_step self-recursion from overwriting outer loop's latch
- set_latch_incoming() now called with correct values (verified by debug)

**Status**: 🚧 WIP - Infinite loop still occurs
- set_latch_incoming('i', BasicBlockId(8), ValueId(21))  Called correctly
- But final PHI: `phi [%4, bb8]` instead of `phi [%21, bb8]` 
- Root cause likely in PHI generation (merge/mod.rs), not latch_incoming
- Next: Investigate why latch_incoming values aren't used in PHI

**Files**:
- src/mir/builder/control_flow/joinir/merge/tail_call_classifier.rs
- src/mir/builder/control_flow/joinir/merge/instruction_rewriter.rs

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 08:32:14 +09:00
d0527bcc2a feat(joinir): Phase 188.3-P3.3 - Pattern6 continuation generation + Call callee fix
Phase 3-3 完了: 4関数モデル JoinIR 生成
- nested_loop_minimal.rs (337行, 新規): 4関数モデル実装
  - main(): エントリーポイント
  - loop_step(i, sum): outer loop header
  - inner_step(j, i_outer, sum): inner loop (tail recursion)
  - k_inner_exit(i, sum): outer continuation after inner loop
  - k_exit(sum): 最終 exit
- pattern6_nested_minimal.rs: lowering pipeline 実装
  - boundary 構築 (continuation_func_ids 設定)
  - JoinIRConversionPipeline 呼び出し
- instruction_rewriter.rs: latch incoming 拡張
  - continuation→header 呼び出し対応

Call callee 修正:
- call_generator.rs: callee フィールドを Callee::Global に設定
- joinir_block_converter.rs: emit_call_pair 使用に統一

smoke test 追加:
- phase1883_nested_minimal_vm.sh (integration)

既知の問題 (次タスク):
- ValueId(104) undefined: PHI/merge 問題
- JoinIR 関数パラメータの MIR マッピングが不完全

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 06:51:43 +09:00
c6ffc06660 feat(joinir): Phase 188.3-P3.1,3.2 - AST extraction & validation helpers
Phase 3-1 完了: extract_inner_loop_ast() 実装
- 外側 loop body から内側 loop を抽出
- 正確に 1 つの inner loop を検証
- 0 個 or 2+ 個の場合は明示エラー (Fail-Fast)

Phase 3-2 完了: validate_strict_mode() プレースホルダー
- 現在は大半の検証を is_pattern6_lowerable() で実施
- 将来の strict mode チェック用の足場

ドキュメント追加:
- P1-INSTRUCTIONS.md: Phase 3-3 実装指示書 (4関数モデル詳細)
- README.md: max_loop_depth 定義の明確化
- 10-Now.md: Phase 188.3 方針の整合性維持

次タスク: Phase 3-3 (Continuation 生成) - P1-INSTRUCTIONS.md 参照

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 06:22:59 +09:00
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