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
dc68104fd9
refactor(mir): Phase 6-1 - Add BasicBlock/MirFunction helper methods (foundation for ~50 line reduction)
...
【目的】
JSON v0 Bridge(if_else.rs, try_catch.rs, loop_.rs)で重複するPHI生成・terminator設定パターンを統一するための基礎ヘルパーメソッド追加
【実装内容】
1. BasicBlock::update_phi_input()メソッド追加(17行)
- loop back-edge PHI更新を簡略化
- 手動ループ検索パターンを統一化
- エラーハンドリング統一
2. MirFunction::set_jump_terminator()メソッド追加(14行)
- if/else/loop降下での終端設定を簡略化
- 未終端チェックを内包
- Option処理を統一
3. MirFunction::set_branch_terminator()メソッド追加(15行)
- if/else条件分岐の終端設定を簡略化
- Option処理を統一
【技術的改善】
- **Single Source of Truth**: 終端設定・PHI更新ロジックが一元化
- **エラーハンドリング統一**: Result型で明示的エラー処理
- **箱化**: 関連処理を BasicBlock/MirFunction に箱化
【修正箇所】
- src/mir/basic_block.rs:
- HashMap import追加
- update_phi_input()メソッド追加(17行)
- src/mir/function.rs:
- MirInstruction import追加
- set_jump_terminator()メソッド追加(14行)
- set_branch_terminator()メソッド追加(15行)
【テスト結果】
✅ ビルド成功(0 errors)
✅ userbox_*スモークテスト: 全6テストPASS
【次のフェーズ(Phase 6-2予定)】
これらのヘルパーメソッドを使って以下を簡略化予定:
- loop_.rs: ~10行削減(update_phi_input使用)
- if_else.rs: ~5行削減(set_branch_terminator使用)
- try_catch.rs: ~15行削減(両メソッド使用)
- 合計: ~30行削減見込み
【Phase 15目標への寄与】
- フェーズ1完了(基礎ヘルパー追加)
- フェーズ2準備完了(~150行削減可能な土台確立)
- 箱理論準拠: 「箱にする」「境界を作る」「戻せる」完全実現
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-01 15:15:21 +09:00
79b9d2b32c
fix(mir): edge-copy insertion before terminator - resolve ValueId undefined errors
...
【問題】
Stage-B(JSON v0 Bridge)で「use of undefined value ValueId(...)」エラー発生
- 原因: merge.rs:38-42でedge-copyを終端命令**後**に追加していた
- 結果: Copy命令が到達不能となり、ValueIdが未定義のまま参照される
【根本原因分析】
1. if_else.rs:34で`set_terminator(Jump)`を設定
2. if_else.rs:62で`merge_var_maps()`呼び出し
3. merge.rs:39で`add_instruction(Copy)` ← **ここで終端後に追加!**
4. BasicBlock構造上、terminator設定後のadd_instruction()は到達不能
【修正内容】
1. BasicBlock::add_instruction_before_terminator()メソッド追加
- 終端命令の有無に関わらず、instructions vecに追加
- terminator自体の追加は許可しない(panic)
2. merge_values()でedge-copy挿入方法を変更
- add_instruction() → add_instruction_before_terminator()
- これによりCopyが終端の**前**に配置される
【修正箇所】
- src/mir/basic_block.rs: add_instruction_before_terminator()追加(12行)
- src/runner/json_v0_bridge/lowering/merge.rs: 呼び出し変更(2行)
【テスト結果】
✅ if文PHIテスト: /tmp/phi_simple_if2.nyash → 出力 1
✅ loop文PHIテスト: /tmp/phi_loop_test.nyash → 出力 10
✅ userbox_*スモークテスト: 全6テストPASS
⚠️ Stage-B: namespace conflict未解決のため未確認
(apps/selfhost.vm.* と lang/hakorune.vm.* の競合)
【影響範囲】
- JSON v0 Bridge経路のif/else合流処理
- edge-copy(PHI-off mode)の正しい配置保証
- Builder経路は元々正常動作(影響なし)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-01 14:37:54 +09:00
adbb0201a9
chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt
2025-09-17 07:43:07 +09:00
840c1b85ef
feat: Fix VM SSA loop execution with proper phi node handling
...
Fixed infinite loop issue in VM by addressing phi node caching problem.
The phi node was caching the initial value and returning it for all
subsequent iterations, preventing loop variable updates.
Changes:
- Created vm_phi.rs module to separate loop execution logic (similar to mir/loop_builder.rs)
- Disabled phi node caching to ensure correct value selection each iteration
- Added LoopExecutor to track block transitions and handle phi nodes properly
- Fixed VM to correctly track previous_block for phi input selection
The VM now correctly executes SSA-form loops with proper variable updates:
- Loop counter increments correctly
- Phi nodes select the right input based on control flow
- Test case now completes successfully (i=1,2,3,4)
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-08-18 23:36:40 +09:00
ba568f7dfb
Implement Local and TryCatch lowering in MirBuilder
...
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com >
2025-08-13 07:13:53 +00:00
774e0bb241
🚀 MIR Stage 1 Basic Infrastructure Complete - 20 Instructions + SSA + Effects
...
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com >
2025-08-12 11:33:48 +00:00