Phase47-B/C: extend P3 normalized shapes and quiet dev warnings

This commit is contained in:
nyash-codex
2025-12-12 07:13:34 +09:00
parent 7200309cc3
commit 386cbc1915
11 changed files with 503 additions and 73 deletions

View File

@ -333,6 +333,16 @@ pub fn normalize_pattern2_minimal(structured: &JoinModule) -> NormalizedModule {
{
max = max.max(6);
}
if shapes.iter().any(|s| {
matches!(
s,
NormalizedDevShape::Pattern3IfSumMinimal
| NormalizedDevShape::Pattern3IfSumMulti
| NormalizedDevShape::Pattern3IfSumJson
)
}) {
max = max.max(6);
}
}
max
};
@ -528,29 +538,49 @@ pub fn normalize_pattern2_minimal(structured: &JoinModule) -> NormalizedModule {
norm
}
/// Phase 47-A: Normalize Pattern3 if-sum minimal to Normalized JoinIR
/// Phase 47-A/B: Normalize Pattern3 if-sum shapes to Normalized JoinIR
#[cfg(feature = "normalized_dev")]
pub fn normalize_pattern3_if_sum_minimal(
structured: &JoinModule,
) -> Result<NormalizedModule, String> {
// Guard: Must be Structured and match Pattern3IfSumMinimal shape
normalize_pattern3_if_sum_shape(structured, NormalizedDevShape::Pattern3IfSumMinimal)
}
/// Phase 47-B: Normalize Pattern3 if-sum multi-carrier (sum+count) shape.
#[cfg(feature = "normalized_dev")]
pub fn normalize_pattern3_if_sum_multi_minimal(
structured: &JoinModule,
) -> Result<NormalizedModule, String> {
normalize_pattern3_if_sum_shape(structured, NormalizedDevShape::Pattern3IfSumMulti)
}
/// Phase 47-B: Normalize JsonParser if-sum (mini) shape.
#[cfg(feature = "normalized_dev")]
pub fn normalize_pattern3_if_sum_json_minimal(
structured: &JoinModule,
) -> Result<NormalizedModule, String> {
normalize_pattern3_if_sum_shape(structured, NormalizedDevShape::Pattern3IfSumJson)
}
#[cfg(feature = "normalized_dev")]
fn normalize_pattern3_if_sum_shape(
structured: &JoinModule,
target_shape: NormalizedDevShape,
) -> Result<NormalizedModule, String> {
if !structured.is_structured() {
return Err("[normalize_p3] Not structured JoinIR".to_string());
}
// Use shape detection to verify P3 shape
let shapes = shape_guard::supported_shapes(&structured);
if !shapes.contains(&NormalizedDevShape::Pattern3IfSumMinimal) {
return Err("[normalize_p3] Not Pattern3IfSumMinimal shape".to_string());
let shapes = shape_guard::supported_shapes(structured);
if !shapes.contains(&target_shape) {
return Err(format!(
"[normalize_p3] shape mismatch: expected {:?}, got {:?}",
target_shape, shapes
));
}
// Phase 47-A minimal: Reuse P2 normalization temporarily
// TODO: Implement proper P3-specific normalization with:
// - EnvLayout for i, sum carriers
// - IfCond → ThenUpdates / ElseUpdates step sequence
// - Proper JpInst::If for conditional carrier updates
// For now, delegate to P2 normalization (works for simple cases)
// Phase 47-B: P3 if-sum は既存の P2 ミニ正規化器で十分に表現できる
// Select/If/Compare/BinOp をそのまま JpInst に写す)。
Ok(normalize_pattern2_minimal(structured))
}
@ -974,6 +1004,16 @@ pub(crate) fn normalized_dev_roundtrip_structured(
.expect("P3 normalization failed");
normalized_pattern2_to_structured(&norm)
})),
NormalizedDevShape::Pattern3IfSumMulti => catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_pattern3_if_sum_multi_minimal(module)
.expect("P3 multi normalization failed");
normalized_pattern2_to_structured(&norm)
})),
NormalizedDevShape::Pattern3IfSumJson => catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_pattern3_if_sum_json_minimal(module)
.expect("P3 json normalization failed");
normalized_pattern2_to_structured(&norm)
})),
// Phase 48-A: P4 minimal (delegates to P2 for now, but uses proper guard)
NormalizedDevShape::Pattern4ContinueMinimal => catch_unwind(AssertUnwindSafe(|| {
let norm = normalize_pattern4_continue_minimal(module)