-
Notifications
You must be signed in to change notification settings - Fork 260
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
Proof dependency warnings #4542
Merged
robin-aws
merged 56 commits into
dafny-lang:master
from
atomb:proof-dependency-warnings
Sep 16, 2023
Merged
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
9ed559a
Basic implementation of proof dependency analysis
atomb b52bec3
Merge branch 'master' into verification-coverage-ids
jtristan 088eca9
Rename utility methods
atomb adbe5bc
Basic tracking of assignments
atomb d260984
Track a few more proof dependencies
atomb d6f9eea
Fix customBoogie.patch
atomb 8bb2303
Fix unit test for slightly different message
atomb 671b7f6
Revert message change for preconditions
atomb 9ab8bfd
Better dependency messages, assignment tracking
atomb 2b8d580
Order text logger output by source location
atomb ac55f3f
Add test for proof dependency logging
atomb d40f73a
Adjust test output to account for changes
atomb 595bded
Silence warning
atomb 2804ef9
Remove obsolete statement
atomb 698b067
Sort proof dependencies in text logger
atomb 6803cad
Fix some expected test outputs
atomb 8e098f9
Merge remote-tracking branch 'upstream/master' into verification-cove…
atomb 80d174a
Move ProofDependencyManager to its own file
atomb 5c6deff
Clean up ProofDependency
atomb 6a671dd
Fix duplicate IDs in Boogie code
atomb 3e4a91b
Fix NPE in test generation code
atomb ea859c5
Merge remote-tracking branch 'upstream/master' into verification-cove…
atomb 50ee917
Merge remote-tracking branch 'upstream/master' into verification-cove…
atomb 9e2ad02
Fix expected test output
atomb 9133cf7
Various small cleanups
atomb 2dc0052
Merge remote-tracking branch 'upstream/master' into verification-cove…
atomb 04fca88
Use structured dependency labels from Boogie
atomb 3c9b47d
Merge remote-tracking branch 'upstream/master' into verification-cove…
atomb 813b190
Limit proof dependency analysis to one core
atomb 5e75656
Fix customBoogie.patch
atomb 1f9f243
Bump Boogie dependency
atomb c2a7c60
Merge remote-tracking branch 'upstream/master' into verification-cove…
atomb 9e4bd05
Bump Boogie version in dotnet-tools.json, too
atomb 1ced519
Warn about vacuous proofs and unused assumptions
atomb 97f0fc2
Most basic in-IDE reporting of proof dependencies
atomb 0fd5060
Refactor to work with Boogie 3.0.2+
atomb 1989ec8
Display vacuity and redundancy warnings in the IDE
atomb 68ae66d
Don't subtract 1 from columns
atomb 9765ae8
Filter out some vacuity warnings
atomb a1bfbf1
Fix typo in description
atomb 300c2ff
Merge remote-tracking branch 'upstream/master' into lsp-proof-coverage
atomb b98b14c
WIP
atomb 7772a21
Remove IDE changes from this branch
atomb 965b3fd
Add test for proof dependency warnings
atomb 0eec7b4
Fix setting of TrackVerificationCoverage option
atomb 570f1a6
Fix typos in .expect files
atomb 32146b1
Fix test to account for :id attributes
atomb 9bc6021
Merge remote-tracking branch 'upstream/master' into proof-dependency-…
atomb cfcf464
Address review comments
atomb 4b88f75
Merge branch 'master' into proof-dependency-warnings
atomb 5b9fda2
Add release notes entry
atomb cfa6cd1
Update docs/dev/news/4542.feat
atomb b82a523
Update release notes and hide options
atomb 1cdd1a0
Add disclaimers to option descriptions
robin-aws f6958b5
Merge branch 'master' into proof-dependency-warnings
robin-aws faa1ffa
Merge branch 'master' into proof-dependency-warnings
robin-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Linq; | ||
using DafnyCore.Verifier; | ||
using Microsoft.Dafny.ProofObligationDescription; | ||
|
||
namespace Microsoft.Dafny; | ||
|
||
public class ProofDependencyWarnings { | ||
public static void WarnAboutSuspiciousDependencies(DafnyOptions dafnyOptions, ErrorReporter reporter, ProofDependencyManager depManager) { | ||
var verificationResults = (dafnyOptions.Printer as DafnyConsolePrinter).VerificationResults.ToList(); | ||
var orderedResults = | ||
verificationResults.OrderBy(vr => | ||
(vr.Implementation.Tok.filename, vr.Implementation.Tok.line, vr.Implementation.Tok.col)); | ||
foreach (var (implementation, result) in orderedResults) { | ||
WarnAboutSuspiciousDependenciesForImplementation(dafnyOptions, reporter, depManager, implementation, result); | ||
} | ||
} | ||
|
||
public static void WarnAboutSuspiciousDependenciesForImplementation(DafnyOptions dafnyOptions, ErrorReporter reporter, ProofDependencyManager depManager, DafnyConsolePrinter.ImplementationLogEntry logEntry, DafnyConsolePrinter.VerificationResultLogEntry result) { | ||
var potentialDependencies = depManager.GetPotentialDependenciesForDefinition(logEntry.Name); | ||
var usedDependencies = | ||
result | ||
.VCResults | ||
.SelectMany(vcResult => vcResult.CoveredElements.Select(depManager.GetFullIdDependency)) | ||
.OrderBy(dep => (dep.RangeString(), dep.Description)); | ||
var unusedDependencies = | ||
potentialDependencies | ||
.Except(usedDependencies) | ||
.OrderBy(dep => (dep.RangeString(), dep.Description)); | ||
|
||
var unusedObligations = unusedDependencies.OfType<ProofObligationDependency>(); | ||
var unusedRequires = unusedDependencies.OfType<RequiresDependency>(); | ||
var unusedEnsures = unusedDependencies.OfType<EnsuresDependency>(); | ||
var unusedAssumeStatements = | ||
unusedDependencies | ||
.OfType<AssumptionDependency>() | ||
.Where(d => d is AssumptionDependency ad && ad.IsAssumeStatement); | ||
if (dafnyOptions.Get(CommonOptionBag.WarnContradictoryAssumptions)) { | ||
foreach (var dep in unusedObligations) { | ||
if (ShouldWarnVacuous(logEntry.Name, dep)) { | ||
reporter.Warning(MessageSource.Verifier, "", dep.Range, $"proved using contradictory assumptions: {dep.Description}"); | ||
} | ||
} | ||
|
||
foreach (var dep in unusedEnsures) { | ||
if (ShouldWarnVacuous(logEntry.Name, dep)) { | ||
reporter.Warning(MessageSource.Verifier, "", dep.Range, $"ensures clause proved using contradictory assumptions"); | ||
} | ||
} | ||
} | ||
|
||
if (dafnyOptions.Get(CommonOptionBag.WarnRedundantAssumptions)) { | ||
foreach (var dep in unusedRequires) { | ||
reporter.Warning(MessageSource.Verifier, "", dep.Range, $"unnecessary requires clause"); | ||
} | ||
|
||
foreach (var dep in unusedAssumeStatements) { | ||
reporter.Warning(MessageSource.Verifier, "", dep.Range, $"unnecessary assumption"); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Some proof obligations that don't show up in the dependency list | ||
/// are innocuous. Either they come about because of internal Dafny | ||
/// design choices that the programmer has no control over, or they | ||
/// just aren't meaningful in context. This method identifies cases | ||
/// where it doesn't make sense to issue a warning. Many of these | ||
/// cases should perhaps be eliminated by changing the translator | ||
/// to not generate vacuous proof goals, but that may be a difficult | ||
/// change to make. | ||
/// </summary> | ||
/// <param name="dep">the dependency to examine</param> | ||
/// <returns>false to skip warning about the absence of this | ||
/// dependency, true otherwise</returns> | ||
private static bool ShouldWarnVacuous(string verboseName, ProofDependency dep) { | ||
if (dep is ProofObligationDependency poDep) { | ||
// Dafny generates some assertions about definite assignment whose | ||
// proofs are always vacuous. Since these aren't written by Dafny | ||
// programmers, it's safe to just skip them all. | ||
if (poDep.ProofObligation is DefiniteAssignment) { | ||
return false; | ||
} | ||
|
||
// Similarly here | ||
if (poDep.ProofObligation is MatchIsComplete or AlternativeIsComplete) { | ||
return false; | ||
} | ||
|
||
} | ||
|
||
// Ensures clauses are often proven vacuously during well-formedness checks. | ||
if (verboseName.Contains("well-formedness") && dep is EnsuresDependency) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ah there's the "potential" word I was looking for :)