(@goerz suggested I cross-post this here from Slack, so it can be referenced in the future)
I learned of another good reason not to commit piracy yesterday, illustrated by the following example:
Suppose we have two packages X and Y. Y depends on X, and commit type-piracy wrt. to X’s types, e.g., defining (in Y):
using X
Base.isapprox(a::T, b::T) where T <: StructFromX = ...
Suppose that, one day, the author of Y realizes the shortcomings of their buccaneering ways and transfers the method to X, where it rightly belongs. A new non-breaking release of X is made with the new method, and a new release of Y is also made with the piracy removed.
All is good and piracy is in the past, right? Unfortunately, no: the new version of X – being non-breaking – is picked up by the resolver in all earlier versions of Y. This is a problem, since now both X and Y will attempt to define the same method, resulting in an error:
WARNING: Method definition isapprox(T, T) where {T <: X.StructFromX} in module X at
[…]/X/src/X.jl:[…] overwritten in module Y at
[…]/Y/src/Y.jl:[…].
ERROR: Method overwriting is not permitted during Module precompilation.
The attempted fix therefore breaks every earlier version of Y, that is compatible with the existing major version of X. It’s retroactively breaking releases of Y.
There are at least two ways to do this without breaking earlier releases:
- Release a breaking version of X. But this feels off – piracy was committed by Y, not X, so X should not pay any price to fix this.
- Retroactively compat bound Y in the General registry, capping all earlier (pirating) versions of Y to the version of X that did not define the
isapproxmethod. This should ideally then be done before the new version of X is released.
In my context, the situation was the following:
- I had at one point split out a sub-package Bravais (X) from a parent package Crystalline (Y). By some oversight, I had forgotten to transfer an
isapproxmethod definition from Crystalline to Bravais – and belatedly realized it a few days ago, years after the split. So, obviously not intentional piracy, but simply imperfectly thorough copy-pasting work; but the same result. For now, I’ve tried to fix it via path 2 above.
But I can see a tempting route to commit the same fallacy:
- I am developing both packages Y and X (Y depending on X). I realize that X really ought to have defined methods so-and-so on its types, but want the development of Y to move fast, so I just pirate-define them temporarily in Y, intending to transfer them properly to X later. If I register a version of Y with the piracy, that version will be broken if I ever do this transfer.
A final consideration is the ability of the authors of X to break Y:
- If I am the author of X but not of Y, and for whatever reason am adversarially inclined toward Y, then I can break all earlier releases of Y if it has pirated any method of X: I simply define the pirated method in X and release a non-breaking version of X.