ADR 0054: A module declares the Lyth version it is written for
Status: Accepted (2026-10-28). Needed before 1.0 so that changes after it can be opt-in.
Context
Section titled “Context”After 1.0, a change that would stop working code from building, or change
what it means, cannot be made for everyone. Go gates such changes with the
go line of go.mod: loop variables became per-iteration only for modules
that declare go 1.22. Lyth has no equivalent, and needs one more than Go
does: since ADR 0053, the installed
lyth checks the Lyth sources of every dependency, including libraries
written for an older Lyth.
The version must travel with the module (in the module zip), survive the
go command editing go.mod, and be readable without running anything.
Decision
Section titled “Decision”-
Where. A comment directive in
go.mod, after thegoline:module example.com/appgo 1.26//lyth:version 1.0The
gocommand rejects unknown directives, so the version cannot be a directive of its own, but it keeps comments:go mod tidy,go mod edit, andgo getpreserve this line (checked with Go 1.27).go.modis in every module zip, so dependencies carry it. -
Meaning. The module’s Lyth code is checked with the rules of that version. A change after 1.0 that could break code applies only to modules that declare the version that introduced it or a newer one; a dependency is checked with its own declaration.
-
Missing. A module without the line is written for 1.0, the first version with a promise, and so is a module that declares a version before 1.0. Before 1.0, nothing is gated and the line is only recorded.
-
Newer than the compiler. A module compiled with the program (the main module, a workspace module, a module replaced by a directory) that declares a version newer than the installed
lythis an error at thego.modline (E0602), naming both versions and the fix, upgradinglyth; so are a malformed line and a second one. For a dependency from the module cache, it is W0014: the program uses the dependency’s published Go, and code that needs its Lyth declarations fails with the errors W0014 explains. -
Writing it.
lyth initwrites the installed version (LangVersion, the major and minor of the release). Nothing raises it implicitly:lyth fix -lang=1.Nraises it, before compiling, so the fixes for the changes up to 1.N apply, asgo fixdoes for Go’s. It refuses to lower the version or to raise it past the installedlyth. -
New checks. New compile-time checks still start as warnings (compatibility); a check that becomes an error does so only from the version that makes it one.
Alternatives
Section titled “Alternatives”- A file of its own (
lyth.mod). It also travels with the module, but is one more file in every project for one line, and editors and tools would have to find it. Ago.modcomment sits beside thegoline, which has the same role. - A directive per file (
//lyth:version 1.2at the top of a file). Go allows per-file versions with//go:build go1.22only to lower the version; a per-module version is what changes are reasoned about. - No version, only
lyth fix. Works for respellings, not for changes of meaning, and not for dependencies, which the program cannot rewrite.
Two questions were settled with the decision:
- A flag of
lyth fix, not alyth mod edit -lyth. Raising the version is worth doing only with the fixes it brings, andlyth fixis the command that rewrites code after an upgrade. - W0014, not an error, for a dependency newer than the compiler. Its
published Go builds, so a program that uses only what Go sees still builds;
one that needs the Lyth declarations fails anyway, and W0014 at the import
says why. An error would let one library release stop every program that
depends on it until each upgrades
lyth.
Consequences
Section titled “Consequences”- The line is in
go.modof every modulelyth initcreates; existing modules gain it withlyth initorlyth fix -lang, and need nothing before 1.0. - The first change after 1.0 that is gated passes the version of the package’s module to the checker; until then nothing reads it but the checks above.
LangVersionis bumped withdevVersionafter each release (TestLangVersionFollowsDevVersion).- Tested by
TestLythVersionDirective(newer, malformed, and duplicate lines; a replaced module;go mod editkeeps the line),TestLythLibraryFromOtherModule(a dependency written for a newer Lyth),TestInit, andTestFixLang.