code_explain/
code_explain.rs

1pub type Code = String;
2
3/// This likely could be changed to a Diff patch format
4pub type Patch = String;
5
6
7/// Does this structure work for:
8/// a) Mutations: correct -> mutate (broken, benign) -> delta errors (rustc, clippy)
9/// b) Cargo suggest: two runs of cargo -> delta code, delta error, maybe interaction loop for
10///    picking between multiple options of fixes, and adding text to annotate what we fix
11/// c) Commit benchmark: Issue, Repo -> Explain text (PR, Commit), Patch
12
13pub struct CodeExplain {
14    /// Context of larger context under which this code operates
15    /// E.g., other functions and data structures it references,
16    /// types, assertions/assumptions, etc.
17    /// This could be gathered from uses of the code fragment,
18    /// its repository context, run traces, etc.
19    context: String,
20
21    /// Code fragment under consideration
22    code: Code,
23
24    /// The error associated with this code. This could come straight
25    /// from the compiler, or linter (e.g., clippy), MIRI (extra safety)
26    warn_error: Option<String>,
27
28    /// Is the code correct or not?
29    is_valid: bool,
30
31    /// Reason for "why correct" or if incorrect then "why broken"
32    /// - In the case of correct it could be a MIRI or symbolic
33    ///   execution run that reasons step by step why its correct.
34    /// - In the case of broken code, it could be an example or
35    ///   symbolic step by step for why its invalid
36    explain: String,
37
38    /// If the code is not correct, is there a fix for it?
39    fix: Option<Patch>,
40
41    /// Explain fix
42    fix_explain: String,
43}
44
45impl CodeExplain {
46    pub fn init(context: String, code: Code, warn_error: Option<String>,
47            is_valid: bool, explain: String,
48            fix: Option<Patch>, fix_explain: String) -> CodeExplain {
49        CodeExplain {
50            context,
51            code,
52            warn_error,
53            is_valid,
54            explain,
55            fix,
56            fix_explain,
57        }
58    }
59}
60
61pub struct CodeExplainSet {
62    data: Vec<CodeExplain>,
63}
64
65impl CodeExplainSet {
66    pub fn init() -> CodeExplainSet { CodeExplainSet { data: vec![] } }
67
68    pub fn add(&mut self, point: CodeExplain) {
69        self.data.push(point)
70    }
71}