feat(joinir): Phase 170-C-2b LoopUpdateSummary wiring into shape detection
Wire LoopUpdateSummary box into real code paths: - Add `update_summary: Option<LoopUpdateSummary>` field to LoopFeatures - Add `detect_with_updates()` method to CaseALoweringShape - Uses UpdateKind (CounterLike/AccumulationLike) for classification - Single CounterLike carrier → StringExamination - AccumulationLike present → ArrayAccumulation or IterationWithAccumulation - Update loop_to_join.rs to use detect_with_updates() - Update deprecated detect() to use detect_with_updates() internally - Set update_summary: None in AST-based feature extraction Carrier name heuristics now encapsulated in LoopUpdateSummary box. No regression: 15/16 loop smoke tests pass (1 failure is pre-existing). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -202,6 +202,68 @@ impl CaseALoweringShape {
|
||||
}
|
||||
}
|
||||
|
||||
/// Phase 170-C-2b: LoopUpdateSummary を使った精度向上版
|
||||
///
|
||||
/// `features.update_summary` から UpdateKind を取得して判定。
|
||||
/// これにより、carrier 名を直接見るコードを CaseALoweringShape から排除できる。
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `features` - LoopFeatures (update_summary 含む)
|
||||
/// * `carrier_count` - Number of carrier variables
|
||||
/// * `has_progress_carrier` - Whether progress carrier exists
|
||||
///
|
||||
/// # Returns
|
||||
/// CaseALoweringShape classification based on UpdateSummary
|
||||
pub fn detect_with_updates(
|
||||
features: &crate::mir::loop_pattern_detection::LoopFeatures,
|
||||
carrier_count: usize,
|
||||
has_progress_carrier: bool,
|
||||
) -> Self {
|
||||
use crate::mir::join_ir::lowering::loop_update_summary::UpdateKind;
|
||||
|
||||
// Case-A requirement: must have a progress carrier
|
||||
if !has_progress_carrier {
|
||||
return CaseALoweringShape::NotCaseA;
|
||||
}
|
||||
|
||||
// Case-A requirement: no complex control flow (continue)
|
||||
if features.has_continue {
|
||||
return CaseALoweringShape::NotCaseA;
|
||||
}
|
||||
|
||||
// Phase 170-C-2b: Use UpdateSummary if available
|
||||
if let Some(ref summary) = features.update_summary {
|
||||
// Single carrier with CounterLike update → StringExamination
|
||||
if summary.carriers.len() == 1
|
||||
&& summary.carriers[0].kind == UpdateKind::CounterLike
|
||||
{
|
||||
return CaseALoweringShape::StringExamination;
|
||||
}
|
||||
|
||||
// Any AccumulationLike carrier → ArrayAccumulation (for single carrier)
|
||||
// or IterationWithAccumulation (for multiple carriers)
|
||||
if summary.carriers.iter().any(|c| c.kind == UpdateKind::AccumulationLike) {
|
||||
if carrier_count == 1 {
|
||||
return CaseALoweringShape::ArrayAccumulation;
|
||||
} else {
|
||||
return CaseALoweringShape::IterationWithAccumulation;
|
||||
}
|
||||
}
|
||||
|
||||
// Multiple carriers without clear accumulation → IterationWithAccumulation
|
||||
if carrier_count >= 2 {
|
||||
return CaseALoweringShape::IterationWithAccumulation;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to carrier count heuristic
|
||||
match carrier_count {
|
||||
0 => CaseALoweringShape::NotCaseA,
|
||||
1 => CaseALoweringShape::Generic,
|
||||
2.. => CaseALoweringShape::IterationWithAccumulation,
|
||||
}
|
||||
}
|
||||
|
||||
/// Typical index variable name detection
|
||||
///
|
||||
/// StringExamination パターン(skip/trim)で使われる典型的なインデックス名:
|
||||
@ -229,6 +291,12 @@ impl CaseALoweringShape {
|
||||
let has_progress_carrier = scope.progress_carrier.is_some();
|
||||
let carrier_count = scope.carriers.len();
|
||||
|
||||
// Phase 170-C-2b: Build update_summary from carrier names
|
||||
// Note: carriers is BTreeSet<String>, so each item is already a String
|
||||
let carrier_names: Vec<String> = scope.carriers.iter().cloned().collect();
|
||||
let update_summary =
|
||||
crate::mir::join_ir::lowering::loop_update_summary::analyze_loop_updates(&carrier_names);
|
||||
|
||||
// Create stub features (Phase 170-B will use real LoopFeatures)
|
||||
let stub_features = crate::mir::loop_pattern_detection::LoopFeatures {
|
||||
has_break: false, // Unknown from LoopScopeShape alone
|
||||
@ -238,9 +306,10 @@ impl CaseALoweringShape {
|
||||
carrier_count,
|
||||
break_count: 0,
|
||||
continue_count: 0,
|
||||
update_summary: Some(update_summary),
|
||||
};
|
||||
|
||||
Self::detect_from_features(&stub_features, carrier_count, has_progress_carrier)
|
||||
Self::detect_with_updates(&stub_features, carrier_count, has_progress_carrier)
|
||||
}
|
||||
|
||||
/// Is this a recognized lowering shape?
|
||||
|
||||
Reference in New Issue
Block a user