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

propertyhow
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 automaticallytrine 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 requiredNothing the compiler outputs depends on it. Deleting it, or git clean -X, changes nothing.
deterministicEntries are named by content hash, so rebuilding gives the same files.
tolerantMalformed 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:

  1. Edit. After check and build: - git status is clean, with no untracked files; - git reports the store as ignored; - git add -A stages nothing from it.
  2. Diff. git diff shows exactly the source change.
  3. Merge of a rename (the hard case). Branch rename renames area to surface at every use. Branch feature adds a new caller of area. - 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 name area — area was renamed to surface: same definition (hash 3d6d95ae294a), so surface here 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.
  4. Conflicts. When both branches edit the same definition, the conflict involves only the source file. The store never conflicts, because git never tracks it.
  5. Cache behaviour: - git clean -X removes the store, and the output is identical without it; - the rebuilt store has exactly the same hashes; - a corrupted names/history file 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.
  6. 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