refactor(joinir): Phase 260 P0.1 Step 2 - Extract logging.rs (DEBUG-177 style)

Extract logging utilities into dedicated module (safest first split).
Provides log_if() function + rewriter_log!() macro as alternatives to local log! macro.

Changes:
- NEW: rewriter/logging.rs - log_if() + rewriter_log!() macro
- CHANGED: rewriter/mod.rs - declare logging module

Design:
- log_if(trace, enabled, msg): Function form for explicit control
- rewriter_log!(): Macro form for format!() convenience
- Both wrap JoinLoopTrace::stderr_if() (existing infrastructure)

Status:
- instruction_rewriter.rs still uses local log! macro (unchanged)
- Future: Gradually migrate to logging::log_if() or rewriter_log!()
- cargo check PASS 

Next: Extract is_skippable_continuation to helpers.rs (smallest function)
This commit is contained in:
2025-12-21 06:06:29 +09:00
parent 4bc469239d
commit b87760e247
2 changed files with 63 additions and 5 deletions

View File

@ -0,0 +1,54 @@
//! Logging utilities for instruction rewriter
//!
//! Phase 260 P0.1: Extracted from instruction_rewriter.rs
//! Provides centralized logging with verbose flag control (DEBUG-177 style).
use crate::mir::builder::control_flow::joinir::trace::JoinLoopTrace;
/// Log message conditionally based on enabled flag
///
/// Equivalent to the log! macro in instruction_rewriter.rs:
/// ```
/// macro_rules! log {
/// ($enabled:expr, $($arg:tt)*) => {
/// trace.stderr_if(&format!($($arg)*), $enabled);
/// };
/// }
/// ```
///
/// # Example
///
/// ```ignore
/// let trace = trace::trace();
/// log_if(&trace, true, "[DEBUG] Block {:?} processed", block_id);
/// ```
#[inline]
pub(super) fn log_if(trace: &JoinLoopTrace, enabled: bool, message: &str) {
trace.stderr_if(message, enabled);
}
/// Macro version for format string convenience
///
/// Usage: `log!(trace, enabled, "format {}", arg);`
///
/// This macro forwards to log_if() with format!() handling.
#[macro_export]
macro_rules! rewriter_log {
($trace:expr, $enabled:expr, $($arg:tt)*) => {
$crate::mir::builder::control_flow::joinir::merge::rewriter::logging::log_if(
$trace,
$enabled,
&format!($($arg)*)
)
};
}
// Phase 260 P0.1: Keep local macro compatibility
//
// The original log! macro was defined locally in merge_and_rewrite().
// This module provides both function (log_if) and macro (rewriter_log!) forms.
//
// Migration strategy:
// 1. First, use logging::log_if() to replace some log! calls (verify)
// 2. Then, replace remaining log! with rewriter_log! macro
// 3. Finally, remove local log! macro from instruction_rewriter.rs

View File

@ -18,14 +18,18 @@
// Phase 260 P0.1 Step 1: Forward all declarations to parent instruction_rewriter.rs
// This allows gradual migration without breaking existing code.
//
// When modules are ready:
// - mod terminator;
// - mod exit_line;
// - mod carriers;
// - mod logging;
// Modules (extracted):
// - logging: DEBUG-177 style verbose logs ✅
// Future modules (pending):
// - terminator: Branch/Jump/Return remapping
// - exit_line: ExitLine/exit-phi wiring
// - carriers: loop_invariants, exit_bindings
//
// For now, re-export from parent to maintain compatibility.
pub(super) mod logging; // Phase 260 P0.1 Step 2: Logging extracted ✅
// Re-export public API from parent instruction_rewriter module
pub(super) use super::instruction_rewriter::is_skippable_continuation;
pub(super) use super::instruction_rewriter::merge_and_rewrite;