02 — Workspace & Crates

A Cargo workspace of small, single-responsibility crates. The crate dependency graph is a DAG by construction — Cargo refuses cycles, so law L5 (enforced boundaries, no monolith, no "circular imports") is guaranteed by the build system, not by discipline. Each crate has a soft size budget (~2–4k lines); crossing it is a signal to split.

Crate DAG

flowchart TD
    base --> syntax
    base --> diagnostics
    syntax --> hir
    diagnostics --> hir
    base --> ty
    hir --> ty
    db["skydb (salsa database + queries)"]
    syntax --> db
    hir --> db
    ty --> db
    db --> lower
    lower --> codegen
    codegen --> project["project (build driver, sky.toml, ffi, go build)"]
    db --> project
    ffi["ffi (deterministic Go inspector interface)"] --> project
    project --> cli["sky (build/run/check/fmt/doc/test/watch)"]
    db --> lsp["sky-lsp"]
    ty --> lsp
    project --> lsp
    fmt["fmt (formatter over CST)"] --> cli
    syntax --> fmt
    project --> testrunner["testrunner (sky test)"]

Crates

CrateResponsibilityKey depsDoc
baseInterners, ids (FileId/ModuleId/DefId/Name/Span), arenas, Text, small utils. No logic.la-arena, smol_str, indexmap01, 03
diagnosticsDiagnostic type, severities, labels, suggested fixes, one renderer for CLI + LSP (Elm-style output).base, annotate-snippets07(L7)
syntaxLexer + lossless CST (rowan), typed AST view, error recovery, layout/indentation.base, rowan, logos(lexer)04
hirDesugared, name-resolved high-level IR. Imports, scopes, DefId resolution, module items.base, syntax, diagnostics05
tyHM inference, arena union-find, generalisation, exhaustiveness, the type table.base, hir, syntax, diagnostics06
skydbThe salsa database + query spike (target: every query; today: one input + one tracked query, doc 01).salsa, base, syntax, hir, ty, diagnostics01
lowerTyped lowering IR (Sky-typed → Go-IR), type-directed lowering, inline auto-TCO, demand-driven DCE. No monomorphiser — the Go ABI is erased and shape mismatches are closed by eta-expansion (07 §5.1).base, ty, hir, syntax, skydb07
codegenDeterministic Go source emission from the Go-IR; the runtime ABI/interface.base, lower08
ffiDeterministic Go-package inspection → pinned .skyi surface; reproducible, committed.base, serde, serde_json, include_dir09
projectsky.toml, module discovery, dependency graph, driver that runs the build + go build, stdlib embedding.skydb, codegen, lower, hir, ty, syntax, base, ffi08, 09
fmtsky fmt — opinionated formatter over the CST (idempotent, trivia-safe).syntax04, 10
skyThe sky binary: build/run/check/fmt/doc/test/watch/add/etc.project, fmt, testrunner10
sky-lspLSP server over the resolution db (target: the same skydb). Hover/goto/completion/diagnostics/references/rename/semantic-tokens.base, syntax, hir, ty, skydb, project, diagnostics, tower-lsp, tokio10
testrunnersky test (Sky.Test) runner.project10
xtaskDev automation: run corpus, differential-test vs Haskell oracle, reproducibility gate.syntax, base, hir, ty, project, diagnostics11, 12

Implementation status. The Key deps column above reflects the actual Cargo.toml of each crate. Note that lower, project, sky-lsp, and xtask depend directly on the frontend crates (hir/ty/syntax/diagnostics) rather than reaching them only through skydb — because the running pipeline threads values through hir::db::SourceDb, not the salsa DAG (see 01 status). skydb is on the graph and depended on, but as the M0 salsa spike, not yet the assembly point for "the whole compiler". The crate DAG itself (who may depend on whom) is as drawn and enforced by Cargo.

Key external dependencies (and why)

Rules of the workspace