feat(mir/llvm): Phase 273 P0-P1 DomainPlan→CorePlan + LLVM arg fix
Phase 273 P0-P1: Two-layer plan architecture - DomainPlan: Pattern-specific knowledge (ScanWithInit) - CorePlan: Fixed vocabulary (Seq, Loop, If, Effect, Exit) - ValueId references only (String expressions forbidden) - Pipeline: Extractor→Normalizer→Verifier→Lowerer New plan/ module: - mod.rs: Type definitions, SSOT spec - normalizer.rs: DomainPlan→CorePlan + ID allocation - verifier.rs: V1-V6 invariant checks (fail-fast) - lowerer.rs: CorePlan→MIR (pattern-agnostic) LLVM fix (ChatGPT): - function_lower.py: Fix argument reference bug - Phase 258 index_of_string now PASS on LLVM backend 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -25,6 +25,11 @@ use crate::mir::ValueId;
|
||||
|
||||
use crate::mir::loop_pattern_detection::{LoopFeatures, LoopPatternKind};
|
||||
|
||||
// Phase 273 P1: Import Plan components (DomainPlan → Normalizer → Verifier → Lowerer)
|
||||
use crate::mir::builder::control_flow::plan::lowerer::PlanLowerer;
|
||||
use crate::mir::builder::control_flow::plan::normalizer::PlanNormalizer;
|
||||
use crate::mir::builder::control_flow::plan::verifier::PlanVerifier;
|
||||
|
||||
/// Phase 193: Import AST Feature Extractor Box
|
||||
/// (declared in mod.rs as pub module, import from parent)
|
||||
use super::ast_feature_extractor as ast_features;
|
||||
@ -229,11 +234,8 @@ pub(crate) static LOOP_PATTERNS: &[LoopPatternEntry] = &[
|
||||
detect: super::pattern4_with_continue::can_lower,
|
||||
lower: super::pattern4_with_continue::lower,
|
||||
},
|
||||
LoopPatternEntry {
|
||||
name: "Pattern6_ScanWithInit", // Phase 254 P0: index_of/find/contains pattern (before P3)
|
||||
detect: super::pattern6_scan_with_init::can_lower,
|
||||
lower: super::pattern6_scan_with_init::lower,
|
||||
},
|
||||
// Phase 273 P0.1: Pattern6 entry removed (migrated to Plan-based routing)
|
||||
// Pattern6_ScanWithInit now handled via extract_scan_with_init_plan() + PlanLowerer
|
||||
LoopPatternEntry {
|
||||
name: "Pattern7_SplitScan", // Phase 256 P0: split/tokenization with variable step (before P3)
|
||||
detect: super::pattern7_split_scan::can_lower,
|
||||
@ -278,17 +280,57 @@ pub(crate) static LOOP_PATTERNS: &[LoopPatternEntry] = &[
|
||||
/// - Pattern detection: `ctx.pattern_kind` (from `loop_pattern_detection::classify`)
|
||||
/// - No redundant pattern detection in detect functions
|
||||
/// - All patterns use structure-based classification
|
||||
///
|
||||
/// # Phase 273 P1: DomainPlan → Normalizer → Verifier → Lowerer
|
||||
///
|
||||
/// Pattern6 uses the new two-layer Plan architecture:
|
||||
/// - extract_scan_with_init_plan() → DomainPlan (pure extraction)
|
||||
/// - PlanNormalizer::normalize() → CorePlan (pattern knowledge expansion)
|
||||
/// - PlanVerifier::verify() → fail-fast validation
|
||||
/// - PlanLowerer::lower() → MIR emission (pattern-agnostic)
|
||||
pub(crate) fn route_loop_pattern(
|
||||
builder: &mut MirBuilder,
|
||||
ctx: &LoopPatternContext,
|
||||
) -> Result<Option<ValueId>, String> {
|
||||
use super::super::trace;
|
||||
|
||||
// Phase 273 P1: Try Plan-based Pattern6 first (before table iteration)
|
||||
// Flow: Extract → Normalize → Verify → Lower
|
||||
match super::pattern6_scan_with_init::extract_scan_with_init_plan(
|
||||
ctx.condition,
|
||||
ctx.body,
|
||||
ctx.fn_body,
|
||||
)? {
|
||||
Some(domain_plan) => {
|
||||
// DomainPlan extracted successfully
|
||||
trace::trace().pattern("route", "Pattern6_ScanWithInit (DomainPlan)", true);
|
||||
|
||||
// Step 1: Normalize DomainPlan → CorePlan
|
||||
let core_plan = PlanNormalizer::normalize(builder, domain_plan, ctx)?;
|
||||
|
||||
// Step 2: Verify CorePlan invariants (fail-fast)
|
||||
PlanVerifier::verify(&core_plan)?;
|
||||
|
||||
// Step 3: Lower CorePlan → MIR
|
||||
return PlanLowerer::lower(builder, core_plan, ctx);
|
||||
}
|
||||
None => {
|
||||
// Not Pattern6 - continue to other patterns
|
||||
if ctx.debug {
|
||||
trace::trace().debug(
|
||||
"route",
|
||||
"Pattern6 Plan extraction returned None, trying other patterns",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 183: Route based on pre-classified pattern kind
|
||||
// Pattern kind was already determined by ctx.pattern_kind in LoopPatternContext::new()
|
||||
// This eliminates duplicate detection logic across routers.
|
||||
|
||||
// Find matching pattern entry based on pattern_kind
|
||||
// Phase 273 P0.1: Pattern6 skip logic removed (entry no longer in LOOP_PATTERNS)
|
||||
for entry in LOOP_PATTERNS {
|
||||
if (entry.detect)(builder, ctx) {
|
||||
// Phase 195: Use unified trace for pattern matching
|
||||
|
||||
Reference in New Issue
Block a user