-
Notifications
You must be signed in to change notification settings - Fork 35
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
Interaction with Z3 through Z3's Java API instead of StdIO #633
Conversation
(Note on macOS the equivalent is |
…les but needs a different way when set internally??
// workaround: since we cannot create a function application with just the name, we let Z3 parse | ||
// a string that uses the function, take the AST, and get the func decl from there, so that we can | ||
// programmatically create a func app. |
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.
Is this because we don't know the types for the arguments? Are we passing them to Z3 so it can figure out their sorts?
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.
No, the problem is that there is nothing like ctx.getInterpretedFuncDecl(name) in the API that I could give a string like "fp.add" to and get the declaration for floating point addition. Instead, for any built-in interpreted function, there is a separate creator method in the API (e.g., ctx.mkFloatAdd(arg1, arg2)). So I'd have to have a big match-case here that matches all names of all built-in functions and then calls the respectice API method. Which I didn't want to do now because there are a lot of them, and the way we currently use SMTFuncApps, sometimes, the strings aren't actually just a function name but a function name and some number of default argument (e.g., "fp.add RNE", which contains the function name and a first argument that determines the rounding mode).
// the function name we got wasn't just a function name but also contained a first argument. | ||
// this happens with float operations where functionName contains a rounding mode. |
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 this happen for other reasons (e.g. accidentally calling a function with the wrong number of arguments)? Could you whitelist only float-related operations in this branch?
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 guess it could, yes.
I think if we want to avoid this special case (which really shouldn't be here), we should just forbid including arguments in the function name in general, then we wouldn't have to handle this case here. It's just that that was unproblematic when we were dealing only with strings, so I did it when making the factory for floating point operations. If we rewrite that code, I think the only consequence is that users of floating point functions would always have to pass the rounding mode explicitly.
I don't remember if there is anything useful, but you can also check #519. |
One particular difference I noticed is using a "managed" library for the Z3 APIs in |
Oh, I only saw your comments just now. Yes, I agree a proper library dependency is much nicer. |
As far as I'm concerned, since the release is done now, we could merge this. @mschwerhoff what do you think? |
Merged as part of the parallel branch verification PR. |
Requires libz3java to be on the LD_LIBRARY_PATH (or the Windows equivalent) or the java.library.path. The included Java files are from Z3 version 4.8.6, so the library should have the same version, but apparently 4.8.7 also works. Newer versions do not.
Some interesting points:
Probably shouldn't be merged before the release.
I measured a 10-40% speedup for examples from the test suite and much higher speedups for some very long running examples.