- Add MirLikeInst::Print variant for direct output operations
- Implement Print instruction in JSON serialization
- Update simple_while_minimal.rs to use Print instead of BoxCall
- Add Print handling in JoinIR VM bridge and runner
- Add router logic to call Pattern 1 lowerer from main pipeline
Note: Router integration exposes ValueId mismatch issue between
Pattern 1's hardcoded IDs and host function's variables.
This architectural issue needs resolution in next phase.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Problem: HashMap iteration order is non-deterministic due to HashDoS
protection (random seeds), causing different block ID assignments on
each run and breaking Pattern 1 execution.
Evidence:
Run 1: join_func_1:bb2 → bb5
Run 2: join_func_1:bb2 → bb6 // Different!
Run 3: join_func_2:bb0 → bb6 // Collision!
Solution: Sort collections before iteration for deterministic ordering:
- Functions sorted by name (alphabetically)
- Blocks sorted by BasicBlockId value (numerically)
Implementation:
- Lines 404-438: Sort functions+blocks in allocation loop
- Lines 493-522: Sort functions+blocks in merge loop
Verification (3 consecutive runs):
Run 1: join_func_0:bb0→bb3, join_func_1:bb0→bb4...
Run 2: IDENTICAL ✅
Run 3: IDENTICAL ✅
Impact: Zero performance overhead, guaranteed determinism
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
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>
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>
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).