Packages and their dependencies change over time
If A and B require different versions of C it might not be possible to use A and B together
Need a systematic way to find globally-consistent sets of packages
[%g semantic_versioning “Semantic versioning” %] uses three
integers X.Y.Z
X is the major version (breaking changes)
Y is the minor version (new features)
Z is the [%g patch “patch” %] (bug fixes)
Notation
>=1.2.3 means “any version from 1.2.3
onward”
<4 means “any version before 4.anything”
1.0-3.1 means “any version in the specified
range”
[%inc triple.json %]
Imagine a multi-dimensional grid with one axis per package
Possible combinations are points in this grid
[% figure slug=“pack-allowable” img=“allowable.svg” alt=“Allowable versions” caption=“Finding allowable combinations of package versions.” %]
Our example has 3×3×2=18 combinations
Adding one more package with two versions doubles the [%g search_space “search space” %]
A [%g combinatorial_explosion “combinatorial explosion” %]
Brute force solutions are impractical even for small problems
But worth implementing as a starting point and for testing
Generate all possible combinations of package versions
Then eliminate ones that aren’t compatible with the manifest
[%inc exhaustive.py mark=main %]
Create a list of the available versions of each package
Generate their [%g cross_product “cross product” %]
[%inc exhaustive.py mark=possible %]
[% figure slug=“pack-product” img=“product.svg” alt=“Generating a cross-product” caption=“Generating all possible combinations of items.” %]
Compare every entry X against every other entry Y
If they are the same package, keep looking
If package X’s requirements say nothing about package Y, keep searching
If X does depend on Y but this particular version of X doesn’t list this particular version of Y as a dependency, rule out this combination
If combination is still a candidate, add to list
[%inc exhaustive.py mark=compatible %]
[%inc exhaustive.out %]
[%inc manual.py mark=start %]
Create a list of lists of available versions
Create an empty accumulator
Do some magic
Each call to _make_possible handles one package’s
worth of work
Loop over available versions of current package
Add that package to the combination in progress
If more packages, recurse
Otherwise, append to accumulator
[%inc manual.py mark=make %]
Generate-and-discard is inefficient
Stop immediately if a partial combination of packages is illegal
[%inc incremental.py mark=main %]
reverse to allow experimentation[%inc incremental.py mark=find %]
The manifest that tells us what’s compatible with what.
The names of the packages we’ve haven’t considered yet.
An accumulator to hold all the valid combinations we’ve found so far.
The partially-completed combination we’re going to extend next.
A count of the number of combinations we’ve considered so far, which we will use as a measure of efficiency.
[%inc incremental.sh %] [%inc incremental.out %]
[%inc incremental_reverse.sh %] [%inc incremental_reverse.out %]
An automated theorem prover can do much better
Prove that a set of logical propositions (e.g., dependencies) are satisfiable
We will use the [Z3 theorem prover][z3]
[%inc z3_equal.py mark=setup %]
A, B, and C don’t have
values
Instead, each represents the set of possible Boolean values
A == B[%inc z3_equal.py mark=solve %]
[%inc z3_equal.out %]
A to equal B and B to
equal C but A and C to be
unequal[%inc z3_unequal.py mark=solve %] [%inc z3_unequal.out %]
[%inc z3_triple.py mark=setup %]
A[%inc z3_triple.py mark=top %]
A are mutually exclusive[%inc z3_triple.py mark=exclusive %]
B and C[%inc z3_triple.py mark=depends %] [%inc z3_triple.out %]
[% figure slug=“pack-concept-map” img=“concept_map.svg” alt=“Concept map for package manager.” caption=“Concept map.” %]