← Projects · Code

Write it like Julia.
Prove it where it matters.

sophialang is the planned language of the Sophia code store. You start with nothing specified, and the system chooses: garbage collection, a scheduler, compilation on demand. Where it matters, you take control of one aspect of one section, and it is marked unsafe. Add a proof, and it becomes safe. And because every definition is keyed by its structure, not its file, an edit rebuilds and re-tests only what it can affect.

  • Rust today, sophialang later
  • Part of Sophia
  • Planned · an experiment
function add(a::Nat, b::Nat)::Nat
    match a :: Nat
        zero => b
        succ(k) => Nat.succ(add(k, b))
    end
end
content id 8bcfc885 631dfc75 a61dafd5… 8bcfc885 631dfc75 a61dafd5… 8bcfc885 631dfc75 a61dafd5… 8bcfc885 631dfc75 a61dafd5… 8bcfc885 631dfc75 a61dafd5… 8806a207 045dc0d3 5e6eb9ff… same id

as the editor shows it by default

Julia and Rust printed and parsed by sophialang-syntax today, Lean and Unison planned; ids from sophialang-core

Status sophialang is a plan with a first core. It can be written, printed, parsed and stored; it cannot run. Whether it can meet all of its specifications is what the experiment is for.

Not a text format

A programming system, not a programming language.

sophialang is not stored as text, and it is not meant to be read. What the store holds is the normalised, compressed core term. What you read is a projection of it, in the syntax your configuration asks for. So sophialang is less a programming language than a programming system: one store of definitions, with as many surfaces as its users want. The idea is not ours alone: Unison pioneered code stored by the hash of its structure, with names as labels and no source files, and Sophia builds on it.

  • Stored

    Normalised and compressed

    No names, no variables, no whitespace: de Bruijn indices, references as 32-byte hashes, shared structure stored once. It is not meant to be read by anyone.

  • Shown

    In the syntax you choose

    Julia-like, Rust-like, Lean-like, Unison-like or one you configure: a profile is a setting, stored like any other. Two people can read one definition in two syntaxes and edit the same id.

  • Planned

    Agents on the graph

    Today models work through a profile, Julia-like text, and every write is parsed back. We want agents that work on the graph itself: core terms and mined abstractions, with no frontend language in between.

From Sophia's notes Compression and Canonical Form and LLMs and Mixed-Language Code. Compression here is structural sharing, which exists; mining a corpus for abstractions is planned, as a derived layer that never changes ids. Julia and Rust profiles exist; Lean and Unison are planned. Sophia's agent server already lets models query and read the store; agents that edit the graph directly are for the future.

autoresolve → unsafe → safe

Pay for control only where you need it.

Today the hardest part of a program picks the language for all of it. One hot loop that needs manual memory, and the whole codebase lives under a borrow checker; one prototype that needs to move fast, and nothing can ever be proved about it. sophialang makes the choice per section of code and per aspect (memory, concurrency, compilation), each on three levels.

Nothing is specified. The system picks garbage collection, a work-stealing scheduler and compilation on demand, and records what it picked. Like Julia.

section memorythreadscompile
main the entry point
load reads the configuration
simulate! runs the steps
step! the hot loop
save writes the results

autoresolve: the system chooses unsafe: explicit, marked safe: explicit, proved

Runtime linked into the binary

  • GClinked
  • schedulerlinked
  • JITlinked

nothing beyond what C needs

