Commit Graph

6 Commits

Author SHA1 Message Date
af6f95cd4b Phase 33 NORM canon test: enforce normalized dev route for P1/P2/JP mini 2025-12-11 20:54:33 +09:00
95f3aa429e refactor(joinir): Extract legacy binding path to routing_legacy_binding.rs
Phase 179-A Step 2: Separate LoopFrontendBinding JSON construction logic
into dedicated module for better organization.

Changes:
- New file: routing_legacy_binding.rs (223 lines)
- routing.rs: cf_loop_joinir_impl() simplified to 15 lines (delegates to legacy path)
- Routing now clearly separates pattern-based vs. legacy binding paths

Benefits:
- Clear separation of concerns (pattern router vs. legacy whitelist)
- routing.rs reduced from 364 to 146 lines (60% reduction)
- Legacy path isolated for future deprecation
2025-12-08 18:36:13 +09:00
abfe0b198b feat(joinir): Phase 195 - Unified JoinLoopTrace for all JoinIR debug output
Created centralized tracing module for JoinIR loop lowering operations,
consolidating scattered eprintln! calls into a single SSOT interface.

# Implementation

1. **Created trace.rs module** (~233 lines)
   - JoinLoopTrace struct with env var controls
   - Unified API: pattern(), varmap(), joinir_stats(), phi(), merge(), etc.
   - Global singleton via trace() function
   - Supports 5 env vars: NYASH_TRACE_VARMAP, NYASH_JOINIR_DEBUG,
     NYASH_OPTION_C_DEBUG, NYASH_JOINIR_MAINLINE_DEBUG, NYASH_LOOPFORM_DEBUG

2. **Updated debug.rs** - Delegates trace_varmap() to JoinLoopTrace

3. **Updated routing.rs** - All eprintln! replaced with trace calls (10 instances)

4. **Updated pattern routers** - All 3 patterns now use unified trace
   - pattern1_minimal.rs: 6 replacements
   - pattern2_with_break.rs: 6 replacements
   - pattern3_with_if_phi.rs: 6 replacements
   - router.rs: 2 replacements

5. **Updated merge/block_allocator.rs** - 6 eprintln! → trace calls

# Benefits

- **Single Source of Truth**: All trace control through environment variables
- **Consistent Format**: Unified [trace:*] prefix for easy filtering
- **Zero Overhead**: No output when env vars unset
- **Easy Extension**: Add new trace points via existing API
- **Better Debug Experience**: Structured output with clear categories

# Testing

 cargo build --release - Success
 NYASH_TRACE_VARMAP=1 - Shows varmap traces only
 NYASH_JOINIR_DEBUG=1 - Shows joinir + blocks + routing traces
 No env vars - No debug output
 apps/tests/loop_min_while.hako - All tests pass

# Related

- Phase 191-194 groundwork (modular merge structure)
- NYASH_TRACE_VARMAP added today for variable_map debugging
- Consolidates ~80 scattered eprintln! calls across JoinIR

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 22:23:51 +09:00
9764ca3052 refactor: Break down merge_joinir_mir_blocks into 6 modules (Phase 4)
Phase 4 Implementation Complete: Successfully modularized the 714-line
merge_joinir_mir_blocks() function into 6 focused, maintainable modules.

## Changes Made

### 1. Created Module Structure
- `src/mir/builder/control_flow/joinir/merge/` directory
- 5 sub-modules + 1 coordinator (6 files total)

### 2. Module Breakdown (848 lines total)
- **mod.rs** (223 lines) - Coordinator function
  - Orchestrates all 6 phases
  - Handles boundary reconnection
  - Manages entry/exit block jumps
- **block_allocator.rs** (70 lines) - Block ID allocation
  - Allocates new BlockIds for all JoinIR functions
  - Maintains determinism via sorted iteration
- **value_collector.rs** (90 lines) - Value collection
  - Collects all ValueIds from JoinIR functions
  - Builds auxiliary maps for Call→Jump conversion
- **instruction_rewriter.rs** (405 lines) - Instruction rewriting
  - Rewrites instructions with remapped IDs
  - Handles tail call optimization
  - Converts Return → Jump to exit block
- **exit_phi_builder.rs** (60 lines) - Exit PHI construction
  - Builds PHI node merging return values
  - Creates exit block

### 3. Updated control_flow/mod.rs
- Replaced 714-line function with 18-line delegation
- Reduced from 904 lines → 312 lines (65% reduction)
- Added documentation explaining Phase 4 refactoring

## Verification Results

 **Build**: `cargo build --release` - SUCCESS (23.36s)
 **Smoke Test**: loop_min_while.hako - PASS (correct output: 0,1,2)
 **Determinism**: 3 consecutive runs - IDENTICAL OUTPUT
 **Debug Traces**: NYASH_OPTION_C_DEBUG=1 traces work correctly
 **No Regressions**: Behavior preserved 100%

## Benefits

1. **Maintainability**: 714 lines → 6 focused modules (100-150 lines each)
2. **Readability**: Each phase isolated in its own file
3. **Testability**: Individual modules can be tested separately
4. **Future Development**: Easy to modify individual phases
5. **Zero Breaking Changes**: Backward compatible, no API changes

## Technical Notes

- Uses JoinIrIdRemapper (already existed) for ID translation
- Preserves all debug output and trace functionality
- Maintains determinism via BTreeSet/BTreeMap
- All Phase 189 features intact (multi-function support, etc.)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 21:00:55 +09:00
f018eeeba2 refactor: Extract JoinIR routing logic from control_flow.rs (Phase 3)
- Created joinir/routing.rs
- Moved try_cf_loop_joinir() and cf_loop_joinir_impl()
- Updated joinir/mod.rs to include routing module
- Removed ~320 lines from main control_flow.rs
- Zero breaking changes, all tests pass

Phase 1-3 complete:
- control_flow.rs: 1,632 → ~900 lines (45% reduction)
- Extracted 3 modules: debug, patterns (3 files), routing
- All functionality preserved and verified
2025-12-05 20:48:31 +09:00
282d2ef450 refactor: Extract pattern lowerers from control_flow.rs (Phase 2)
- Created joinir/patterns/ subdirectory
- Extracted Pattern 1: pattern1_minimal.rs (Simple While)
- Extracted Pattern 2: pattern2_with_break.rs (Loop with Break)
- Extracted Pattern 3: pattern3_with_if_phi.rs (Loop with If-Else PHI)
- Created patterns/mod.rs dispatcher
- Removed ~410 lines from main control_flow.rs
- Zero breaking changes, all tests pass
2025-12-05 20:45:23 +09:00