-
Notifications
You must be signed in to change notification settings - Fork 48
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
Tiny simplification of constFoldProp #530
Conversation
src/EVM/Expr.hs
Outdated
@@ -1575,8 +1569,7 @@ constFoldProp ps = oneRun ps (ConstState mempty True) | |||
v2 = oneRun [b] s | |||
unless v1 $ go b | |||
unless v2 $ go a | |||
s2 <- get | |||
put $ s{canBeSat=(s2.canBeSat && (v1 || v2))} | |||
put $ s{canBeSat=(s.canBeSat && (v1 || v2))} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do not need to read the state again, because we have the information where any of the two disjunct is inconsistent in the results v1
and v2
. We can use the old value of s.canBeSat
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think not, actually! The oneRun
can change it! If you do git blame
it kinda tries to show it... maybe not too well. But yeah, so it's actually not correct. Kind of a minefield. Maybe you could put a comment here, since I have also made this mistake and I have a feeling someone else may also bump into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up on our offline discussion.
After some exchange of ideas, I believe that updating the state here is unnecessary.
The reasoning is that the correct update already happens in go
statements (if they are executed).
It goes like this:
-
If both
v1
andv2
are true, then both disjuncts are satisfiable, and neither go a or go b will be executed. So we just continue with the same state. No need for any update. -
Suppose that one of the variables is false, say
v1
, but the other is true.
That means that disjuncta
is unsatisfiable,b
is satisfiable. The code will executego b
. That should just keep the variablecanBeSat
of the current state the same, because we already know this branch is satisfiable. And, the map with values will be updated (which is something that is actually not happening inmain
). So we do not have to touch the state, it is already OK. -
If both are unsatisfiable, both
go b
andgo a
will execute, and the latter will make the state unsat plus empty map. So again, no update is necessary afterwards.
e0e0046
to
fa56375
Compare
fa56375
to
13b73a4
Compare
@msooseth, I am gonna add more tests, and rename the method to |
Description
I am trying to learn how different pieces of hevm work and concurrently learning Haskell.
Here is my attempt to simplify a piece of code using monadic operations.