Component architecture

Architecture overview

judgment_shell is a core component of the unified judgment repository, sharing its kernel, version, and Mojo 1.2 toolchain. The whole system is described by its architecture note: the source of truth for the system's architecture, with which this component's design must agree. The package graph gives the import rules. Read the note's sections 1 to 5, then the system overview.

Role

The kernel offers primitive inference rules over handles. Everything a client needs above that, and that is not specific to one engine or one semantic profile, is here:

Part What it gives clients Contract Specification
Term views and builders read a checked term's structure; build terms and propositions without spelling out kernel calls; print terms for debugging L-terms L1
Recipes an untrusted, serializable description of a proof; atomic execution through the session's checked operations; closedness, so that a durable result can be replayed without an engine L-recipes L2
Derived rules weakening into a context, rewriting, congruence, calculational chains, theorem application, quantifier and connective rules, case analysis L-recipes L2
Evidence labels what a result depends on, by class, and which external claims it assumes, so that an uncertified answer stays visible L-labels L2
Matching and metavariables first-order matching modulo associativity, commutativity, and units; metavariable stores with occurs checks and trails L-store L3
Guards and supports guard formulas, their proof-producing normalization, support antichains, activation L-store L3
The theorem store guarded theorems: registration, instantiation, application, indexed lookup L-store L3
Law bundles records naming the constants and laws an engine needs, validated against their expected statements L-bundles L3
Conversions proof-producing rewriting combinators L-engines L4
The engine protocol requests, candidates, results, events, and the Engine trait L-engines L4
Proof authoring Session: typed expressions, goal-first and forward proofs, tactics, calculations, theory branches, and transactions — Proof authoring

Boundaries

  • Imports. std, judgment_core, termbank (for its Budget, which the kernel does not re-export), apn_mojo (for Integer and Rational, the values of the kernel's literals: a direct import downward in the system's graph, which the architecture note's section 27.4 allows when declared), and fp_mojo (fp) for its closed sums and shared trees. Nothing else; in particular no concrete theory (scalar), no engine, no persistence (judgment_store imports this package, not the reverse), and not the public judgment facade, which re-exports the authoring types from here.
  • Trust. Nothing here is trusted. Every judgment it hands out was made by the kernel; every claim it makes about a judgment is read from the kernel.
  • State. The library's stores hold one session's handles and live in its transactions: a store built inside a transaction is discarded with it unless its handles are named in the commit (LG5). Durable state belongs to judgment_store.
  • Consumers. judgment_store (recipes, labels), scalar (builders, derived rules, the store, bundles), the public judgment facade (the authoring surface), and engines and coordinators built on the engine protocol.

The package

judgment_shell        → std, termbank, judgment_core, apn_mojo, fp

The module map lists each module with its specification item.

Module group Contents Specification
errors, heads, views, builders, show typed errors, the head-to-declaration index, term views, proposition and term builders, the debug printer L1
recipes, run, derived the recipe language, execution, closedness, the derived rules L2
labels, claims evidence labels and external claims L2
matching, metavars matching modulo ACU, metavariable stores L3
guards, supports guard formulas, normalization, supports, activation L3
store, index guarded theorems, the theorem store, the discrimination index L3
bundles law bundles and their validation L3
conversions conversion combinators L4
protocol the engine protocol's types and the Engine trait L4
equalities, traversal, acu_proofs, function_acu, transport, propositions, conditionals checked equality composition and traversal, ACU proofs, definition transport, proposition decisions, choice conditionals L2–L4
authoring, tactic_data Session, proofs, tactics, and plain-data tactic programs Proof authoring

How the kernel's design constrains this library

  • Handles carry their session. Every structure here that holds handles belongs to one session, and the library never mixes sessions: a handle of another session, a fork included, is WRONG_KERNEL, and a handle whose rows a discard, rollback, or checkout dropped is stale (KERNEL).
  • Terms are canonical. Matching and lookup work modulo the kernel's canonical forms, so two equal-modulo-ACU terms are one term.
  • Proofs are rows. Every session step writes proof rows, which the stateless checker checks; a recipe is a replayable description, not evidence.
  • Weakening is a derived step; the library provides it (DR-1).
  • Literal values are read with literal_of (K2.3), in the theory a term is used in; the library never decodes a literal's bytes.

Shared checked term operations

A primitive recipe step is dispatched to the session's method for its rule. The recipe layer resolves references and repeated groups; the session's methods write the proof rows, and the stateless checker checks them (G6, G9, G10, LG1).

The library delegates representation-sensitive operations to the session: one-layer term and type inspection, binder opening, simultaneous type/local substitution, sort-aware type matching, ACU-instance applicability, type-parameter collection, local occurrence queries, and the headed parts of declarations. The session returns checked handles and owns canonical rebuilding and scope validation. Public library views and HeadIndex remain adapters and snapshots with their documented errors and lifetime rules.

Theory-based entry points let views, printing, matching, theorem stores, and conversions use these queries without constructing a head index. HeadIndex overloads forward their theory after ownership validation. Engine workspaces created with query_view and Scalar's inspection and theorem-registration paths use the same theory-based APIs. Indexed workspaces remain supported without imposing declaration scans or an index lifetime on other callers. Discrimination reads all potentially ACU constants from the kernel's signature index: a head can become applicable after type specialization or a signature extension, so exact current applicability would be too narrow for candidate indexing (Proposition T-4).

Evidence labeling reads a step's dependencies from the session (Step.dependencies): stored proof closures, each theorem's original signature, canonical laws and literal bases, witnesses, and generated facts' owners, each declaration with the class and source the session records. The library attaches tracked external claims. The shared label budget bounds the traversal as well as the library's metadata work.

Printing, positional reconstruction, first-order pattern validation, discrimination keys, claim-guard positions, and derived-rule inspection share the kernel's lazy syntax reader with checked term/type inspection. It resolves declaration identities, type prefixes, and binder slots from kernel metadata. A cursor follows the exact source DAG, including raw binder bodies and sort atoms, without opening binders or normalizing children. Reads validate the original checked root's lifetime; no bank span survives a read. Argument sequences and names are accessed on demand, so bounded printing does not copy unvisited argument lists or payloads. Discrimination keys retain full head identities and original arities, including type and sort slots; wildcard subtrees are skipped before visiting children. Claim guard depth counts implication and universal prefix steps independently of a syntax cursor's binder depth. These consumers keep a deterministic order and shared budgets (G1–G3, LG3).

The library retains search order, ACU partitions, metavariable assignment trails, and positional proof construction. Positional paths refer to occurrences, so shared DAG nodes may need distinct visits. The printer retains display names, formatting, and truncation; positional reconstruction retains its binder environment and verifies its kernel-built terms (LG2). Authoring also retains its own syntax and scope traversal: normalization can erase arguments whose authored free variables still need checking. These traversals cannot be replaced by queries of canonical syntax.

Generic constructive folds, existential derivations, and endpoint-aware equality composition live in the library. Conversion composition and Scalar model proofs use the same equality operations, retaining dependencies even when literal normalization erases equation syntax. The iterative equality walker owns scheduling, binder opening, context-sensitive memoization, and hook validation; consumers supply mathematical replacement policies. These operations remain untrusted derivations through public kernel rules (G2, G3, G6, LG1); they add no primitive inference rule.

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