Closed edsko closed 5 years ago
This is technically a breaking change, as it changes some exposed functions and types, but I think the impact should be minimal, as those types/functions are in what's effectively q-s-m's internal API.
Re-pushed with signoff
.
Thanks for the quick response! By the way, heads up: I am planning to write a blog post soon about the effective use of q-s-m. If you like I can send you a link to a draft if you want to proofread it before publishing. Don't at all feel obliged though :)
@edsko: I'd be happy to!
Awesome :) Would you be able to fire off a quick email to edsko@well-typed.com so that I have your email address and I can email you a link to the draft before publishing?
Done!
Consider shrinking a set of commands such as
Shrinking is basically a call to QuickCheck's
shrinkList
followed by a validation step, the core of which is implemented invalidCommands
.validCommands
executes each command, checking preconditions, and checking which variables are in scope, and (effectively) renaming variables. For example, given the shrink candidatevalidCommands
will reexecutecmd2
, find all is well, constructHowever, when it then gets to
cmd3
, it finds thatVar 1
is not in scope, and regard the shrink candidate as invalid. This however is not correct:cmd3
refers to the result ofcmd2
, which is still in the shrunk program! Conversely, if the original program wasinstead, with
cmd3
referring to the output of the first command, then the same shrink candidateshould now be rejected (after all,
cmd3
refers to the output ofcmd1
, which has been deleted), but instead may not be, and result in the "validated" programwhere
cmd3
suddenly referse tocmd2
instead.Instead of merely keeping track of the scope, therefore, we need to keep track of this remapping of variables, constructing the validated program
for the first example, and rejecting the second example.
This is implemented in this patch. The essence of the patch is the logic in
go
invalidCommands
. It has a few small knock-on effect:cmd
to beRank2.Traversable
rather than merelyRank2.Foldable
Command
is not correct.validCommands
now uses aMap
rather than aSet
, which requires a few trivial updates to other functions that are defined in terms ofvalidCommands
.