-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FStar.UInt discrepancy #872
Comments
Tough one. Making the two toolchains behave as close as possible is a worthy goal. Given this kind of example, do you think there is any chance we can make both toolchains behave exactly the same? |
The same code also appears in |
Found yet another place where this code was copied: |
Regarding ulib failing to build with the F# build of F* - If I understand this issue correctly, F# does not optimise
Edit: a better solution, if this were the problem, would be to prove that |
@A-Manning worth giving this a try |
This bug is not being caused by differences in F# vs OCaml compiler optimisation. It's a result of the F# build using int32 arithmetic. val pow2_values: x:nat -> Lemma
(requires True)
(ensures (let p = pow2 x in
match x with
...
//| 31 -> p= 2147483648
| 32 -> p=0
| 63 -> p=0
| 64 -> p=0
| _ -> True))
let pow2_values x = match x with
...
//| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 0)
| 63 -> assert_norm (pow2 63 == 0)
| 64 -> assert_norm (pow2 64 == 0)
| _ -> () If we add the ...
(ensures (let p = pow2 x in
match x with
...
| 31 -> p= -2147483648
...
let pow2_values x = match x with
...
| 31 -> assert_norm (pow2 31 == -2147483648)
|
Fixed in #1283 |
This is really more of a request for comments than an actual bug report and issues related to mine have been discussed before (e.g., #357) and this is probably hard to fix with only minor benefits for everybody who's not me.
In my current Windows/F#/.NET setup FStar.UInt.fst currently fails to verify, while the same goes through fine in my Ubuntu/OCaml setup. The core of the issue is this:
fails via F#, but verifies via OCaml.
I suppose this is related to the 2^31 limited OCaml ints, but my immediate consequence is that I get different queries into Z3, when I really expect the same. There are too many steps between the input and the Z3 query for me to comprehend all of them, but superficially it looks to me like via F# we get additional constraints because
pure_return
andpure_null_wp
are instantiated for thepow2
call, while they are not added via OCaml. My guess is that OCaml (or our .ml files) propagates the constant and simplifies thepow2
call before any constraints are generated, while F# thinks that31
is big enough not to compute the result at compile time. (The consequence is that Z3 sees six extra quantifiers that make it bail out early.)In general, what's the strategy regarding this and similar examples? Is the goal to get both toolchains behave exactly the same, or is it okay if one of them can't prove something the other can prove?
The text was updated successfully, but these errors were encountered: