Bet 4: the content-addressed store is invisible to git
Claim. Every definition is identified by the hash of its meaning, and facts about it are stored by that hash. This can live beside ordinary text files without changing how anyone edits, diffs, merges or reviews code.
Kill criterion (CHARTER.md). Edit, diff, merge and review stay unchanged for a user who ignores the store, and merges of renamed definitions are tested. Result: passed. All 24 checks pass in real git repositories (tools/bet4.py, run by cargo test).
Design: a cache that adds information
| property | how |
|---|---|
| git never sees it | .trine/ contains its own .gitignore (*), so no user setup and no edit to the project's .gitignore is needed. This is the same trick Python virtualenvs and pytest's cache use. |
| maintained automatically | trine check and trine build update it. It costs about 0.5 ms on json.tr (4.7 ms against 4.2 ms with TRINE_NO_STORE=1). |
| never required | Nothing the compiler outputs depends on it. Deleting it, or git clean -X, changes nothing. |
| deterministic | Entries are named by content hash, so rebuilding gives the same files. |
| tolerant | Malformed lines, binary garbage and merge markers are skipped. A corrupted entry is rewritten on the next upkeep. If the store can't be written, check and build still succeed silently. Writes are atomic (temp file + rename), so 8 parallel check runs leave a consistent store. |
Layout: defs/<hash> holds the canonical form, facts/<hash> the kind and inferred type, names the checkpoint that trine store reports against, and history every (name, meaning) pair seen on this machine.
The experiment (tools/bet4.py)
A scripted team history runs in throwaway repositories. Each line below is an assertion:
- Edit. After
checkandbuild: -git statusis clean, with no untracked files; - git reports the store as ignored; -git add -Astages nothing from it. - Diff.
git diffshows exactly the source change. - Merge of a rename (the hard case). Branch
renamerenamesareatosurfaceat every use. Branchfeatureadds a new caller ofarea. - Git merges the two cleanly at the text level, and the merged program is broken. This happens with or without a store; it is the classic semantic conflict. - With the store, the error explains it: ``unknown namearea—areawas renamed tosurface: same definition (hash 3d6d95ae294a), sosurfacehere can be replaced safely`` - Without a store, the same error appears without the hint. The store only adds information. - The fixed merge commit contains no store files. - Conflicts. When both branches edit the same definition, the conflict involves only the source file. The store never conflicts, because git never tracks it.
- Cache behaviour: -
git clean -Xremoves the store, and the output is identical without it; - the rebuilt store has exactly the same hashes; - a corruptednames/historyfile and a corrupted entry leave check and run unaffected, and the entry is repaired; - with a file in the store's place, check and build still succeed silently. - Branch switching and clones. Check succeeds across four checkouts. Clones never contain a store, and a fresh clone runs identically.
Review: what the store makes possible
trine semdiff old.tr new.tr compares meanings instead of lines:
$ trine semdiff <(git show main:shapes.tr) shapes.tr # the rename branch
4 definition(s): 3 unchanged, 1 renamed, 0 with code changes, 0 changed only through dependencies, ...
renamed area -> surface (same meaning)
Git shows 4 changed lines for that branch; semdiff shows that no meaning changed. For a real edit, it separates a definition's own change from changes that only reach it through what it calls:
changed sq its own code
changed f only through what it uses (sq)
changed main only through what it uses (f)
That is the reviewer's question ("what actually changed, and what does it affect?") answered from hashes. The test semdiff_separates_own_changes_from_dependency_changes covers it.
Honest notes
- The rename hint depends on local history. It needs a store on this machine that saw the old name with the same meaning: here, the
featuredeveloper rancheckbefore merging. If the renaming branch also changed the definition's meaning, the hashes differ and there is no hint. That is correct, because then it isn't a pure rename. - History is local and unshared by design: sharing it would mean committing it, which would break invisibility. A shared store, like Unison's codebase, is the opposite trade-off.
- Parallel writers can lose a history line (last writer wins). The file is never corrupted, and the next
checkadds the line back. - The store doesn't speed up rebuilds yet.
facts/holds only kinds and types. Caching ownership facts, proofs and native objects by hash, so that a rename rebuilds nothing, is the payoff this bet makes possible. It belongs with modules (#18) and the incremental compiler.