Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

LT import v3 — Decision Ledger

Status: in effect (0.7.0). This design is implemented. This document is the source of truth for the import design. Related amendments have landed in spec.md (§1, §6.1, §13, §15, §16) and grammar.ebnf. package-manager.md is the operational summary. Implementation of phases 0–5 has landed; see CHANGELOG.md.

The change in one sentence: package identity moves from a global name to (dependency, path), external dependencies move to the manifest, and the lock becomes read-only during builds.


1. The problem addressed

The v2 design is sound for a single small project, but it has a ceiling:

  • Package names are unique per build, so two dependencies that both have package user cannot coexist. Aliases do not help because the loader rejects before the alias is read.
  • File paths are public API. Moving a file breaks every import.
  • There is no manifest. A version is a raw URL on the import line; there is no dependency graph, per-dependency update, or frozen mode for CI.
  • lt build and lt check write lt.lock silently.
  • Multi-package files share one import list, and importing one package still loads and emits every package in that file.
  • Unused imports are never reported.

What is not changed because it is already right: mandatory qualifiers, per-declaration export, rejection of dot/blank imports, rejection of import cycles, and the mapping of one package to one host module.


2. Decisions

#DecisionRationale
2.1Package identity = (dependency root, file path). Package names are unique per dependency, not per build.Removes the scaling wall; two libraries may use the same package name.
2.2Two dependencies may both declare package user. If both are imported into the same file, both must be aliased differently; the error only occurs when bindings collide.Aliases only become useful once global uniqueness is dropped. Same model as Go.
2.3One file contains exactly one package. Multi-package per file is removed.Imports become package-scoped, the loader loads only what is referenced, and package = file = output module.
2.4File names are free; the package name is written in the import and verified against the target file. Output module name = directory + package name.The playground and conformance use path casing different from package names; forcing stem = name would break that convention with no semantic benefit.
2.5Specifiers without an extension. Local: ./wallet/money. External: acme/wallet/money, first segment = manifest key.The unit of import is the package, not the file. Single resolution: <path>.lt.
2.6External dependencies are declared only in lt.toml. Local imports stay relative and need no manifest.A single place for versions, sources, and dependency edges.
2.7Manifest v1 contains only [dependencies]. [package], workspaces, and publishing metadata are deferred.Metadata nobody uses is better not invented.
2.8v1 sources: git (https/ssh) and local paths. No registry.Covers early ecosystem needs without building a server, auth, and publishing.
2.9Versions are written as semver ranges, exact tags, or 40-hex commits. Branches are rejected. The lock always pins a commit.Reproducibility without forcing every consumer to bump a version manually on a diamond dependency.
2.10Resolution is transitive, one version per source per build: the highest version satisfying all ranges. Irreconcilable ranges = error.A model that can be explained; multi-version splits type identity and output size.
2.11lt build and lt check never write the lock. An unlocked dependency = an error telling you to run lt update.A lock only means something if a build cannot change it silently.
2.12lt.lock is a versioned-format resolution graph: canonical source, commit, root, sha256 per file, and requirement edges. Entry identity = (source, commit), not content.Enough for per-dependency updates, conflict explanation, and transport integrity.
2.13Path dependencies are not pinned to commits — always live — but their transitive dependencies still enter the lock.Local sources are part of the project, not downloaded artifacts.
2.14Unused imports = a compile error, with autofix. Definition: at least one binding from that import entry is referenced.Dead imports are dependencies that should not be resolved.
2.15Explicit per-name re-export: export import money { Price as P } "./wallet/money". The item list is mandatory; wildcards and list-less forms are rejected. The qualifier stays locally bound but is not re-exported.A stable façade without resurrecting nested namespaces or from.
2.16Re-export is a name alias, not a new type. facade.P and money.Price are the same nominal type.Two identical types that are not assignable to each other are a design bug, not a feature.
2.17Dependency output uses the _deps prefix: src/_deps/<key>/<path>.ts, gen/_deps/<key>/<path>/<package>.go. _deps is reserved at the source root.A stable namespace with no collision with local packages.
2.18Transport: git https/ssh, raw files over https, http:// only for localhost. Auth via git credentials / GITHUB_TOKEN. No custom signatures in v1.Consistent with the reproducibility claim; signatures are a project of their own.
2.19vendor/ is optional and may be committed. Source order: vendor → cache → fetch the locked commit. --offline forbids the network. Path dependencies are not vendored.Offline-first without adding a new way to change versions.
2.20v1 commands: lt add, lt remove, lt update <key>/--all, lt vendor, lt migrate. No lt install.One explicit place that writes the lock.
2.21lt build stays entry-based; unreachable local packages are not emitted.Determinism and minimal output.
2.22lt migrate handles mechanical changes and rejects ambiguous cases. Dry-run by default; --write applies.Humans should see file changes before they are written.
2.23Go constraints remain hard: one package per output directory, no import cycles, Go-valid package names.Go is a first-class target; an import graph that cannot be emitted to Go must not pass.
2.24Deferred: registry, publishing, multi-version per source, workspaces, signatures.Keeps v1 shippable and testable.

