-
Notifications
You must be signed in to change notification settings - Fork 14
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
Pzucker/precondition #101
Pzucker/precondition #101
Conversation
Looking good other than the conflicts! I agree that the smtlib stuff should be in its own module maybe something like |
wp/lib/bap_wp/src/environment.mli
Outdated
(** [get_decls_and_symbols] builds from a the var_map in an environment | ||
a mapping of all Z3 func_decl to their symbol. This is a helper function for | ||
[mk_smtlib2] *) | ||
|
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.
Just a little nitpick, but there are no blank lines between the ocamldoc comments and the function signatures in the other functions, and I think it would be great to be consistent.
exp_to_z3_body body env' | ||
let z3_expr, env = exp_to_z3_body body env' in | ||
let env = Env.remove_var env v in | ||
(z3_expr, env) |
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.
If a variable in the let-binding shares a name with a variable that already existed in the env
, would removing it also remove the original variable? If so, it might be good to write a comment about that.
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.
Correct, this could conceivable occur if some pervert wanted to name a let-bound variable RAX
, or more pragmatically if an inner let shadows an outer let. This should cause a run-time error rather than a mysterious change in semantics. A comment might be appropriate though.
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.
Hmm. That's an interesting point. We didn't implement this correctly basically. We should store the variable we're covering up. In practice it probably isn't a problem because the let bindings seem to use names like "$1", but should probably still be fixed for sanity
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.
This is a really good catch
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 I fixed this
wp/lib/bap_wp/src/compare.ml
Outdated
let compare_subs_eq | ||
~input:(input : Var.Set.t) | ||
~output:(output : Var.Set.t) | ||
~original:(original : Sub.t * Env.t) | ||
~modified:(modified : Sub.t * Env.t) | ||
~smtlib_post:(smtlib_post : string) | ||
~smtlib_pre:(smtlib_pre : string) |
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 agree, hypothesis might be a better name for 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.
So smtlib_hyp
or smtlib_hype
if we're trying to appeal to the youth.
@@ -123,7 +123,7 @@ let test_sub_pair_1 (test_ctx : test_ctxt) : unit = | |||
let output_vars = Var.Set.singleton z in | |||
let compare_prop, _, _ = Comp.compare_subs_eq | |||
~input:input_vars ~output:output_vars | |||
~original:(sub1,env1) ~modified:(sub2,env2) in | |||
~original:(sub1,env1) ~modified:(sub2,env2) ~smtlib_post:"" ~smtlib_pre:"" in |
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.
Should smtlib_post
and smtlib_pre
be optional arguments defaulting to ""
? This one is really up to you.
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.
Yeah. i debated this one. I just hated putting them as the first arguments, which optional seems to require. But it might be the right call
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 vote for true
and false
as defaults, respectively.
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.
Shouldn't the defaults both be true
?
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.
Yes, I think you're right, actually.
wp/lib/bap_wp/src/precondition.ml
Outdated
@@ -833,6 +796,7 @@ let check ?refute:(refute = true) (solver : Solver.solver) (ctx : Z3.context) | |||
else | |||
pre' | |||
in | |||
Printf.printf "Z3 Query:\n%s\n" (Z3.Expr.to_string (Z3.Expr.simplify is_correct None)); |
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.
Do you think we can make this an info
log or something so that it doesn't print out when we run the unit tests?
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.
Seems reasonable. Or perhaps a command line flag.
Is there an insane amount of stuff in info? I would be of the opinion we also suppress the Constrain being printed by default and maybe the BIL.
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'm not against having a flag for verbose
mode, but it's probably out of the scope for this PR. And there isn't too much stuff in info. From grepping, I can see we have 8 info logs.
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.
Yea info
seems reasonable... IDK.
Looks super good! Just a few nitpicks. I agree, putting the smtlib functions in its own module and adding unit test(s) for the compare module is a great idea. Good work! 🎉 |
minor fixes to formatting and 1 silly bug
baa4501
to
70dd0f4
Compare
wp/lib/bap_wp/src/z3_utils.mli
Outdated
|
||
(** | ||
|
||
This module exports types and utilities to process and report results found |
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.
Can we update this comment to match the z3_utils
module?
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.
Fixed. Good catch.
Example usage
TODO: