2c68b04e49
feat(joinir): Phase 188 Pattern 1 tail call parameter binding
...
Problem: Tail call conversion (Call→Jump) was failing because:
1. Function parameters were not bound, causing "undefined value" errors
2. Instructions before Call (like BoxCall for print) were being skipped
Solution: Implemented two-pass tail call conversion:
- First pass: Process all instructions, detect tail calls, skip only Call itself
- Second pass: Insert Copy instructions to bind call arguments to parameters
Implementation:
- Lines 517-609: Two-pass approach with tail_call_target tracking
- Lines 588-603: Parameter binding via Copy instructions (arg → param)
- Lines 566-573: Debug logging for BoxCall verification
Example binding:
Call(loop_step, [i_next])
→ Copy { dst: param_i, src: i_next }
→ Jump(loop_step_entry)
Status: JoinIR firing ✅ , parameter binding ✅
Blocker: Non-deterministic HashMap iteration (next fix)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-05 11:40:05 +09:00
074fab8459
fix(joinir): Phase 189 HashMap collision bug fix - composite keys
...
Problem: Multiple JoinIR functions had blocks with identical BasicBlockIds
(e.g., func_0 and func_2 both had BasicBlockId(0)), causing HashMap key
collisions in merge_joinir_mir_blocks(). This corrupted block mappings
and prevented multi-function JoinIR→MIR merge.
Solution: Use composite keys (String, BasicBlockId) instead of simple
BasicBlockId in the global block_map to guarantee uniqueness across
functions.
Implementation:
- Line 399: Changed block_map type to HashMap<(String, BasicBlockId), BasicBlockId>
- Lines 491-507: Added per-function local_block_map for remap compatibility
- Lines 610-616: Updated entry function block_map access to use composite key
Verification:
- Build: ✅ 0 errors (34 unrelated warnings)
- Coverage: ✅ 100% (all 4 block_map accesses use composite keys)
- Performance: ✅ O(1) HashMap lookups maintained
Phase 189 Status: ✅ COMPLETED (1h vs 4-6h estimate)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-05 11:08:08 +09:00
5bc0fa861f
feat(joinir): Phase 188 Pattern 1 Core Implementation + Phase 189 Planning
...
Phase 188 Status: Planning & Foundation Complete (100%)
Completed Tasks:
✅ Task 188-1: Error Inventory (5 patterns identified)
✅ Task 188-2: Pattern Classification (3 patterns selected)
✅ Task 188-3: Design (51KB comprehensive blueprint)
✅ Task 188-4: Implementation Foundation (1,802 lines scaffolding)
✅ Task 188-5: Verification & Documentation
✅ Pattern 1 Core Implementation: Detection + Lowering + Routing
Pattern 1 Implementation (322 lines):
- Pattern Detection: is_simple_while_pattern() in loop_pattern_detection.rs
- JoinIR Lowering: lower_simple_while_to_joinir() in simple_while_minimal.rs (219 lines)
- Generates 3 functions: entry, loop_step (tail-recursive), k_exit
- Implements condition negation: exit_cond = !(i < 3)
- Tail-recursive Call pattern with state propagation
- Routing: Added "main" to function routing list in control_flow.rs
- Build: ✅ SUCCESS (0 errors, 34 warnings)
Infrastructure Blocker Identified:
- merge_joinir_mir_blocks() only handles single-function JoinIR modules
- Pattern 1 generates 3 functions (entry + loop_step + k_exit)
- Current implementation only merges first function → loop body never executes
- Root cause: control_flow.rs line ~850 takes only .next() function
Phase 189 Planning Complete:
- Goal: Refactor merge_joinir_mir_blocks() for multi-function support
- Strategy: Sequential Merge (Option A) - merge all functions in call order
- Effort estimate: 5.5-7.5 hours
- Deliverables: README.md (16KB), current-analysis.md (15KB), QUICKSTART.md (5.8KB)
Files Modified/Created:
- src/mir/loop_pattern_detection.rs (+50 lines) - Pattern detection
- src/mir/join_ir/lowering/simple_while_minimal.rs (+219 lines) - Lowering
- src/mir/join_ir/lowering/loop_patterns.rs (+803 lines) - Foundation skeleton
- src/mir/join_ir/lowering/mod.rs (+2 lines) - Module registration
- src/mir/builder/control_flow.rs (+1 line) - Routing fix
- src/mir/builder/loop_frontend_binding.rs (+20 lines) - Binding updates
- tools/test_phase188_foundation.sh (executable) - Foundation verification
- CURRENT_TASK.md (updated) - Phase 188/189 status
Next: Phase 189 implementation (merge_joinir_mir_blocks refactor)
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-05 07:47:22 +09:00
fa8a96a51b
docs(joinir): Phase 187 LoopBuilder Physical Removal - Completion Documentation
...
## Changes
- Added Phase 187 section to Phase 180 README documenting complete LoopBuilder deletion
- Documented all 4 tasks completion (187-1 through 187-4)
- Added architectural impact analysis before/after Phase 187
- Documented code deletion summary and archival strategy
- Explained NYASH_LEGACY_LOOPBUILDER variable status after deletion
## Key Achievements
- LoopBuilder module (8 files, ~1000+ lines) completely deleted
- IfInLoopPhiEmitter preserved in minimal new module
- JoinIR Frontend is now sole authoritative loop lowering system
- Explicit failures replace implicit fallbacks
## Architectural Impact
- Single authoritative path (JoinIR Frontend)
- No implicit fallbacks
- Future JoinIR expansion is only way forward
- Fail-Fast principle enforced at architecture level
## Related Phases
- Phase 185: Strict mode semantics unified
- Phase 186: Hard freeze with access control guard
- Phase 187: Physical module deletion (this change)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-04 23:51:49 +09:00
30f94c9550
feat(joinir): Phase 186 LoopBuilder Hard Freeze - Add access control guard
...
Add environment variable check at LoopBuilder fallback point (control_flow.rs:60).
LoopBuilder is now only accessible when NYASH_LEGACY_LOOPBUILDER=1 is explicitly set.
Changes:
- control_flow.rs: Add env guard before LoopBuilder instantiation
- Default behavior: JoinIR-only (LoopBuilder disabled)
- Legacy mode: NYASH_LEGACY_LOOPBUILDER=1 enables fallback
- Error message: Clear hint about legacy mode opt-in
Testing:
- legacy OFF (NYASH_LEGACY_LOOPBUILDER=0): Error (frozen)
- legacy ON (NYASH_LEGACY_LOOPBUILDER=1): Success (allowed)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-04 23:35:33 +09:00
2337e8a378
refactor(phase124): Remove legacy path from MIR Builder cf_if
...
- Delete NYASH_HAKO_CHECK_JOINIR conditional branch logic
- Remove try_cf_if_joinir() placeholder function entirely
- Simplify cf_if() to direct lower_if_form() call (JoinIR-only)
- Update documentation to Phase 124 JoinIR-only architecture
- Apply Fail-Fast principle: no fallback logic
Build: ✅ Success (0 errors, 10 warnings)
Phase 124 Task 3/5 complete
2025-12-04 06:29:54 +09:00
adc10fdf54
Phase 123 proper完了:hako_check JoinIR実装(環境変数選択可能化)
...
## 実装内容
### 1. 環境変数フラグ追加
- NYASH_HAKO_CHECK_JOINIR でJoinIR/Legacy経路を切り替え可能
- src/config/env/hako_check.rs で hako_check_joinir_enabled() 実装
- デフォルト: false(レガシー経路)で後方互換性確保
### 2. MIR Builder JoinIR スイッチ
- cf_if() メソッドにフラグチェック追加
- try_cf_if_joinir() プレースホルダー実装(Phase 124で完全実装)
- JoinIR → legacy フォールバック機構を構築
### 3. テストケース作成(4個)
- phase123_simple_if.hako
- phase123_nested_if.hako
- phase123_while_loop.hako
- phase123_if_in_loop.hako
### 4. テスト結果
✅ Legacy path: 4/4 PASS
✅ JoinIR path: 4/4 PASS
(JoinIR path は現在フォールバック経由で動作)
### 5. ドキュメント更新
- environment-variables.md: NYASH_HAKO_CHECK_JOINIR 記載
- phase121_hako_check_joinir_design.md: Phase 123実装セクション追加
- hako_check_design.md: 2パス実行フロー図を追加
- CURRENT_TASK.md: Phase 123完了を記録
## 数値成果
- 新規ファイル: 2個 (config/env/hako_check.rs, test cases × 4, test script)
- 修正ファイル: 6個
- 総追加行数: 335行
- ビルド: Zero errors
## 設計・実装の特徴
✅ Environment variable で簡単に経路切り替え可能
✅ レガシー経路を完全に保持(後方互換性)
✅ JoinIR基盤を Phase 124 での完全実装に向けて構築
✅ フォールバック機構でリスク最小化
## 次のステップ
Phase 124: JoinIR 完全実装&デフォルト化
- try_cf_if_joinir() を IfSelectLowerer と統合
- Loop JoinIR 統合追加
- JoinIR をデフォルト経路に変更
- NYASH_LEGACY_PHI=1 で legacy フォールバック可能に
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-04 06:17:10 +09:00
8633224061
JoinIR/SSA/Stage-3: sync CURRENT_TASK and dev env
2025-12-01 11:10:46 +09:00
7de192aa6b
feat(mir): Phase 69-3 Fix MIR non-determinism with BTreeSet
...
Replace HashSet with BTreeSet for CFG predecessors/successors:
- BasicBlock.predecessors: HashSet → BTreeSet
- BasicBlock.successors: HashSet → BTreeSet
- LoopFormOps.get_block_predecessors(): returns BTreeSet
- BasicBlock.dominates(): takes &[BTreeSet<BasicBlockId>]
This ensures deterministic PHI generation and test stability.
Test results:
- loop_with_continue_and_break tests: now deterministic (3/3 same output)
- loopform tests: 14/14 PASS (no regressions)
- merge_exit_with_classification tests: 3/3 PASS
Technical changes (6 files):
- basic_block.rs: BTreeSet types + new() initialization
- loopform_builder.rs: trait signature + 2 mock implementations
- phi_ops.rs: return type
- json_v0_bridge/loop_.rs: return type
Same pattern as Phase 25.1 (MirFunction.blocks HashMap → BTreeMap).
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-30 09:38:28 +09:00
c6edbaaf3a
feat(mir): Phase 63-6-1/2 MIR Phi type_hint field & JoinIR propagation
...
Phase 63-6-1: MirInstruction::Phi に type_hint フィールド追加
- Added `type_hint: Option<MirType>` field to Phi instruction
- Updated 21 files with type_hint initialization (all set to None for legacy paths)
- Pattern matching updated across codebase (11 files)
- Test code updated (basic_block.rs)
Phase 63-6-2: JoinIR→MIR Bridge で型ヒント伝播実装
- Modified convert.rs: Select → MIR now creates PHI with type_hint
- Removed Copy instructions from then/else blocks
- PHI instruction at merge block receives type_hint from JoinIR Select
- Test verification: ✅ Type hint propagation successful (Some(Integer))
Modified files:
- instruction.rs: Added type_hint field definition
- join_ir_vm_bridge/convert.rs: Select lowering with PHI + type_hint
- 19 other files: type_hint field initialization
Test results:
- ✅ test_type_hint_propagation_simple: Type hint = Some(Integer) confirmed
- ✅ 7/8 if_select tests passing (1 race condition, passes individually)
Next: Phase 63-6-3 (lifecycle.rs で型ヒント使用)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-30 04:35:40 +09:00
7a1a4bd964
refactor(mir): loop_builder.rs モジュール化 - 6ファイルに分割
...
## リファクタリング内容
### ファイル構造変更
- `src/mir/loop_builder.rs` (1515行) 削除
- `src/mir/loop_builder/` ディレクトリ新設(6ファイル、1529行)
### 新規モジュール構成
1. **mod.rs** (6,293行 → 実際は約150行)
- モジュール定義とre-export
- LoopBuilder構造体定義
2. **loop_form.rs** (25,988行 → 実際は約650行)
- メインループlowering pipeline
- デバッグ/実験フラグ集約
3. **if_lowering.rs** (15,600行 → 実際は約390行)
- In-loop if lowering with JoinIR/PHI bridge
- **Phase 61-2コード完全保持**:
- JoinIR dry-run検証モード
- PhiSpec計算とA/B比較
4. **phi_ops.rs** (12,844行 → 実際は約320行)
- PHI emit helpers
- LoopFormOps/PhiBuilderOps impls
5. **control.rs** (4,261行 → 実際は約107行)
- break/continue capture
- predecessor bookkeeping
6. **statements.rs** (1,673行 → 実際は約42行)
- loop-body statement lowering entry point
7. **README.md** (752行 → 実際は約19行)
- モジュール責務とサブモジュール説明
### 設計原則
- **責務分離**: CFG構築/PHI生成/制御フロー/文処理を分離
- **Phase 61-2保持**: if_lowering.rsにJoinIR dry-run完全移行
- **phi_core委譲**: PHI構築ロジックは`phi_core`に委譲
## テスト結果
- Phase 61-2テスト: ✅ 2/2 PASS(dry-runフラグ、PhiSpec)
- loopformテスト: ✅ 14/14 PASS(退行なし)
- ビルド: ✅ 成功(エラー0件)
## 統計
- **純削減**: -1,521行(25ファイル変更)
- **loop_builder**: 1515行 → 1529行(+14行、6ファイル化)
- **可読性**: 巨大単一ファイル → 責務別モジュール
## ChatGPT設計・Claude確認
大規模リファクタリングをChatGPTが実施、Claudeが検証完了。
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 12:44:40 +09:00
ad9daf37ac
feat(joinir): Phase 56 ArrayExtBox.filter JoinIR lowering完全実装
...
## Summary
ArrayExtBox.filter/2 の JoinIR Frontend lowering を完全実装し、
ConditionalMethodCall 命令を導入して filter パターンに対応。
56 JoinIR テスト全て PASS(退行なし)。
## Technical Changes
### 1. ConditionalMethodCall 命令追加
- **新規命令**: `if pred(v) { acc.push(v) }` パターン用
- **構造**: cond が true なら method 実行、false なら no-op
- **MIR 変換**: 4ブロック構造 (cond→then/else→merge)
### 2. AST JSON 拡張
- Break/Continue/FunctionCall に "type" フィールド追加
- ArrayLiteral/MapLiteral に "type" フィールド追加
- JoinIR Frontend 互換性向上
### 3. Expression Handler 拡張
- Unary 演算子(not, 負号)サポート
- Call(変数関数呼び出し)を MethodCall に変換
### 4. Loop Pattern Binding 修正
- `BoundExpr::Variable("n")` 問題修正
- `MethodCall { receiver: "arr", method: "size" }` に変更
- external_refs (arr, pred) を step 関数に伝播
### 5. If Statement Handler 拡張
- 条件付き側効果パターン(ケース4)追加
- MethodCall/Method 形式の statement を ConditionalMethodCall に変換
## Files Modified (10 files, +456/-45 lines)
- ast_json.rs: AST JSON "type" フィールド追加
- loop_frontend_binding.rs: n バインディング修正
- control_flow.rs: external_refs params 追加
- loop_patterns.rs: external_refs step 関数伝播
- expr.rs: Unary, Call handler 追加
- stmt_handlers.rs: ConditionalMethodCall パターン追加
- mod.rs: ConditionalMethodCall, UnaryOp 定義
- json.rs: ConditionalMethodCall, UnaryOp シリアライズ
- join_ir_runner.rs: ConditionalMethodCall, UnaryOp スタブ
- convert.rs: ConditionalMethodCall → MIR 変換
## Test Results
- 56 JoinIR tests: ✅ PASSED
- Regression: ❌ None
- ArrayExtBox.filter/2: ✅ JoinIR lowering 成功
## Milestone
JoinIR 2ループ完走達成:
- ✅ JsonTokenizer.print_tokens/0
- ✅ ArrayExtBox.filter/2 (NEW!)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 06:51:43 +09:00
e27934d91a
feat(joinir): Phase 52-53 LoopFrontendBinding JSON + Statement Handlers
...
Phase 52: LoopFrontendBinding JSON generation fixes
- Add receiver_to_json() for Field node structure (me.tokens)
- Add needs_me_receiver() for instance method detection
- Fix "condition" → "cond" key for JoinIR Frontend
- Add me parameter propagation in loop_patterns.rs
- Add JoinIR-compatible type fields in ast_json.rs
- Variable → "type": "Var"
- Literal → "type": "Int"/"Bool" (literal_to_joinir_json)
- BinaryOp → "type": "Binary"/"Compare" (is_compare_op)
- MethodCall → "type": "Method"
Phase 53: Statement Handler module for loop body
- NEW: stmt_handlers.rs with StatementEffect type
- Support: Local, Assignment, Print, Method, If statements
- If lowering: single variable update → Select instruction
- Remove hardcoded assert in loop_patterns.rs
- Replace with generic lower_statement() calls
Test results: 56 JoinIR tests PASS, 7 loop_frontend_binding tests PASS
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 04:42:16 +09:00
3dc691d39f
feat(joinir): Phase 50 Loop Frontend Binding layer
...
Phase 50 implements the Loop Frontend Binding layer that maps
actual loop variables to JoinIR Frontend's expected names (i, acc, n).
## Changes
- Add loop_frontend_binding.rs module with:
- LoopFrontendBinding struct for variable mapping
- for_print_tokens() and for_array_filter() factory methods
- generate_local_declarations() for JSON v0 format
- rename_body_variables() for out → acc renaming
- Integrate binding with cf_loop_joinir_impl:
- Create binding based on function name
- Inject i/acc/n Local declarations into JSON v0
- Use correct JoinIR Frontend type names (Int/Var/Method)
## Limitations Found
JoinIR Frontend doesn't support:
- Field access (me.tokens) - blocks print_tokens
- NewBox (new ArrayBox()) - blocks array_filter
These will be addressed in Phase 51.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-28 20:59:54 +09:00
1e1b2183b2
feat(joinir): Phase 49-4 multi-target routing with graceful fallback
...
- Add ArrayExtBox.filter/2 as second JoinIR mainline target
- Fix function name arity: print_tokens is /0 (no implicit me in arity)
- Construct proper JSON v0 format with defs array for JoinIR Frontend
- Add catch_unwind for graceful fallback on unsupported patterns
- Add 3 array_filter tests (smoke, fallback, A/B comparison)
- All 6 Phase 49 tests passing
Dev flags:
- HAKO_JOINIR_PRINT_TOKENS_MAIN=1: JsonTokenizer.print_tokens/0
- HAKO_JOINIR_ARRAY_FILTER_MAIN=1: ArrayExtBox.filter/2
Note: Currently all loops fall back to legacy LoopBuilder due to
JoinIR Frontend expecting hardcoded variable names (i, acc, n).
Full JoinIR integration pending variable scope support in Phase 50+.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-28 20:12:39 +09:00
20d9b412b2
feat(joinir): Phase 49-3.2 merge_joinir_mir_blocks full implementation
...
Implement actual block merging for JoinIR Frontend mainline integration:
- Block ID remapping: Allocate new IDs from block_gen for all JoinIR blocks
- Value ID remapping: Allocate new IDs from next_value_id() for all values
- Instruction cloning: Clone all instructions with remapped IDs
- Return→Jump conversion: Convert Return terminators to Jump to exit block
- Control flow wiring: Jump from current block to JoinIR entry
Helper functions added:
- collect_values_in_block(): Collect all ValueIds in a block
- collect_values_in_instruction(): Collect all ValueIds in an instruction
- remap_instruction(): Remap ValueIds and BlockIds in an instruction
A/B tests (3 total):
- phase49_joinir_mainline_pipeline_smoke
- phase49_joinir_mainline_fallback_without_flag
- phase49_joinir_mainline_ab_comparison (Route A vs Route B)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-28 19:45:23 +09:00
a8db5682cb
feat(joinir): Phase 49-3 JoinIR Frontend mainline integration
...
Implement AST→JSON→JoinIR→MIR pipeline in cf_loop for print_tokens:
- Add cf_loop_joinir_impl() with full pipeline:
- AST Loop node → Program JSON
- AstToJoinIrLowerer::lower_program_json() → JoinModule
- convert_join_module_to_mir_with_meta() → MirModule
- merge_joinir_mir_blocks() (MVP: logging only)
- Add Phase 49 smoke tests (2 tests):
- phase49_joinir_mainline_pipeline_smoke
- phase49_joinir_mainline_fallback_without_flag
- Dev flag: HAKO_JOINIR_PRINT_TOKENS_MAIN=1
- Debug flag: NYASH_JOINIR_MAINLINE_DEBUG=1
MVP limitations:
- Block merge is logging only (Phase 49-3.2 for full impl)
- if-analysis meta is empty (Phase 40+ territory)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-28 19:29:45 +09:00
e258973dba
feat(builder): Phase 49 cf_loop JoinIR Frontend mainline integration point
...
Add try_cf_loop_joinir() method to control_flow.rs as the routing point
for JoinIR Frontend mainline integration.
- First target: JsonTokenizer.print_tokens/1
- Controlled by HAKO_JOINIR_PRINT_TOKENS_MAIN=1 flag
- Currently falls through to legacy LoopBuilder (Phase 49-3 will implement)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-28 19:12:59 +09:00
f9d100ce01
chore: Phase 25.1 完了 - LoopForm v2/Stage1 CLI/環境変数削減 + Phase 26-D からの変更
...
Phase 25.1 完了成果:
- ✅ LoopForm v2 テスト・ドキュメント・コメント完備
- 4ケース(A/B/C/D)完全テストカバレッジ
- 最小再現ケース作成(SSAバグ調査用)
- SSOT文書作成(loopform_ssot.md)
- 全ソースに [LoopForm] コメントタグ追加
- ✅ Stage-1 CLI デバッグ環境構築
- stage1_cli.hako 実装
- stage1_bridge.rs ブリッジ実装
- デバッグツール作成(stage1_debug.sh/stage1_minimal.sh)
- アーキテクチャ改善提案文書
- ✅ 環境変数削減計画策定
- 25変数の完全調査・分類
- 6段階削減ロードマップ(25→5、80%削減)
- 即時削除可能変数特定(NYASH_CONFIG/NYASH_DEBUG)
Phase 26-D からの累積変更:
- PHI実装改善(ExitPhiBuilder/HeaderPhiBuilder等)
- MIRビルダーリファクタリング
- 型伝播・最適化パス改善
- その他約300ファイルの累積変更
🎯 技術的成果:
- SSAバグ根本原因特定(条件分岐内loop変数変更)
- Region+next_iパターン適用完了(UsingCollectorBox等)
- LoopFormパターン文書化・テスト化完了
- セルフホスティング基盤強化
Co-Authored-By: Claude <noreply@anthropic.com >
Co-Authored-By: ChatGPT <noreply@openai.com >
Co-Authored-By: Task Assistant <task@anthropic.com >
2025-11-21 06:25:17 +09:00
f74b7d2b04
📦 Hotfix 1 & 2: Parameter ValueId Reservation + Exit PHI Validation (Box-First Theory)
...
**箱理論に基づく根治的修正**:
## 🎯 Hotfix 1: Parameter ValueId Reservation (パラメータ ValueId 予約)
### 根本原因
- MirFunction counter が params.len() を考慮していなかった
- local variables が parameter ValueIds を上書き
### 箱理論的解決
1. **LoopFormContext Box**
- パラメータ予約を明示的に管理
- 境界をはっきりさせる
2. **MirFunction::new() 改善**
- `initial_counter = param_count.max(1)` でパラメータ予約
- Parameters are %0, %1, ..., %N-1
3. **ensure_counter_after() 強化**
- パラメータ数 + 既存 ValueIds 両方を考慮
- `min_counter = param_count.max(max_id + 1)`
4. **reserve_parameter_value_ids() 追加**
- 明示的な予約メソッド(Box-First)
## 🎯 Hotfix 2: Exit PHI Predecessor Validation (Exit PHI 検証)
### 根本原因
- LoopForm builder が存在しないブロックを PHI predecessor に追加
- 「幽霊ブロック」問題
### 箱理論的解決
1. **LoopFormOps.block_exists() 追加**
- CFG 存在確認メソッド
- 境界を明確化
2. **build_exit_phis() 検証**
- 非存在ブロックをスキップ
- デバッグログ付き
### 実装ファイル
- `src/mir/function.rs`: Parameter reservation
- `src/mir/phi_core/loopform_builder.rs`: Context + validation
- `src/mir/loop_builder.rs`: LoopFormOps impl
- `src/mir/builder/stmts.rs`: Local variable allocation
### 業界標準準拠
- ✅ LLVM IR: Parameters are %0, %1, ...
- ✅ SSA Form: PHI predecessors must exist in CFG
- ✅ Cytron et al. (1991): Parameter reservation principle
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-18 06:39:45 +09:00
eadde8d1dd
fix(mir/builder): use function-local ValueId throughout MIR builder
...
Phase 25.1b: Complete SSA fix - eliminate all global ValueId usage in function contexts.
Root cause: ~75 locations throughout MIR builder were using global value
generator (self.value_gen.next()) instead of function-local allocator
(f.next_value_id()), causing SSA verification failures and runtime
"use of undefined value" errors.
Solution:
- Added next_value_id() helper that automatically chooses correct allocator
- Fixed 19 files with ~75 occurrences of ValueId allocation
- All function-context allocations now use function-local IDs
Files modified:
- src/mir/builder/utils.rs: Added next_value_id() helper, fixed 8 locations
- src/mir/builder/builder_calls.rs: 17 fixes
- src/mir/builder/ops.rs: 8 fixes
- src/mir/builder/stmts.rs: 7 fixes
- src/mir/builder/emission/constant.rs: 6 fixes
- src/mir/builder/rewrite/*.rs: 10 fixes
- + 13 other files
Verification:
- cargo build --release: SUCCESS
- Simple tests with NYASH_VM_VERIFY_MIR=1: Zero undefined errors
- Multi-parameter static methods: All working
Known remaining: ValueId(22) in Stage-B (separate issue to investigate)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-17 00:48:18 +09:00
dda65b94b7
Phase 21.7 normalization: optimization pre-work + bench harness expansion
...
- Add opt-in optimizations (defaults OFF)
- Ret purity verifier: NYASH_VERIFY_RET_PURITY=1
- strlen FAST enhancement for const handles
- FAST_INT gate for same-BB SSA optimization
- length cache for string literals in llvmlite
- Expand bench harness (tools/perf/microbench.sh)
- Add branch/call/stringchain/arraymap/chip8/kilo cases
- Auto-calculate ratio vs C reference
- Document in benchmarks/README.md
- Compiler health improvements
- Unify PHI insertion to insert_phi_at_head()
- Add NYASH_LLVM_SKIP_BUILD=1 for build reuse
- Runtime & safety enhancements
- Clarify Rust/Hako ownership boundaries
- Strengthen receiver localization (LocalSSA/pin/after-PHIs)
- Stop excessive PluginInvoke→BoxCall rewrites
- Update CURRENT_TASK.md, docs, and canaries
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-13 16:40:58 +09:00
dd65cf7e4c
builder+vm: unify method calls via emit_unified_call; add RouterPolicy trace; finalize LocalSSA/BlockSchedule guards; docs + selfhost quickstart
...
- Unify standard method calls to emit_unified_call; route via RouterPolicy and apply rewrite::{special,known} at a single entry.\n- Stabilize emit-time invariants: LocalSSA finalize + BlockSchedule PHI→Copy→Call ordering; metadata propagation on copies.\n- Known rewrite default ON (userbox only, strict guards) with opt-out flag NYASH_REWRITE_KNOWN_DEFAULT=0.\n- Expand TypeAnnotation whitelist (is_digit_char/is_hex_digit_char/is_alpha_char/Map.has).\n- Docs: unified-method-resolution design note; Quick Reference normalization note; selfhosting/quickstart.\n- Tools: add tools/selfhost_smoke.sh (dev-only).\n- Keep behavior unchanged for Unknown/core/user-instance via BoxCall fallback; all tests green (quick/integration).
2025-09-28 20:38:09 +09:00
9142476484
parser(match): add MVP type patterns (IntegerBox(x)/StringBox(s)) via AST If-chain; keep literal-only path using PeekExpr; add smoke app (apps/tests/match_type_pattern_basic.nyash); build + stage-2 smokes green
2025-09-19 08:34:29 +09:00
b8e416fb03
refactor: MIR builder modularization complete - ready for handoff
...
- MIRビルダーのモジュール化完了(1,547行→6モジュール)
- core.rs (205行): MirBuilder本体
- expressions.rs (621行): 式変換処理
- statements.rs (165行): 文変換処理
- control_flow.rs (194行): 制御フロー
- box_handlers.rs (73行): Box処理
- 現在builder_modularizedに退避(MIR命令構造変更により調整必要)
- フルビルド可能な状態を維持
- CURRENT_TASK.mdに引き継ぎポイント記載
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-08-25 19:33:07 +09:00
17adc4347d
refactor: MIR builder - complete modularization (Phase 6-8)
...
- Phase 6: statements.rs (165 lines) - 6 functions
- build_print_statement, build_block
- build_local_statement, build_return_statement
- build_throw_statement, build_nowait_statement
- Phase 7: control_flow.rs (194 lines) - 4 functions
- build_if_statement, build_loop_statement
- build_try_catch_statement, is_current_block_terminated
- Phase 8: box_handlers.rs (73 lines) - 2 functions
- build_static_main_box, build_box_declaration
Total: 30 functions moved across 4 modules
Original builder.rs reduced from 1547 lines
Build verified successfully
2025-08-25 18:43:45 +09:00
cff58dbc0a
refactor: MIR Builder Phase 1 - モジュール分割準備完了
...
【Phase 1完了内容】
- src/mir/builder/ ディレクトリ構造作成
- MirBuilder コア機能を core.rs に分離(8関数実装済み)
- 責務別モジュール準備(expressions/statements/control_flow/box_handlers)
- ビルド確認: 新構造でコンパイル正常完了
【技術詳細】
- MirBuilder本体 + emit_instruction/emit_type_check等コア機能
- プレースホルダー実装でビルド安全性確保
- CURRENT_TASK.md更新(Phase 1完了状況記録)
- 49関数/1547行の段階的分割準備
【次のPhase】
- Phase 2: 実際の関数移動(expressions.rs最優先)
- 慎重アプローチ: デッドコード削除は後回し
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-08-25 17:49:21 +09:00