3. Syntax

// src/app.lt
// imports come before the package block

// local, no extension
import money { Price, format } "./wallet/money"
import money as cash { Price as P } "../shared/money"

// external: the first segment is a key in lt.toml
import post "acme/blog/post"

// groups are still allowed; one entry per line, no commas
import (
  money { Price } "./wallet/money"
  post  "acme/blog/post"
)

// façade: only the items inside { … } enter this package's API
export import money { Price as P } "./wallet/money"

Syntax rules:

  • import always comes at the top of the file, before the package block.
  • export import is valid only as a single entry, not inside a group.
  • export import must have a non-empty item list.
  • The qualifier (money) stays bound after destructuring and after export import, but the qualifier is not re-exported.
  • Dot imports, blank imports, and from are still rejected with dedicated messages.
  • Empty item lists {} and empty import groups () remain errors.

4. Semantics

4.1 Project root and resolution

  1. Project root = the nearest ancestor of the entry that has lt.toml. Without lt.toml, the project may only use local imports.
  2. A specifier starting with ./ or ../ resolves relative to the importing file: <specifier>.lt. There are no directory imports and no index files.
  3. Any other specifier is treated as <key>/<path>: key must exist in [dependencies]. Target file = <checkout>/<root>/<path>.lt.
  4. Every loaded file must declare exactly one package. File names are free; the package name determines identity and the output module name.
  5. Package names must be unique within one dependency. Two different dependencies may use the same name.
  6. Import cycles are detected on the file/package graph, with a message showing the cycle chain.

4.2 Imports and aliases

  • import money "./wallet/money" binds the qualifier money.
  • import money { Price, format } "./wallet/money" binds the qualifier money and the names Price/format without a qualifier.
  • import money as cash { Price as P } "./wallet/money" binds cash and P.
  • An import name must not shadow a local declaration or another import name.
  • If two packages with the same name from two dependencies are imported into the same file, both must use different aliases. The error only appears when bindings collide, not when the package declaration is read.
  • Using a type/function from a package that is not imported remains a compile error; there is no implicit resolution.

4.3 Unused import

  • An import entry counts as used if at least one of its bindings is referenced, including in type positions, inside template strings, and in export import.
  • export import always counts as used because it is part of the API.
  • An unused entry = compile error. Autofix removes that entry; if the entry is the only content of a group, the group is removed too.
  • v1 does not check for unused destructured items as long as the import entry itself is used.

4.4 Re-export

  • export import money { Price as P } "./wallet/money" adds P to this package’s export table. A consumer can write import facade { P } "./facade" or import facade "./facade" and then facade.P.
  • A re-exported name must be part of the origin package’s API: a declaration with export or the result of an explicit re-export from that package. Private names = error.
  • Re-exports may be aliased; a conflict with a local declaration or with another re-export result = error.
  • A re-export does not create a new type. Nominal identity stays with the origin package, and the emitter refers to the origin module, not the façade package.
  • Re-exports are not implicitly transitive: package A only exposes the names it explicitly re-exports.
  • Because import cycles are forbidden, the re-export graph cannot loop.

4.5 Versions and conflicts

  • The manifest writes semver ranges, exact tags, or 40-hex commits. The tag v1.2.0 normalizes to 1.2.0; non-semver tags are valid only as exact versions.
  • v1 range operators: ^, ~, =/exact, and *. Other comparison operators are not supported yet and are rejected as an exact version/tag that is not found.
  • The resolver reads each dependency’s manifest, collects all requirements, then picks the highest version that satisfies all of them.
  • If no version satisfies all ranges, the build fails and prints every parent with its range.
  • One source has only one version per build. There is no side-by-side version selection in v1.
  • The lock stores the chosen commit; a build never re-selects a version.

4.6 Read-only lock

  • lt build/lt check verify that the lock satisfies the current manifest. A missing, incomplete, or non-satisfying lock = an error with the repair command (lt update <key> or lt update --all).
  • lt update <key> re-resolves that key and its closure. If the change touches a shared dependency, other entries are updated too and reported.
  • lt update --all re-resolves the whole graph.
  • lt add writes the manifest and the lock; lt remove removes the manifest then prunes lock entries that are no longer reachable.

5. Manifest

# lt.toml
[dependencies]
acme  = { git = "https://github.com/acme/lt-lib", version = "^1.2", root = "." }
utils = { path = "../utils" }
  • Dependency keys follow [a-z][a-z0-9_]* and become the first segment of external specifiers.
  • git + version (required) or path (required); the two must not appear together.
  • root is optional, default ".": the subdirectory inside the checkout that becomes the dependency’s package root. That directory must contain the dependency’s lt.toml.
  • No [package], workspaces, or publishing fields in v1.
  • The manifest is written by hand or via lt add; lt fmt does not touch it in v1.

