| @@ -0,0 +1,129 @@ |
| 1 | +# ADR 0088: Versioned git dependencies — minimum version selection (revises ADR 0020) |
| 2 | + |
| 3 | +**Status:** Proposed (2026-11-17, issue #475); needs engineering review (#44). |
| 4 | + |
| 5 | +## Context |
| 6 | + |
| 7 | +- The packages in `packages/` are released by the compiler's tags. Every app pins each package to the same `vX` tag (`{ git = ".../louise.git", tag = "v0.21.0", subdir = "packages/web" }`), so taking one package fix moves every package, and the compiler, in every app. Issue #475 moves the packages to a repository of their own (`louise-lang/packages`), each with its own releases. |
| 8 | +- Per-package tags alone do not help, because of how ADR 0020 (and its Revision 1) identifies packages. In a build, a git package is (URL, directory, **commit of the whole repository**), and the build holds one commit per package. Say an app takes `json` at a newer tag and keeps `web` at an older one. `web` reaches `form` through `path = "../form"` at *web's* commit, while the app's own `form` is at another, so the build stops ("conflicting versions of `form`"), even if `form` only gained a compatible fix. That is the "update everything" problem again. |
| 9 | +- ADR 0020 rejected picking a version on a conflict because "git references carry no version order, so there is no 'newest compatible' to pick", and because choosing would depend on traversal order (:108, :149). It listed "version requirements and unification (semver)" under *Not in v1* (:136). |
| 10 | +- Module names are global (`json`, `json/...`), so a build can still hold only one version of each package. That part of ADR 0020 stands. |
| 11 | +- `[package] louise = ">= x.y.z"` (issue #296) already names compiler versions with a single comparison (`version.rs`). |
| 12 | + |
| 13 | +## Decision |
| 14 | + |
| 15 | +**Each package declares its version, each dependency names the versions it accepts, and the build picks, per package, the highest minimum anyone asked for. If that version is outside what some package of the build accepts, the build stops and names both chains.** This is minimal version selection, as Go modules do it, with requirement syntax from Hex (Gleam, Elixir). |
| 16 | + |
| 17 | +### Versions and tags |
| 18 | +- **`[package] version = "0.21.0"`**: `MAJOR.MINOR.PATCH`, with no `v` and no pre-release suffix. Older compilers ignore it, since `[package]` accepts unknown keys. |
| 19 | +- **A release is an annotated tag named after the package's directory in its repository:** `<subdir>-v<version>`, e.g. `json-v0.21.0` for `subdir = "json"`, and `tools/gen-v1.0.0` for `tools/gen`. A package at the top of its repository uses `v<version>`. The prefix comes from the directory, not from the package's name: a dependency's name need not be its `[package] name`, and the directory is what a dependency names. |
| 20 | +- **A tag must hold the version it names.** If tag `form-v0.21.1` holds a `louise.toml` whose `version` is `0.21.0`, then using that tag is an error. |
| 21 | + |
| 22 | +### Requirements |
| 23 | +A dependency names a `version`, from git or by path: |
| 24 | + |
| 25 | +```toml |
| 26 | +[dependencies] |
| 27 | +json = { git = "https://toboggan.cloud/louise-lang/packages.git", subdir = "json", version = "~> 0.21.0" } |
| 28 | +web = { git = "https://toboggan.cloud/louise-lang/packages.git", subdir = "web", version = ">= 0.21.0 and < 0.23.0" } |
| 29 | +form = { path = "../form", version = "~> 0.21.1" } |
| 30 | +``` |
| 31 | + |
| 32 | +| Requirement | Means | |
| 33 | +|---|---| |
| 34 | +| `~> 0.21.1` | `>= 0.21.1 and < 0.22.0` | |
| 35 | +| `~> 1.2` | `>= 1.2.0 and < 2.0.0` | |
| 36 | +| `~> 1.2.3` | `>= 1.2.3 and < 1.3.0` | |
| 37 | +| `0.21.0`, `= 0.21.0`, `== 0.21.0` | exactly `0.21.0` | |
| 38 | +| `>= A and < B` | clauses joined by `and`, each one of `>=`, `<=`, `<`, `=`/`==` and a version | |
| 39 | + |
| 40 | +- **Every requirement has a minimum:** a `>=`, a `~>` or an exact version. `< 2.0.0` alone is refused, and so is `>` (write `>=`). |
| 41 | +- **Refused:** `or`, a range that no version satisfies, and a leading `v`. |
| 42 | +- **`~> 0.Y` (two parts) is refused while the major version is 0.** It would accept `0.Y+1`, and in 0.x a minor release may break. The error suggests `~> 0.Y.0`. |
| 43 | +- **`version` goes with `path`, or with `git` (and `subdir`)**, never with `tag`, `branch` or `rev`. Those stay, as exact pins. |
| 44 | +- **`[package] louise` keeps its own one-comparison syntax.** It names compilers, not packages. |
| 45 | + |
| 46 | +### The kinds of dependency |
| 47 | +- **Versioned:** `git` with `version`, or a `path` with `version` inside a package that came from git. The package is (URL, directory). For a path inside a git checkout, the directory is the parent's joined with the path, normalised without leaving the repository. When `web` comes from git, its `form = { path = "../form", version = "~> 0.21.0" }` is resolved against `form`'s tags in the same repository, not taken at web's commit. |
| 48 | +- **Pinned:** `git` with `tag`, `branch` or `rev`, or a `path` *without* `version` inside a git checkout. These are ADR 0020's rules unchanged: a pinned package is a commit, and packages reached by path without a version share their parent's commit. Every tag released before this ADR keeps resolving as it does today. |
| 49 | +- **Local:** a `path` from a package on disk. It is used as it is. If it carries a `version`, the package there must declare a `[package] version` that satisfies it, otherwise the build stops (`form` at ../form is 0.20.0; `web` needs ~> 0.21.0). Inside a checkout of `louise-lang/packages`, the siblings are used from disk. |
| 50 | + |
| 51 | +### Selection |
| 52 | +1. **Visit.** Start from the root package (and its dev-dependencies, which are the only dev-dependencies that count, ADR 0064). Each versioned requirement visits the **lowest tagged version that satisfies it**, and every visited version's requirements are visited in turn. |
| 53 | +2. **Select.** For each package, the build uses the **highest version visited**. That is always a version somebody asked for, never "the newest available", so the result does not depend on the order of the walk or on tags released since. It needs no solver. |
| 54 | +3. **Check.** Walk the build again, through the selected versions only. Every requirement made by a package *in the build* must accept the selected version. Requirements of versions that were visited but not selected are not checked. Otherwise the build stops, naming the chain of the requirement that fails and the chain that raised the selection: |
| 55 | + |
| 56 | + ```text |
| 57 | + error: conflicting requirements on `form` (https://toboggan.cloud/louise-lang/packages.git, form): |
| 58 | + app → web 0.21.2 → form ~> 0.21.1 |
| 59 | + app → form ~> 0.22.0 (selects 0.22.0) |
| 60 | + a build holds one version of each package: make these requirements agree (ADR 0088) |
| 61 | + ``` |
| 62 | + |
| 63 | +4. **Pins and versions on one package:** |
| 64 | + - **Pins only:** they must name one commit (ADR 0020). |
| 65 | + - **A pin made by the root package overrides** (as Go's `replace` does). The build uses the pinned commit. Every versioned requirement on that package must accept the `[package] version` found there. This is how an app tests a fix on a branch before it is released. |
| 66 | + - **A pin made by another package** never raises the selection, and must name the selected version's commit. Otherwise it is a conflict whose hint is to give that dependency a `version`. |
| 67 | +5. **Problems found on a version** (no tag satisfies a requirement; a tag holds another version; its manifest cannot be read) are errors only if that version ends up in the build. The name checks of ADR 0020 also apply to the build only: the same package under two names, two packages under one name. So does the `[package] louise` check. |
| 68 | + |
| 69 | +Only the manifests of visited versions are read, from the git objects (`git cat-file`), not from checkouts. Only selected versions are checked out. Manifests of commits never change, so they are cached once read. |
| 70 | + |
| 71 | +### The lockfile: a floor |
| 72 | +- **One entry per versioned package of the build**, with its version and commit: |
| 73 | + |
| 74 | + ```toml |
| 75 | + version = 2 |
| 76 | + |
| 77 | + [[package]] |
| 78 | + name = "json" |
| 79 | + git = "https://toboggan.cloud/louise-lang/packages.git" |
| 80 | + subdir = "json" |
| 81 | + version = "0.21.0" |
| 82 | + commit = "…" |
| 83 | + ``` |
| 84 | + |
| 85 | + It is keyed by (URL, directory). Pinned dependencies keep ADR 0020's entries, keyed by (name, URL, reference). |
| 86 | +- **The locked version is a floor.** The build uses the higher of the selected version and the locked one, as if the root required it. A floor counts only for a package that some requirement still reaches, so a dependency removed from every manifest leaves the lockfile. |
| 87 | +- **A version's commit comes from the lockfile when that version is locked,** and from its tag otherwise. A tag moved after locking does not change a locked build (as in ADR 0020). |
| 88 | +- **A floor that no longer fits** (a requirement was narrowed below it): |
| 89 | + 1. The build tries all floors first. |
| 90 | + 2. If that fails, it tries none. If that fails too, the lockfile is not the cause, and that conflict is reported. |
| 91 | + 3. Otherwise it adds the floors back one at a time, in the order of the packages' URLs and directories, keeping each one that still builds. Each one it drops is reported (`downgrading json 0.22.0 -> 0.21.3`). |
| 92 | + |
| 93 | + `--locked` makes any such drop an error, as for any other change. |
| 94 | +- **The lockfile's `version` is 2 only when it holds a versioned entry.** A project with only pinned dependencies keeps writing version 1, so upgrading the compiler does not rewrite its lockfile. |
| 95 | + |
| 96 | +### `louise update` |
| 97 | +`louise update [name]` raises floors. For each package it updates (the one named, or every versioned one), in the same order, it tries that package's tags from the newest down. It skips any tag whose `[package] louise` this compiler does not satisfy, and keeps the first one with which the build passes the check. `louise.toml` is never rewritten. This is greedy: it may miss a combination a solver would find, and then the conflict names its chains. A name is matched against the dependency names of the build, as before. `update` always fetches. Without `update`, a repository is fetched only when a requirement has no satisfying tag in the cache, when a package is not locked yet, or when a locked commit is missing; `--offline` never fetches. |
| 98 | + |
| 99 | +### Diagnostics |
| 100 | +Every resolution failure stays `E0801`, in the manifest at fault, for the language server. A problem in the manifest of a version read from git names that version and tag (`form 0.21.0 (tag form-v0.21.0): …`), since no file on disk holds it. |
| 101 | + |
| 102 | +## Consequences |
| 103 | +- **A package can be released on its own,** and an app can take one package's fix without moving the others. Shared dependencies meet at the highest minimum, which is a version someone tested against. |
| 104 | +- **A conflict is explicit and names both chains.** Nothing is picked silently, and nothing depends on traversal order. |
| 105 | +- **What a release is (`AGENTS.md` of `louise-lang/packages`):** |
| 106 | + - a version bump plus an annotated tag; |
| 107 | + - a package raises a dependency's minimum only when it needs something newer; |
| 108 | + - a breaking change starts a new line: a 0.x minor, or a major from 1.0. |
| 109 | +- **Older compilers refuse `version` on a dependency** ("unknown field `version`"), before reading `[package] louise`, and they refuse a version 2 lockfile. From this release on, `[package] louise` is read before the rest of the manifest, so later format changes report the compiler requirement instead. |
| 110 | +- **Reading visited manifests from git costs** one `for-each-ref` per repository plus one `cat-file --batch` per run. Parsed manifests are cached on disk by commit. The language server resolves offline from the cache, as before. |
| 111 | +- **A local package and a git package are never the same package.** An app that uses a local copy of `form` while `web` brings `form` from git gets "two different packages named `form`", as ADR 0020 says. The supported way to test a fix across packages is a root pin on a branch (`git = "file:///…/packages", branch = "fix", subdir = "form"`). A `[patch]`-style path override is a follow-up. |
| 112 | +- **A version that is visited but not selected can still raise the selection.** If an older `web` asks for a newer `form` than the newest `web` does, the build takes that `form`. Go has the same property; it keeps the result independent of order. The conflict message then shows the chain through that older version. |
| 113 | +- **Tests:** |
| 114 | + - `crates/louise_package` tests the selection against in-memory packages; |
| 115 | + - `crates/louise/tests/packages.rs` tests it end to end against local repositories with per-package tags: a compatible diamond, a conflict with both chains, floors and `update`, a root pin, and the archived same-tag layout unchanged. |
| 116 | + |
| 117 | +## Alternatives considered |
| 118 | +- **Exact commit identity (ADR 0020, today).** Simple, and reproducible without a lockfile. But it forces every package of a repository to move together, which is what issue #475 removes. |
| 119 | +- **Identity by the tree of the package's directory.** Two commits would be one package if the directory is byte-identical. That only helps when the shared package did not change at all; a compatible fix still conflicts. |
| 120 | +- **Semver ranges with a solver** (Cargo, PubGrub): the newest versions that satisfy every range. More upgrades happen without asking, but the result depends on what has been released since. It needs backtracking and, for good errors, a solver like PubGrub. MVS gives the same guarantee for the common case with a walk and a maximum. |
| 121 | +- **"Newest compatible" without a lockfile floor.** A build would change when someone tags a release. |
| 122 | +- **`>= x.y.z` alone, as `[package] louise` writes it.** It would read as unbounded, yet a breaking line must still be refused, so the same text would mean two things. Hex's `~>` says the bound, and Gleam users know it. |
| 123 | +- **A tag prefix from the package's name.** A dependency names a directory, not a package name, so the name is unknown until the manifest is read. |
| 124 | +- **A `[patch]` override of a git package by a local path.** It is useful, but it is a separate decision (see Consequences). |
| 125 | + |
| 126 | +## Open questions for the engineering review |
| 127 | +- **Should `louise update` stay greedy,** or try combinations when the newest version of one package conflicts? |
| 128 | +- **Is reading every visited version's manifest from git acceptable for the language server's load,** given the on-disk cache, or should visited versions be limited (for example, to the lowest version per breaking line)? |
| 129 | +- **Should `~> 0.Y` be refused, or only warned about?** |