[darcs-devel] hunk moves as a new kind of prim patch

Ben Franksen ben.franksen at online.de
Sat Feb 24 19:17:23 UTC 2018


I have started to implement hunk moves, in particular I have worked out
a number of commutation rules, implemented them, and am now in the
process of debugging them with the (invaluable) help of the existing
unit tests.

Getting the commutation rules right is harder than I thought!

After tracking down and fixing a stupid mistake I made when writing the
hunk move test case generator, I found I had made numerous errors in my
commutation rules. I have disabled most of them (defaulting for
commutation to fail) and re-enable them now bit by bit, running tests,
fixing the code, etc.

This is all pretty fascinating and I am having lots of fun.

There is also some fallout in the form of refactorings that I will send
as patch bundles. For instance, I have spent almost two full days
working through the Prim V1 hunk application code, which seemed quite a
lot more convoluted to me than the apparently simple task required. But
when I thought I had understood it and started refactoring I found that
some of the complication is in fact justified, because this is one of
the (few) places where darcs' internal model of file content ("a list of
lines") collides with reality (the last line may not be terminated with
a newline).

The way darcs resolves this conflict is bizarr: when you add a line that
is not newline-terminated to an empty file, darcs creates a hunk that
first removes an empty line, before adding the new content. WTH? How can
you remove something from an empty file? Yet the code works and after a
while I found a suitable mental model that explains all the stangeness.
I added a somewhat longer comment to explain this model and also every
non-obvious detail in the code.

I have also improved the error messages for some of the failing
properties to make it easier to see what exactly fails.

BTW, the Show instances for all the Patch types are completely useless
in practice. It would be more helpful to have them default to something
like displayPatch, especially when showing failing test cases.

Cheers
Ben



More information about the darcs-devel mailing list