refactor(mir): Phase 139-P3-A - CapabilityTag enum 定義

- CapabilityTag enum を定義(8 variants)
- to_tag() メソッドでエラータグ文字列に変換
- description() メソッドで人間可読な説明を提供
- legacy capability_tags モジュールを deprecated マーク(P3-B で削除予定)
- 型安全性向上:コンパイル時エラー検出、IDE 支援
This commit is contained in:
nyash-codex
2025-12-16 06:58:13 +09:00
parent 32d1814130
commit 146f14a019

View File

@ -66,17 +66,75 @@ impl RoutingDecision {
} }
// ============================================================================ // ============================================================================
// Capability Tags // Capability Tags (Type-Safe Enum)
// ============================================================================ // ============================================================================
/// Capability tags - Standardized vocabulary for Fail-Fast reasons /// Capability tag - Type-safe vocabulary for pattern requirements
/// ///
/// These constants define the capabilities required by different patterns. /// Each tag represents a specific capability that a loop pattern requires.
/// When a loop lacks a required capability, it uses the corresponding tag /// Using an enum (instead of string constants) provides:
/// to explain why it cannot be lowered by that pattern. /// - Compile-time error detection for typos
/// - IDE auto-completion
/// - Exhaustiveness checking in match expressions
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CapabilityTag {
/// Requires: Carrier update is constant step (i = i + const)
ConstStep,
/// Requires: Single break point only
SingleBreak,
/// Requires: Single continue point only
SingleContinue,
/// Requires: Pure header condition (no side effects)
PureHeader,
/// Requires: Outer local condition variable
OuterLocalCond,
/// Requires: Complete exit bindings
ExitBindings,
/// Requires: Carrier promotion support
CarrierPromotion,
/// Requires: Consistent break value types
BreakValueType,
}
impl CapabilityTag {
/// Error message tag for contract_checks integration
pub fn to_tag(&self) -> &'static str {
match self {
Self::ConstStep => "CAP_MISSING_CONST_STEP",
Self::SingleBreak => "CAP_MISSING_SINGLE_BREAK",
Self::SingleContinue => "CAP_MISSING_SINGLE_CONTINUE",
Self::PureHeader => "CAP_MISSING_PURE_HEADER",
Self::OuterLocalCond => "CAP_MISSING_OUTER_LOCAL_COND",
Self::ExitBindings => "CAP_MISSING_EXIT_BINDINGS",
Self::CarrierPromotion => "CAP_MISSING_CARRIER_PROMOTION",
Self::BreakValueType => "CAP_MISSING_BREAK_VALUE_TYPE",
}
}
/// Human-readable description
pub fn description(&self) -> &'static str {
match self {
Self::ConstStep => "Carrier update is constant step (i = i + const)",
Self::SingleBreak => "break statement appears in single location only",
Self::SingleContinue => "continue statement appears in single location only",
Self::PureHeader => "Loop header condition has no side effects",
Self::OuterLocalCond => "Condition variable is defined in outer scope",
Self::ExitBindings => "Exit bindings are complete (no missing values)",
Self::CarrierPromotion => "LoopBodyLocal can be promoted to carrier",
Self::BreakValueType => "break value types are consistent across all branches",
}
}
}
// ============================================================================
// Legacy Capability Tags (Deprecated - will be removed in Phase 139-P3-B)
// ============================================================================
/// Legacy capability tags - Standardized vocabulary for Fail-Fast reasons
/// ///
/// NOTE: This module will be deprecated in Phase 139 in favor of the /// ⚠️ DEPRECATED: Use CapabilityTag enum instead for type safety.
/// CapabilityTag enum for type safety. /// This module will be removed in Phase 139-P3-B.
#[deprecated(since = "Phase 139-P3-A", note = "Use CapabilityTag enum instead")]
pub mod capability_tags { pub mod capability_tags {
/// Requires: Carrier update is constant step (`i = i + const`) /// Requires: Carrier update is constant step (`i = i + const`)
pub const CAP_MISSING_CONST_STEP: &str = "CAP_MISSING_CONST_STEP"; pub const CAP_MISSING_CONST_STEP: &str = "CAP_MISSING_CONST_STEP";