2025-12-05 20:48:31 +09:00
|
|
|
|
//! JoinIR routing logic for loop lowering
|
|
|
|
|
|
|
|
|
|
|
|
use crate::ast::ASTNode;
|
|
|
|
|
|
use crate::mir::builder::MirBuilder;
|
|
|
|
|
|
use crate::mir::ValueId;
|
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
|
|
|
|
use super::trace;
|
2025-12-05 20:48:31 +09:00
|
|
|
|
|
|
|
|
|
|
impl MirBuilder {
|
|
|
|
|
|
/// Phase 49: Try JoinIR Frontend for mainline integration
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Returns `Ok(Some(value))` if the current function should use JoinIR Frontend,
|
|
|
|
|
|
/// `Ok(None)` to fall through to the legacy LoopBuilder path.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// # Phase 49-4: Multi-target support
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Targets are enabled via separate dev flags:
|
|
|
|
|
|
/// - `HAKO_JOINIR_PRINT_TOKENS_MAIN=1`: JsonTokenizer.print_tokens/0
|
|
|
|
|
|
/// - `HAKO_JOINIR_ARRAY_FILTER_MAIN=1`: ArrayExtBox.filter/2
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Note: Arity in function names does NOT include implicit `me` receiver.
|
|
|
|
|
|
/// - Instance method `print_tokens()` → `/0` (no explicit params)
|
|
|
|
|
|
/// - Static method `filter(arr, pred)` → `/2` (two params)
|
|
|
|
|
|
pub(in crate::mir::builder) fn try_cf_loop_joinir(
|
|
|
|
|
|
&mut self,
|
|
|
|
|
|
condition: &ASTNode,
|
|
|
|
|
|
body: &[ASTNode],
|
|
|
|
|
|
) -> Result<Option<ValueId>, String> {
|
|
|
|
|
|
// Get current function name
|
|
|
|
|
|
let func_name = self
|
|
|
|
|
|
.current_function
|
|
|
|
|
|
.as_ref()
|
|
|
|
|
|
.map(|f| f.signature.name.clone())
|
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
|
|
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
|
|
|
|
// Phase 195: Use unified trace
|
|
|
|
|
|
trace::trace().routing("router", &func_name, "try_cf_loop_joinir called");
|
2025-12-05 20:48:31 +09:00
|
|
|
|
|
|
|
|
|
|
// Phase 49-4 + Phase 80: Multi-target routing
|
|
|
|
|
|
// - Core ON なら代表2本(print_tokens / ArrayExt.filter)は JoinIR を優先し、失敗したら LoopBuilder へフォールバック
|
|
|
|
|
|
// - Core OFF では従来通り dev フラグで opt-in
|
|
|
|
|
|
// Note: Arity does NOT include implicit `me` receiver
|
|
|
|
|
|
// Phase 188: Add "main" routing for loop pattern expansion
|
2025-12-07 01:45:03 +09:00
|
|
|
|
// Phase 170: Add JsonParserBox methods for selfhost validation
|
2025-12-05 20:48:31 +09:00
|
|
|
|
let core_on = crate::config::env::joinir_core_enabled();
|
|
|
|
|
|
let is_target = match func_name.as_str() {
|
|
|
|
|
|
"main" => true, // Phase 188-Impl-1: Enable JoinIR for main function (Pattern 1)
|
|
|
|
|
|
"JoinIrMin.main/0" => true, // Phase 188-Impl-2: Enable JoinIR for JoinIrMin.main/0 (Pattern 2)
|
|
|
|
|
|
"JsonTokenizer.print_tokens/0" => {
|
|
|
|
|
|
if core_on {
|
|
|
|
|
|
true
|
|
|
|
|
|
} else {
|
|
|
|
|
|
std::env::var("HAKO_JOINIR_PRINT_TOKENS_MAIN")
|
|
|
|
|
|
.ok()
|
|
|
|
|
|
.as_deref()
|
|
|
|
|
|
== Some("1")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
"ArrayExtBox.filter/2" => {
|
|
|
|
|
|
if core_on {
|
|
|
|
|
|
true
|
|
|
|
|
|
} else {
|
|
|
|
|
|
std::env::var("HAKO_JOINIR_ARRAY_FILTER_MAIN")
|
|
|
|
|
|
.ok()
|
|
|
|
|
|
.as_deref()
|
|
|
|
|
|
== Some("1")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-07 01:45:03 +09:00
|
|
|
|
// Phase 170-A-1: Enable JsonParserBox methods for JoinIR routing
|
|
|
|
|
|
"JsonParserBox._trim/1" => true,
|
|
|
|
|
|
"JsonParserBox._skip_whitespace/2" => true,
|
|
|
|
|
|
"JsonParserBox._match_literal/2" => true,
|
|
|
|
|
|
"JsonParserBox._parse_string/2" => true,
|
|
|
|
|
|
"JsonParserBox._parse_array/2" => true,
|
|
|
|
|
|
"JsonParserBox._parse_object/2" => true,
|
|
|
|
|
|
// Phase 170-A-1: Test methods (simplified versions)
|
|
|
|
|
|
"TrimTest.trim/1" => true,
|
|
|
|
|
|
"Main.trim/1" => true, // Phase 171-fix: Main box variant
|
2025-12-07 05:07:28 +09:00
|
|
|
|
"Main.trim_string_simple/1" => true, // Phase 33-13: Simple trim variant
|
2025-12-07 12:59:33 +09:00
|
|
|
|
"TrimTest.main/0" => true, // Phase 170: TrimTest.main for loop pattern test
|
2025-12-05 20:48:31 +09:00
|
|
|
|
_ => false,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if !is_target {
|
|
|
|
|
|
return Ok(None);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Debug log when routing through JoinIR Frontend
|
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
|
|
|
|
// Phase 195: Check trace flags directly from JoinLoopTrace
|
|
|
|
|
|
let debug = trace::trace().is_loopform_enabled() || trace::trace().is_mainline_enabled();
|
|
|
|
|
|
trace::trace().routing("router", &func_name, "Routing through JoinIR Frontend mainline");
|
2025-12-05 20:48:31 +09:00
|
|
|
|
|
|
|
|
|
|
// Phase 49-3: Implement JoinIR Frontend integration
|
|
|
|
|
|
self.cf_loop_joinir_impl(condition, body, &func_name, debug)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Phase 49-3: JoinIR Frontend integration implementation
|
|
|
|
|
|
///
|
|
|
|
|
|
/// # Pipeline
|
|
|
|
|
|
/// 1. Build Loop AST → JSON v0 format (with "defs" array)
|
|
|
|
|
|
/// 2. AstToJoinIrLowerer::lower_program_json() → JoinModule
|
|
|
|
|
|
/// 3. convert_join_module_to_mir_with_meta() → MirModule
|
|
|
|
|
|
/// 4. Merge MIR blocks into current_function
|
|
|
|
|
|
///
|
|
|
|
|
|
/// # Phase 49-4 Note
|
|
|
|
|
|
///
|
|
|
|
|
|
/// JoinIR Frontend expects a complete function definition with:
|
|
|
|
|
|
/// - local variable initializations
|
|
|
|
|
|
/// - loop body
|
|
|
|
|
|
/// - return statement
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Since cf_loop only has access to the loop condition and body,
|
|
|
|
|
|
/// we construct a minimal JSON v0 wrapper with function name "simple"
|
|
|
|
|
|
/// to match the JoinIR Frontend's expected pattern.
|
|
|
|
|
|
pub(in crate::mir::builder) fn cf_loop_joinir_impl(
|
|
|
|
|
|
&mut self,
|
|
|
|
|
|
condition: &ASTNode,
|
|
|
|
|
|
body: &[ASTNode],
|
|
|
|
|
|
func_name: &str,
|
|
|
|
|
|
debug: bool,
|
|
|
|
|
|
) -> Result<Option<ValueId>, String> {
|
|
|
|
|
|
use super::super::super::loop_frontend_binding::LoopFrontendBinding;
|
|
|
|
|
|
use crate::mir::join_ir::frontend::{AstToJoinIrLowerer, JoinFuncMetaMap};
|
|
|
|
|
|
use crate::mir::join_ir_vm_bridge::convert_join_module_to_mir_with_meta;
|
|
|
|
|
|
use crate::mir::types::ConstValue;
|
|
|
|
|
|
use crate::mir::MirInstruction;
|
|
|
|
|
|
use crate::r#macro::ast_json::ast_to_json;
|
|
|
|
|
|
|
2025-12-05 22:11:39 +09:00
|
|
|
|
// Phase 194: Use table-driven router instead of if/else chain
|
|
|
|
|
|
// This makes adding new patterns trivial - just add an entry to LOOP_PATTERNS table
|
|
|
|
|
|
use super::patterns::{route_loop_pattern, LoopPatternContext};
|
2025-12-05 20:48:31 +09:00
|
|
|
|
|
2025-12-05 22:11:39 +09:00
|
|
|
|
let ctx = LoopPatternContext::new(condition, body, &func_name, debug);
|
|
|
|
|
|
if let Some(result) = route_loop_pattern(self, &ctx)? {
|
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
|
|
|
|
// Phase 195: Use unified trace
|
|
|
|
|
|
trace::trace().routing("router", func_name, "Pattern router succeeded");
|
2025-12-05 22:11:39 +09:00
|
|
|
|
return Ok(Some(result));
|
2025-12-05 20:48:31 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
// Phase 195: Use unified trace
|
|
|
|
|
|
trace::trace().routing("router", func_name, "Pattern router found no match, continuing to legacy path");
|
2025-12-05 20:48:31 +09:00
|
|
|
|
|
|
|
|
|
|
// Phase 50: Create appropriate binding based on function name
|
|
|
|
|
|
let binding = match func_name {
|
|
|
|
|
|
"JsonTokenizer.print_tokens/0" => LoopFrontendBinding::for_print_tokens(),
|
|
|
|
|
|
"ArrayExtBox.filter/2" => LoopFrontendBinding::for_array_filter(),
|
|
|
|
|
|
_ => {
|
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
|
|
|
|
// Phase 195: Use unified trace
|
|
|
|
|
|
trace::trace().routing("router", func_name, "No binding defined, falling back");
|
2025-12-05 20:48:31 +09:00
|
|
|
|
return Ok(None);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
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
|
|
|
|
// Phase 195: Use unified trace
|
|
|
|
|
|
trace::trace().debug(
|
|
|
|
|
|
"router",
|
|
|
|
|
|
&format!(
|
|
|
|
|
|
"Using binding for '{}': counter={}, acc={:?}, pattern={:?}",
|
|
|
|
|
|
func_name, binding.counter_var, binding.accumulator_var, binding.pattern
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
2025-12-05 20:48:31 +09:00
|
|
|
|
|
|
|
|
|
|
// Step 1: Convert condition and body to JSON
|
|
|
|
|
|
let condition_json = ast_to_json(condition);
|
|
|
|
|
|
let mut body_json: Vec<serde_json::Value> = body.iter().map(|s| ast_to_json(s)).collect();
|
|
|
|
|
|
|
|
|
|
|
|
// Phase 50: Rename variables in body (e.g., "out" → "acc" for filter)
|
|
|
|
|
|
binding.rename_body_variables(&mut body_json);
|
|
|
|
|
|
|
|
|
|
|
|
// Phase 50: Generate Local declarations from binding
|
|
|
|
|
|
let (i_local, acc_local, n_local) = binding.generate_local_declarations();
|
|
|
|
|
|
|
|
|
|
|
|
// Phase 52/56: Build params from external_refs
|
|
|
|
|
|
// Instance methods need `me`, static methods need their parameters (arr, pred, etc.)
|
|
|
|
|
|
let mut params: Vec<serde_json::Value> = Vec::new();
|
|
|
|
|
|
|
|
|
|
|
|
// Phase 52: Add 'me' for instance methods
|
|
|
|
|
|
if binding.needs_me_receiver() {
|
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
|
|
|
|
// Phase 195: Use unified trace
|
|
|
|
|
|
trace::trace().debug("router", "Adding 'me' to params (instance method)");
|
2025-12-05 20:48:31 +09:00
|
|
|
|
params.push(serde_json::json!("me"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Phase 56: Add external_refs as parameters (arr, pred for filter)
|
|
|
|
|
|
for ext_ref in &binding.external_refs {
|
|
|
|
|
|
// Skip "me" and "me.*" as they're handled above
|
|
|
|
|
|
if ext_ref == "me" || ext_ref.starts_with("me.") {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
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
|
|
|
|
// Phase 195: Use unified trace
|
|
|
|
|
|
trace::trace().debug("router", &format!("Adding '{}' to params (external_ref)", ext_ref));
|
2025-12-05 20:48:31 +09:00
|
|
|
|
params.push(serde_json::json!(ext_ref));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Step 2: Construct JSON v0 format with "defs" array
|
|
|
|
|
|
// The function is named "simple" to match JoinIR Frontend's pattern matching
|
|
|
|
|
|
// Phase 50: Include i/acc/n Local declarations to satisfy JoinIR Frontend expectations
|
|
|
|
|
|
let program_json = serde_json::json!({
|
|
|
|
|
|
"defs": [
|
|
|
|
|
|
{
|
|
|
|
|
|
"name": "simple",
|
|
|
|
|
|
"params": params,
|
|
|
|
|
|
"body": {
|
|
|
|
|
|
"type": "Block",
|
|
|
|
|
|
"body": [
|
|
|
|
|
|
// Phase 50: Inject i/acc/n Local declarations
|
|
|
|
|
|
i_local,
|
|
|
|
|
|
acc_local,
|
|
|
|
|
|
n_local,
|
|
|
|
|
|
{
|
|
|
|
|
|
"type": "Loop",
|
|
|
|
|
|
"cond": condition_json, // JoinIR Frontend expects "cond" not "condition"
|
|
|
|
|
|
"body": body_json
|
|
|
|
|
|
},
|
|
|
|
|
|
// Return the accumulator (or null for side-effect loops)
|
|
|
|
|
|
{
|
|
|
|
|
|
"type": "Return",
|
|
|
|
|
|
"value": { "kind": "Variable", "name": "acc" }
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
});
|
|
|
|
|
|
|
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
|
|
|
|
// Phase 195: Use unified trace
|
|
|
|
|
|
trace::trace().debug(
|
|
|
|
|
|
"router",
|
|
|
|
|
|
&format!(
|
|
|
|
|
|
"Generated JSON v0 for {}: {}",
|
2025-12-05 20:48:31 +09:00
|
|
|
|
func_name,
|
|
|
|
|
|
serde_json::to_string_pretty(&program_json).unwrap_or_default()
|
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
|
|
|
|
),
|
|
|
|
|
|
);
|
2025-12-05 20:48:31 +09:00
|
|
|
|
|
|
|
|
|
|
// Step 3: Lower to JoinIR
|
|
|
|
|
|
// Phase 49-4: Use catch_unwind for graceful fallback on unsupported patterns
|
|
|
|
|
|
// The JoinIR Frontend may panic if the loop doesn't match expected patterns
|
|
|
|
|
|
// (e.g., missing variable initializations like "i must be initialized")
|
|
|
|
|
|
let join_module = {
|
|
|
|
|
|
let json_clone = program_json.clone();
|
|
|
|
|
|
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
|
|
|
|
|
let mut lowerer = AstToJoinIrLowerer::new();
|
|
|
|
|
|
lowerer.lower_program_json(&json_clone)
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
match result {
|
|
|
|
|
|
Ok(module) => module,
|
|
|
|
|
|
Err(e) => {
|
|
|
|
|
|
// Extract panic message for debugging
|
|
|
|
|
|
let panic_msg = if let Some(s) = e.downcast_ref::<&str>() {
|
|
|
|
|
|
s.to_string()
|
|
|
|
|
|
} else if let Some(s) = e.downcast_ref::<String>() {
|
|
|
|
|
|
s.clone()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
"unknown panic".to_string()
|
|
|
|
|
|
};
|
|
|
|
|
|
|
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
|
|
|
|
// Phase 195: Use unified trace
|
|
|
|
|
|
trace::trace().debug(
|
|
|
|
|
|
"router",
|
|
|
|
|
|
&format!(
|
|
|
|
|
|
"JoinIR lowering failed for {}: {}, falling back to legacy",
|
2025-12-05 20:48:31 +09:00
|
|
|
|
func_name, panic_msg
|
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
|
|
|
|
),
|
|
|
|
|
|
);
|
2025-12-05 20:48:31 +09:00
|
|
|
|
// Return None to fall back to legacy LoopBuilder
|
|
|
|
|
|
return Ok(None);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
// Phase 49-3 MVP: Use empty meta map (full if-analysis is Phase 40+ territory)
|
|
|
|
|
|
let join_meta = JoinFuncMetaMap::new();
|
|
|
|
|
|
|
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
|
|
|
|
// Phase 195: Use unified trace
|
|
|
|
|
|
trace::trace().joinir_stats(
|
|
|
|
|
|
"router",
|
|
|
|
|
|
join_module.functions.len(),
|
|
|
|
|
|
join_module
|
|
|
|
|
|
.functions
|
|
|
|
|
|
.values()
|
|
|
|
|
|
.map(|f| f.body.len())
|
|
|
|
|
|
.sum(),
|
|
|
|
|
|
);
|
2025-12-05 20:48:31 +09:00
|
|
|
|
|
|
|
|
|
|
// Step 4: Convert JoinModule to MIR
|
|
|
|
|
|
let mir_module = convert_join_module_to_mir_with_meta(&join_module, &join_meta)
|
|
|
|
|
|
.map_err(|e| format!("JoinIR→MIR conversion failed: {}", e.message))?;
|
|
|
|
|
|
|
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
|
|
|
|
// Phase 195: Use unified trace for MIR module stats
|
|
|
|
|
|
if trace::trace().is_joinir_enabled() {
|
|
|
|
|
|
trace::trace().debug(
|
|
|
|
|
|
"router",
|
|
|
|
|
|
&format!("MirModule has {} functions", mir_module.functions.len()),
|
2025-12-05 20:48:31 +09:00
|
|
|
|
);
|
|
|
|
|
|
for (name, func) in &mir_module.functions {
|
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
|
|
|
|
trace::trace().debug(
|
|
|
|
|
|
"router",
|
|
|
|
|
|
&format!(
|
|
|
|
|
|
" - {}: {} blocks, entry={:?}",
|
|
|
|
|
|
name,
|
|
|
|
|
|
func.blocks.len(),
|
|
|
|
|
|
func.entry_block
|
|
|
|
|
|
),
|
2025-12-05 20:48:31 +09:00
|
|
|
|
);
|
|
|
|
|
|
// Phase 189: Debug - show block contents
|
|
|
|
|
|
for (block_id, block) in &func.blocks {
|
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
|
|
|
|
trace::trace().blocks(
|
|
|
|
|
|
"router",
|
|
|
|
|
|
&format!("Block {:?}: {} instructions", block_id, block.instructions.len()),
|
|
|
|
|
|
);
|
2025-12-05 20:48:31 +09:00
|
|
|
|
for (i, inst) in block.instructions.iter().enumerate() {
|
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
|
|
|
|
trace::trace().instructions("router", &format!("[{}] {:?}", i, inst));
|
2025-12-05 20:48:31 +09:00
|
|
|
|
}
|
|
|
|
|
|
if let Some(ref term) = block.terminator {
|
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
|
|
|
|
trace::trace().instructions("router", &format!("terminator: {:?}", term));
|
2025-12-05 20:48:31 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Step 5: Merge MIR blocks into current_function
|
|
|
|
|
|
// For Phase 49-3, we'll use a simplified approach:
|
|
|
|
|
|
// - Add generated blocks to current_function
|
|
|
|
|
|
// - Jump from current_block to the entry of generated loop
|
|
|
|
|
|
// - The loop exit becomes the new current_block
|
|
|
|
|
|
// Phase 188-Impl-3: Pass None for boundary (legacy path without boundary)
|
|
|
|
|
|
// Phase 189: Discard exit PHI result (legacy path doesn't need it)
|
|
|
|
|
|
let _ = self.merge_joinir_mir_blocks(&mir_module, None, debug)?;
|
|
|
|
|
|
|
|
|
|
|
|
// Return void for now (loop doesn't have a meaningful return value in this context)
|
|
|
|
|
|
let void_val = self.next_value_id();
|
|
|
|
|
|
self.emit_instruction(MirInstruction::Const {
|
|
|
|
|
|
dst: void_val,
|
|
|
|
|
|
value: ConstValue::Void,
|
|
|
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(Some(void_val))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|