r/ProgrammingLanguages • u/edgmnt_net • Feb 01 '26
Discussion On tracking dependency versions
Hopefully this isn't too offtopic, but I want to express some thoughts on dependencies and see what people think.
For context, there are two extremes when it comes to declaring dependency versions. One is C, where plenty of stuff just tests dependencies, say via autotools, and versions are considered very loosely. The other is modern ecosystems where numbers get pinned exactly.
When it comes to versions, I think there are two distinct concerns:
- What can we work with?
- What should we use for this specific build?
That being said, there's value in both declaring version ranges (easy upgrades, fixing security issues, solving version conflicts) and pinning exact versions (reproducible builds, testing, preventing old commits from becoming unbuildable, supply chain security). So package management / build systems should do both.
SemVer implicitly solves the first concern, but incompletely since you have no way to specify "this should work with 4.6.x and 4.7.x". Secondly, while pinning is great for some purposes, you still want an easy unobtrusive way to bump all version numbers to the latest compatible version out there according to stated constraints. However, the tricky part is getting assurance with respect to transitive dependencies, because not everything is under your control. C-based FOSS sort of defers all that to distrbutions, although they do release source and likely test based on specific combinations. More modern ecosystems that end up pinning things strictly largely end up in a similar spot, although you may get version conflicts and arguably it's easier to fall into the trap of making it too hard / unreliable to upgrade (because "that's not the blessed version").
What do you think is the best way to balance these concerns and what should tooling do? I think we should be able to declare both ranges and specific versions. Both should be committed to repos in at least some way, because you need to be able to get back to old versions (e.g. bisection). But possibly not in a way that requires a lot of commits which are just for bumping versions trivially, although even here there are security concerns related to staleness. So what's a good compromise here? Do we need separate ranges for more riskier (minor version) / less riskier (security release) upgrades? Should you run release procedures (e.g. tests) for dependencies that get rebuilt with different transitive versions; i.e. not just your tests? Should all builds of your software try the latest (security) version first, then somehow allow regressing to the declared pin in case the former doesn't work?
View all comments
Show parent comment
3
u/WittyStick Feb 02 '26 edited Feb 02 '26
Content-addressing is nice and I like the approach Unison takes, but IMO it is not a complete solution to the problem.
To give an example, lets say we have some function
fooin libraryLibFoo. FunctionbarinLibBarmakes a call tofoo, andbazinLibBazalso makes a call tofoo. Our program depends onLibBarandLibBaz, and some functionquxcalls bothbarandbazand obviously wants them to share the samefooimplementation as it may share data structures.However, unless we're doing whole program compilation, our
barcould pin a different version offooto the onebazdoes. We would have two, potentially incompatible definitions offooin our resulting program.With content addressing, the identities of
barandbazare Merkle roots, withfooas a leaf. In our project,quxis the Merkle root andbarandbazare its leaves.quxdoesn't referencefoodirectly, only indirectly via the content-addresses ofbarandbaz, so this doesn't ensure they're compatible.What we need is a way to pin a specific version of
fooin addition to the specific versions ofbarandbazwhich share the samefooas a dependency.quxshould not only use the content-addresses ofbarandbaz, but also some additional information which states that they have compatiblefoo.To do this we need to kind of invert the dependencies. We need a
foowhich is context-aware - a foo that knows it is shared betweenbarandbaz. I call this a context-address, and it basically works by forming a Merkle tree of compatiblebarandbazcontent-addresses as the Merkle leaves, to produce a context-address forfoowhich is the Merkle root.quxthen only needs to depend on the context-address offoo, which transitively has dependencies on the content-addresses of compatible versions ofbarandbaz, and its own definition.Context-addressing is expensive though - perhaps too expensive to be practical. We have to recompute the whole tree whenever anything changes. With content-addressing, we don't have to recompute the addresses of the dependencies if those dependencies have not changed, only the dependants. Context-addressing requires that we first have all the content addresses of the Merkle roots in our codebase, then we use those roots as the leaves for the context-address tree.
To give a more concrete visualization of what I mean by context-addressing: Lowercase letters are content-addresses and uppercase letters are context-addresses. The context-address tree is basically a mirror-image of the content-address tree.
If we want to depend on
b, its content-address doesn't take into account that it is used within a bigger context wherea,c,d, andeare also used, which isf/F. The context-addressBon the other hand, captures the entire context in which it is used.