Packages and dependency lenses¶
This page states what a package build is, what a lockfile pins, how a version is computed from an interface change, and what migrating a dependent along a dependency lens preserves. The surface is in packages, lockfiles, and versions.
Builds¶
A package is a manifest and a set of modules whose paths begin with the package's name. A requirement names a package and either a pinned source (a directory, a git commit, or the standard library) or a minimum version in an index. A build is a map from package names to package versions.
Write \(v \sqsubseteq w\) when the versions \(v\) and \(w\) share a compatibility line (the components up to the leftmost nonzero one) and \(v \le w\). An indexed requirement \((p, v)\) is satisfied by a version \(w\) of \(p\) when \(v \sqsubseteq w\).
Minimal version selection. Let \(R_0\) be the root's requirements. The visited set \(N\) is the least set of package versions such that every indexed requirement \((p, v)\) in \(R_0\) or in the requirements of a member of \(N\) puts \(p@v\) in \(N\), and every pinned requirement puts the package at its source in \(N\). The build selects, for each package \(p\) with only indexed requirements, the largest \(v\) with \(p@v \in N\) (Cox, 2018); for a pinned package, its source's version. The build is refused when, for some \(p\),
- two requirements name different pinned sources,
- two indexed requirements lie on different compatibility lines,
- a pinned version fails to satisfy an indexed requirement on it, or
- a visited version is not in its index.
Every requirement is a lower bound, so the selection is monotone: adding versions to an index never changes a build (only a new requirement can), and the selection depends on the manifests and the index content alone. A refusal is explained by the derivation PubGrub reports (The Dart team, 2018): the two requirements that no version satisfies are an incompatibility, and each requirement edge from the root down to them lifts it one step, ending at the root.
Pins¶
For a module \(m\) checked as the root of its own module graph, with the build's links,
- \(\mathrm{core}(m)\) is the digest of the multiset of \((k, h)\) over \(m\)'s own checked declarations of kind \(k\) and content hash \(h\);
- \(\mathrm{interface}(m)\) is the digest of \(m\)'s public interface (its exported names, their kinds, and their origins).
A module that needs holes no link fills is hashed by its checking program, which checks it against the holes' signatures. The lockfile records \((\mathrm{core}(m), \mathrm{interface}(m))\) for every exposed module of every dependency, and a build recomputes and compares them before checking anything else. Since \(\mathrm{core}\) is invariant under renaming, reformatting, and comments, a pin fails exactly when a declaration's meaning changes or the module's public names change. An indexed version also carries the pins its index entry publishes, and a build refuses a source that does not hash to them. The standard library ships with quivers, so its version, the quivers release, identifies it.
Interfaces and versions¶
The interface \(I\) of a package version is a finite set of symbols. Each symbol \(s\) has a path \(\pi(s)\) (how dependents spell it), a kind, an identity \(\iota(s)\), facts (type, effects, support, index), and a body hash. The identity of a declaration is its content hash, of a constructor its family's hash and its ordinal, of a site its site identity, and of a data parameter its program's hash and ordinal. Facts are digests of core forms in which references to declarations are their content hashes, so a fact is invariant under renaming any declaration.
For interfaces \(I\) and \(J\), a rename is a pair \((s, t)\) with \(s \in I\), \(t \in J\), \(\pi(s) \notin \pi(J)\), \(\pi(t) \notin \pi(I)\), the same kind, \(\iota(s) = \iota(t)\), and no other such pair sharing \(s\) or \(t\)'s identity. The renames define a partial map \(\phi : \pi(I) \rightharpoonup \pi(J)\): identity on paths present in both, the rename on renamed paths, and undefined on removed paths. A path of \(J\) outside the image of \(\phi\) is added.
Each change is classified as in the reference: a removal, a rename, a changed fact, a changed kind, and an added symbol that dependents must supply data for are major; any other added symbol, and a changed body of a program fit to data, are minor; any other changed body is a patch. The required version is the old one bumped at the largest level, and a published version below it is refused. A semantic version is then a claim about dependents that the interface diff supports (Lam et al., 2020): a patch keeps every fact and path, a minor change keeps every path and fact of the old interface, and only a major change removes or alters one.
Dependency lenses¶
A dependency lens is stated in panproto's terms, as bidirectional transformations of tree-shaped data are (Foster et al., 2007; Litt et al., 2020):
- the inventory of \(I\) is a schema with one vertex per path of \(I\) (with a vertex for the places that name it), and a dependent's usage is an instance of the inventory: each path it names, with the places it names it;
- \(\phi\) restricted to the paths it is defined on is a theory morphism between the inventories' theories;
- the residual chain \(\eta\) is the protolens chain panproto derives from the inventory of \(I\) and the inventory of \(J\) spelled in \(I\)'s paths (through \(\phi^{-1}\)): it drops exactly the removed paths and adds exactly the added ones;
- the composite of \(\eta\), lifted along \(\phi\), is applied to every dependent's usage schema at once. Getting a usage through the lens it instantiates keeps every place that names a path in the domain of \(\phi\) and puts every other place in the lens's complement.
A kept place is respelled \(\phi(\pi(s))\); a place in the complement has no lens and is reported with its location. Nothing is dropped silently: the complement is exactly the set of places naming removed symbols. A run record is migrated by the same construction over the sites of its program, with the record's site table as \(I\) and the migrated program's as \(J\).
Preservation. Let \(m\) be a dependent module that checks against \(I\) and whose usage has an empty complement, and let \(m'\) be its migration. Every name of \(m'\) that names a symbol of \(J\) resolves to \(\phi\) of the symbol it named in \(m\) (the migration checks this after rewriting and refuses a module in which a new name is captured by another declaration), and a renamed symbol keeps its content hash. Since a reference to a declaration enters a content hash as the declaration's hash, every own declaration of \(m'\) checked against \(J\) has the content hash it had in \(m\) checked against \(I\): a dependency lens changes spellings, never meaning, and the migrated programs give the same results.
Cited sources¶
Russ Cox. Minimal Version Selection. Go & Versioning, Part 4, 2018. URL: https://research.swtch.com/vgo-mvs.
The Dart team. PubGrub: Next-Generation Version Solving. Design document of the Dart package manager's version solver, 2018. URL: https://github.com/dart-lang/pub/blob/master/doc/solver.md.
Patrick Lam, Jens Dietrich, and David J. Pearce. Putting the Semantics into Semantic Versioning. In Proceedings of the 2020 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software, 157–179. 2020. doi:10.1145/3426428.3426922.
J. Nathan Foster, Michael B. Greenwald, Jonathan T. Moore, Benjamin C. Pierce, and Alan Schmitt. Combinators for Bidirectional Tree Transformations: A Linguistic Approach to the View-Update Problem. ACM Transactions on Programming Languages and Systems, 29(3):17, 2007. doi:10.1145/1232420.1232424.
Geoffrey Litt, Peter van Hardenberg, and Orion Henry. Project Cambria: Translate Your Data with Lenses. Ink & Switch, 2020. URL: https://www.inkandswitch.com/cambria/.