Skip to content

Packages, lockfiles, and versions

A package is a directory with a qvr.toml manifest. It provides the modules whose paths start with its name, depends on other packages from directories, git repositories, or a package index, and is built from a lockfile that pins every module of the build by content hash. Its version is computed from how its interface changed, and a breaking change ships a dependency lens that migrates its dependents and their stored runs. The rules are in the semantics of packages; the Python interface is quivers.packages.

The manifest

[package]
name = "discourse"
version = "1.2.0"
modules = ["discourse.score", "discourse.sigs"]
source = "src"

[holes]
Worlds = { default = "worlds.boolean" }

[links]
Lexicon = "lexicon.core"

[dependencies]
worlds = { version = "1.0.0", index = "main" }
lexicon = { git = "https://example.org/lexicon.git", rev = "v2.0.0" }
grammar = { path = "../grammar" }

[indexes]
main = "https://example.org/qvr-index.git"
Key Meaning
package.name a lowercase identifier, the first segment of every module path the package provides
package.version MAJOR.MINOR.PATCH
package.modules the modules other packages may import; every other module of the package is private to it
package.source the directory below the package that module paths are relative to (. by default)
holes the package's holes, each with the module that fills it when no link does
links links this package's builds use, overriding every default
dependencies each dependency, from a path, a git repository at rev (a commit, a tag, or a branch), or an indexed version
indexes the package indexes indexed dependencies are looked up in

A module of the package discourse is discourse or discourse.*, found below source: discourse.score is src/discourse/score.qvr. An unknown key, a mistyped value, a module outside the namespace, a dependency that names two sources, and a version range are refused, each naming the key:

qvr.toml: dependencies.worlds: '>=1.0.0' is a version range; a dependency names the minimum
version it was built against (e.g. 1.2.0), and any later version on that compatibility line
satisfies it

Versions and compatibility

Two versions are compatible when they share a compatibility line, the components up to the leftmost nonzero one: 1.4.2 is on line 1.x, 0.3.7 on 0.3.x, and 0.0.4 only on itself. An indexed dependency names the version it was built against, and any later version on that line satisfies it.

The standard library

The package std ships with quivers, and every package depends on it without naming it. Its modules (std.semiring, ...) are found from any entry point, with or without a manifest; its version is the release of quivers it ships with. Naming std as a dependency is refused.

Resolution and the lockfile

qvr lock resolves the manifest, checks every module of every package, and writes qvr.lock beside the manifest:

