rust-djinn: You Should Specify Your Code Unambiguously (and Prove That You Did)

Simon Henniger (email me)

I have a program that grants wishes, as long as I can state them precisely. Instead of implementing a Rust function, I describe what it should do, and the Djinn writes code that provably does exactly that. Suppose I want to sort a list. I write:

djinn! {
    pub fn sort(v: &[i32]) -> r: Vec<i32> {
        // My sorted list is the same length…
        v.len() == r.len();
        // … and it contains all the same elements …
        for x in v { v.iter().filter(|y| y == x).count() == r.iter().filter(|y| y == x).count(); }
        // … and it is sorted!
        for i in 0..r.len() - 1 { r[i] <= r[i + 1]; }
    }
}