overview design

Sources: original to this vault (design and analysis; no single paper)

Theory (CT-ML wiki): Curry-Howard-Lambek Correspondence · E-Graph · Institution · Attributed C-Set

This folder is the design half of the vault. Background Concepts explains background concepts, State of the Art surveys what other people have built, and these notes state what Sophia itself is supposed to be: a content-addressed graph database of code, its types, its proofs and all of its intermediate representations, with a compiler that is expressed as queries over that database.

The one-paragraph version

Every syntactic object — a declaration, a type, an expression, an MLIR operation, an LLVM instruction, a test, a doc comment, a proof — becomes a node keyed by a hash of its own normalised structure (see Hashing and Identity). Relationships between them — “has type”, “lowers to”, “depends on”, “is proved equivalent to” — become edges (see Graph Schema). Frontends elaborate source languages into one common Core Calculus; backends lower core terms through MLIR into LLVM IR. Cross-language unification is not achieved by a calling convention but by storing equivalence edges carrying machine-checkable evidence. Compilation is then a sequence of queries and rewrites over the graph rather than a pass pipeline over a file (see Compilation as Query).

The layer cake

JuliaC++LeanSophiaCoreMLIRdialectsLLVMIRmachinecodeelabJelabCelabLlowerlowerllc

Every arrow in that diagram is a stored relation, not a transient step inside a compiler process. If elab_J runs twice on the same input it produces the same hashes and writes nothing new; that is the whole point.

Notes in this folder

NoteWhat it settles
Repository LayoutWhere code and docs live, and why
Core CalculusThe common language every frontend targets
Hashing and IdentityWhat a node’s identity is, formally
Graph SchemaNode kinds, edge kinds, storage mapping
Equivalence and WitnessesWhat “these two programs are the same” means and how strong the claim is
Compilation as QueryHow a compiler falls out of a database
Multi-AST LayeringTerms, types and proofs as three views of one graph
Effects Memory and ResourcesEffect rows, ownership, GC vs. manual memory
Cross-Language Semantic HazardsThe concrete ways “same thing” turns out to be false
Trusted Computing BaseWhat has to be correct for any of this to mean anything
Naming and Change PropagationNames as mutable labels over immutable hashes
Tests and Documentation as NodesNon-compiled statements in the graph
Content-Addressed PrecompilationThe original Julia motivation, made precise
Query CookbookConcrete queries in Cypher, Datalog and SQL
RoadmapMilestones M0–M7
Open Problems and RisksHonest list of what may sink this
GlossaryProject vocabulary

Three claims this project is making

  1. Identity should be structural, not nominal. Borrowed wholesale from Unison / Content-Addressed Code. This part is known to work.
  2. A compiler’s intermediate state is worth persisting. Nobody does this — compilers throw away every IR they build. Whether the query cost of reconstructing IR from a database beats rebuilding it from source is an open empirical question (Open Problems and Risks).
  3. Interop can be an assertion plus evidence, instead of an ABI. This is the genuinely novel and genuinely risky claim; see Equivalence and Witnesses and State of the Art - Cross-Language Interoperability.

See also