Commit Graph

905 Commits

Author SHA1 Message Date
29058d2c9a feat(phase40-3): dev flag実装 + テストインフラ準備
Phase 40-3成果:
- dev flag追加: use_joinir_for_array_filter() (env.rs)
- テストドキュメント更新 (phase40_array_ext_filter_test.rs)

フルパイプライン統合はPhase 40-3.5+に延期

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 10:34:50 +09:00
88358a4086 feat(joinir): Phase 40-1 JoinFuncMetaインフラ構築
Phase 40-1成果:
- JoinFuncMeta構造体 + JoinFuncMetaMap型(func_meta.rs)
- lower_loop_with_if_meta() 実験用API
- convert_join_module_to_mir_with_meta() MIRラッパ
- extract_if_in_loop_modified_vars() helper methods
- Integration tests 3/3 PASS

削減: 0行(レガシー経路が現役のため保留)
成果: JoinIR SSOTへの橋を架けた

新規ファイル:
- src/mir/join_ir/frontend/func_meta.rs (25行)
- src/tests/joinir_frontend_if_in_loop_test.rs (160行)
- src/tests/phase40_array_ext_filter_test.rs (135行)

変更ファイル:
- src/mir/join_ir/frontend/ast_lowerer.rs (+89行)
- src/mir/join_ir_vm_bridge.rs (+80行)
- src/tests/mod.rs (+2行)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 09:26:28 +09:00
a3f617874d feat(joinir): Add Phase 40 implementation templates and integration points
Phase 35-39整理(C): JoinIR Frontend拡張雛形作成
- ast_lowerer.rs: extract_if_in_loop_modified_vars() template (~80 lines)
- ast_lowerer.rs: extract_assigned_vars_from_body() template (~80 lines)
- ast_lowerer.rs: lower_loop_case_a_simple() integration point marked
- join_ir_vm_bridge.rs: convert_join_function_to_mir() extension template (~100 lines)

Templates include:
- Detailed purpose and implementation plan
- Integration points in existing code
- Example usage (array_ext.filter)
- Links to Phase 39 design docs
- TODO(Phase 40-1/2/3/4) markers

Effect: Phase 40 implementation ready to start (追加箇所明確、実装漏れ防止)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 07:34:26 +09:00
231eb6e138 docs(phi-reduction): Add Phase 40/41+ deletion markers to if_phi.rs/conservative.rs
Phase 35-39整理(B): ソースコード責務マーキング
- if_phi.rs: Module-level Phase 35-41+ deletion plan added
- if_phi.rs: Function-level markers for Level 2/3 targets
- conservative.rs: Phase 40/41+ deletion plan added

Markers include:
- Deletion phase (40-1/40-2/40-3/40-4, 41+)
- Deletion conditions (prerequisites)
- Replacement path (JoinIR Frontend, JoinIR Verifier)
- Callsites (file:line)
- Reduction effect (line counts)

Effect: Deletion plan visible in code for developers and AI agents

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 07:30:01 +09:00
bec2e2ffe6 feat(joinir): Phase 38 If-side PHI Level 1 deletion (90 lines, LOW safety)
Phase 38: Level 1 deletion complete (exceeded target by 22 lines)
- Deleted merge_modified_with_control (51 lines, dead code, 0 callsites)
- Deleted extract_assigned_var (39 lines, JoinIR AST lowering replacement)
- Updated callsites: if_form.rs (2), phi.rs (2) → replaced with None

File changes:
- if_phi.rs: 315 → 225 lines (90 lines, 28.6% reduction)
- Callsites updated: 4 sites (if_form.rs, phi.rs)

Technical achievements:
 JoinIR coverage verification (None replacement passes all tests)
 Dead code elimination (merge_modified_with_control 0 callsites)
 Staged deletion strategy validation (Phase 37 3-level plan works)

Test results:
 cargo build --release: Clean
 PHI tests: 58/58 PASS (no regression)
 JoinIR Frontend tests: 37/38 PASS (1 failure pre-existing test ordering)
 Full lib tests: 399-400/460 PASS (10-12 non-deterministic failures baseline)

Phase 35-38 cumulative: 605 lines deleted (430+107+90)
Phase 39+ potential: 415 lines (Level 2: 115, Level 3: 300)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 05:01:04 +09:00
e202b95555 feat(joinir): Phase 36 PHI box midrange reduction (MEDIUM safety)
Phase 36-4: LoopSnapshotMergeBox reduction (470 → 363 lines, 22.8%)
- Removed dead code: merge_continue_for_header() + tests (~100 lines)
- Removed superseded helpers: optimize_same_value/sanitize_inputs + tests (~94 lines)
- Removed unused fields: header_phi_inputs/exit_phi_inputs + new/Default (~19 lines)
- Converted to pure static utility (no state, only static methods)

Phase 36-5: PhiBuilderBox responsibility markers
- Added Phase 36 Responsibility Classification section to file header
- Added responsibility markers to all public methods:
  - Loop-only: set_if_context() (if-in-loop PHI context)
  - Common: new(), generate_phis() (stable API for both If and Loop)
  - If-only: generate_if_phis(), compute_modified_names_if(), get_conservative_if_values()
  - Stub: generate_loop_phis() (Phase 37+ implementation target)
- No code changes (markers only)

LoopSnapshotMergeBox changes:
- Removed merge_continue_for_header(): NEVER CALLED in production
- Removed optimize_same_value(): superseded by PhiInputCollector::optimize_same_value()
- Removed sanitize_inputs(): superseded by PhiInputCollector::sanitize()
- Removed test_merge_continue_for_header_*: tests for dead method
- Removed test_optimize_same_value_*: tests for superseded method
- Removed test_sanitize_inputs_*: tests for superseded method
- Added 3 new tests for merge_exit_with_classification():
  - test_merge_exit_with_classification_simple_carrier(): carrier variable
  - test_merge_exit_with_classification_skips_body_local_internal(): Option C logic
  - test_merge_exit_with_classification_break_only_loop(): Case B (header not in exit preds)

PhiBuilderBox changes:
- No wrapper created (hybrid usage pattern - only 1 Loop-specific method)
- Responsibility markers document Loop/If/Common method classification
- Usage pattern clarified: if-in-loop PHI vs loop PHI

Test results:
 cargo build --release: Clean build
 Loop tests: All PASS (no regression)
 If tests: All PASS (unchanged)
 Phase 34 tests: All PASS

