Repository navigation
Fix float ghost default values - #539
MohammedZaid1740 wants to merge 2 commits into
Conversation
CatarinaGamboa
left a comment
There was a problem hiding this comment.
Hi @MohammedZaid1740 thanks for your interest in contributing to our project!
I left a couple of comments in the PR.
The main issue is changing floats to 32-bit (FP32) since the verifier accept some programs it should reject, for example:
-
0.1fgets the wrong value.mkFP(0.1, FPSort32)gives0.099999994, but Java's0.1fis0.10000000149(why). So this wrong call is accepted:static void bad(@Refinement("x < 0.1") double x) {} float f = 0.1f; bad(f);
-
Assignments like
f += 0.1break later checks. Java rounds the result to a float before storing it (JLS §5.1.3), but here it isn't rounded. No float can equal the unrounded value, so the verifier ends up with impossible facts and accepts everything after it:static void neg(@Refinement("_ < 0") float x) {} float f = 1.0f; f += 0.1; neg(f); // accepted, but f is 1.1
So one option is to keep the floats as FP64 and maybe in a followup we can make more changes to use FP32 using the roundings on assigments and literals.
| } | ||
|
|
||
| public Expr<?> makeFloatLiteral(double value) { | ||
| return z3.mkFP(value, z3.mkFPSort32()); |
There was a problem hiding this comment.
Since value is a double it won't convert well to Z3FP 32, convert the value first to float in Java, or just keep it FPSort64
| } | ||
|
|
||
| public String toString() { | ||
| return Double.toString(value); |
There was a problem hiding this comment.
This ignores is float so a message can look like found f == 0.1 but expected f == 0.1
|
|
||
| LiteralReal other = (LiteralReal) obj; | ||
| return Double.doubleToLongBits(value) == Double.doubleToLongBits(other.value); | ||
| return Double.doubleToLongBits(value) == Double.doubleToLongBits(other.value) && isFloat == other.isFloat; |
There was a problem hiding this comment.
why do we want this?
| import liquidjava.api.CommandLineLauncher; | ||
| import liquidjava.diagnostics.Diagnostics; | ||
|
|
||
| class TestFloatGhostDefault { |
There was a problem hiding this comment.
Instead of this can we have a test-suite file with a passing and failing test? Look at the examples in liquidjava-example/src/main/java/testSuite/. We can have like CorrectFloatGhost.java
|
Thanks for the detailed review and suggestions! I've updated the implementation based on your feedback:
I reran Thanks again for your guidance! |
Description
Fixed the issue where declaring a
floatghost caused the verifier to crash with the error"Ghost not implemented for type float".Changes made:
0.0as the default value forfloatghosts.floatfrom 64-bitdoubleliterals.Example
A class with a
floatghost can now be processed without the previous unsupported-type crash.Related Issue
Closes #443
Type of change
Checklist
liquidjava-example/src/main/java/testSuite/(Correct*/Error*)mvn testpasses locally