0279. Module aliases and qualified names
- Status: Accepted (maintainer, 2026-11-22; recommended defaults for all open questions; frozen-file edits listed here approved)
- Date: 2026-11-22
- Plan: D7 (backlog); no plan task yet
- Review: Design Critic #17; partially supersedes the "no module aliases or qualified use sites" sentences of 0064 and 0073
Context
Today import a.b { f, T } binds selected public
items as bare names, and f as local renames one of
them. Larger apps (TUI widgets, an HTTP layer and the agent stack
in one root) collide on short names such as render,
Style and Event. The only fix is to
alias item by item. A module that is loaded only for its impls (a
coherence bridge) needs a dummy item import, because IDIOMS says
"there is no empty import bridge {}". ADR-0064
already rewrites module items to dotted internal names
(tui.widgets.button) before resolution, so a
qualified use site only needs a resolver mapping. In compact
source an import is I [segments] [name Opt alias],
and both lists must be nonempty.
Decision
Whole-module import. Familiar
import tui.widgets binds the module name
widgets, the last segment as in Go.
import tui.widgets as w binds w.
as stays contextual. The compact form reuses
I with a zero-length item list followed by one
Opt identifier: I2;3:tui7:widgets0;~ or
I2;3:tui7:widgets0;+1:w. A zero-length list is
invalid today, so existing files keep the same bytes. An alias
equal to the last segment is not canonical: E0125 with an edit to
~.
One form per module per file. A file imports a given module either selectively or whole, never both: E0229 (free today; allocate at implementation). Importing the same whole module twice is E0224.
Qualified names are exactly
alias.item, one level deep. Modules do not nest.
- Calls use
w.button(x)and enum variants usew.Color.red. - Record literals use
w.Style { … }. Types usew.Style, generic boundsT: w.Show, implsimpl w.Show for T, and derivesderive w.gen for T. - In compact, a qualified frame
N:alias.itemmay appear wherever an item name is read:Ocallee,N(for example a variant receiver),Precord name, named typen, bounds, impl and derive heads. The reader knows every alias from the leadingIrecords. A dot in any other identifier frame is still E0125. - Canonical form:
Mwith anNreceiver that names a module alias is E0125, with an edit toO(O8:w.button1;a). A qualified call therefore has one spelling, and a method call can never reach a module.
Resolution (modules.rs only).
alias.item resolves through the alias's ModuleId to
the existing dotted internal name. A missing item is E0222, and a
private item is E0223. Newtype constructors and
.value stay file-private (ADR-0069). Module names
live in file scope. A clash with an item, an imported name or
another alias is E0224. A local or parameter spelled like an alias
is rejected by the no-shadowing rule (ADR-0013). That is what
makes w.f() unambiguous.
Coherence and methods. Impls stay global
(ADR-0027/0069). An alias neither scopes nor hides an impl. For
method lookup, a whole-module import counts every pub
interface of that module as imported in the file. Existing
ambiguity diagnostics apply. A whole-module import with no
qualified uses still loads the module, which replaces the dummy
bridge import.
Generated companions (ADR-0080). A companion
sees its host's module names. An import edge whose alias is used
only in derive heads is generator-only.
Tools (ADR-0049).
outlinelistsimportwithitems: []and analiasfield.- Renaming a module alias rewrites the alias and every
alias.qualifier. - A provider rename with
--rootrewritesw.oldsites. editandcontextselectors are unchanged.
Formatting. Imports keep source order, as today. fmt never converts between selective and whole forms.
LANGUAGE.md. Replace "No module aliases or qualified paths." (+≈30 tokens; spec-keeper trims ≈30) with:
import a.borimport a.b as mbinds moduleb/m(no items) for qualifiedm.f(x),m.T,m.E.v; one import form per module per file.
IDIOMS line 128: the bridge idiom becomes
import bridge.
Prior art
- Go import declarations; package name is the default qualifier: https://go.dev/ref/spec#Import_declarations
- Python
import x as y: https://docs.python.org/3/reference/simple_stmts.html#the-import-statement - Rust
use a::b as c: https://doc.rust-lang.org/reference/items/use-declarations.html - Zig
const w = @import("w.zig"): https://ziglang.org/documentation/master/#import - Kotlin import aliases: https://kotlinlang.org/docs/packages.html#imports
Alternatives considered
- Require an explicit
asalias (no Go default). This means more typing andimport a.b as bnoise. The default is predictable, and canonicality forbids the redundant form. - Allow selective and whole-module imports of the same module together. The same item would have two names in one file, against ADR-0009 "few forms".
- Nested paths
tui.widgets.button(x)without imports (Rust/Java style). Use sites get longer, and the file loses its explicit import list. Tools and agents read dependencies from imports. - Resolve
w.f()as a method call in the type checker. That mixes namespaces. The canonicalOform keeps the decision in the resolver.
Consequences
- UX: no direct change. Apps can compose more plugins without renames.
- DX: no item-by-item aliasing.
w.shows where a name comes from, and bridge modules load with one line. - AX: there is one qualified spelling, and the reader rejects
the
Mform with an exact edit. Collisions keep the existing codes, plus E0229. The primer and explain cards gain one example each. - No IR, C, runtime or interpreter change. The interpreter
shares the front end (
driver::parse_file→modules.rs). - Frozen files: none.
Implementation slices
- Compact: zero-item
Iwith an optional alias, qualified frames in name slots, theM→Ocanonical check, and the encoder. AddsImportDecl.module_alias: Option<Ident>, with reader unit tests. Areas:compact.rs,compact/{reader,expr,encode}.rs,ast.rs,PRIMITIVE_GRAMMAR.md. Frozen files: no. Agent: Claude Sonnet. - Resolver: alias binding, qualified rewrite to dotted internal
names, E0222/E0223/E0224/E0229, interface lookup set, and
generator-only edges. Areas:
modules.rs,resolve.rs,types.rs(per-file interfaces),gen.rs. Frozen files: no. Agent: Claude Sonnet, with Opus review. - Tooling:
outline.rs,references.rs(rename),compact_tools.rsprimer, anditem_hashes.rsif import rows hash. Frozen files: no. Agent: Claude Sonnet. - Docs: LANGUAGE.md, IDIOMS.md, diagnostics.md (E0229 and E0224
text), and a
teach-core.tsvcard. Frozen files: no. Agent: Gemini (agy Argon Low).
Open questions (resolved)
Resolved by maintainer on 2026-11-22: every question takes its stated default.
- Should the default name be the last segment, with optional
as? Default: yes (Go-style). - Should mixing selective and whole imports of one module be forbidden? Default: yes (E0229).
- Should a whole-module import expose its
pubinterfaces for method lookup? Default: yes. Otherwise users need a selective import as well, which would conflict with question 2. - Should a package import
import a(selectinga.lib) bindarather thanlib? Default:a, the written segment. - Should a qualified frame be allowed in an
Ocallee for plugin modules (import cli)? Default: yes. Plugins are ordinary modules (ADR-0006).