ryo-suggest 0.1.0

[experimental] Pattern-based suggestion engine for RYO
Documentation
//! Performance suggestions - Detect performance improvement opportunities
//!
//! This module provides suggestions for improving code performance by analyzing
//! data flow patterns, type usage, and ownership semantics.
//!
//! # Available Suggestions
//!
//! | Code | Name | Description |
//! |------|------|-------------|
//! | RP001 | `UnnecessaryClone` | Detect clone() calls where ownership is not needed |
//!
//! # Architecture
//!
//! Performance suggestions leverage multiple analysis layers:
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │  Performance Suggest Detection                                   │
//! │  ────────────────────────────                                    │
//! │                                                                  │
//! │  Layer 1: DataFlowGraphV2 (Variable-level flow)                 │
//! │    ├─ FlowKind::Clone detection                                 │
//! │    ├─ impact() - downstream variable tracking                   │
//! │    └─ provenance() - upstream value tracking                    │
//! │                                                                  │
//! │  Layer 2: CodeGraphV2 (Symbol-level relationships)              │
//! │    └─ callers_chain() - call site analysis                      │
//! │                                                                  │
//! │  Layer 3: TypeFlowGraphV2 (Type relationships)                  │
//! │    ├─ type_users_chain() - type usage patterns                  │
//! │    ├─ UsageContext - how types are used                         │
//! │    └─ RefKind - ownership vs borrowing                          │
//! └─────────────────────────────────────────────────────────────────┘
//! ```

mod unnecessary_clone;

pub use unnecessary_clone::UnnecessaryClone;

use crate::{LintSeverity, OpportunityContext, OpportunityId, SuggestLocation, SuggestOpportunity};

/// Performance diagnostic details: current pattern, suggested pattern, and confidence.
pub struct PerformanceDetails {
    /// The current code pattern that could be improved
    pub current_pattern: String,
    /// The suggested optimized pattern
    pub suggested_pattern: String,
    /// Confidence score [0.0, 1.0]
    pub confidence: f32,
}

/// Trait for performance-related suggestions
///
/// Provides common utilities for performance detection patterns.
pub trait PerformanceSuggest {
    /// Get the rule code (e.g., "RP001")
    fn code(&self) -> &'static str;

    /// Get the default severity for this performance issue
    fn default_severity(&self) -> LintSeverity {
        LintSeverity::Warning
    }

    /// Create a performance opportunity with standard context
    fn create_performance_opportunity(
        &self,
        id: OpportunityId,
        targets: Vec<ryo_analysis::SymbolId>,
        location: SuggestLocation,
        message: String,
        details: PerformanceDetails,
    ) -> SuggestOpportunity {
        SuggestOpportunity::new(
            id,
            targets,
            location,
            message,
            details.confidence,
            OpportunityContext::Lint {
                code: self.code().to_string(),
                rule: self.code().to_string(),
                severity: self.default_severity(),
                suggestion: Some(details.suggested_pattern),
                expected: Some("Optimized pattern".to_string()),
                actual: Some(details.current_pattern),
            },
        )
    }
}