Line reduction: 107 lines (LoopSnapshotMergeBox)
Phase 37+ potential: ~3,275 lines remaining

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 02:04:26 +09:00
c2fb9dab6b feat(joinir): Phase 35-5 PHI box deletion (430 lines HIGH safety)
Phase 35-5: First wave deletion
- Deleted if_body_local_merge.rs (339 lines, 0 external calls)
  - Inlined logic into PhiBuilderBox::compute_modified_names_if()
  - Absorbed into PhiBuilderBox (isolated box with no external dependencies)
- Deleted phi_invariants.rs (91 lines, moved to JoinIR Verifier)
  - Removed ensure_if_values_exist() call from phi_builder_box.rs
  - Validation responsibility transferred to JoinIR Verifier
- Updated PHI_BOX_INVENTORY.md with deletion records

Phase 35-3/4: Documentation and route unification
- Added frontend_covered column to PHI_BOX_INVENTORY.md
- Documented JoinIR Runner routes (Route A: SSOT, Route B: structure validation)
- Updated join_ir_runner.rs module docstring with clear route guidelines

Build and test status:
 cargo build --release: Clean
 Phase 34 tests: All PASS (no regression)
 JoinIR tests: joinir_frontend_if_select, test_if_merge_simple_pattern PASS

Total reduction: 430 lines (HIGH safety achieved)
Phase 36+ potential: ~3,275 lines (MEDIUM/LOW safety)

Related docs:
- docs/private/roadmap2/phases/phase-35-phi-reduction/README.md
- docs/private/roadmap2/phases/phase-35-phi-reduction-investigation-report.md
- docs/private/roadmap2/phases/phase-30-final-joinir-world/PHI_BOX_INVENTORY.md

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 01:18:57 +09:00
853d80ba74 feat(joinir): Phase 34-7.5 helpers + Phase 34-8 Break/Continue implementation
Phase 34-7.5: Code organization improvements
- Added type conversion helpers (as_cont/as_func) in join_ir/mod.rs
- Enhanced docstrings for JoinCall/JoinJump with usage examples
- Improved error messages in join_ir_vm_bridge.rs

JoinIrFrontendTestRunner box implementation
- Created src/tests/helpers/joinir_frontend.rs (119 lines)
- Reduced test code by 83% (70 lines → 12 lines per test)
- 26% overall reduction in test file (284 → 209 lines)

Phase 34-8: Break/Continue pattern implementation
- Extended ast_lowerer.rs (+630 lines)
  - lower_loop_break_pattern(): Break as Jump (early return)
  - lower_loop_continue_pattern(): Continue as Select + Call
  - Added Bool literal support in extract_value()
- Created 2 fixtures: loop_frontend_{break,continue}.program.json
- Added 2 A/B tests (all 6 Phase 34 tests PASS)

Technical achievements:
- Break = Jump (early return pattern)
- Continue = Select + Call (NOT Jump) - critical discovery
- 3-function structure sufficient (no k_continue needed)
- SSA-style re-assignment with natural var_map updates

Test results:
 joinir_frontend_if_select_simple_ab_test
 joinir_frontend_if_select_local_ab_test
 joinir_frontend_json_shape_read_value_ab_test
 joinir_frontend_loop_simple_ab_test
 joinir_frontend_loop_break_ab_test
 joinir_frontend_loop_continue_ab_test

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 01:02:49 +09:00
588129db65 feat(joinir): Phase 34-6 MethodCall 構造と本物の substring 意味論
**Phase 34-6 実装完了**: MethodCall 構造を JoinIR に追加し、本物の substring
呼び出しを通すことに成功。

## 主要変更

### 1. MethodCall 構造追加 (34-6.1)
- `src/mir/join_ir/mod.rs`: JoinInst::MethodCall バリアント (+8 lines)
  - 構造: `{ dst, receiver, method, args }`
  - 設計原則: JoinIR は構造のみ、意味論は MIR レベル

### 2. extract_value 更新 (34-6.2)
- `src/mir/join_ir/frontend/ast_lowerer.rs`: Method 処理本物化 (+37 lines)
  - receiver/args を extract_value で再帰処理
  - ダミー Const(0) 削除 → 本物の MethodCall 生成
  - cond 処理修正: ValueId(0) ハードコード → extract_value で取得

### 3. JoinIR→MIR 変換実装 (34-6.3)
- `src/mir/join_ir_vm_bridge.rs`: MethodCall → BoxCall 変換 (+12 lines)
- `src/mir/join_ir/json.rs`: MethodCall JSON シリアライゼーション (+16 lines)
- `src/mir/join_ir_runner.rs`: MethodCall 未対応エラー (+7 lines)

### 4. テスト更新 (34-6.4)
- `docs/.../fixtures/json_shape_read_value.program.json`: 本物の substring 構造
- `src/tests/joinir_frontend_if_select.rs`: run_joinir_via_vm 使用
- テスト成功: v="hello", at=3 → "hel" 

## 成果

-  テスト全通過(1 passed; 0 failed)
-  設計原則確立: JoinIR = 構造 SSOT、意味論 = MIR レベル
-  Phase 33-10 原則との整合性: Method でも同じ原則適用

**ドキュメント更新**: CURRENT_TASK.md + TASKS.md(Phase 34-6 完了記録)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 17:05:46 +09:00
6a5701ead9 feat(joinir): Phase 34-4 & 34-5 — JoinIR Frontend Stage-1/meta 対応 & extract_value 汎用化
Phase 34-4: Stage-1/meta 実用関数対応
- 対象関数: JsonShapeToMap._read_value_from_pair/1
- フィクスチャ簡略化(Int 10/20 ダミー値)
- match 分岐に "_read_value_from_pair" 追加(1行変更)
- テスト追加: joinir_frontend_json_shape_read_value_ab_test
- DRY 原則維持(Phase 34-3 refactoring の完全勝利)

Phase 34-5: extract_value 汎用化 & 実用 if の意味論対応
- ExtractCtx 構造体追加(ValueId カウンタ + 変数名マップ)
- extract_value 実装(Int/Var/Method 対応)
- lower_if_return_pattern を extract_value ベースに統一
- extract_int_value 削除(重複コード削減)
- コメント更新(Phase 34-5 反映)

変更ファイル:
- src/mir/join_ir/frontend/ast_lowerer.rs: +248 -62 lines (ExtractCtx + extract_value)
- src/tests/joinir_frontend_if_select.rs: +66 lines (json_shape テスト)
- CURRENT_TASK.md: Phase 34-4 & 34-5 記録追加
- docs/private: Phase 34 ドキュメント追加(README/TASKS/fixtures)