Audit: unproved unsafe sections reachable from main

    none

    Content ids changed by proofs

    0

    proofs are annotations, never part of the id

    An illustration of the rules in SPEC-002 §2–§3, drawn in your browser; nothing is compiled. A runtime library is linked only when some section leaves its aspect to the system; the audit is the query Rust's unsafe keyword makes possible, extended to memory, concurrency and compilation. “Mostly safe”, a proof with named assumptions, is recorded as such and never rounded up.

    Keyed by structure

    Change one thing. Rebuild one thing.

    In Sophia a definition's identity is the hash of its normalised structure, and so is every compiled specialisation and every test result. A rename changes no hash. A proof changes no hash. A real edit changes the hashes of exactly the definitions that refer to it. So the question “what must be recompiled, which tests must re-run?” has a precise answer, instead of “the package”.

    Change one thing:
    Keyed by files and packages a typical build cache
    Keyed by files and packages Nat + add even double mean fib test fib test add test even test double test mean
    0/ 7 definitions recompiled
    0/ 5 tests re-run
    Keyed by structure sophialang’s rules
    Keyed by structure (Int64, Int64) (Float64, Float64) Nat + add even double mean fib test fib test add test even test double test mean
    0/ 7 definitions recompiled
    0/ 5 tests re-run

    A toy program; the rules are those of SPEC-002 §4 and §8. The Nat case is sophialang-core's own dependency test: changing Nat changes add and its test, but not double. Tools differ in how coarse they are today (Julia's package images, a crate, a file), and a precise cache is what content-addressed precompilation is about: the win is not caching, it is precision of invalidation. A test with effects that escape the store (files, network, clocks) is never cached. Content-addressed definitions, with names as labels, come from Unison.

    Why another language

    One language, from prototype to proof.

    Julia showed that dynamism and performance can be reconciled by design. Rust showed that safety can be checked without a garbage collector. Lean and Idris showed that proofs and programs can be one thing, and Idris 2 that types can cost nothing at run time. Unison showed that code can be identified by the hash of its structure rather than by its name or file. sophialang is the bet that these do not have to be five different languages.

    choosing a language todaysophialang, the goal
    Getting startedPick the language by the hardest part of the program: dynamic and garbage-collected, or explicit and checkedWrite nothing about memory, threads or compilation; the system chooses, as Julia does
    Low-level controlAll or nothing per language: a borrow checker everywhere, or none anywherePer section and per aspect: explicit memory in the hot loop, defaults everywhere else
    GuaranteesWhat the language's one fixed checker can seeProofs where you write them, in a DSL per aspect, checked by a versioned checker
    The type systemFixed by the languageExchangeable: a dependent, refinement or other checker is something a build may require, never something the code generator needs
    Cost of types and proofsZero in some languages, boxes and checks in othersErased: no run-time representation unless the program asks for one
    RuntimeAlways there (GC, JIT), or neverLinked only for the aspects some section leaves to the system
    What a function isText in a file, at a lineA definition keyed by the hash of its normalised structure; names are labels on it
    After an editRebuild and re-test by file, crate or packageExactly the changed ids and what depends on them
    Computational trinitarianism

    Three views of one subject. One language.

    Computational trinitarianism is Robert Harper's name for an old observation: logic, type theory and category theory are three views of one subject. A proposition is a type is an object; a proof is a program is a morphism. Each correspondence is a theorem, so what is found in one view holds in the other two.

    logictype theorycategory theory
    a proposition Aa type Aan object A
    a proof of A ⊢ Ba program x : A ⊢ t : Ba morphism A → B
    A ∧ B, A ∨ Ba pair, a sum typea product, a coproduct
    A ⇒ Ba function type A → Ban exponential object
    a Horn clausea Datalog rule, a relationa relation in a regular category

    So sophialang is not three languages.

    Most systems ship a type language, a query language and a proof language, each with its own syntax, its own semantics and its own tools. Under the trinity they are the same thing seen three ways, and sophialang treats them as one language over one store.

    • The typing language. A specification is a type, stored as a definition like any other. Dependent, refinement or ownership types are sophialang, not a second notation bolted on.
    • The query language. A query is a set of Horn clauses over the store's facts: logic programs, written as sophialang relation and rule definitions, hashed and named like functions.
    • The logic. A proof is a term of the type it proves. It is stored, hashed, renamed and queried like code, and erased before the program runs.
    Compiling is a query · Sophia's query syntax
    # everything main depends on, statically:
    # a graph walk over the store's refs
    query closure(main::Id)
        dep(a, b) = refs(a, b)
        dep(a, c) = refs(a, b) && dep(b, c)
        select d where dep(main, d)
    end
    
    # the binary is the compiled answer, plus the
    # methods dispatch can reach at pinned versions
    binary(main) = compile(closure(main) ∪ dispatch_closure(main))
    An exact binary is a query

    Because a definition's id is the hash of its structure, the set of everything main needs is not a guess: it is the answer to a recursive query over the graph store. Compiling to a minimal binary is that query, compiled. No “include the whole package”, no heuristic tree shaking. Types, proofs, tests and the store itself are erased, and a GC, dispatcher or JIT is linked only when some section of the closure asks for it.

    From Sophia's notes Computational Trinitarianism and Minimal Binaries; see also Harper, The Holy Trinity (2011). Today Sophia's query language runs (it is the store's only language at L5) as its own crate on shared primitives; folding it into sophialang's relations is the design, not yet the code. The query above is in that syntax; compile and the dispatch closure need M5. The binary is exact under a closed-world contract: no eval, reflection or dynamic loading unless their runtime is linked.

    Zero inherent overhead

    Types and proofs cost nothing at run time.

    sophialang may contain nothing that makes compiled code inherently slower than C++, Rust or Julia. When in doubt about behaviour, it does what Julia does: machine integers, IEEE floats, multiple dispatch, promotion as ordinary methods.

    • Erased. Every binder carries a usage; usage-0 binders (types, proofs) have no run-time representation. The quantitative type theory of Atkey and Idris 2.
    • Exchangeable. The code generator needs only representation types and the types dispatch sees. A dependent or refinement checker changes what a build accepts, never what it generates.
    • Visible costs. Concrete types are unboxed. An abstract type is boxed because you asked for it, and the store records the fact.
    • No store in the hot path. Every identity is resolved at build time; the compiled program never queries the store.
    A sketch of the intended surface · none of this runs yet
    # autoresolve: GC, JIT, dynamic dispatch,
    # chosen for you and recorded as facts
    function mean(xs::Vector{Float64})::Float64
        sum(xs) / length(xs)
    end
    
    # unsafe: explicit memory, shown in every view
    function step!(w::World)
        unsafe(:memory) do
            buf = alloc(w.arena, Float64, w.n)
            # …
        end
    end
    
    # safe: the same code, plus a checked proof;
    # step!'s content id does not change
    proves(:memory, step!, Ownership(w.arena))
    Where it stands

    An experiment, with a first core.

    sophialang exists as specifications and two Rust crates, sophialang-core and sophialang-syntax. They are already what Moonkale edits through Sophia. Everything that makes it a language you can run is planned. We do not know yet whether all of it can be had at once; finding out is the point.

    levelstate
    L1 · Parsed Two rendering profiles; a parser with limits and diagnostics exists
    L2 · Normalised Core terms, canonical encoding, hashing; names never change ids exists
    L3 · Resolved Locals, the store's names, built-ins and constructors exists
    L4 · Lowered The target IR: other languages would lower into it by design
    L5 · Executable No evaluator and no type checker yet planned
    L6 · Verified Not yet planned

    Not built yet

    • An interpreter over core terms: nothing runs yet (milestone M4)
    • A type checker, dispatch resolution as stored facts, tests as cached facts (M4)
    • Lowering to LLVM, minimal binaries, a JIT cache keyed by content id and argument types (M5)
    • The proof DSLs for memory, concurrency and compilation
    • A language for defining type systems: the third part of sophialang, not yet specified
    • Self-hosting: sophialang written in sophialang (M6)

    Open questions

    • Open method tables against content addressing: generic functions must be nominal, and invalidation must be precise (SP-006)
    • Relations need an identity of their own: two with the same signature and no rules would otherwise be one
    • Whether the proof DSLs are something working programmers will write
    • Whether Julia's semantics, zero overhead and optional dependent types fit in one language at all

    From Sophia's vault: the SophiaLang overview, the principles, the core calculus, SP-006 and the open problems and risks.

    The road

    1. M4

      It runs

      An interpreter over core terms, a simple checker, dispatch resolution recorded as facts, and tests cached as facts.

    2. M5

      It compiles

      Lowering through MLIR to LLVM, minimal binaries, and a JIT cache keyed by content id and argument types.

    3. M6

      It hosts itself

      The printer in sophialang, then the compile DSL and the dependent checker; the Rust code becomes a small bootstrap kernel.

    4. B-037

      Type systems as data

      A language for defining type systems, so a checker is a stored, versioned thing a build can ask for.

    5. Later

      Agents on the graph

      Models that read and write core terms and mined abstractions directly, instead of working through a frontend language like Julia.

    6. B-045

      In the browser

      sophialang compiled to WebAssembly, and Sophia's crates opened and queried in a browser.

    7. P0 · 3

      Reproducible dispatch

      A method table changes, and an earlier world still reproduces the original calls. It passes in the store; end to end it needs M4's interpreter.

    Milestones and backlog rows as in Milestones; none has a date.

    Get involved

    Tell us where it breaks.

    sophialang is an experiment, and we are learning as we go. If you work on Julia's compiler, Rust's ownership model, quantitative or dependent type theory, separation logic or build systems, and you see why this cannot work, or how it could, we would like to hear from you.