Skip to content
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

Merged
merged 14 commits into from
Jan 9, 2023
Merged

Improve Z3 detection #3233

merged 14 commits into from
Jan 9, 2023

Conversation

atomb
Copy link
Member

@atomb atomb commented Dec 20, 2022

  • Be more explicit about the path of the executable to invoke.
  • Identify the version and set different Z3 options accordingly.

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.

* 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)
@atomb atomb marked this pull request as ready for review January 6, 2023 21:02
@atomb atomb enabled auto-merge (squash) January 6, 2023 22:22
Copy link
Member

@MikaelMayer MikaelMayer left a 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!


var z3binName = isUnix ? "z3" : "z3.exe";
var platform = System.Environment.OSVersion.Platform;
var isUnix = platform == PlatformID.Unix || platform == PlatformID.MacOSX || (int)platform == 128;
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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");
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

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 "=".

Copy link
Member Author

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.

@@ -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.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Member Author

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.

@atomb atomb requested a review from MikaelMayer January 9, 2023 22:44
@atomb atomb merged commit 1ad148e into dafny-lang:master Jan 9, 2023
atomb added a commit to atomb/dafny that referenced this pull request Jan 10, 2023
* 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.
davidcok pushed a commit to davidcok/dafny that referenced this pull request Jan 20, 2023
* 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.
atomb added a commit to atomb/dafny that referenced this pull request Jan 20, 2023
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.
atomb added a commit that referenced this pull request Jan 24, 2023
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.
@atomb atomb deleted the z3-path-version branch January 4, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If Z3 can't be run, Dafny sometimes hangs instead of reporting an error
2 participants