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

Add --solver-option flag and move others around #3943

Merged
merged 20 commits into from
May 8, 2023

Conversation

atomb
Copy link
Member

@atomb atomb commented May 2, 2023

Adds a --solver-option flag to correspond to the old (Boogie) /proverOpt flag. In the process, this also refactors a few things:

  • Rearranges some of the option code to move some Boogie-related options from CommonOptionBag to BoogieOptionBag.
  • Makes --solver-option, --solver-path, --solver-plugin, --solver-log, and --resource-limit available to the generate-tests and find-dead-code commands.

Includes some refactoring to DafnyTestGenerator, thanks to @Dargones, to make it easier to support arbitrary options there.

Addresses #3468 but doesn't entirely resolve it.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@atomb atomb marked this pull request as ready for review May 2, 2023 23:33
@atomb atomb marked this pull request as draft May 3, 2023 17:46
@Dargones
Copy link
Collaborator

Dargones commented May 4, 2023

Thank you, @atomb! I have made a PR to this PR's branch that should make --solver-option, --solver-path, --solver-log, and --resource-limit work with test generation (I also did some refactoring that should hopefully make addition of new options easier in the future).

Re: --boogie and --solver-plugin options - would you have any pointer on how to copy these from one DafnyOptions instance to another?

@atomb
Copy link
Member Author

atomb commented May 4, 2023

Thank you, @atomb! I have made a PR to this PR's branch that should make --solver-option, --solver-path, --solver-log, and --resource-limit work with test generation (I also did some refactoring that should hopefully make addition of new options easier in the future).

Thanks!

Re: --boogie and --solver-plugin options - would you have any pointer on how to copy these from one DafnyOptions instance to another?

I think, for --solver-plugin, it should be sufficient to copy the ProverDllName and TheProverFactory fields. I think it should be safe for multiple threads to share a reference to the same factory, since we're already doing that when solving multiple goals in parallel during normal Dafny verification.

As for --boogie, it may be more trouble than it's worth. I considered adding that as a catch-all for any Boogie option that I didn't think to add, but I don't specifically know that it's needed.

@atomb atomb marked this pull request as ready for review May 4, 2023 23:08
@@ -10,9 +10,16 @@ namespace Microsoft.Dafny;
public class GenerateTestsCommand : ICommandSpec {
public IEnumerable<Option> Options =>
new Option[] {
// IMPORTANT: Before adding new options, make sure they are
Copy link
Member

@keyboardDrummer keyboardDrummer May 5, 2023

Choose a reason for hiding this comment

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

This seems frail. Why not make the code more robust instead of adding this comment? Why doesn't CopyForProcedure use the DafnyOptions clone constructor?

Copy link
Collaborator

@Dargones Dargones May 5, 2023

Choose a reason for hiding this comment

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

Merging this one line PR to Boogie would allow using the DafnyOption's clone constructor and indeed make the code more robust.

The problem is that the ProcsToCheck field of DafnyOptions (inherited from Boogie's CommadLineOptions) does not have a setter. The clone constructor copies the field anyway using reflection but ProcsToCheck is a list, so the constructor copies the reference and one cannot modify the 'copied' list without modifying the original. The best solution would be to add a setter, like I do in the PR to Boogie above.

@@ -8,9 +8,15 @@ namespace Microsoft.Dafny;
public class DeadCodeCommand : ICommandSpec {
public IEnumerable<Option> Options =>
new Option[] {
// IMPORTANT: Before adding new options, make sure they are
Copy link
Member

Choose a reason for hiding this comment

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

This seems frail. Why not make the code more robust instead of adding this comment? Why doesn't CopyForProcedure use the DafnyOptions clone constructor?

@@ -21,6 +27,8 @@ public class DeadCodeCommand : ICommandSpec {
}

public void PostProcess(DafnyOptions dafnyOptions, Options options, InvocationContext context) {
// IMPORTANT: Before adding new default options, make sure they are
Copy link
Member

Choose a reason for hiding this comment

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

This seems frail. Why not make the code more robust instead of adding this comment? Why doesn't CopyForProcedure use the DafnyOptions clone constructor?

"Can be used to specify a custom SMT solver to use for verifying Dafny proofs.") {
};
public static readonly Option<IList<string>> SolverOption = new("--solver-option",
"Specify an option to control how the solver works.") {
Copy link
Member

Choose a reason for hiding this comment

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

This line doesn't tell me how to use this. Could you mention that these arguments are passed directly to the solver CLI; that the default solver is Z3 with a link to its CLI documentation; and that Dafny is already configuring some options, so not all of options might be usable.

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 added a --solver-option-help flag that describes what all the options are, and expanded the help text for --solver-option.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks


public static readonly Option<bool> IsolateAssertions = new("--isolate-assertions", @"Verify each assertion in isolation.");

public static readonly Option<FileInfo> SolverPath = new("--solver-path",
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 set SolverPath, SolverOption and SolverPlugin (which I still think should be named BoogiePlugin) to hidden, since using them requires looking up additional documentation outside of Dafny. If there are particular Z3 options that we think users are likely to get a benefit front, I suggest we expose them as first class Dafny options.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, my goal with #3938 is to expose more control over the verification process in a friendly way. But this allows expert users to get that control immediately, if they know they could benefit from it. And it allows us to conveniently experiment with various options to help decide which might be worth exposing in a nicer way.

I agree that SolverOption should be hidden, and I've made it that way. I'm less convinced about the two Path options, which I think will be used more frequently.

As far as the name of SolverPlugin, Boogie plugins can only control how it interfaces with the solver. It doesn't provide any mechanism for them to do anything else. So I still prefer --solver-plugin.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks

atomb added 2 commits May 5, 2023 08:49
The line breaks in the previous version were preserved in the output,
leading to awkwardly-displayed text.
This explains the valid arguments to `--solver-option`.
@keyboardDrummer keyboardDrummer enabled auto-merge (squash) May 8, 2023 08:55
@keyboardDrummer keyboardDrummer merged commit e48820a into dafny-lang:master May 8, 2023
@atomb atomb self-assigned this Aug 28, 2023
@atomb atomb deleted the more-solver-options branch January 4, 2024 17:07
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.

3 participants