Skip to content
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

Feat code actions forall calc #6044

Merged
merged 14 commits into from
Jan 24, 2025
Merged

Conversation

MikaelMayer
Copy link
Member

@MikaelMayer MikaelMayer commented Jan 11, 2025

What was changed?

First, for implicit assertions, if they are surrounded by a declaration that supports by clause (like AssertStmt or CallStmt), the by clause is preferred to inserting the assertion before.
InsertVarByStatement
And that works also for well-formedness, since well-formedness is now proved by by-blocks (thanks @keyboardDrummer for that, and @alex-chew for creating Dafny expressions for well-formedness)
InsertAssertByPreconditionStatement
Moreover, if a by clause already exist, the code action will insert into it.
InsertAssertExistingByPreconditionStatement

Second, assertion of foralls now support a proof sketch by inserting forall statement
InsertForallStatement

Third, assertions of equalities or equivalence now support a proof sketch by inserting a calc statement.
InsertCalcStatement
InsertCalcEquivStatement

The code for inserting such proof sketches has been refactored so that it will be even more easy to extend in the future.

How has this been tested?

  • Tests were updated for the insertion point (var....by) when possible and insert there if it already exist.
  • Tests were added for foralls, equalities and equivalences, and also new insertion points

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@MikaelMayer MikaelMayer enabled auto-merge (squash) January 15, 2025 17:25
Copy link
Member

@keyboardDrummer keyboardDrummer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool features!

return new DafnyCodeActionEdit[] { };
}

if (insertionNode is AssertStmt or VarDeclStmt or CallStmt && insertionNode.EndToken is { val: ";" } endToken) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract the condition to a variable to make it easier to read what it does

indentation2 + GetStatementToInsert(indentation2) + "\n" +
indentation + "}";
return ReplaceWith(endToken, block);
} else if (insertionNode is AssertStmt or VarDeclStmt or CallStmt && insertionNode.OwnedTokens.FirstOrDefault(t => t.val == "by") is { Next: { val: "{" } braceToken } byToken) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract the condition to a variable to make it easier to read what it checks

private readonly Expression failingImplicitAssertion;
private readonly Node program;
private readonly Range selection;
public static INode? GetInsertionNode(Node program, Range selection, out List<INode>? nodesSinceFailure, out bool needsIsolation) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is an insertion node? Can you use a longer name to explain what this is?

What is nodesSinceFailure?

Can you move GetInsertionNode to after the method that calls is?

@MikaelMayer MikaelMayer merged commit 867e0e2 into master Jan 24, 2025
22 checks passed
@MikaelMayer MikaelMayer deleted the feat-code-actions-forall-calc branch January 24, 2025 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants