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

state-machine: don't limit number of transitions that can be deleted in shrinking #392

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions proptest-state-machine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

### Bug Fixes

- Removed the limit of number of transitions that can be deleted in shrinking that depended on the number the of transitions given to `prop_state_machine!` or `ReferenceStateMachine::sequential_strategy`.
- Fixed logging of state machine transitions to be enabled when verbose config is >= 1. The "std" feature is added to proptest-state-machine as a default feature that allows to switch the logging off in non-std env.
48 changes: 20 additions & 28 deletions proptest-state-machine/src/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub trait ReferenceStateMachine {
/// `Shrink::DeleteTransition` and `Shrink::Transition`.
///
/// 1. We start by trying to delete transitions from the back of the list, until
/// we can do so no further (the list has reached the `min_size`).
/// we can do so no further (reached the beginning of the list).
/// We start from the back, because it's less likely to affect the state
/// machine's pre-conditions, if any.
/// 2. Then, we again iteratively attempt to shrink the individual transitions,
Expand Down Expand Up @@ -209,7 +209,6 @@ impl<
acceptable_transitions,
included_transitions,
shrinkable_transitions,
min_size,
max_ix,
// On a failure, we start by shrinking transitions from the back
// which is less likely to invalidate pre-conditions
Expand Down Expand Up @@ -271,8 +270,6 @@ pub struct SequentialValueTree<
included_transitions: VarBitSet,
/// The bit-set of transitions that can be shrunk further
shrinkable_transitions: VarBitSet,
/// The minimum number of `transitions`
min_size: usize,
/// The maximum index in the `transitions` vector (its size - 1)
max_ix: usize,
/// The next shrink operation to apply
Expand All @@ -293,32 +290,27 @@ impl<
/// applied.
fn try_simplify(&mut self) -> bool {
if let DeleteTransition(ix) = self.shrink {
if self.included_transitions.count() == self.min_size {
// Can't delete any more transitions, move on to shrinking them
self.shrink = Transition(0);
} else {
// Delete the index from the included transitions
self.included_transitions.clear(ix);
// Delete the index from the included transitions
self.included_transitions.clear(ix);

self.last_shrink = Some(self.shrink);
self.shrink = if ix == 0 {
// Reached the beginning of the list, move on to shrinking
Transition(0)
} else {
// Try to delete the previous transition next
DeleteTransition(ix - 1)
};
// If this delete is not acceptable, undo it and try again
if !self.check_acceptable(None) {
self.included_transitions.set(ix);
self.last_shrink = None;
return self.try_simplify();
}
// If the delete was accepted, remove this index from shrinkable
// transitions
self.shrinkable_transitions.clear(ix);
return true;
self.last_shrink = Some(self.shrink);
self.shrink = if ix == 0 {
// Reached the beginning of the list, move on to shrinking
Transition(0)
} else {
// Try to delete the previous transition next
DeleteTransition(ix - 1)
};
// If this delete is not acceptable, undo it and try again
if !self.check_acceptable(None) {
self.included_transitions.set(ix);
self.last_shrink = None;
return self.try_simplify();
}
// If the delete was accepted, remove this index from shrinkable
// transitions
self.shrinkable_transitions.clear(ix);
return true;
}

while let Transition(ix) = self.shrink {
Expand Down
Loading