-
Notifications
You must be signed in to change notification settings - Fork 271
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
Use CanCall everywhere #5654
Merged
RustanLeino
merged 229 commits into
dafny-lang:master
from
RustanLeino:can-call-everywhere
Jan 3, 2025
Merged
Use CanCall everywhere #5654
RustanLeino
merged 229 commits into
dafny-lang:master
from
RustanLeino:can-call-everywhere
Jan 3, 2025
Conversation
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
# Conflicts: # Source/Dafny/Verifier/Translator.cs # Source/DafnyCore/Verifier/BoogieGenerator.TrStatement.cs # Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/FunctionSpecifications.dfy # Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-370.dfy # Test/dafny0/FunctionSpecifications.dfy.expect # Test/git-issues/git-issue-370.dfy.expect
dafny4/Fstar-QuickSort.dfy
Fixes comp/Comprehensions.dfy
…dafny into can-call-everywhere
# Conflicts: # Source/DafnyCore/AST/Expressions/Expression.cs # Source/DafnyCore/Verifier/BoogieGenerator.Decreases.cs # Source/DafnyCore/Verifier/BoogieGenerator.ExpressionTranslator.cs # Source/DafnyCore/Verifier/BoogieGenerator.ExpressionWellformed.cs # Source/DafnyCore/Verifier/BoogieGenerator.Fields.cs # Source/DafnyCore/Verifier/BoogieGenerator.Functions.Wellformedness.cs # Source/DafnyCore/Verifier/BoogieGenerator.Functions.cs # Source/DafnyCore/Verifier/BoogieGenerator.Iterators.cs # Source/DafnyCore/Verifier/BoogieGenerator.LetExpr.cs # Source/DafnyCore/Verifier/BoogieGenerator.Methods.cs # Source/DafnyCore/Verifier/BoogieGenerator.Types.cs # Source/DafnyCore/Verifier/Statements/BoogieGenerator.TrForallStmt.cs # Source/DafnyCore/Verifier/Statements/BoogieGenerator.TrLoop.cs # Source/DafnyCore/Verifier/Statements/BoogieGenerator.TrStatement.cs # Source/IntegrationTests/TestFiles/LitTests/LitTest/HigherOrderIntrinsicSpecification/ReadPreconditionBypass4.dfy.expect
typerSniper
approved these changes
Jan 3, 2025
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.
looks good to go! there were a couple of minor things that I fixed and committed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
run-integration-tests
Forces running the CI for integration tests even if the deep tests fail
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.
Description
This PR changes the axiomatization of functions to uniformly rely on "
CanCall
certificates". Not only does this simplify the logical encoding, but it also enables further improvements to the encoding of functions, which will appear in separate PRs.The essence of CanCall
Consider a function
The fact that this function yields a value that's twice its argument is captured by the function's definition axiom. To a first order of approximation, the definition axiom is
Prior to each use of the function, the verifier generates a proof obligation that checks the arguments to have the appropriate types and the preconditions to be met. For example, an assignment
z := F(y);
is (to a first order of approximation) translated into Boogie asTo reason about the value assigned to
z
, the verifier uses the definition axiom. To obtain the factz == 2 * y
, the verifier first needs to discharge the axiom's antecedent. This may seem redundant, since the assertion before the use ofF
makes sure that the antecedent holds, but it required for soundness (as demonstrated by replacing the body ofF
byif x == 157 then 1 + F(x) else 2 * x
). The cost of this redundancy is often neglible, but if the function's precondition uses disjunctions and quantifiers, then there is extra effort involved in discharging the antecedent, even after proving the assertion.To remove the cost of the redundancy and to clean up what is generated, this PR makes use of a so-called
CanCall
function, which acts as a "certificate" that says "the function's precondition has been validated for the arguments ...". This changes the definition axiom toand changes the translation of the assignment above to
(
CanCall
antecedents are used not only in definition axioms, but also in other axioms generated from a function: consequence axioms, override axioms.)CanCall's before this PR
Dafny introduced
CanCall
s a long time ago (perhaps 10 years ago?). However, previously,CanCall
s were only a possible shortcut to discharging the antecedent. Specifically, the definition axiom had (to a first order of approximation) the formWhile this gives the verifier the opportunity to use the
CanCall
, it still pollutes the axiom with the function's type constraints and precondition.In fact, the axiom was even slightly more complicated, namely
for some numeric constant
K
determined from the given program. The antecedentK <= $FunctionContextHeight
remains even after this PR, but it will soon be removed in a separate PR.To rely solely on
CanCall
, the verifier needed to be changed to emit theCanCall
assumptions everywhere. The work to emit theseCanCall
assumptions everywhere was started by @typerSniper in 2021. We picked this up again in the last year and have now completed the task.Other changes
The PR also contains some other improvements and bug fixes:
$OneHeap
) in places where the heap argument is not used (for example, in aseq
constructor that's given a total function).Co-authored-by: Jatin Arora [email protected]
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.