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>
- 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>
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>
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>
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>
- 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).