-
Notifications
You must be signed in to change notification settings - Fork 269
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
Chore: Not generate boogie translation if not verifying #6067
Changes from 1 commit
3dbf68f
865aa96
2e5d2c8
61a457f
54e6ec2
9cf72a0
4f2b8e1
29394cf
6512bc3
4d5a51b
025e739
9946191
68b9ab0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.CommandLine; | ||
using System.CommandLine.Builder; | ||
using System.CommandLine.Invocation; | ||
using System.CommandLine.Parsing; | ||
using System.Diagnostics; | ||
using System.IO.Pipelines; | ||
using System.Reactive.Concurrency; | ||
using System.Reflection; | ||
using System.Text; | ||
using Microsoft.Dafny; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using OmniSharp.Extensions.JsonRpc; | ||
using OmniSharp.Extensions.JsonRpc.Client; | ||
using OmniSharp.Extensions.JsonRpc.Serialization; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
using XunitAssertMessages; | ||
using Command = System.CommandLine.Command; | ||
|
||
namespace DafnyDriver.Test; | ||
|
||
|
||
public class OptionsTest { | ||
[Fact] | ||
public async Task RunFlagsOverride() { | ||
await TestCliRunArgs([], options => { | ||
Assert.True(options.DafnyVerify); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of tests for values in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implementation details can still be tested by unit tests, and this is the meaning of that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But why test like this? You could also test without looking at internals. For example, by using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not know about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Concretely, I plan on removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The two commands output exactly the same thing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, If |
||
Assert.True(options.Verify); | ||
return 0; | ||
}); | ||
await TestCliRunArgs(["--no-verify"], options => { | ||
Assert.False(options.DafnyVerify); | ||
Assert.False(options.Verify); | ||
return 0; | ||
}); | ||
await TestCliRunArgs(["--no-verify", "--do-boogie-translation"], options => { | ||
Assert.True(options.DafnyVerify); | ||
Assert.False(options.Verify); | ||
return 0; | ||
}); | ||
await TestCliRunArgs(["--no-verify", "--bprint=-"], options => { | ||
Assert.True(options.DafnyVerify); | ||
Assert.False(options.Verify); | ||
return 0; | ||
}); | ||
} | ||
|
||
private static async Task TestCliRunArgs(string[] cmdArgs, Func<DafnyOptions, int> optionsCallback) { | ||
var fullArgs = new string[] { | ||
"run" | ||
}; | ||
fullArgs = fullArgs.Concat(cmdArgs).Concat(new string[] { "file.dfy" }).ToArray(); | ||
var callbackCalled = false; | ||
var newOptionsCallback = (DafnyOptions options) => { | ||
callbackCalled = true; | ||
return optionsCallback(options); | ||
}; | ||
Command cmd = RunCommand.Create(newOptionsCallback); | ||
var rootCommand = new RootCommand("Test root command"); | ||
rootCommand.AddCommand(cmd); | ||
var builder = new CommandLineBuilder(rootCommand).UseDefaults(); | ||
var parser = builder.Build(); | ||
TextReader inputReader = new StringReader(""); | ||
var outputWriter = new StringWriter(); | ||
var errorWriter = new StringWriter(); | ||
var console = new WritersConsole(inputReader, outputWriter, errorWriter); | ||
var exitCode = await DafnyNewCli.ExecuteForParser(console, fullArgs, parser); | ||
Assert.Equal<object>("", errorWriter.ToString()); | ||
Assert.Equal(0, exitCode); | ||
Assert.True(callbackCalled); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ static RunCommand() { | |
Concat(DafnyCommands.ConsoleOutputOptions). | ||
Concat(DafnyCommands.ResolverOptions); | ||
|
||
public static Command Create() { | ||
public static Command Create(Func<DafnyOptions, int> continuation = null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's to be able to create a Run command but with a continuation different than the one that launches the regular pipeline, to be able to test the parsing of options only. If you have any other way I could achieve the same result, I'd happily consider it. |
||
var result = new Command("run", "Run the program."); | ||
result.AddArgument(DafnyCommands.FileArgument); | ||
result.AddArgument(UserProgramArguments); | ||
|
@@ -63,7 +63,9 @@ public static Command Create() { | |
options.Compile = true; | ||
options.RunAfterCompile = true; | ||
options.ForceCompile = options.Get(BoogieOptionBag.NoVerify); | ||
|
||
if (continuation != null) { | ||
return continuation(options); | ||
} | ||
return await SynchronousCliCompilation.Run(options); | ||
}); | ||
return result; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2294,6 +2294,8 @@ and what information it produces about the verification process. | |
|
||
* `--no-verify` - turns off verification (for translate, build, run commands) | ||
|
||
* `--do-boogie-translation` - turns on translation to Boogie after resolving or if `--no-verify` is set. Automatically set if `--bprint` is set. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outdated, please remove |
||
|
||
* `--verify-included-files` (was `-verifyAllModules`) - verify modules that come from include directives. | ||
|
||
By default, Dafny only verifies files explicitly listed on the command | ||
|
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.
It seems strange to have an option that can only be used if another option is also used. Why not have the first option imply the second then? Instead of
--do-boogie-translation
why not have--no-verify-boogie
that tells Dafny to translate to Boogie but not verify it.That way, whenever the user would type
--no-verify --do-boogie-translation
they only have to type--no-verify-boogie
.Secondly, I would make this option hidden since it only seems useful for the purpose of debugging the Dafny verification pipeline.
Thirdly, why are you adding this option? Is someone missing this? An alternative would be to let
--no-verify --bprint ...
cause Dafny to translate to Boogie but not verify that Boogie, and--no-verify
to not translate to Boogie at all.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.
Let's do the simple way. Since we already have --bprint, we can use it as the flag to do boogie translation, period. I like that idea.
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.
Same for
--sprint
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.
And
--pprint
as well. Added