Skip to content

Commit 01c924a

Browse files
Add the --solver-path option (#3184)
### Changes Add the `--solver-path` option to allow customising the SMT solver used when using the new Dafny CLI. ### Testing Option is used in a new littish test. <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
1 parent b7125bf commit 01c924a

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

Source/DafnyCore/Options/CommonOptionBag.cs

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ Note that quantifier variable domains (<- <Domain>) are available in both syntax
110110
false - The char type represents any UTF-16 code unit.
111111
true - The char type represents any Unicode scalar value.".TrimStart());
112112

113+
public static readonly Option<string> SolverPath = new("--solver-path",
114+
"Can be used to specify a custom SMT solver to use for verifying Dafny proofs.");
113115
public static readonly Option<bool> VerifyIncludedFiles = new("--verify-included-files",
114116
"Verify code in included files.");
115117
public static readonly Option<bool> WarningAsErrors = new("--warn-as-errors",
@@ -123,50 +125,40 @@ Note that quantifier variable domains (<- <Domain>) are available in both syntax
123125
"Include the Dafny runtime as source in the target language.");
124126

125127
static CommonOptionBag() {
128+
DafnyOptions.RegisterLegacyBinding(SolverPath, (options, value) => {
129+
if (!string.IsNullOrEmpty(value)) {
130+
options.ProverOptions.Add($"PROVER_PATH={value}");
131+
}
132+
});
133+
126134
DafnyOptions.RegisterLegacyBinding(ManualLemmaInduction, (options, value) => {
127135
if (value) {
128136
options.Induction = 1;
129137
}
130138
});
131-
DafnyOptions.RegisterLegacyBinding(IncludeRuntime, (options, value) => {
132-
options.UseRuntimeLib = !value;
133-
});
134-
DafnyOptions.RegisterLegacyBinding(WarnShadowing, (options, value) => {
135-
options.WarnShadowing = value;
136-
});
137-
DafnyOptions.RegisterLegacyBinding(WarnMissingConstructorParenthesis, (options, value) => {
138-
options.DisallowConstructorCaseWithoutParentheses = value;
139-
});
140-
DafnyOptions.RegisterLegacyBinding(WarningAsErrors, (options, value) => {
141-
options.WarningsAsErrors = value;
142-
});
143-
DafnyOptions.RegisterLegacyBinding(VerifyIncludedFiles, (options, value) => {
144-
options.VerifyAllModules = value;
145-
});
139+
DafnyOptions.RegisterLegacyBinding(IncludeRuntime, (options, value) => { options.UseRuntimeLib = !value; });
140+
DafnyOptions.RegisterLegacyBinding(WarnShadowing, (options, value) => { options.WarnShadowing = value; });
141+
DafnyOptions.RegisterLegacyBinding(WarnMissingConstructorParenthesis,
142+
(options, value) => { options.DisallowConstructorCaseWithoutParentheses = value; });
143+
DafnyOptions.RegisterLegacyBinding(WarningAsErrors, (options, value) => { options.WarningsAsErrors = value; });
144+
DafnyOptions.RegisterLegacyBinding(VerifyIncludedFiles,
145+
(options, value) => { options.VerifyAllModules = value; });
146146

147-
DafnyOptions.RegisterLegacyBinding(Target, (options, value) => {
148-
options.CompilerName = value;
149-
});
147+
DafnyOptions.RegisterLegacyBinding(Target, (options, value) => { options.CompilerName = value; });
150148

151149

152-
DafnyOptions.RegisterLegacyBinding(QuantifierSyntax, (options, value) => {
153-
options.QuantifierSyntax = value;
154-
});
150+
DafnyOptions.RegisterLegacyBinding(QuantifierSyntax, (options, value) => { options.QuantifierSyntax = value; });
155151

156-
DafnyOptions.RegisterLegacyBinding(Plugin, (options, value) => {
157-
options.AdditionalPluginArguments = value;
158-
});
152+
DafnyOptions.RegisterLegacyBinding(Plugin, (options, value) => { options.AdditionalPluginArguments = value; });
159153

160154
DafnyOptions.RegisterLegacyBinding(Prelude, (options, value) => {
161155
options.DafnyPrelude = value;
162-
options.ExpandFilename(options.DafnyPrelude, x => options.DafnyPrelude = x, options.LogPrefix, options.FileTimestamp);
163-
});
164-
DafnyOptions.RegisterLegacyBinding(Libraries, (options, value) => {
165-
options.LibraryFiles = value.ToHashSet();
166-
});
167-
DafnyOptions.RegisterLegacyBinding(Output, (options, value) => {
168-
options.DafnyPrintCompiledFile = value;
156+
options.ExpandFilename(options.DafnyPrelude, x => options.DafnyPrelude = x, options.LogPrefix,
157+
options.FileTimestamp);
169158
});
159+
DafnyOptions.RegisterLegacyBinding(Libraries,
160+
(options, value) => { options.LibraryFiles = value.ToHashSet(); });
161+
DafnyOptions.RegisterLegacyBinding(Output, (options, value) => { options.DafnyPrintCompiledFile = value; });
170162

171163
DafnyOptions.RegisterLegacyBinding(CompileVerbose, (o, v) => o.CompileVerbose = v);
172164
DafnyOptions.RegisterLegacyBinding(DisableNonLinearArithmetic, (o, v) => o.DisableNLarith = v);
@@ -177,12 +169,13 @@ static CommonOptionBag() {
177169
RelaxDefiniteAssignment.AddValidator(optionResult => {
178170
var enforceDeterminismResult = optionResult.FindResultFor(EnforceDeterminism);
179171
if (enforceDeterminismResult is not null && enforceDeterminismResult.GetValueOrDefault<bool>()) {
180-
optionResult.ErrorMessage = $"The option {RelaxDefiniteAssignment.Name} can not be used in conjunction with {EnforceDeterminism.Name}.";
172+
optionResult.ErrorMessage =
173+
$"The option {RelaxDefiniteAssignment.Name} can not be used in conjunction with {EnforceDeterminism.Name}.";
181174
}
182175
});
183-
DafnyOptions.RegisterLegacyBinding(RelaxDefiniteAssignment, (options, value) => {
184-
options.DefiniteAssignmentLevel = value ? 1 : 2;
185-
});
176+
DafnyOptions.RegisterLegacyBinding(RelaxDefiniteAssignment,
177+
(options, value) => { options.DefiniteAssignmentLevel = value ? 1 : 2; });
186178

187179
}
188180
}
181+

Source/DafnyCore/Options/ICommandSpec.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static ICommandSpec() {
2929
public static IReadOnlyList<Option> VerificationOptions = new Option[] {
3030
BoogieOptionBag.VerificationTimeLimit,
3131
CommonOptionBag.VerifyIncludedFiles,
32-
CommonOptionBag.ManualLemmaInduction
32+
CommonOptionBag.ManualLemmaInduction,
33+
CommonOptionBag.SolverPath,
3334
}.ToList();
3435

3536
public static IReadOnlyList<Option> ExecutionOptions = new Option[] {

Test/cli/proverPath.dfy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %baredafny verify %args --solver-path="%z3" "%s" > "%t"
2+
// RUN: %diff "%s.expect" "%t"
3+
// UNSUPPORTED: windows
4+
method m() {
5+
assert 1 + 1 == 2;
6+
}

Test/cli/proverPath.dfy.expect

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Dafny program verifier finished with 1 verified, 0 errors

0 commit comments

Comments
 (0)