Publication¶
A library's files are written once and named by their content: partitions
are kind-6 containers in parts/, manifests kind-4 containers in
manifests/, each named by the SHA-256 of its bytes. One small file,
CURRENT, names the current version's manifest, and only it ever changes.
One current version¶
LibraryChange.publish() holds the library's LOCK while it writes. It
installs each new partition as soon as it has encoded it, then the manifest,
each written to a temporary file, flushed and renamed into place. It then
reads CURRENT again and replaces it with an atomic rename only if it still
names change.base(); otherwise it refuses with CONFLICT and CURRENT
stays as it was (ST7.2).
A reader reads CURRENT once and then only immutable files, so it always
sees one complete version.
A file that already exists under its name is compared with the bytes to write and kept. The same holds within one publication: two sub-partitions of a chain whose rows encode alike have the same bytes, so the file is written once and the manifest names it at both positions (ST9.1).
Example¶
This program publishes two versions of a library: the same exports give
the same version identity, and a change whose base is no longer CURRENT
is refused with CONFLICT.
"""Publish theorems into a proof-DAG library and verify deterministic versions and conflict checks."""
from std.tempfile import mkdtemp
from std.testing import assert_equal, assert_true
from judgment_shell import Session
from judgment_store import Library
from termbank import Budget
def main() raises:
var budget = Budget(10000000)
var path = String(mkdtemp(), "/lib")
var lib = Library.create(path, "none")
# Author two checked theorems over the library's profile snapshot and export them.
var s = Session.open(lib.profile_snapshot(budget))
var t_fact = s.prove_step("basics.truth", s.truth(s.base()))
var t_step = s.truth(s.base())
var both_fact = s.prove_step("pairs.both", s.and_intro(t_step, t_step))
var first_change = lib.change()
first_change.add(s.export(t_fact, "basics.truth"))
first_change.add(s.export(both_fact, "pairs.both"))
var first = first_change.publish()
print("Published version 1 with", len(Library.open(path).theorems()), "theorems")
# Publication is deterministic: the same exports yield the same version identity.
var twin_path = String(mkdtemp(), "/twin")
var twin = Library.create(twin_path, "none")
var twin_change = twin.change()
twin_change.add(s.export(t_fact, "basics.truth"))
twin_change.add(s.export(both_fact, "pairs.both"))
var same = twin_change.publish()
print("Same exports, same version:", same == first)
# A stale change built on the initial version is refused with CONFLICT.
var stale = lib.change()
stale.add(s.export(t_fact, "basics.extra"))
var kind = String("accepted")
try:
_ = stale.publish()
except error:
kind = String(error.kind)
assert_equal(kind, "CONFLICT")
print("Publishing from a stale base:", kind)
# Rebasing onto CURRENT succeeds and advances CURRENT.
stale.rebase()
var second = stale.publish()
var current: String
with open(String(path, "/CURRENT"), "r") as f:
current = f.read()
assert_true(not (second == first))
print("CURRENT names version 2:", current == String(second, "\n"))
Run from the repository root pixi run mojo run -I src docs/examples/store/publish_library.mojo
Output
Published version 1 with 2 theorems
Same exports, same version: True
Publishing from a stale base: CONFLICT
CURRENT names version 2: True
See also¶
- Publishing a library
- ST9 proof-DAG partitions
- ST8 partition metadata sections