-
Notifications
You must be signed in to change notification settings - Fork 261
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
Improve Z3 detection #3233
Improve Z3 detection #3233
Conversation
* Be more explicit about the path of the executable to invoke. * Identify the version and set different Z3 options accordingly. Fixes dafny-lang#2370 Enables a fix for dafny-lang#1477 Interacts with dafny-lang#1914 (which may already be fixed)
This avoids errors when not doing verification.
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.
Some slight changes, but otherwise, thanks for migrating z3 detection from DafnyLanguageServer to Dafny and making it even more robust!
Source/DafnyCore/DafnyOptions.cs
Outdated
|
||
var z3binName = isUnix ? "z3" : "z3.exe"; | ||
var platform = System.Environment.OSVersion.Platform; | ||
var isUnix = platform == PlatformID.Unix || platform == PlatformID.MacOSX || (int)platform == 128; |
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 you please add a comment about this 128?
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 honestly don't know what it is. The code previously compared with three constant integers that weren't explained. I saw that two of them were equal to named constants in the PlatformID
class, so I changed the code to refer to those, but the third one didn't correspond to any documented value. I suspect it actually shows up in practice, but I don't know when. This version seems better than the old code, even if not perfect.
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 would feel comfortable removing it as, according to the documentation, 128 is not a valid value:
https://learn.microsoft.com/en-us/dotnet/api/system.platformid?view=net-7.0
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.
Sounds good to me.
if (z3Version is not null && z3Version.Major == 4 && z3Version.Minor == 8 && z3Version.Build == 5) { | ||
// These options tend to help with Z3 4.8.5 but hurt with newer versions of Z3. | ||
SetZ3Option("smt.case_split", "3"); | ||
SetZ3Option("smt.arith.solver", "2"); |
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.
How much are they hurting? Can you please describe the problem in a separate issue?
Also consider describing a range of versions in the conditional, rather than an exact version. Perhaps refactor this:
https://github.com/dafny-lang/dafny/pull/3233/files#diff-b3d55f76ae78d57880964c42ed16a37e9e6a8a3a7ca4022cb96367bccda8d667R80
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.
My experience is that any version newer than 4.8.5 works better with those options removed. I considered adding code to produce an error if it detects a version older than 4.8.5. If I do that, then the conditional above really should just be for a single version. What do you think?
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 you add this error if we detect a version older than 4.8.5, then yes that's fine. Where would you add this error?
If you do not add it in this PR, then I would prefer to see a version "<=" instead of just "=".
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 went for changing it to <=
for now, since it's a little awkward to a signal an error from that location and I haven't actually seen evidence that versions < 4.8.5 don't work. Before we release 4.0 we may want to test those early versions and have a more complete strategy for how to handle the entire range of available versions.
Source/DafnyCore/DafnyMain.cs
Outdated
@@ -319,6 +319,12 @@ private class IncludeComparer : IComparer<Include> { | |||
Microsoft.Boogie.Program boogieProgram, string programId) { | |||
var moduleId = (programId ?? "main_program_id") + "_" + moduleName; | |||
|
|||
var proverPath = DafnyOptions.O.ProverOptions.Find(o => o.StartsWith("PROVER_PATH=")); | |||
if (proverPath is null && DafnyOptions.O.Verify) { | |||
Console.WriteLine("Z3 not found in explicit --solver-path option, Dafny distribution, or PATH environment variable."); |
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.
Console.WriteLine("Z3 not found in explicit --solver-path option, Dafny distribution, or PATH environment variable."); | |
Console.WriteLine("Z3 not found. Please either provide a path to the z3 executable using the `--solver-path <path>` option, or manually place the `z3` folder next to the Dafny executable you are using (this folder should contain `bin/z3` or `bin/z3.exe`), or set the PATH environment variable to also target the folder containing the z3 executable."); |
Errors with explicit action items are always appreciated.
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 updated the text to a slightly reworded version of your suggestion.
And check for versions <= 4.8.5, rather than just ==.
* Be more explicit about the path of the executable to invoke. * Identify the version and set different Z3 options accordingly. Fixes dafny-lang#2370 Enables a fix for dafny-lang#1477 Interacts with dafny-lang#1914 (which may already be fixed) By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
* Be more explicit about the path of the executable to invoke. * Identify the version and set different Z3 options accordingly. Fixes dafny-lang#2370 Enables a fix for dafny-lang#1477 Interacts with dafny-lang#1914 (which may already be fixed) By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
This returns to the behavior prior to PR dafny-lang#3233. It seems that the case_split change makes "time travelling triggers" more likely: dafny-lang#3362 And, although the arith_solver change sped up verification of some programs, it seems that it slowed down more programs. I'd still like to leave the version detection logic in, though, since the language server uses it, and since I think other parts of the CLI will likely use it soon.
This returns to the behavior prior to PR #3233. It seems that the case_split change makes "time travelling triggers" more likely: #3362 And, although the arith_solver change sped up verification of some programs, it seems that it slowed down more programs. I'd still like to leave the version detection logic in, though, since the language server uses it, and since I think other parts of the CLI will likely use it soon. By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
Fixes #2370
Enables a fix for #1477
Interacts with #1914 (which may already be fixed)
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.