1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
pub type Code = String;

/// This likely could be changed to a Diff patch format
pub type Patch = String;


/// Does this structure work for:
/// a) Mutations: correct -> mutate (broken, benign) -> delta errors (rustc, clippy)
/// b) Cargo suggest: two runs of cargo -> delta code, delta error, maybe interaction loop for
///    picking between multiple options of fixes, and adding text to annotate what we fix
/// c) Commit benchmark: Issue, Repo -> Explain text (PR, Commit), Patch

pub struct CodeExplain {
    /// Context of larger context under which this code operates
    /// E.g., other functions and data structures it references,
    /// types, assertions/assumptions, etc.
    /// This could be gathered from uses of the code fragment,
    /// its repository context, run traces, etc.
    context: String,

    /// Code fragment under consideration
    code: Code,

    /// The error associated with this code. This could come straight
    /// from the compiler, or linter (e.g., clippy), MIRI (extra safety)
    warn_error: Option<String>,

    /// Is the code correct or not?
    is_valid: bool,

    /// Reason for "why correct" or if incorrect then "why broken"
    /// - In the case of correct it could be a MIRI or symbolic
    ///   execution run that reasons step by step why its correct.
    /// - In the case of broken code, it could be an example or
    ///   symbolic step by step for why its invalid
    explain: String,

    /// If the code is not correct, is there a fix for it?
    fix: Option<Patch>,

    /// Explain fix
    fix_explain: String,
}

impl CodeExplain {
    fn init(context: String, code: Code, warn_error: Option<String>,
            is_valid: bool, explain: String,
            fix: Option<Patch>, fix_explain: String) -> CodeExplain {
        CodeExplain {
            context,
            code,
            warn_error,
            is_valid,
            explain,
            fix,
            fix_explain,
        }
    }

}