Commit Graph

1 Commits

Author SHA1 Message Date
2bdf1abe78 feat(mir): Phase 1 - Loop Canonicalizer type definitions
Implements the foundation for loop canonicalization - a preprocessing
layer that decomposes AST loops into normalized skeleton representation
to prevent combinatorial explosion in pattern detection.

## Implementation (Phase 1)

Created `src/mir/loop_canonicalizer/mod.rs` with:

1. **Core Types**:
   - `LoopSkeleton`: Canonical loop representation
   - `SkeletonStep`: Step kinds (HeaderCond, BreakCheck, ContinueCheck, Update, Body)
   - `UpdateKind`: Carrier update classification (ConstStep, Conditional, Arbitrary)
   - `ExitContract`: Exit presence tracking (break/continue/return)
   - `CarrierSlot`: Loop variables with roles and update rules
   - `CarrierRole`: Semantic roles (Counter, Accumulator, ConditionVar, Derived)
   - `CapturedSlot`: Outer scope variable capture

2. **Capability Guard**:
   - `RoutingDecision`: Pattern selection with diagnostics
   - `capability_tags` module: Standardized Fail-Fast vocabulary
     (CAP_MISSING_CONST_STEP, CAP_MISSING_SINGLE_BREAK, etc.)

3. **Helper Methods**:
   - Skeleton counting (break_checks, continue_checks)
   - Carrier name extraction
   - Exit contract queries
   - Display implementations for debugging

4. **Unit Tests**: 6 tests covering all basic functionality

## Design Principles

- **Input**: AST only (no JoinIR dependencies)
- **Output**: LoopSkeleton only (no BlockId/ValueId)
- **Boundary**: Clear separation from lowering concerns
- **Fail-Fast**: Capability-based rejection with clear reasons

## Next Steps (Not in this commit)

- Phase 2: `LoopCanonicalizer::canonicalize(ast) -> Result<LoopSkeleton>`
- Phase 3: Test with skip_whitespace fixture
- Phase 4: Integration with existing JoinIR lowering

## Acceptance Criteria

 `cargo build --release` succeeds
 `cargo test --release --lib` passes (1039 tests)
 6 new unit tests for loop_canonicalizer pass
 No regressions in existing tests

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-16 04:59:26 +09:00