テスト結果: 3 passed; 0 failed
- joinir_frontend_if_select_simple_ab_test (Phase 34-2)
- joinir_frontend_if_select_local_ab_test (Phase 34-3)
- joinir_frontend_json_shape_read_value_ab_test (Phase 34-4)

技術的成果:
- Int ダミー値 → 本物の式(Var)への段階的移行成功
- extract_value 統一により、今後の expr 拡張が容易に
- Method 呼び出し pattern match 実装(Phase 34-6 への準備完了)
- DRY 原則遵守(extract_int_value 削除、重複コード削減)

ガードレール完全遵守:
- Phase 34 frontend テスト専用(既定経路不変)
- JoinIR = PHI 生成器の原則維持
- 未対応パターンは panic(tiny テスト専用で合理的)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 16:31:06 +09:00
bb170a171e refactor(joinir): DRY principle - unify simple/local lowering
lower_simple_if と lower_local_if の重複コード(132行×2)を統合。

**変更内容**
- lower_simple_if → lower_if_return_pattern にリネーム
- lower_local_if を削除(完全に同じロジックのため)
- 関数名分岐を "test" | "local" に統合
- Phase 34-2/34-3 のコメント統一

**効果**
- コード削減: 340行 → 236行(31%削減)
- 保守性向上: 修正1箇所で済む
- 意図明確化: simple/local が同じパターンであることを型で表現

**技術的意義**
- DRY原則遵守: 重複コード完全排除
- 「値としての if」の統一: Select への正規化が1関数に集約
- Phase 34-4 への準備: パターン追加が容易な構造

テスト: 2 passed (simple + local) 

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 15:34:30 +09:00
66fecd3d14 feat(joinir): Phase 34-2/34-3 JoinIR Frontend implementation
AST→JoinIR フロントエンド経路の基盤完成。simple/local pattern で
「値としての if」が同じ JoinIR Select に正規化されることを実証。

**Phase 34-2: Simple pattern 実装**
- AstToJoinIrLowerer::lower_program_json() 実装
- Program(JSON v0) → JoinModule 変換パイプライン確立
- IfSelectTest.test: if cond { return 10 } else { return 20 }
- 変数ID衝突バグ修正(params分スキップ)

**Phase 34-3: Local pattern 対応**
- lower_simple_if/lower_local_if 関数分岐実装
- IfSelectTest.local: 意味論的 local pattern 対応
- simple と local で JoinIR 出力が同じことを実証

**技術的成果**
- JoinIR = 意味論の SSOT: 構文の違いを Select に統一
- PHI 不要の証明: 値としての if は Select のみで表現可能
- テスト: 2 passed (simple + local)

**実装ファイル**
- src/mir/join_ir/frontend/ast_lowerer.rs (340 lines)
- src/mir/join_ir/frontend/mod.rs (46 lines)
- src/tests/joinir_frontend_if_select.rs (140 lines)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 15:31:12 +09:00
9e9e08eb84 feat(joinir): Phase 33-9.1 Loop/If lowering responsibility separation
Implement clear separation between Loop and If lowering responsibilities:

**Guard Implementation:**
- Add is_loop_lowered_function() to identify 6 Loop-dedicated functions
- Exclude Loop functions from If lowering path in try_lower_if_to_joinir()
- Enforce "1 function → 1 lowering" principle

**Documentation:**
- Add responsibility comments to loop_to_join.rs
- Add responsibility comments to if_select.rs and if_merge.rs
- Update if_joinir_design.md with Phase 33-9.1 section

**Testing:**
- Add unit test test_is_loop_lowered_function() (PASS)
- Verify no regression in existing JoinIR tests

**Loop-dedicated functions (6):**
- Main.skip/1
- FuncScannerBox.trim/1
- FuncScannerBox.append_defs/2
- Stage1UsingResolverBox.resolve_for_source/5
- StageBBodyExtractorBox.build_body_src/2
- StageBFuncScannerBox.scan_all_boxes/1

This prevents future conflicts when both Loop and If lowering expand.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 10:58:56 +09:00
517b20fe88 feat(joinir): Phase 33-8 Stage-1 rollout infrastructure
Add environment variable controls and debug logging for JoinIR lowering rollout.

Changes:
- Add HAKO_JOINIR_STAGE1 env var for Stage-1 function rollout control
- Add HAKO_JOINIR_DEBUG (0-3) for granular debug logging
  - Level 0: Silent (default)
  - Level 1: Basic lowering info
  - Level 2: Pattern matching details
  - Level 3: Full variable/instruction dump
- Implement 3-tier whitelist system:
  - Tier 1: Test functions (always enabled)
  - Tier 2: Stage-1 rollout (env-controlled)
  - Tier 3: Explicit approvals (validated in Phase 33-4)
- Add A/B test automation script (tools/joinir_ab_test.sh)
- Update if_merge.rs and if_select.rs with debug_level support

Environment variables (with NYASH_* fallback for compatibility):
- HAKO_JOINIR_IF_SELECT: Enable JoinIR lowering
- HAKO_JOINIR_STAGE1: Enable Stage-1 function rollout
- HAKO_JOINIR_DEBUG: Debug log level (0-3)

A/B test verification: PASSED on joinir_if_merge_{simple,multiple}.hako

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 09:30:54 +09:00
5b7818f5c9 feat(joinir): Phase 33-7 IfMerge lowering for multiple-variable PHI
Implements IfMerge instruction lowering to support multiple variables
merging from if/else branches (Phase 33-7: return pattern only).

## Changes

- Add src/mir/join_ir/lowering/if_merge.rs (232 lines)
  - IfMergeLowerer with pattern matching for common variables
  - extract_written_vars() / find_written_value() helpers
  - Phase 33-7 constraint: return pattern only (k_next=None)

- Update src/mir/join_ir/lowering/mod.rs
  - Unified entry point: try_lower_if_to_joinir()
  - Priority: IfMerge → Select → if_phi fallback
  - Add IfMergeTest.* to whitelist

- Add unit tests in src/tests/mir_joinir_if_select.rs
  - test_if_merge_simple_pattern (2 variables)
  - test_if_merge_multiple_pattern (3 variables)
  - All 7/7 tests PASS 

