refactor(mir): Phase 137-6-S1 - choose_pattern_kind SSOT入口を新設
## 目的 Pattern 選択ロジックを SSOT 化し、将来の Canonicalizer 委譲に備える ## 変更内容 ### 新規関数: `choose_pattern_kind()` - 場所: `src/mir/builder/control_flow/joinir/routing.rs` - 責務: Pattern 選択の SSOT 入口 - 実装: 既存の LoopFeatures ベース選択ロジックを集約 ### LoopPatternContext の更新 - `new()` で `choose_pattern_kind()` を使用 - 既存の分散した選択ロジックを SSOT に統一 ## 効果 - ✅ Pattern 選択ロジックの SSOT 化(1箇所に集約) - ✅ 将来の Canonicalizer 委譲に備えた構造確立 - ✅ 既定挙動完全不変(既存テスト全て PASS) ## テスト結果 - ✅ `cargo build --release`: 成功 - ✅ スモークテスト(simple_*): 5/5 PASS - ✅ 退行なし 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -36,15 +36,37 @@ pub static OPERATORS_DIV_RULES: &[(&str, &str, &str, &str)] = &[
|
|||||||
];
|
];
|
||||||
pub fn lookup_keyword(word: &str) -> Option<&'static str> {
|
pub fn lookup_keyword(word: &str) -> Option<&'static str> {
|
||||||
for (k, t) in KEYWORDS {
|
for (k, t) in KEYWORDS {
|
||||||
if *k == word {
|
if *k == word { return Some(*t); }
|
||||||
return Some(*t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static SYNTAX_ALLOWED_STATEMENTS: &[&str] = &[
|
pub static SYNTAX_ALLOWED_STATEMENTS: &[&str] = &[
|
||||||
"box", "global", "function", "static", "if", "loop", "break", "return", "print", "nowait",
|
"box",
|
||||||
"include", "local", "outbox", "try", "throw", "using", "from",
|
"global",
|
||||||
|
"function",
|
||||||
|
"static",
|
||||||
|
"if",
|
||||||
|
"loop",
|
||||||
|
"break",
|
||||||
|
"return",
|
||||||
|
"print",
|
||||||
|
"nowait",
|
||||||
|
"include",
|
||||||
|
"local",
|
||||||
|
"outbox",
|
||||||
|
"try",
|
||||||
|
"throw",
|
||||||
|
"using",
|
||||||
|
"from",
|
||||||
];
|
];
|
||||||
pub static SYNTAX_ALLOWED_BINOPS: &[&str] = &["add", "sub", "mul", "div", "and", "or", "eq", "ne"];
|
pub static SYNTAX_ALLOWED_BINOPS: &[&str] = &[
|
||||||
|
"add",
|
||||||
|
"sub",
|
||||||
|
"mul",
|
||||||
|
"div",
|
||||||
|
"and",
|
||||||
|
"or",
|
||||||
|
"eq",
|
||||||
|
"ne",
|
||||||
|
];
|
||||||
@ -88,11 +88,7 @@ impl<'a> LoopProcessingContext<'a> {
|
|||||||
///
|
///
|
||||||
/// This should be called after running the canonicalizer.
|
/// This should be called after running the canonicalizer.
|
||||||
/// After this call, `verify_parity()` can be used to check consistency.
|
/// After this call, `verify_parity()` can be used to check consistency.
|
||||||
pub fn set_canonicalizer_result(
|
pub fn set_canonicalizer_result(&mut self, skeleton: LoopSkeleton, decision: RoutingDecision) {
|
||||||
&mut self,
|
|
||||||
skeleton: LoopSkeleton,
|
|
||||||
decision: RoutingDecision,
|
|
||||||
) {
|
|
||||||
self.skeleton = Some(skeleton);
|
self.skeleton = Some(skeleton);
|
||||||
self.decision = Some(decision);
|
self.decision = Some(decision);
|
||||||
}
|
}
|
||||||
@ -304,8 +300,10 @@ mod tests {
|
|||||||
let mut ctx = make_simple_context(&condition, &body);
|
let mut ctx = make_simple_context(&condition, &body);
|
||||||
|
|
||||||
// Set canonicalizer result with fail-fast decision
|
// Set canonicalizer result with fail-fast decision
|
||||||
let decision =
|
let decision = RoutingDecision::fail_fast(
|
||||||
RoutingDecision::fail_fast(vec![CapabilityTag::ConstStep], "Test fail-fast".to_string());
|
vec![CapabilityTag::ConstStep],
|
||||||
|
"Test fail-fast".to_string(),
|
||||||
|
);
|
||||||
ctx.set_canonicalizer_result(
|
ctx.set_canonicalizer_result(
|
||||||
LoopSkeleton {
|
LoopSkeleton {
|
||||||
steps: vec![],
|
steps: vec![],
|
||||||
|
|||||||
@ -70,6 +70,7 @@ impl<'a> LoopPatternContext<'a> {
|
|||||||
/// Phase 192: Extract features and classify pattern from AST
|
/// Phase 192: Extract features and classify pattern from AST
|
||||||
/// Phase 193: Feature extraction delegated to ast_feature_extractor module
|
/// Phase 193: Feature extraction delegated to ast_feature_extractor module
|
||||||
/// Phase 131-11: Detects infinite loop condition
|
/// Phase 131-11: Detects infinite loop condition
|
||||||
|
/// Phase 137-6-S1: Use choose_pattern_kind() SSOT entry point
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
condition: &'a ASTNode,
|
condition: &'a ASTNode,
|
||||||
body: &'a [ASTNode],
|
body: &'a [ASTNode],
|
||||||
@ -84,8 +85,9 @@ impl<'a> LoopPatternContext<'a> {
|
|||||||
// Phase 131-11: Pass condition for infinite loop detection
|
// Phase 131-11: Pass condition for infinite loop detection
|
||||||
let features = ast_features::extract_features(condition, body, has_continue, has_break);
|
let features = ast_features::extract_features(condition, body, has_continue, has_break);
|
||||||
|
|
||||||
// Phase 192: Classify pattern based on features
|
// Phase 137-6-S1: Use SSOT pattern selection entry point
|
||||||
let pattern_kind = crate::mir::loop_pattern_detection::classify(&features);
|
use crate::mir::builder::control_flow::joinir::routing::choose_pattern_kind;
|
||||||
|
let pattern_kind = choose_pattern_kind(condition, body);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
condition,
|
condition,
|
||||||
|
|||||||
@ -5,6 +5,30 @@ use crate::ast::ASTNode;
|
|||||||
use crate::mir::builder::MirBuilder;
|
use crate::mir::builder::MirBuilder;
|
||||||
use crate::mir::ValueId;
|
use crate::mir::ValueId;
|
||||||
|
|
||||||
|
/// Pattern 選択の SSOT 入口
|
||||||
|
///
|
||||||
|
/// 既存の分散した選択ロジックをここに集約する。
|
||||||
|
/// 将来的には Canonicalizer decision に委譲する。
|
||||||
|
///
|
||||||
|
/// Phase 137-6-S1: 現時点では既存の router ロジック(LoopFeatures ベース)を使用
|
||||||
|
pub(in crate::mir::builder) fn choose_pattern_kind(
|
||||||
|
condition: &ASTNode,
|
||||||
|
body: &[ASTNode],
|
||||||
|
) -> crate::mir::loop_pattern_detection::LoopPatternKind {
|
||||||
|
use crate::mir::builder::control_flow::joinir::patterns::ast_feature_extractor as ast_features;
|
||||||
|
use crate::mir::loop_pattern_detection;
|
||||||
|
|
||||||
|
// Phase 193: Use AST Feature Extractor Box for break/continue detection
|
||||||
|
let has_continue = ast_features::detect_continue_in_body(body);
|
||||||
|
let has_break = ast_features::detect_break_in_body(body);
|
||||||
|
|
||||||
|
// Phase 193: Extract features using modularized extractor
|
||||||
|
let features = ast_features::extract_features(condition, body, has_continue, has_break);
|
||||||
|
|
||||||
|
// Phase 192: Classify pattern based on features
|
||||||
|
loop_pattern_detection::classify(&features)
|
||||||
|
}
|
||||||
|
|
||||||
impl MirBuilder {
|
impl MirBuilder {
|
||||||
/// Phase 49: Try JoinIR Frontend for mainline integration
|
/// Phase 49: Try JoinIR Frontend for mainline integration
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user