-
Notifications
You must be signed in to change notification settings - Fork 269
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
Conversation
# Conflicts: # Source/DafnyLanguageServer/Language/ImplicitFailingAssertionCodeActionProvider.cs
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.
Really cool features!
return new DafnyCodeActionEdit[] { }; | ||
} | ||
|
||
if (insertionNode is AssertStmt or VarDeclStmt or CallStmt && insertionNode.EndToken is { val: ";" } endToken) { |
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.
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) { |
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.
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) { |
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.
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?
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](https://private-user-images.githubusercontent.com/3601079/402182613-add8e4c4-f4e1-4818-9374-0c69dd10e387.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyODA3NjksIm5iZiI6MTczOTI4MDQ2OSwicGF0aCI6Ii8zNjAxMDc5LzQwMjE4MjYxMy1hZGQ4ZTRjNC1mNGUxLTQ4MTgtOTM3NC0wYzY5ZGQxMGUzODcuZ2lmP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMTMyNzQ5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MmM3NzcxNzgxNmM3MjJhNjczNTQzOWNjMjAyOTA2NmYxNjI1YTk2N2M1MzA2ZDRmZmNjOTdjYjY4OTdmMDhkMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.lv7XMXkj8E1by3N1wVav9vapB3k-3w90h_DSm_ZKodA)
![InsertAssertByPreconditionStatement](https://private-user-images.githubusercontent.com/3601079/402184316-7b4fe592-abf6-4b31-9ee3-3cfc75749284.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyODA3NjksIm5iZiI6MTczOTI4MDQ2OSwicGF0aCI6Ii8zNjAxMDc5LzQwMjE4NDMxNi03YjRmZTU5Mi1hYmY2LTRiMzEtOWVlMy0zY2ZjNzU3NDkyODQuZ2lmP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMTMyNzQ5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjRhZjU5NTRiOWUxNDEyZWIyYmE3ZGYzNjgyZWYxNTViNDBmNjY5MWE1OTZlYWQyNDkzNDI1NjdjNDRjOTFiOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.T1xwKoqh36THvNjiLptXgficx9g71XOcynfRdRuB0pA)
![InsertAssertExistingByPreconditionStatement](https://private-user-images.githubusercontent.com/3601079/402196885-bce3c787-1655-410d-9dc6-52fe924a976c.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyODA3NjksIm5iZiI6MTczOTI4MDQ2OSwicGF0aCI6Ii8zNjAxMDc5LzQwMjE5Njg4NS1iY2UzYzc4Ny0xNjU1LTQxMGQtOWRjNi01MmZlOTI0YTk3NmMuZ2lmP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMTMyNzQ5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjZkM2E3NTg2ZjdhN2FiY2E0OTZjNmFkZGZhMjRhOTI5YzQwMDA2YTRmMTFlYWZlOTI3YmNjMGZmOTRkZjdjNSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.ITMKnJhqwF_WhywtSqG4pafYoYd1EeTFd0mTbYk6RVI)
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)
Moreover, if a by clause already exist, the code action will insert into it.
Second, assertion of foralls now support a proof sketch by inserting forall statement
![InsertForallStatement](https://private-user-images.githubusercontent.com/3601079/402182183-c411570d-8f33-463f-ab7a-af093a594a31.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyODA3NjksIm5iZiI6MTczOTI4MDQ2OSwicGF0aCI6Ii8zNjAxMDc5LzQwMjE4MjE4My1jNDExNTcwZC04ZjMzLTQ2M2YtYWI3YS1hZjA5M2E1OTRhMzEuZ2lmP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMTMyNzQ5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ODQ4NzY1M2E3YTBhMDc4MmU3ZTkzNTI1ODY5MzQyODE5YTZiOGU2YmJkOWIzN2Y4M2QxNzU0YWI3Y2U4MzQzOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.i1N8KHyV-LWb_hH2XMgaBLbwt4QK3p6qBGHQ0B8Xd20)
Third, assertions of equalities or equivalence now support a proof sketch by inserting a calc statement.
![InsertCalcStatement](https://private-user-images.githubusercontent.com/3601079/402182408-fb76312a-51b5-4325-a0cd-457ef5dc444e.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJj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1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMTMyNzQ5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9N2MyZDQ1ZThhMzBkZjAyZGEwN2YzMzZlOGVmODBiNmExMzBiZThhOTI5ZTlmNDAxZmE1NjkyZWM1ZWQ2ZGQ0NiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.W2pXtBVruQk8f4YKY_P1GQ7tx-j5ObAxwWGoM0iS-Fk)
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?
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.