6. Lock

Format sketch (not a final byte contract; the content is what is locked):

version = 1

[[root]]
key = "acme"
source = "git+https://github.com/acme/lt-lib"

[[package]]
source = "git+https://github.com/acme/lt-lib"
commit = "0123456789abcdef0123456789abcdef01234567"
root = "."

[[package.files]]
path = "wallet/money.lt"
sha256 = "…"

[[package.dependencies]]
key = "utils"
source = "git+https://github.com/acme/lt-utils"
commit = "89abcdef0123456789abcdef0123456789abcdef"
requirement = "^2.0"
  • source is the canonical normalized URL (host, path, no .git, no trailing slash). The ssh and https forms of the same repo normalize to the same identity.
  • commit is always 40-hex for git. Path dependencies still get an entry (without commit, source path+… relative to the project root) so that edges and prunes can still be tracked; their content is always live and not verified from the lock.
  • files records every file actually loaded, with the sha256 of its content.
  • dependencies records requirement edges, so conflicts can be explained and per-key updates know what changed.
  • version is the lock format version. An old lock without version = an error telling you to run lt update --all.

7. Output

OriginTypeScriptPythonGo
Localsrc/<dir>/<package>.tsgen/<dir>/<package>.pygen/<dir>/<package>/<package>.go
Dependencysrc/_deps/<key>/<dir>/<package>.tsgen/_deps/<key>/<dir>/<package>.pygen/_deps/<key>/<dir>/<package>/<package>.go

The paths above are relative to the target output directory (out/ts, out/py, out/go), following the existing emitter convention.

  • _deps is reserved at the source root; a project must not have a directory named _deps containing local sources.
  • Tests and usage are emitted only for packages owned by the root project, not for dependency packages.
  • The runtime stays one file per output package; dependency modules import the runtime with a relative path computed by the emitter.
  • Type identity stays nominal per module; the output path does not change identity.
  • Source file names are free; the output module uses the file’s directory + the package name.

8. Commands

lt add acme --git https://github.com/acme/lt-lib --version "^1.2"
lt add utils --path ../utils
lt remove acme
lt update acme
lt update --all
lt vendor
lt build -t ts src/app.lt
lt check src/
lt migrate [--write]
  • build/check/test/vendor accept --offline; build/check are read-only with respect to the lock and manifest.
  • vendor copies the locked source tree from the cache (or fetches the locked commit) into vendor/; --offline forbids the network.
  • migrate is dry-run by default; --write applies.

9. Migration

lt migrate handles:

  1. Removing .lt from every local specifier.
  2. Moving URL imports into [dependencies] entries. The key is derived from the repo name; the path inside the repo becomes part of the specifier.
  3. Splitting multi-package files into one file per package, copying only the imports each package actually uses.
  4. Not renaming files: file names are free and package names are preserved.

It refuses and stops with a clear message when:

  • There are two different URLs/refs for the same source (violating one version per source).
  • A dependency key already used by another source = error; choose another key manually.
  • A file name produced by the split is already used by another package.
  • An import cannot be mapped to a path inside the repo (e.g. a non-git URL).

Dry-run prints the plan per file; --write then writes. After migration, the user runs lt update --all to write a new lock.

This repo itself has ~8 import sites and zero multi-package files, so its migration is small. File names do not need to change because file names need not match package names.


10. Implementation plan

PhaseContentsCrate
0This document, spec/grammar amendments, breaking-release notesdocs/
1One package per file, extension-less specifiers, export import, unused imports, per-dependency uniquenesslt-syntax, lt-hir, lt-lsp
2lt.toml, git/path resolver + semver + transitive, lock graph, read-only build/checklt-pkg, lt-hir, lt-cli
3_deps output, test/usage filtering, runtime pathslt-ir, lt-emit-*
4lt add/remove/update/vendor/migrate, error messages, manifest-aware LSPlt-cli, lt-lsp
5New conformance, examples, docs, CItests/, examples/, docs/

Phase 1 deliberately does not depend on the resolver: language changes can land and be tested with local imports only, before lt-pkg is torn apart.


11. v1 non-goals

Registry and publishing, multi-version per source, workspaces, multi-package per file, custom signatures, and [package] in the manifest. Accepted consequences: large packages must be split into several packages or use a re-export façade, and the resolver depends on the git binary (not a Git library).


12. Implementation notes

  • The git resolver uses the git CLI in v1 (ls-remote, fetch, checkout); semver uses the semver crate. Both can be replaced without changing the manifest/lock.
  • The ModuleId type stays per package; what changes is the loader key and the uniqueness validation.
  • The checker must extend the export table with re-export results before validating import items, but TypeName.module still points to the origin package.
  • The emitter computes relative paths from the output name; the _deps prefix only needs to be added in one place (module name computation), not in every emitter.
  • lt check with multiple entries is valid only if they are all under the same project root.