proto: integrate with Hax#128
Conversation
|
@maximebuyse I think this is getting pretty close. All the following items used in the
Remaining TODO:
Are we missing anything? |
@mkovaxx Great! I pushed a small commit to make sure we produce the right calls to the hax macros (limited to the cases of function and trait contracts for now). We can refactor to limit the number of For now I am testing by running I think your list would cover most of what we need. There will still be a few things missing like refinement types but we're also refactoring our annotations so we'll see what we do with this feature. |
cb7e544 to
1ec971d
Compare
|
@maximebuyse I've refactored this a bit, introducing an |
|
@maximebuyse The transforms to handle quantifiers, loops, and opaque expressions are now implemented. Please give it a try! Remaining TODOs:
|
@mkovaxx Great! I tried quickly and:
pub fn f_loop(x: &[u8]) -> u8 {
let mut max = 0;
#[spec(
maintains: forall(|j: usize| implies!(j < i, x[j] <= max)),
)]
for i in 0..x.len() {
if x[i] > max {
max = x[i]
}
}
max
}Here rust cannot infer the type of #[spec(
maintains: |i: &usize| forall(|j: usize| implies!(j < i, x[j] <= max)),
)]
for i in 0..x.len() {
..
}I imagine we need to take a reference here to make it work with rutnime checks as well, but this can work for hax too. |
|
@maximebuyse Thanks for trying it out and writing down the feedback! :) I've made the changes so that a In the long term, I hope that we'd be able to simplify the surface language syntax so that a loop invariant is always a bare expression (as opposed to a closure). I think moving integration deeper (to Hax's Can you think of anything about the semantics of Hax's loop invariants that might prevent simplifying the surface language like that? |
|
@mkovaxx Thanks! I'll try this. Closures for loop invariants can be confusing so accepting bare expressions would be an improvement. I think the processing of invariants in the hax engine could recognize the loop index and reconstruct a closure (doing it in the frontend/rustc_driver seems more fragile and we want it to work through charon as well). |
|
@maximebuyse Integrating with Charon is something I'm also considering. I think we could prevent duplicated effort by extending Charon with a notion of specs. I'll allocate some time to build a prototype! :) CC @Nadrieril |
|
I'm open to that! Do note that a solution based on THIR can't work in Charon, as that would prevent fetching specs from foreign crates. |
The main purpose of this PR at this point is to enable discussion over concrete prototype code.