From 1be23887353ae0771bd0bb287097b5a78e655952 Mon Sep 17 00:00:00 2001 From: Aleksandr Fedchin Date: Thu, 16 Nov 2023 04:30:18 -0800 Subject: [PATCH 01/13] Counterexample parity for extension vs command line --- Source/DafnyCore/DafnyConsolePrinter.cs | 5 ++- Source/DafnyCore/DafnyOptions.cs | 13 ++++-- Source/DafnyCore/Options/CommonOptionBag.cs | 15 ++++++- Source/DafnyCore/Options/DafnyCommands.cs | 3 +- Source/DafnyDriver/CompilerDriver.cs | 40 +++++++++++-------- Source/DafnyLanguageServer/LanguageServer.cs | 7 ---- .../ProgramModification.cs | 19 --------- .../server/counterexample_commandline.dfy | 2 +- .../counterexample_commandline.dfy.expect | 21 +--------- 9 files changed, 53 insertions(+), 72 deletions(-) diff --git a/Source/DafnyCore/DafnyConsolePrinter.cs b/Source/DafnyCore/DafnyConsolePrinter.cs index 87744bb3028..64da91b90a6 100644 --- a/Source/DafnyCore/DafnyConsolePrinter.cs +++ b/Source/DafnyCore/DafnyConsolePrinter.cs @@ -35,13 +35,14 @@ public record VerificationResultLogEntry( ConditionGeneration.Outcome Outcome, TimeSpan RunTime, int ResourceCount, - List VCResults); + List VCResults, + List Counterexamples); public record ConsoleLogEntry(ImplementationLogEntry Implementation, VerificationResultLogEntry Result); public static VerificationResultLogEntry DistillVerificationResult(VerificationResult verificationResult) { return new VerificationResultLogEntry( verificationResult.Outcome, verificationResult.End - verificationResult.Start, - verificationResult.ResourceCount, verificationResult.VCResults.Select(DistillVCResult).ToList()); + verificationResult.ResourceCount, verificationResult.VCResults.Select(DistillVCResult).ToList(), verificationResult.Errors); } private static VCResultLogEntry DistillVCResult(VCResult r) { diff --git a/Source/DafnyCore/DafnyOptions.cs b/Source/DafnyCore/DafnyOptions.cs index 9e273019b37..49d0d04205b 100644 --- a/Source/DafnyCore/DafnyOptions.cs +++ b/Source/DafnyCore/DafnyOptions.cs @@ -729,6 +729,7 @@ public enum IncludesModes { case "extractCounterexample": ExtractCounterexample = true; + EnhancedErrorMessages = 1; return true; case "verificationLogger": @@ -1148,6 +1149,13 @@ public enum IncludesModes { SetZ3Option("type_check", "true"); SetZ3Option("smt.qi.eager_threshold", "100"); // TODO: try lowering SetZ3Option("smt.delay_units", "true"); + SetZ3Option("model_evaluator.completion", "true"); + SetZ3Option("model.completion", "true"); + if (z3Version is null || z3Version < new Version(4, 8, 6)) { + SetZ3Option("model_compress", "false"); + } else { + SetZ3Option("model.compact", "false"); + } // This option helps avoid "time travelling triggers". // See: https://github.com/dafny-lang/dafny/discussions/3362 @@ -1419,10 +1427,7 @@ the program. /extractCounterexample If verification fails, report a detailed counterexample for the - first failing assertion. Requires specifying the /mv: option as well - as /proverOpt:O:model_compress=false (for z3 version < 4.8.7) or - /proverOpt:O:model.compact=false (for z3 version >= 4.8.7), and - /proverOpt:O:model.completion=true. + first failing assertion (experimental). ---- Compilation options --------------------------------------------------- diff --git a/Source/DafnyCore/Options/CommonOptionBag.cs b/Source/DafnyCore/Options/CommonOptionBag.cs index 3f23b1a1dc5..2428d5dbe3e 100644 --- a/Source/DafnyCore/Options/CommonOptionBag.cs +++ b/Source/DafnyCore/Options/CommonOptionBag.cs @@ -291,6 +291,11 @@ public enum DefaultFunctionOpacityOptions { Not compatible with the --unicode-char:false option. "); + public static readonly Option ExtractCounterexample = new("--extract-counterexample", () => false, + @" +If verification fails, report a detailed counterexample for the first failing assertion (experimental).".TrimStart()) { + }; + static CommonOptionBag() { DafnyOptions.RegisterLegacyUi(Target, DafnyOptions.ParseString, "Compilation options", "compileTarget", @" cs (default) - Compile to .NET via C#. @@ -475,6 +480,11 @@ public enum DefaultFunctionOpacityOptions { } }); + DafnyOptions.RegisterLegacyBinding(ExtractCounterexample, (options, value) => { + options.ExtractCounterexample = value; + options.EnhancedErrorMessages = 1; + }); + DooFile.RegisterLibraryChecks( new Dictionary() { { UnicodeCharacters, DooFile.CheckOptionMatches }, @@ -522,8 +532,9 @@ public enum DefaultFunctionOpacityOptions { OptimizeErasableDatatypeWrapper, AddCompileSuffix, SystemModule, - ExecutionCoverageReport - ); + ExecutionCoverageReport, + ExtractCounterexample + ); } public static readonly Option FormatPrint = new("--print", diff --git a/Source/DafnyCore/Options/DafnyCommands.cs b/Source/DafnyCore/Options/DafnyCommands.cs index 28edb04304f..865537e26e2 100644 --- a/Source/DafnyCore/Options/DafnyCommands.cs +++ b/Source/DafnyCore/Options/DafnyCommands.cs @@ -43,7 +43,8 @@ public static class DafnyCommands { CommonOptionBag.WarnContradictoryAssumptions, CommonOptionBag.WarnRedundantAssumptions, CommonOptionBag.NoTimeStampForCoverageReport, - CommonOptionBag.VerificationCoverageReport + CommonOptionBag.VerificationCoverageReport, + CommonOptionBag.ExtractCounterexample }.ToList(); public static IReadOnlyList