- Add reference test cases
  - apps/tests/joinir_if_merge_simple.hako (2-var pattern)
  - apps/tests/joinir_if_merge_multiple.hako (3-var pattern)

## Test Results

 Simple pattern (2 vars): merges=2, k_next=None
 Multiple pattern (3 vars): merges=3, k_next=None
 test result: ok. 7 passed; 0 failed

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 08:18:09 +09:00
2d30277e97 fix(joinir): Correct JsonShapeToMap function name and add Phase 33-5 test whitelist
Changes:
1. **Naming fix**: JsonShapeParser → JsonShapeToMap
   - Updated function name in whitelist to match actual static box name
   - Affected: JsonShapeToMap._read_value_from_pair/1 (lang/src/runtime/meta/json_shape_parser.hako)

2. **Phase 33-5 test whitelist**: Added Stage1JsonScannerTestBox.* pattern
   - Enables A/B testing for Stage-B if/else patterns
   - Test verified: Route A (if_phi) and Route B (Select) both RC=0 

Testing:
- Route A (NYASH_JOINIR_IF_SELECT=0): RC 0 ✓
- Route B (NYASH_JOINIR_IF_SELECT=1): RC 0 ✓
- Pattern: simple if/else return (Stage1JsonScannerBox.value_start_after_key_pos/2 style)

Phase 33-5: Stage-B if/Select A/B testing実施完了

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 05:39:29 +09:00
79cbf26f98 Phase 33-4: Stage-1/Stage-B expansion complete (33-4.1 to 33-4.3)
## Code Changes
- Extended function name whitelist in try_lower_if_to_joinir()
- Added: JsonShapeParser._read_value_from_pair/1 (Stage-1)
- Added: Stage1JsonScannerBox.value_start_after_key_pos/2 (Stage-B)

## Validation
- A/B testing: Route A (if_phi) vs Route B (Select) → identical results (RC 0)
- Test cases: joinir_if_select_simple.hako, joinir_if_select_local.hako
- Build: cargo build --release successful

## Documentation (docs/private submodule)
- TASKS.md: Phase 33-4.1 to 33-4.3 marked complete
- if_joinir_design.md: Section 9 added (candidate analysis)

## Next Steps
- Phase 33-4.4: CI/smoke test updates (pending)
2025-11-27 04:58:01 +09:00
bb4e3044a8 test(joinir): fix Phase 33-3.2 test flakiness by unifying env-dependent tests
Phase 33-3.2 test stabilization:
- Unified 4 env-dependent tests into 1 (test_if_select_pattern_matching)
- Eliminated race condition from parallel test execution
- All 5 tests now pass consistently (5/5 stable PASS)

Before: 8 tests (flaky 7-8/8 due to env var race)
After: 5 tests (stable 5/5, no flakiness)

Test coverage maintained:
- Simple pattern lowering (env ON)
- Local pattern lowering (env ON)
- Disabled by default (env OFF)
- Wrong function name filter (env ON)
- 4 verify tests (env-independent, kept separate)

Documentation:
- Updated TASKS.md with test flake resolution notes
- Updated docs/private submodule to 81ec67f

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 04:27:57 +09:00
4ba3fcd615 Phase 33-3.2: phi_invariants/conservative の JoinIR 側への移譲
実装内容:
- verify_select_minimal() 実装(Select 命令の最小 invariant チェック)
- phi_invariants.rs / conservative.rs のエッセンス抽出・移譲
- 4 テスト追加(simple/local with verify, reject multiple selects, check invariants)

移譲した責務:
- phi_invariants.rs::ensure_if_values_exist() → 型一貫性・完全性チェック
- conservative.rs::ConservativeMerge → 単一 PHI チェック

テスト結果:
-  8/8 tests PASS
-  simple/local パターン: Verifier PASS
-  不正パターン(複数 Select): Verifier REJECT
-  invariant ログ: conservative.rs / phi_invariants.rs からの移譲を明記

制限事項:
- IfSelectTest.* のみ対象、本線 if_phi は保持
- 削除は Stage-1/Stage-B/selfhost への適用後に行う

Phase 33-3.2 完了(2025-11-27)
2025-11-27 03:55:45 +09:00
5cfb0e1d5b Phase 33-3: If/PHI MIR pattern matching + Select lowering (minimal patterns)
Implementation:
- Implement MIR pattern matching in if_select.rs (simple/local patterns)
- Add try_lower_if_to_joinir() entry point in lowering/mod.rs
- Create comprehensive integration tests (4/4 passing)

Pattern Support:
- Simple pattern: if cond { return 1 } else { return 2 }
  - Both blocks must have Return only (no instructions)
- Local pattern: if cond { x = a } else { x = b }; return x
  - Each branch has exactly 1 Copy instruction
  - Both branches jump to same merge block
  - Merge block Returns the assigned variable

Safety Mechanisms:
- Dev toggle: NYASH_JOINIR_IF_SELECT=1 required
- Function name filter: Only IfSelectTest.* functions
- Fallback: Returns None on pattern mismatch
- Zero breaking changes: Existing if_phi path untouched

Tests (4/4 PASS):
- test_if_select_simple_pattern
- test_if_select_local_pattern
- test_if_select_disabled_by_default
- test_if_select_wrong_function_name

Files:
- Modified: src/mir/join_ir/lowering/if_select.rs (pattern matching)
- Modified: src/mir/join_ir/lowering/mod.rs (entry point)
- New: src/tests/mir_joinir_if_select.rs (integration tests)
- Modified: src/tests/mod.rs (module registration)

Phase 33-3.2/3.3 (legacy removal) pending

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 03:28:32 +09:00
35cd93a37a Phase 33-2: JoinInst::Select implementation + minimal If JoinIR lowering
Implementation:
- Add JoinInst::Select variant to JoinIR schema
- Implement Select execution in JoinIR Runner (Bool/Int cond support)
- Add Select handling in JoinIR→MIR Bridge (4-block structure)
- Create test cases (joinir_if_select_simple/local.hako)
- Add dev toggle NYASH_JOINIR_IF_SELECT=1
- Create lowering infrastructure (if_select.rs, stub for Phase 33-3)

Tests:
- 3/3 unit tests pass (test_select_true/false/int_cond)
- Integration tests pass (RC: 0)
- A/B execution verified (existing if_phi vs JoinIR Select)

Files changed:
- New: apps/tests/joinir_if_select_{simple,local}.hako
- New: src/mir/join_ir/lowering/if_select.rs
- Modified: src/mir/join_ir/{mod,json,runner,vm_bridge}.rs
- Modified: src/config/env.rs (joinir_if_select_enabled)
- Modified: docs/reference/environment-variables.md

