Repository navigation
Suggest result checks and argument conditions in state hints - #474
Open
CatarinaGamboa wants to merge 1 commit into
Open
CatarinaGamboa wants to merge 1 commit into
CatarinaGamboa wants to merge 1 commit into
Conversation
Methods whose state refinements mention their parameters or result were left out of the state machine, so the hints could not suggest checking canRedo() before redo(), or calling setCompressionMode(int) with mode == 2. They are now kept as call variants: with any arguments, with arguments meeting each condition the refinement tests, and, for a boolean result, with the result checked. Boolean methods whose return refinement relates the result to the state are kept as checks too. The solver works out what a variant does only when a hint needs it. A check is suggested only if the verifier allows it in every state the receiver can be in, its result can have the value checked, and the failing call is then allowed; if several checks would do, none is suggested. An argument condition is suggested only if every argument meeting it leads to a state that allows the call, and the value shown for an earlier call's argument is now checked the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
[Codex review] The parameterized guard hint is not a usable Java edit: the new test expects |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #454, fixes #455, fixes #473.
What changes
The state machine behind the state hints used to drop every method whose state refinements mention a parameter or the result. That meant
canRedo()could never be suggested beforeredo(), andsetCompressionMode(int)withmode == 2could never be suggested beforesetCompressionType. Those methods are now kept as call variants:mode == 2,lo < hi, its negationlimit <= 0)_/!_)tomentions the resultBoolean methods without a state refinement whose return refinement relates the result to the state, such as
@Refinement("_ == true --> hasMore(this)") boolean hasNext(), are kept as guards too.What a variant does is worked out by the solver only when a hint needs it, and then cached. Building the machine costs the same as on main.
When a hint is given
fromholds in all of them. The result must be able to have the value checked, and the failing call must then be allowed in every state that is left. It is shown when the state is unknown or was checked without being decided. In a known state, it is shown only if no call sequence exists or the state depends on the path taken. If several checks would do, none is shown, because the refinements can't tell them apart (e.g. a coarse UndoManager spec wherecanUndo,canRedoandcanUndoOrRedoall imply the same state).Hints
A1_56 (study spec, three state sets):
After guarding
redo(), theundo()call gets "Guard this call with if (undoManager.canUndo()): when it returns true, undoManager is undoable", and with both guards the program verifies.A1_01:
Negated guard: "Guard this call with if (!c.isClosed()): when it returns false, c is open".
#454 can close fully. Part (a) (name only the needed state, don't suggest
undo()) was done in #458, and part (b) (suggestcanRedo()) is done here.Tests
ErrorStateHintGuards(11 cases: negated guard, guard with a parameter, known state, and 8 cases that must get no guard, including several checks proving the same thing)ErrorStateHintArgumentConditions(7 cases, including the State hint "with mode == N" uses one example value without checking it always works #473 example)CorrectStateHintGuards(the hints applied: it verifies)state_hint_compression_mode_error(A1_01)state_hint_study_undo_manager_error/_correct(A1_56 with the study's spec, unchanged)TestStateHintsasserts every hint text.StateMachineTestcovers how refinements are chosen for a set of states.Performance
For the study's 12-state UndoManager (
state_hint_study_undo_manager_error):The extra cost is the guard check in an unknown state, paid once per class per run. To keep it down, the possible states are narrowed one state set at a time, and a check of the result reuses the states found for any result.
🤖 Generated with Claude Code