refactor(joinir): Phase 244 - ConditionLoweringBox trait unification

Unify condition lowering logic across Pattern 2/4 with trait-based API.

New infrastructure:
- condition_lowering_box.rs: ConditionLoweringBox trait + ConditionContext (293 lines)
- ExprLowerer implements ConditionLoweringBox trait (+51 lines)

Pattern migrations:
- Pattern 2 (loop_with_break_minimal.rs): Use trait API
- Pattern 4 (loop_with_continue_minimal.rs): Use trait API

Benefits:
- Unified condition lowering interface
- Extensible for future lowering strategies
- Clean API boundary between patterns and lowering logic
- Zero code duplication

Test results: 911/911 PASS (+2 new tests)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-11 02:35:31 +09:00
parent 2dfe363365
commit d4f90976da
131 changed files with 3123 additions and 42 deletions

View File

@ -308,6 +308,58 @@ impl<'env, 'builder, S: ScopeManager> ExprLowerer<'env, 'builder, S> {
}
}
// ============================================================================
// Phase 244: ConditionLoweringBox trait implementation
// ============================================================================
use super::condition_lowering_box::{ConditionLoweringBox, ConditionContext};
impl<'env, 'builder, S: ScopeManager> ConditionLoweringBox<S> for ExprLowerer<'env, 'builder, S> {
/// Phase 244: Implement ConditionLoweringBox trait for ExprLowerer
///
/// This allows ExprLowerer to be used interchangeably with other condition
/// lowering implementations through the unified ConditionLoweringBox interface.
///
/// # Design
///
/// This implementation is a thin wrapper around the existing `lower()` method.
/// The `ConditionContext` parameter is currently unused because ExprLowerer
/// already has access to ScopeManager through its constructor.
///
/// # Example
///
/// ```ignore
/// // Pattern 2: Use ExprLowerer via ConditionLoweringBox trait
/// let mut lowerer = ExprLowerer::new(&scope, ExprContext::Condition, &mut builder);
///
/// let context = ConditionContext {
/// loop_var_name: "i".to_string(),
/// loop_var_id: ValueId(1),
/// scope: &scope,
/// alloc_value: &mut alloc_fn,
/// };
///
/// let cond_value = lowerer.lower_condition(&break_cond_ast, &context)?;
/// ```
fn lower_condition(
&mut self,
condition: &ASTNode,
_context: &ConditionContext<S>,
) -> Result<ValueId, String> {
// Delegate to existing lower() method
// ConditionContext is unused because ExprLowerer already has scope access
self.lower(condition).map_err(|e| e.to_string())
}
/// Phase 244: Check if ExprLowerer supports a given condition pattern
///
/// This delegates to the existing `is_supported_condition()` static method,
/// allowing callers to check support before attempting lowering.
fn supports(&self, condition: &ASTNode) -> bool {
Self::is_supported_condition(condition)
}
}
#[cfg(test)]
mod tests {
use super::*;