Phase 33-3 ready: MIR pattern recognition + auto-lowering pending

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 02:58:38 +09:00
b8893787dc feat(joinir): L-5.3 Phase 1 - progress carrier guard for generic_case_a
## 実装内容

1. has_safe_progress() helper 追加 (loop_to_join.rs:186-195)
   - Phase 1: scope.progress_carrier.is_some() をチェック (保守的)
   - Phase 2 (future): MirQuery で Add 命令チェック予定

2. is_supported_case_a_loop_view() に progress guard 追加 (256-266)
   - 無限ループの可能性があるループを事前にフォールバック
   - デバッグログで reject 理由を出力

## テスト結果

 25 passed; 0 failed - JoinIR 関連テスト全通過
 skip_ws / trim / append_defs / Stage‑1 UsingResolver 全ケース PASS
 既存テストへの影響なし

## 技術メモ

- 保守的アプローチ: progress_carrier.is_some() のみチェック
- LoopScopeShape で progress_carrier を carriers の先頭として設定済み
- ignored テスト失敗は MIR 自体の PHI バグで、本変更とは無関係 (git stash で確認済み)

関連: Phase 29 L-5.3 (TASKS.md), CURRENT_TASK.md 1-00v
2025-11-26 16:08:49 +09:00
1eea40454f test(joinir): L-2.2 Step-3 - Add Stage-B JoinIR→MIR structure tests
- Expose `convert_joinir_to_mir` as `pub(crate)` for test access
- Add `joinir_stageb_body_structure_test` and
  `joinir_stageb_funcscanner_structure_test` to `joinir_json_min.rs`
- Verify: JoinIR lowering succeeds, JoinIR→MIR conversion succeeds,
  function count matches, each function has >= 1 block
- Result: Both Stage-B functions produce 2 JoinIR functions
  (entry + loop_step) with appropriate block counts
- Note: Current tests verify handwritten JoinIR→MIR bridge layer,
  not full MIR→JoinIR roundtrip (future improvement)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 11:38:45 +09:00
e61e7a2be6 feat(joinir): L-2.2 Step-2 - Add Stage-B to VM bridge dispatch
Add Stage-B BodyExtractor and FuncScanner to JoinIR VM bridge dispatch:
- Import stageb_body and stageb_funcscanner lowering functions
- Add routing for StageBBodyExtractorBox.build_body_src/2
- Add routing for StageBFuncScannerBox.scan_all_boxes/1
- Add try_run_stageb_body() and try_run_stageb_funcscanner() (lowering verification only)

Also cleanup unused imports in funcscanner_trim.rs and stage1_using_resolver.rs

Note: Stage-B functions use lowering verification pattern (like Stage-1)
because ArrayBox/MapBox args are not yet supported in JoinValue.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 11:02:21 +09:00
9d769e9217 refactor(joinir): L-2.2 Step-1 - Unify Stage-B lowering via LoopToJoinLowerer
Stage-B minimal JoinIR lowering統一化:

1. Add Case-A helpers to loop_to_join.rs:
   - lower_case_a_for_stageb_body (StageBBodyExtractorBox.build_body_src/2)
   - lower_case_a_for_stageb_funcscanner (StageBFuncScannerBox.scan_all_boxes/1)

2. Update stageb_body.rs and stageb_funcscanner.rs:
   - Replace manual LoopForm construction with construct_simple_while_loopform
   - Route through LoopToJoinLowerer like other Case-A functions
   - Remove unused imports (LoopForm, MirQuery)

Now all 6 JoinIR lowering modules use the same unified pattern:
- skip_ws, trim, append_defs, stage1_resolver, stageb_body, stageb_funcscanner
All route through LoopToJoinLowerer for consistency.

Test results: JSON snapshot 6/6 PASS

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 10:47:35 +09:00
853cb36800 refactor(joinir): L-1.3 - Rename minimal helpers to Case-A helpers
LoopToJoinLowerer API cleanup:

1. Rename methods to reflect their purpose as Case-A helpers:
   - lower_minimal_skip_ws_case_a → lower_case_a_for_skip_ws
   - lower_minimal_trim_case_a → lower_case_a_for_trim
   - lower_minimal_append_defs_case_a → lower_case_a_for_append_defs
   - lower_minimal_stage1_case_a → lower_case_a_for_stage1_resolver

2. Update comments to clarify these are thin wrappers over `lower()`
   - "Case-A 汎用 lowerer の薄いラッパー"
   - Actual logic is centralized in `lower` method

3. Update all 4 call sites:
   - skip_ws.rs
   - funcscanner_trim.rs
   - funcscanner_append_defs.rs
   - stage1_using_resolver.rs

Test results: standalone (2/2), JSON snapshot (6/6) PASS

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 10:28:03 +09:00
51ff558904 feat(phase32): L-2.1 Stage-1 UsingResolver JoinIR integration + cleanup
Phase 32 L-2.1 complete implementation:

1. Stage-1 UsingResolver main line JoinIR connection
   - CFG-based LoopForm construction for resolve_for_source/5
   - LoopToJoinLowerer integration with handwritten fallback
   - JSON snapshot tests 6/6 PASS

2. JoinIR/VM Bridge improvements
   - Simplified join_ir_vm_bridge.rs dispatch logic
   - Enhanced json.rs serialization
   - PHI core boxes cleanup (local_scope_inspector, loop_exit_liveness, loop_var_classifier)

3. Stage-1 CLI enhancements
   - Extended args.rs, groups.rs, mod.rs for new options
   - Improved stage1_bridge module (args, env, mod)
   - Updated stage1_cli.hako

4. MIR builder cleanup
   - Simplified if_form.rs control flow
   - Removed dead code from loop_builder.rs
   - Enhanced phi_merge.rs

5. Runner module updates
   - json_v0_bridge/lowering.rs improvements
   - dispatch.rs, selfhost.rs, modes/vm.rs cleanup

6. Documentation updates
   - CURRENT_TASK.md, AGENTS.md
   - Various docs/ updates

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 10:17:37 +09:00
7d0581c9a4 refactor(joinir): Extract construct_simple_while_loopform helper, delete legacy code
Phase 32 cleanup:

1. Delete legacy is_supported_case_a_loop function from loop_to_join.rs
   - Replaced by is_supported_case_a_loop_view() in Phase 32 Step 3

