mod compiler;
mod diagnostic;
mod encoder;
mod error;
mod metrics;
mod neural;
mod pattern;
pub use compiler::{
CargoProject, CompilationMetrics, CompilationMode, CompilationResult, CompileOptions,
CompiledArtifact, CompilerInterface, CompilerVersion, RustCompiler, RustEdition,
};
pub use diagnostic::{
CodeReplacement, CompilerDiagnostic, CompilerSuggestion, DiagnosticLabel, DiagnosticSeverity,
SourceSpan, SuggestionApplicability, TypeInfo,
};
pub use encoder::{
EdgeType, ErrorEmbedding, ErrorEncoder, GNNErrorEncoder, NodeType, ProgramFeedbackGraph,
};
pub use error::{CITLError, CITLResult};
pub use metrics::{
CompilationTimeMetrics, ConvergenceMetrics, ErrorFrequencyMetrics, FixAttemptMetrics,
MetricsSummary, MetricsTracker, PatternUsageMetrics,
};
pub use neural::{
ContrastiveLoss, NeuralEncoderConfig, NeuralErrorEncoder, TrainingSample, TripletDistance,
TripletLoss, Vocabulary,
};
pub use pattern::{ErrorFixPattern, FixTemplate, PatternLibrary, PatternMatch};
use std::collections::HashMap;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ErrorCode {
pub code: String,
pub category: ErrorCategory,
pub difficulty: Difficulty,
}
impl ErrorCode {
#[must_use]
pub fn new(code: &str, category: ErrorCategory, difficulty: Difficulty) -> Self {
Self {
code: code.to_string(),
category,
difficulty,
}
}
#[must_use]
pub fn from_code(code: &str) -> Self {
Self {
code: code.to_string(),
category: ErrorCategory::Unknown,
difficulty: Difficulty::Medium,
}
}
}
impl std::fmt::Display for ErrorCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.code)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ErrorCategory {
TypeMismatch,
TraitBound,
Unresolved,
Ownership,
Borrowing,
Lifetime,
Async,
TypeInference,
MethodNotFound,
Import,
Unknown,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Difficulty {
Easy,
Medium,
Hard,
Expert,
}
impl Difficulty {
#[must_use]
pub fn score(&self) -> f32 {
match self {
Difficulty::Easy => 0.25,
Difficulty::Medium => 0.5,
Difficulty::Hard => 0.75,
Difficulty::Expert => 1.0,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Language {
Python,
C,
Ruchy,
Bash,
Rust,
}
impl std::fmt::Display for Language {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Language::Python => write!(f, "Python"),
Language::C => write!(f, "C"),
Language::Ruchy => write!(f, "Ruchy"),
Language::Bash => write!(f, "Bash"),
Language::Rust => write!(f, "Rust"),
}
}
}
#[allow(missing_debug_implementations)]
pub struct CITL {
compiler: Arc<dyn CompilerInterface>,
encoder: ErrorEncoder,
pattern_library: PatternLibrary,
config: CITLConfig,
}
#[derive(Debug, Clone)]
pub struct CITLConfig {
pub max_iterations: usize,
pub confidence_threshold: f32,
pub enable_self_training: bool,
}
impl Default for CITLConfig {
fn default() -> Self {
Self {
max_iterations: 10,
confidence_threshold: 0.7,
enable_self_training: true,
}
}
}
#[allow(missing_debug_implementations)]
pub struct CITLBuilder {
compiler: Option<Arc<dyn CompilerInterface>>,
pattern_library_path: Option<String>,
config: CITLConfig,
}
impl Default for CITLBuilder {
fn default() -> Self {
Self::new()
}
}
impl CITLBuilder {
#[must_use]
pub fn new() -> Self {
Self {
compiler: None,
pattern_library_path: None,
config: CITLConfig::default(),
}
}
#[must_use]
pub fn compiler<C: CompilerInterface + 'static>(mut self, compiler: C) -> Self {
self.compiler = Some(Arc::new(compiler));
self
}
#[must_use]
pub fn pattern_library(mut self, path: &str) -> Self {
self.pattern_library_path = Some(path.to_string());
self
}
#[must_use]
pub fn max_iterations(mut self, n: usize) -> Self {
self.config.max_iterations = n;
self
}
#[must_use]
pub fn confidence_threshold(mut self, threshold: f32) -> Self {
self.config.confidence_threshold = threshold;
self
}
pub fn build(self) -> CITLResult<CITL> {
let compiler = self.compiler.ok_or(CITLError::ConfigurationError {
message: "Compiler interface is required".to_string(),
})?;
let pattern_library = if let Some(path) = self.pattern_library_path {
PatternLibrary::load(&path).unwrap_or_default()
} else {
PatternLibrary::new()
};
Ok(CITL {
compiler,
encoder: ErrorEncoder::new(),
pattern_library,
config: self.config,
})
}
}
include!("citl_impl.rs");