phase29ao(p21): tighten pattern1 subset to step-only body
This commit is contained in:
@ -5,6 +5,7 @@ use crate::ast::{ASTNode, BinaryOperator};
|
||||
|
||||
// Phase 282 P9a: Use common_helpers
|
||||
use super::common_helpers::has_control_flow_statement as common_has_control_flow;
|
||||
use crate::mir::builder::control_flow::plan::policies::pattern1_subset_policy::is_pattern1_step_only_body;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Pattern1Parts {
|
||||
@ -200,6 +201,10 @@ pub(crate) fn extract_pattern1_plan(
|
||||
None => return Ok(None), // No loop increment found
|
||||
};
|
||||
|
||||
if !is_pattern1_step_only_body(body, &parts.loop_var) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
Ok(Some(DomainPlan::Pattern1SimpleWhile(Pattern1SimpleWhilePlan {
|
||||
loop_var: parts.loop_var,
|
||||
condition: condition.clone(),
|
||||
|
||||
@ -6,6 +6,7 @@ use crate::mir::builder::control_flow::plan::extractors::common_helpers::{
|
||||
extract_loop_increment_plan, has_break_statement, has_continue_statement, has_if_else_statement,
|
||||
has_return_statement,
|
||||
};
|
||||
use crate::mir::builder::control_flow::plan::policies::pattern1_subset_policy::is_pattern1_step_only_body;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(in crate::mir::builder) struct Pattern1SimpleWhileFacts {
|
||||
@ -35,6 +36,10 @@ pub(in crate::mir::builder) fn try_extract_pattern1_simplewhile_facts(
|
||||
_ => return Ok(None),
|
||||
};
|
||||
|
||||
if !is_pattern1_step_only_body(body, &loop_var) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
if !is_increment_step_one(&loop_increment, &loop_var) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
@ -40,6 +40,8 @@ pub(in crate::mir::builder) mod composer;
|
||||
pub(in crate::mir::builder) mod emit;
|
||||
// Phase 29ai P6: Extractors moved into plan layer
|
||||
pub(in crate::mir::builder) mod extractors;
|
||||
// Phase 29ao P21: Pattern1 subset policy (SSOT gate)
|
||||
pub(in crate::mir::builder) mod policies;
|
||||
// Phase 29ai P5: JoinIR router → single plan extraction entrypoint
|
||||
pub(in crate::mir::builder) mod single_planner;
|
||||
|
||||
|
||||
3
src/mir/builder/control_flow/plan/policies/mod.rs
Normal file
3
src/mir/builder/control_flow/plan/policies/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
//! Phase 29ao P21: Pattern1 subset policy SSOT
|
||||
|
||||
pub(in crate::mir::builder) mod pattern1_subset_policy;
|
||||
@ -0,0 +1,42 @@
|
||||
//! Phase 29ao P21: Pattern1 subset policy (step-only body)
|
||||
|
||||
use crate::ast::{ASTNode, BinaryOperator, LiteralValue};
|
||||
|
||||
pub(crate) fn is_pattern1_step_only_body(body: &[ASTNode], loop_var: &str) -> bool {
|
||||
if body.len() != 1 {
|
||||
return false;
|
||||
}
|
||||
|
||||
let ASTNode::Assignment { target, value, .. } = &body[0] else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let ASTNode::Variable { name, .. } = target.as_ref() else {
|
||||
return false;
|
||||
};
|
||||
if name != loop_var {
|
||||
return false;
|
||||
}
|
||||
|
||||
let ASTNode::BinaryOp {
|
||||
operator: BinaryOperator::Add,
|
||||
left,
|
||||
right,
|
||||
..
|
||||
} = value.as_ref()
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
if !matches!(left.as_ref(), ASTNode::Variable { name, .. } if name == loop_var) {
|
||||
return false;
|
||||
}
|
||||
|
||||
matches!(
|
||||
right.as_ref(),
|
||||
ASTNode::Literal {
|
||||
value: LiteralValue::Integer(1),
|
||||
..
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user