2. Extract construct_simple_while_loopform helper to common.rs
   - Unified LoopForm construction for simple while loops
   - Parameters: entry_is_preheader (trim=true, stage1=false)
                 has_break (trim=true, stage1=false)
   - Sets latch=body to satisfy is_simple_case_a_loop check

3. Update lowering modules to use the common helper:
   - funcscanner_trim.rs: entry_is_preheader=true, has_break=true
   - stage1_using_resolver.rs: entry_is_preheader=false, has_break=false

Test results: JSON snapshot 6/6 PASS, VM bridge trim 2/2 PASS

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 10:15:31 +09:00
ec69b49446 feat(mir): Phase 32 Step 0-3B - LoopRegion/LoopControlShape view methods
Phase 32 introduces a "view pattern" for loop structures, enabling
gradual migration without breaking existing code.

Changes:
- control_form.rs: Add new ID types (LoopId, ExitEdgeId, ContinueEdgeId)
  and structures (LoopRegion, LoopControlShape, ExitEdge, ContinueEdge)
- control_form.rs: Add view methods on LoopShape:
  - to_region_view() - returns LoopRegion
  - to_control_view() - returns LoopControlShape
  - to_exit_edges() - returns Vec<ExitEdge>
  - to_continue_edges() - returns Vec<ContinueEdge>
- loop_scope_shape.rs: Use views in from_existing_boxes_legacy()
- loop_to_join.rs: Add debug logging with Phase 32 views

All 4 minimal lowerers (skip_ws/trim/append_defs/stage1) now use
view-based block ID extraction via shared from_existing_boxes_legacy().

Tests: joinir_runner_standalone_*, joinir_vm_bridge_trim_* PASS

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 08:01:32 +09:00
b35b477c9c feat(phase32): L-1 - Enable JoinIR by default for FuncScannerBox.trim/1
Phase 32 L-1: Make JoinIR the default execution path for verified targets.

- Added is_default_joinir_target() function to check default-enabled functions
- FuncScannerBox.trim/1 is now enabled by default (break=[], Case-A verified)
- Main.skip/1 excluded from default (break=[2], needs Case-B support)
- Environment variable NYASH_JOINIR_VM_BRIDGE=1 still works for other targets

Test results:
- trim: Route C (JoinIR) returns correct value "abc"
- trim: Route A (VM) returns "void" due to PHI bug
- JoinIR correctly handles PHI issues that affect direct VM path

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 06:23:07 +09:00
acffd9974b feat(phase31): Step 3-A/B - Add early return and structure checks to LoopToJoinLowerer
Phase 31 Step 3-A: Add early return using is_case_a_minimal_target() filter
- Check before LoopScopeShape construction for efficiency
- Returns None immediately for non-target functions

Phase 31 Step 3-B: Add structural validation to is_supported_case_a_loop()
- Single exit check: loop_form.break_targets.len() <= 1
- Variable presence check: !carriers.is_empty() || !pinned.is_empty()
- Debug logging for rejection reasons

Also refactored lower_with_scope() from if-else chain to match expression for clarity.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 06:02:52 +09:00
7a29ebd268 refactor(phase31): Connect 4 lowerers to LoopToJoinLowerer
Phase 31 Step 2 complete:
- skip_ws.rs: use LoopToJoinLowerer::lower_minimal_skip_ws_case_a()
- funcscanner_trim.rs: use LoopToJoinLowerer::lower_minimal_trim_case_a()
- funcscanner_append_defs.rs: use LoopToJoinLowerer::lower_minimal_append_defs_case_a()
- stage1_using_resolver.rs: use LoopToJoinLowerer::lower_minimal_stage1_case_a()

Eliminates direct generic_case_a calls, routing through unified box.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 02:36:43 +09:00
ef9fd4417a feat(phase31): Add LoopToJoinLowerer unified box
Phase 31 Step 1 complete:
- Create src/mir/join_ir/lowering/loop_to_join.rs
- Add LoopToJoinLowerer struct with lower() method
- Implement lower_minimal_skip_ws_case_a() via generic_case_a
- Support for trim, append_defs, stage1 patterns
- Re-export from mod.rs

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 01:18:32 +09:00
bbafd9c8b1 refactor(phi_core): Phase 30 F-2.2 delete LoopSnapshotManager (test-only)
Remove LoopSnapshotManager which was only used by its own internal tests.
No external call sites existed.

- Delete loop_snapshot_manager.rs (~458 lines)
- Update mod.rs to remove module declaration
- Update PHI_BOX_INVENTORY.md and TASKS.md

Analysis showed all other F-2.2 candidates have production dependencies
and must wait for JoinIR coverage expansion:
- PhiBuilderBox - loop_builder.rs
- LoopSnapshotMergeBox - loopform_builder.rs, json_v0_bridge
- if_phi.rs - lifecycle.rs, if_form.rs, loop_builder.rs
- if_body_local_merge.rs - phi_builder_box.rs, loop_builder.rs
- phi_invariants.rs, conservative.rs, phi_input_collector.rs - multiple

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 00:44:11 +09:00
bf3893b2cc feat(mir): Phase 30 F-3.0.7 LoopScopeShape Case-A minimal routing
Add func_name-based routing in LoopScopeShape::from_existing_boxes()
to prepare for MIR-based independent analysis:

- Add is_case_a_minimal_target() helper for 4 Case-A targets
- Add analyze_case_a() method (delegates to legacy, future MIR-based)
- Add from_existing_boxes_legacy() for backward compatibility
- Update from_existing_boxes() with func_name: Option<&str> parameter
- Update 4 production call sites with specific func_name
- Update 6 test cases with None for legacy path
- Update module documentation with routing logic diagram

Tests: 10/10 LoopScopeShape tests PASS, 6/7 JoinIR VM bridge tests PASS

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 00:36:41 +09:00
2b47f47061 refactor(phi_core): F-2.1 - 早期グループPHI箱削除(約2,500行削減)
## 削除したファイル
- header_phi_builder.rs (~628行) - バイパス関数を loopform_builder.rs に移動
- exit_phi_builder.rs (~1000行) - バイパス関数を loopform_builder.rs に移動
- body_local_phi_builder.rs (~550行) - 依存なし
- loop_phi.rs (~288行) - LoopPhiOps実装も削除

