Proof library & interchange theory

Bundles and import

These results define what a partition holds, the reconstruction support it records for its declarations (ST1.5) and what importing declarations by their bytes establishes. A library's partitions are loaded by Algorithm L-5 (libraries), which rebuilds every declaration from its bytes into a fresh bank.

Partitions

Definition BU-1 (partition). A partition (ST8, ST9) holds:

  • the identities of the declarations it imports (the core's, the profile's and those of earlier partitions, which are loaded first);
  • its own declarations, serialized (Definition I-1), each with its identity, in the writer's commit order (Definition I-3); a declaration with parts appears once, and its parts are cited as references to it;
  • for each own declaration and each imported support block, a reconstruction-support record, empty in library format 2.2 (below);
  • one named theory, the set (by identity) of its own declarations;
  • for each own axiom, its provenance class (the library's Definition E-1);
  • its proof rows and its export table;
  • a SHA-256 digest of everything above, for integrity.

Reconstruction support

A declaration's syntactic references do not describe its whole rebuilding scope. In particular, f(a,a,a) names f but does not name the ACU declaration that makes this binary operator accept a flattened spine. An instance used by implicit sort checking need not occur as a syntax head either.

For a theory \(T\), let \(S(T)\) be the set of its non-core ACU operator, literal kind, instance definition, class instance, and class relation blocks. This is a conservative support set, not a claim of minimal logical dependencies. Class declarations and type constructors themselves are ordinary explicit references; instance witnesses and ACU/literal laws are reached through their blocks' references.

For each own declaration \(d\), its support is \(S_d = S(P_d)\), where \(P_d\) is its source parent, the theory just before \(d\); it never contains \(d\) itself, since a declaration that adds support is checked in the signature before its extension. An imported support block \(x\) has support \(S_x = S(P_x)\) in the same sense.

Definition BU-1a (support basis). For a support block \(y\) of the partition, own or imported, let \(\mathrm{cl}(y) = \{y\} \cup S_y\). The basis of a support set \(S\) is \(B(S) = \{x \in S : x \notin S_y \text{ for every } y \in S,\ y \neq x\}\).

The records of library format 2.2. A partition's section 6 holds one record per own declaration and per imported support block, and every record is empty (ST1.5): the format does not record \(B_d\). It does not need to, because a loader does not choose a declaration's theory from its support. It rebuilds the partition's own declarations in section-2 order, each in the theory just after the previous one over the partition's imports, its commit-order prefix \(T_d\) (Algorithm BU-2, step 3.2). \(T_d\) holds every declaration \(d\) can depend on, so \(S(P_d) \subseteq S(T_d)\) whenever \(P_d \subseteq T_d\), and the checker and the byte comparison of step 3.4 decide whether \(d\) rebuilds in \(T_d\) to the recorded bytes. The empty records are recomputed and compared like every other metadata section, so they are fixed bytes of the format, not a claim about \(S_d\). Proposition BU-1b below is the mathematics of a basis; the format uses none.

Proposition BU-1b (a basis determines its support). \(S_d = \bigcup_{x \in B_d} \mathrm{cl}(x)\), and \(B_d\) is the only subset \(B \subseteq S_d\) with that union in which no element lies in \(S_y\) for another element \(y \in B\).

Proof. A theory that contains a declaration contains the theory before it, so \(y \in S_d\) gives \(P_y \subseteq P_d\) and \(S_y \subseteq S_d\): the union is contained in \(S_d\). Conversely, \(x \in S_y\) implies that \(x\) precedes \(y\) in creation order, so the relation is well founded; every element of \(S_d\) outside \(B_d\) lies in \(S_y\) for some \(y \in S_d\), and following such \(y\) upward reaches an element of \(B_d\). For uniqueness, let \(B\) have both properties. An element \(m\) of \(B_d\) lies in \(\mathrm{cl}(x)\) for some \(x \in B\); as \(m\) is in no other block's support, \(m = x \in B\). An element \(x \in B\) outside \(B_d\) lies in \(S_y\) for some \(y \in S_d\), and \(y \in \mathrm{cl}(x')\) for some \(x' \in B\); then \(x \in S_{x'}\) with \(x' \neq x\), which the second property forbids. \(\square\)

A theory built by a chain of extensions gives every basis at most one element, the latest support block; a merge of independent branches gives one per branch.

The reconstruction dependencies of an own declaration \(d\) are the block identities in its syntax reference table and, for a Proven declaration, the declarations its proof cites. A reference to a part contributes its block. Each is the core, an import, or an earlier own declaration in the commit order of section 2: the writer's bank could only reference rows it had committed, and the loader refuses a reference to a later row (ST9.8).

Support is partition content, covered by the container checksum, but is excluded from ser(d) and id(d). Thus declarations retain their version-one identities.

Algorithm BU-2 (import). Within a load (Algorithm L-5), in its fresh bank, for each partition in the load order:

  1. Require every section of the partition (ST8.1). Check the container, digest, lengths, tags, counts, unique identities and names, the one-to-one support records and export-table entries, and dependency order (section 2 lists the declarations in the writer's commit order). A reference must name the core, an import, or an earlier declaration, with a valid part number. Validate tables before constructing terms.
  2. Resolve imports among the declarations the bank holds: the core, the profile and the declarations of the partitions already loaded; an absent import is MISSING_DEPENDENCY. Their identities are computed from their canonical bytes: an association by identity alone is not evidence of content. No declaration outside the load satisfies an undeclared import or a forward reference.
  3. For each declaration in order (its DECL row, ST9.8):
    1. compute the identity of its recorded syntax bytes and compare it with the recorded identity;
    2. take \(T_d\), the commit-order prefix: the theory of the partition's imports, extended by its own declarations before \(d\) in section-2 order. Choose this theory before rebuilding nodes. It depends on nothing the partition records about support;
    3. rebuild types and terms in \(T_d\) and its root context, and declare the rebuilt declaration; a Proven takes the proof row its export-table entry names, which the checker checks with every other row of the load (Algorithm L-5, step 4);
    4. serialize the declaration the bank holds and compare its bytes exactly with the recorded syntax bytes;
    5. record the block and its parts by identity, for the rows and partitions that follow.
  4. Form each named theory by merging its listed declarations' theories. Require its actual non-core block identities that the partition imports or declares to equal the listed set; any other member must be a declaration the reader already knows (in a library load, one of an earlier partition), which the partition need not cite. Validate exactly one provenance record per own axiom; imported axioms retain their existing provenance.
  5. The load returns its bank only if every check of every partition succeeded (Algorithm L-5, step 7). Otherwise it drops the bank, and the caller's sessions, libraries and registries are unchanged (SG3). Validation and capacity checks complete before the bank is returned: no fallible content check follows it. Budgets remain spent on failure.

The loader recomputes section 6 from the bank, one empty record per own declaration and per imported block of a support kind, and refuses a section that differs (FORMAT, ST1.5). Support is never an axiom, a proof, or a substitute for the checker's validation. The reader cannot check the writer's source parent: a declaration the writer made in a smaller theory than \(T_d\) loads only if it rebuilds in \(T_d\) to the same bytes, and is otherwise refused. A checksum is not an authenticity claim.

Theorem BU-3 (import is faithful or fails). If Algorithm BU-2 succeeds, the bank gains exactly the partition's declarations, each validated by the checker, with serializations equal to the partition's, and nothing else. If it fails, nothing outside the load's fresh bank changes.

Proof. Step 3.3 declares each declaration through the checker's rules in \(T_d\), which step 3.2 fixes from section-2 order alone, and step 4 of Algorithm L-5 checks the theories and every row; step 3.4 checks the syntax bytes, so what the bank declared serializes to what the partition recorded, whatever the writer's theory was. Step 4 checks named theory membership. Step 5 returns the bank only after every check; a failed load drops its fresh bank, which holds every entry the import made. \(\square\)

Theorem BU-4 (forged or inconsistent partitions are rejected). An import fails when: a recorded identity is not the identity of the recorded bytes (a forged digest or identity, acceptance test A23); the recorded bytes are not the serialization of what they declare (bytes that are not canonical, or content that the checker builds otherwise); a declaration's name is already declared with other content in a theory it must join (the checker's NAME_CLASH, or a join refusing); or a declaration is invalid in its theory.

Proof. Steps 3.1 and 3.4, and the checker's validation. \(\square\)

Importing axioms adds axioms. Each keeps its provenance record (section 4 of its partition), and every result that depends on one shows it in its label (the library's Theorem E-1). An import never claims that an axiom is a theorem.

judgment v1.0.0 for Mojo 1.2 · Apache License 2.0 with LLVM Exceptions · Source on GitHub