$ qvr lock
locked discourse 0.3.0 (https://example.org/discourse.git at 3f0c1d9e2a7b), 2 modules
locked worlds 1.0.0 (https://example.org/qvr-index.git), 1 module
wrote /work/experiments/qvr.lock

Resolution is minimal version selection (Cox, 2018): it visits every version any requirement names, with that version's own requirements, and selects for each package the largest version any visited requirement names. It never moves to a newer version on its own, needs no search, and gives the same build from the same manifest and index anywhere. A package from a directory or a git commit is pinned: its version is its manifest's, every requirement on it must name the same source, and every indexed requirement on it must be satisfied by that version.

Requirements no single version satisfies are refused with a derivation in the style of PubGrub (The Dart team, 2018), from the two conflicting requirements up to the root:

Because alpha 1.0.0 depends on core 1.x from 1.2.0
  and beta 3.0.0 depends on core 2.x from 2.0.0,
  alpha 1.0.0 is incompatible with beta 3.0.0 (no version of core is on both 1.x and 2.x).
And because app depends on alpha 1.x from 1.0.0, app is incompatible with beta 3.0.0.
So, because app depends on beta 3.x from 3.0.0, version solving failed.

The same form explains a version the index does not list, a pinned version older than a requirement, and one package required from two sources.

The lockfile records the root's dependencies, the commit of each index read, and for every other package its version, its source (a directory relative to the root, a repository and commit with the revision that named it, an index, or builtin), its dependencies, and, per module it provides, two hashes:

[[package]]
name = "worlds"
version = "1.0.0"
source = "index"
location = "https://example.org/qvr-index.git"
commit = "9d2c4f0a7e5b13c86f2a0d1e4b7c9a3f5e8d2b6c"
dependencies = ["std"]

[[package.module]]
path = "worlds.boolean"
core = "1f9e..."
interface = "51c0..."

core hashes the module's checked declarations, which renaming, reformatting, and comments leave unchanged; interface is the digest of its public interface. Nothing about the machine (cache locations, absolute paths, times) enters the file. The standard library is recorded by its version alone.

Building

qvr build resolves the manifest against the lockfile (the index and git commits it records, so a build whose commits are cached needs no network), refuses a lockfile the manifest has moved away from, recomputes every pinned module's hashes and refuses any that differ, and checks every module of the package:

qvr: error[package-pin-mismatch]: qvr.lock pins core hash 1f9e0c3a4b6d8e2f for module
worlds.boolean of worlds 1.0.0 (path ../worlds), but its source has 7a2b...: the content changed
under a pinned source
qvr: error[package-lock-stale]: the lockfile does not match the manifest: discourse is new to the
build; run `qvr lock` to resolve again

Within a package, qvr check, qvr run, qvr doc, and qvr transpile read a module of the package (a file in its namespace, or a module path) in the package's build: the lockfile's, or the one its manifest resolves to when it has none.

A build enforces the package boundary at every import, naming the import:

Code Refuses
package-module-private importing a module a dependency does not expose
package-not-a-dependency importing a module of a package one's own package does not depend on
package-hole-unlisted a hole a package's modules declare that its [holes] does not list
package-hole-unknown a hole [holes] lists that no module declares
package-link-conflict two packages giving one hole different defaults, unless the root links it

A package with holes checks without a filling, against the holes' signatures. A build links each hole some module imports: by the root's [links] and link statements first, else by the default of the package that lists it.

Package indexes

An index is a git repository of package metadata; no service is needed. Each published version is one file, <name>/<version>.toml:

[package]
name = "worlds"
version = "1.0.0"
git = "https://example.org/worlds.git"
commit = "3f0c1d9e2a7b5c4d6e8f0a1b2c3d4e5f6a7b8c9d"

[dependencies]
logic = "1.0.0"

[[module]]
path = "worlds.boolean"
core = "1f9e..."
interface = "51c0..."

qvr publish INDEX --git URL --rev REV reads the package at a commit of its repository (so what is published is what dependents fetch), checks and pins its exposed modules, compares its interface with the newest version the index lists and refuses a version that understates the change, refuses a version already listed, and commits the entry in INDEX, a working tree of the index; pushing it is left to the publisher. A published package depends only on packages of its own index. A build refuses an indexed version whose modules do not hash to what its entry publishes.

Versions from interface diffs

qvr bump --against REF checks the package and the previous version (REF is a directory or a git revision of the repository holding the package, such as the tag v1.2.0), compares their interfaces symbol by symbol, and prints every change with the version it requires (Lam et al., 2020):

$ qvr bump --against v1.0.0
major  lib.model.model.prior: the site:sample was renamed to lib.model.model.center; dependents migrate along the lens
lib: a major change from 1.0.0; the next version is 2.0.0

The interface of a package version lists every exported declaration, constructor, sample site of an exported program, and data parameter. Each change is classified:

Change Level
an export or a sample site removed or renamed major
a computation's type, a family's shape, a site's support, an effect row, or a data parameter's index type changed major
a symbol's kind changed major
an observed site or a data parameter added (dependents must supply data) major
an export added, or a sample site added (it has a default, its prior) minor
the body of an exported program fit to data changed (its fits change meaning) minor
a body changed under an unchanged interface patch

Types are compared modulo renaming: references to other declarations are their content hashes, so renaming a family changes the family's path but not the type of any computation over it. A rename is recognized by identity: the new interface keeps the symbol's content hash (for a site, its identity) under a new path.

The leftmost nonzero component is the one a breaking change moves: on 1.x a major change bumps the major version, a minor change the minor one, and a patch the patch; on 0.3.x a breaking change bumps to 0.4.0 and any other change bumps the patch. --to VERSION, or a manifest whose version already differs from the previous one, is checked, and a version that understates the change is refused with every change it understates:

qvr: lib 1.1.0 understates the change from 1.0.0: it is a major change, so the version must be at least 2.0.0:
  major  lib.model.model.prior: the site:sample was renamed to lib.model.model.center; dependents migrate along the lens

--write writes the required version into qvr.toml when it still has the previous one, and --json prints the changes as data. A major change writes its dependency lens to lenses/<name>-<old>-to-<new>.json in the package, which qvr migrate --dependency reads from the new version's source.

Migrating dependents

qvr migrate --dependency worlds@1.0.0..2.0.0 [RECORDS...] moves the package's modules, and the run records given, from the locked version of a dependency to the version its manifest now resolves to. Edit the manifest (the rev, the version, or the path) and run it before qvr lock:

$ qvr migrate --dependency worlds@1.0.0..2.0.0 runs/fit.json
migrated experiments/pick.qvr
migrated experiments/tally.qvr
migrated runs/fit.json
run `qvr lock` to pin worlds 2.0.0

Every name that resolves to a renamed symbol is respelled, in imports, selection lists, qualified references, and patterns; a run record's site table and site values are rewritten to the new program's sites, matched by identity. A place that names a symbol the new version removed has no lens and is listed with its location, and its file is left unchanged:

experiments/pick.qvr:1:40: unmigratable: worlds.boolean.weight: worlds.boolean.weight was removed from worlds in 3.0.0 and has no replacement

The migration guide describes the procedure in full: migrating dependents of a package.

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.