## 移動した関数
loopform_builder.rs に以下を移動:
- get_loop_bypass_flags() / LoopBypassFlags struct
- is_joinir_header_bypass_target()
- joinir_exit_bypass_enabled()
- is_joinir_exit_bypass_target()

## 修正したファイル
- loop_builder.rs: バイパス関数の参照先変更 + LoopPhiOps impl削除
- mod.rs: モジュール宣言削除

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 23:42:35 +09:00
a898ff3f83 refactor(joinir): Phase 30 F-2.0/F-3 - PHI箱インベントリと旧APIレガシー削除
F-3 レガシー削除:
- generic_case_a.rs: 旧API関数4個削除(_with_scope 移行完了)
- loop_scope_shape.rs: CaseAContext::new() 削除(from_scope() に統一)
- mod.rs: 不要な pub use 削除
- #[allow(dead_code)] 除去(5関数)
- 未使用import削除(コード削減約150行)

F-2.0 PHI箱インベントリ:
- PHI_BOX_INVENTORY.md 作成: 13箱+11補助構造体の棚卸し
- 削除順ポリシー: 早期/中期/最終の3段階
- TASKS.md/CURRENT_TASK.md 更新

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 23:25:39 +09:00
6598cd3272 refactor(joinir): F-3 add _with_scope variant for skip_ws lowering
Phase 30 F-3: LoopScopeShape 実データ運用の一歩目

変更内容:
- lower_case_a_skip_ws_with_scope(scope) 追加
  - LoopScopeShape を直接受け取る新 API
  - CaseAContext::from_scope() 経由で ctx 構築
- lower_case_a_skip_ws_core(ctx) 抽出
  - 共通ロジックを分離
  - _for_minimal_skip_ws と _with_scope で共有

設計意図:
- lowerer が scope を明示的に構築できる API を提供
- 将来の boxes 削除時に移行しやすい構造を準備
- 既存 API は後方互換性を維持

テスト結果:
- JoinIR 関連テスト: 全 PASS
- loop_scope_shape テスト: 10/10 PASS

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 15:48:00 +09:00
de5d5fae52 feat(mir): Phase 30 F-1 LoopScopeShape SSOT preparation
LoopScopeShape を変数分類の唯一の情報源 (SSOT) にするための準備:

F-1.1 LoopVarClassBox:
- 4分類(Pinned/Carrier/BodyLocalExit/BodyLocalInternal)の仕様を
  loop_scope_shape.rs にドキュメント化(PHI生成ルール表付き)
- LoopScopeShape.classify() / classify_all() メソッド追加
- LoopVarClassBox.classify_with_scope() 委譲メソッド追加
- 旧APIにPhase 30 TODOコメント追加

F-1.2 LoopExitLivenessBox:
- exit_live フィールドにSSOT説明ドキュメント追加
- get_exit_live_from_scope() 委譲メソッド追加

F-1.3 LocalScopeInspectorBox:
- Phase 30移行中のTODOコメント追加
- is_available_in_all_with_scope() 委譲メソッド追加

未使用フィールド削除:
- CaseAContext::scope フィールド削除
- LoopBypassFlags::exit フィールド削除
- PhiBuilderBox::loop_context / LoopPhiContext 削除

テスト結果: 37テスト全てPASS
- loop_scope_shape: 12 PASS (+2 new)
- loop_var_classifier: 11 PASS
- loop_exit_liveness: 3 PASS
- local_scope_inspector: 11 PASS

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 15:14:54 +09:00
e93727dd37 fix(joinir): Stage-1 string concat BinOp::Or → Add + ArrayBox support
Fixes:
1. BinOp::Or → BinOp::Add for string concatenation in Stage-1 lowering
2. ArrayBox/MapBox support via JoinValue::BoxRef (ChatGPT implementation)

Results:
- n=0: JoinIR → "init"  (VM → "void" PHI bug)
- n=3: JoinIR → "ABC"  (VM → "void" PHI bug)

Stage-1 JoinIR VM Bridge now fully working!

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 13:33:01 +09:00
6d10fc45ba feat(joinir): Stage-1 Route B execution test - prove PHI fix
Add Route B execution tests for Stage-1 UsingResolver:

Results:
- n=0 (no loop): JoinIR returns "init"  vs VM returns "void" (PHI bug)
- n=3 (loop runs): JoinIR errors "IntegerBox.get" - needs ArrayBox support

This proves JoinIR can fix PHI bugs in Stage-1 loops.
Next step: JoinValue extension for ArrayBox/MapBox arguments.

Test: joinir_vm_bridge_stage1_usingresolver_route_b_*

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 12:53:12 +09:00
29ae922a57 feat(joinir): Stage-1 UsingResolver JoinIR VM Bridge A/B test
Phase 30.x: Stage-1 ループでも PHI バグが発生することを確認・JoinIR で設計根絶可能を実証

変更内容:
- src/tests/joinir_vm_bridge_stage1_usingresolver.rs: 新規作成(モジュール化・削除容易)
  - empty_entries: VM → "void" (PHI bug, expected "init")
  - with_entries: VM → "void" (PHI bug, expected "ABC")
  - lowering_sanity: 常時実行の構造検証
- src/runner/modes/vm.rs: Stage1UsingResolverBox.resolve_for_source/5 検出・JoinIR lowering 確認
- src/tests/mod.rs: モジュール追加(1行で削除可能)
- docs: Phase 30 TASKS.md に L-0.5 追加

発見:
  Stage-1 ループでも PHI バグが発生 → JoinIR で設計根絶可能を確認
  (ArrayBox/MapBox 引数対応は TODO)

テスト結果:
   empty_entries ... ok (VM="void", expected="init", PHI bug detected)
   with_entries ... ok (VM="void", expected="ABC", PHI bug detected)
   lowering_sanity ... ok (JoinIR structure: 2 functions)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 12:34:20 +09:00
ee2b3115ee feat(joinir): FuncScannerBox.trim/1 JoinIR VM Bridge A/B test
Phase 30.x: JoinIR VM Bridge でPHI問題を設計で解決できることを実証

変更内容:
- src/runner/modes/vm.rs: FuncScannerBox.trim/1 検出時にJoinIR経由実行
- src/mir/join_ir_vm_bridge.rs: Non-tail call サポート追加
  - dst=Some(id) の場合、結果を格納して次の命令へ継続
- src/tests/joinir_vm_bridge_trim.rs: A/Bテスト新規作成
  - メインテスト: Route A (VM) → "void" (PHI bug), Route C (JoinIR) → "abc" 
  - エッジケース: 5パターン全てPASS
