0161: vc storage unit is the formatted item
Status: Accepted — implementation authorized 2026-11-05
Context
Item-level history, merge and incremental gates need the
program stored in units smaller than a file. The candidates are
files, AST nodes, or item text. fmt is canonical
(ADR-0018) and keeps comments in source order, but it drops blank
lines and has no per-item printer. The ADR-0075 hashes ignore
comments and layout, so they cannot be the stored identity.
ADR-0075 canonical names need a package root, and they change when
a file moves. ADR-0075 also has no per-method identity.
Decision
A .hn file whose bytes equal fmt
output is stored as a module object, which holds:
- the formatter version (a new
FMT_VERSIONconstant); - an optional header chunk: the imports, with the comments before and between them;
- an ordered list of units;
- an optional footer chunk: the comments after the last item.
A unit is one of:
- an item chunk keyed by its
outlineselector:fn f,struct S,enum E,type T,interface Iorderive G for T; - an impl, made of a head chunk, a tail chunk, and one chunk per
method keyed
I for T.m. That key isFnEntry::full_selector.
Keys come from the parser alone. Splitting therefore needs no name resolution, and moving a file leaves its keys unchanged.
A chunk is the item's slice of the fmt output, including the
comments before it. Join is concatenation with fixed separators,
and join(split(f)) == f for every fmt-clean
f. Exact grammar: FORMAT.md.
Files that do not parse, are not fmt-clean, or repeat a key are
stored as raw blobs. They land like any other file:
whether a .hn file must be fmt-clean is the gate's
policy, not the store's, and about 20% of this repository's
.hn files are deliberate parse-error or unformatted
fixtures. Generated files, identified by the gen magic line, are
plain blobs. Other files are whole-file blobs, and directories are
tree objects.
The following are derived data, cached per (tree, toolchain) and never stored in objects:
- ASTs;
- ADR-0075 canonical names and
sig/bodyhashes; - per-commit item change lists;
- dependency edges.
Consequences
Comments survive, agents read stored text directly, and identical items deduplicate. Commits are independent of the toolchain.
The cost is that a change to the formatter's output rewrites
every chunk. FMT_VERSION plus a digest test over the
corpus turns each such change into an explicit, single
vc reformat commit. Join must also be closed under
merge: fmt(join(m)) == join(m) for reordered and
merged modules. Both properties run in the gate.
Alternatives
- A serialized AST: semantically pure, but it loses comments unless the AST carries them, and it adds a second canonical format to version and migrate.
- Whole files: simplest, but there is no item-level merge, history or dependency-driven gate.
- ADR-0075 hashes as identity: two items that differ only in comments would collide.
- ADR-0075 canonical names as keys: these need a package root and resolution, change when a file moves, and give methods no identity.
- Storing change lists in commits: reads are faster, but derived, toolchain-dependent data becomes part of object identity.