- src/config/env.rs: joinir_vm_bridge_debug() 追加
- docs: Phase 30 TASKS.md に L-0.4 追加

テスト結果:
  Route A (MIR→VM直接):     "void"  ← PHI バグ
  Route C (MIR→JoinIR→VM):  "abc"   ← 正解 

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 12:22:08 +09:00
de16ff9b7f feat(joinir): Phase 30.x jsonir v0 snapshot tests
Implement JSON snapshot testing for JoinIR regression detection.

Implementation:
- tests/fixtures/joinir/v0_*.jsonir: 6 snapshot fixtures for minimal JoinIR cases
- src/tests/joinir_json_min.rs: Added 6 snapshot comparison tests

Fixtures:
- v0_skip_ws_min.jsonir (1338 bytes)
- v0_funcscanner_trim_min.jsonir (4484 bytes)
- v0_funcscanner_append_defs_min.jsonir (988 bytes)
- v0_stage1_usingresolver_min.jsonir (987 bytes)
- v0_stageb_body_min.jsonir (1074 bytes)
- v0_stageb_funcscanner_min.jsonir (962 bytes)

Usage:
  # Run snapshot tests
  NYASH_JOINIR_SNAPSHOT_TEST=1 cargo test --release joinir_json_v0_

  # Regenerate fixtures (after intentional changes)
  NYASH_JOINIR_SNAPSHOT_TEST=1 NYASH_JOINIR_SNAPSHOT_GENERATE=1 cargo test --release joinir_json_v0_

Purpose:
- Fix current JoinIR shape as v0 baseline (pre-generic state)
- Detect unintended regressions during genericization
- Allow intentional fixture updates when design changes

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 10:19:02 +09:00
e9c7d27a7f feat(joinir): Phase 30.x jsonir v0 - JoinIR JSON serialization
Implement JSON serialization for JoinIR module.

Implementation:
- src/mir/join_ir/json.rs: JSON serializer (~250 lines, no external deps)
- src/tests/joinir_json_min.rs: Integration tests (8 unit + 2 integration)
- 10 tests total, all passing

Features:
- JoinModule → JSON serialization
- All instruction types: Call, Jump, Ret, Compute
- All MirLikeInst types: Const, BinOp, Compare, BoxCall
- Full ConstValue support: Integer, Bool, String, Null
- Full operator coverage: Add/Sub/Mul/Div/Or/And, Lt/Le/Gt/Ge/Eq/Ne
- JSON string escaping for special characters

Usage:
  use crate::mir::join_ir::json::join_module_to_json_string;
  let json = join_module_to_json_string(&module);

Non-goals (this phase):
- CLI flag (--emit-joinir-json)
- JSON → JoinIR reverse conversion

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 09:53:26 +09:00
c479e5f527 fix(dx): Quick Win 1-3 for better error messages and API simplification
Quick Win 1: Show available boxes on "Unknown Box type" error
- vm.rs, vm_fallback.rs: Display sorted list of available user-defined boxes
- Before: "Unknown Box type: Foo"
- After:  "Unknown Box type: Foo. Available: Bar, Baz, Main"

Quick Win 2: Show stderr on child process timeout
- child.rs, selfhost_exe.rs: Capture and display stderr (up to 500 chars)
- Helps diagnose what went wrong in selfhost compiler child process

Quick Win 3: Simplify Stage-B compiler API (SSOT)
- compiler_stageb.hako: Add StageBDriverBox.compile() as single entry point
- compiler_stageb.hako: Remove StageBMain compatibility wrapper
- compiler.hako: Change from `using ... as StageBMain` to direct import
- compiler.hako: Call StageBDriverBox.compile() directly

Also includes child_env.rs NYASH_MODULES env var for module mapping.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 08:44:31 +09:00
6726ee246d fix(selfhost): Phase 28.2 Ny compiler child process fixes
- Use --stage-b flag for file-based compilation (Stage-A expects source
  content, not path; Stage-B uses FileBox to read files)
- Remove redundant env overrides that conflicted with
  apply_selfhost_compiler_env() settings
- Re-enable plugins in selfhost compiler env (NYASH_DISABLE_PLUGINS=0)
  so compiler.hako can use FileBox to read source files

Note: Pipeline infrastructure now works, but compiler.hako has a MIR
SSA bug (undefined ValueId(374)) that needs separate investigation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 07:49:47 +09:00
22575aa1db refactor(selfhost): clean up selfhost.rs - remove duplicates, unify env access
## Changes

### Duplicate code removal
- Remove nested double cli_verbose() checks (2 places)
- Remove duplicate pre_run_reset_oob_if_strict() calls
- Remove duplicate OOB strict check blocks

### Environment variable access unification
- All raw std::env::var() calls replaced with config::env functions
- Added new config::env functions:
  - ny_compiler_use_py()
  - macro_selfhost_pre_expand()
  - scopebox_enable()
  - loopform_normalize()
  - selfhost_inline_force()

### Common helper extraction
- maybe_dump_mir_verbose(): MIR dump with verbose check
- check_oob_strict_exit(): OOB strict mode check and exit
- execute_with_oob_check(): Combined run + OOB check

## Result
- Net ~11 lines reduction
- Much better code structure and maintainability
- Consistent environment variable access through config::env

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 07:18:29 +09:00
94b2bd2799 feat(selfhost): add observation logs for Ny compiler path diagnosis
Add NYASH_CLI_VERBOSE>=2 observation logs to trace the Ny compiler
child process path (NYASH_USE_NY_COMPILER=1):
- Log when spawning child process
- Log when receiving Program(JSON v0)
- Log before/after maybe_dump_mir with dump path info
- Report whether MIR dump file was created

Key finding: apps/selfhost/compiler/compiler.hako doesn't exist,
so the preferred child process route never fires. This explains
why RUST_MIR_DUMP_PATH doesn't create files in Ny compiler path.

Also update environment-variables.md with:
- NYASH_CLI_VERBOSE=2 level documentation
- Ny compiler observation template for Phase 29

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 07:08:32 +09:00
8ae5280be2 feat(joinir): promote joinir_runner_standalone_trim to mainline test
Remove #[ignore] from trim test, following skip_ws promotion pattern:
- NYASH_JOINIR_EXPERIMENT=1 toggle controls execution
- Normal cargo test skips via early return (lightweight)
- Two JoinIR standalone tests now available as PHI-independent baselines

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 06:54:35 +09:00