The workspace
tsox is a Cargo workspace of twelve crates under crates/ and a root package, tsox, that is the public face of the library crates. The split follows the layers the checker already had; it moves code and adds boundaries, and changes no behavior. cargo test --workspace --all-features passes with the same tests as before the split.
Crates
| Crate | Owns | Depends on (tsox) | External |
|---|---|---|---|
tsox-base | Identities and hashing (keys, stable_hash, fxhash), diagnostics and their codes, FileId, LineIndex, check options, the project-wide small helpers (stack_guard, source_depth, reference_directives), the generated list of tsc's global type names, the vendored TypeScript lib files (lib/, data only), the scratchpad | none | thiserror, xxhash-rust; serde (wasm), bumpalo (scratchpad) |
tsox-types | The type system: TypeArena and Type, subtyping, generics inference (semantic/), namespace, type_annotation, type_display, explain, and portable (declarations as arena-free data, ImportSource) | base | oxc_ast, oxc_ast_visit, oxc_span, oxc_semantic, smallvec |
tsox-model | The semantic model: arena-free, offset-free, versioned tables (node type, node symbol, flow facts, constants, module info) that emit, the language server and the IR read. The checker writes it on each unit's output (UnitOutput.model). Expression-node types are not in it yet | base, types | xxhash-rust |
tsox-checker | The single-file checker: bridge/ (parse, bind, declare, imports, exports, narrowing, statements, expressions, whole-file passes) and unit (a file as a unit of work: UnitContext, UnitOutput, Worker) | base, types | oxc parser, allocator, cfg, semantic; tracing |
tsox-project | Many files: module_resolution/ (graph, config, discovery, resolver, check, schedule, partial results), scc. Feature incremental switches on the hooks the query layer needs | base, types, checker | oxc_resolver, rayon |
tsox-db | The Salsa query layer over the project driver (incremental, incremental/project.rs) | base, types, checker, project | salsa |
tsox-cli | The tsox command line: src/main.rs and its integration tests in tests/ (cli_project, corpus_aborts, depth_guard, determinism, partial_reasons, recursion_guards). The binary is still named tsox, so target/release/tsox and cargo build --bin tsox are unchanged | tsox (facade only) | mimalloc (optional) |
tsox-lsp | The language server: a stdio tower service with a worker that owns the incremental project, hover, navigation, symbols and diagnostics (see lsp) | tsox (facade, with its incremental feature), tsox-base | tokio, tower-lsp-server, oxc parser and semantic, tracing |
tsox-wasm | The browser front end: TsoxChecker, a wasm-bindgen cdylib (src/lib.rs) | tsox (facade only, with its wasm feature) | wasm-bindgen, serde, serde-wasm-bindgen, console_error_panic_hook |
tsox-emit | JavaScript emit: parse, strip types with Oxc's transformer, print with source maps (emit_js). Reads the semantic model only for import elision and const enum inlining | base, model | oxc_parser, oxc_semantic, oxc_transformer, oxc_codegen |
tsox-ir | A typed mid-level IR for native and WASM back ends; every value records whether its type is trusted. A skeleton: nothing lowers into it yet | base, model | none |
tsox-xtask | The development tools: the harness and compare-tsc binaries (src/bin/) and harness_launcher | tsox (facade only) | xxhash-rust |
tsox (root) | The facade: src/lib.rs re-exports the public API. Also the library's integration tests in tests/, the benches and the examples | base, types, checker, project, db | oxc crates, tracing |
The rule
A crate depends only on crates above it in the table. The order is
tsox-base < tsox-types < tsox-model < tsox-checker < tsox-project < tsox-db < tsox < tsox-ir < tsox-cli | tsox-emit | tsox-lsp | tsox-wasm | tsox-xtasktsox-ir is a skeleton. The five on the right share the top layer: each depends on the lower crates it needs and none on another. tsox-cli, tsox-lsp, tsox-wasm and tsox-xtask are the front ends and the tools, and they reach the checker through the tsox facade.
Dev-dependencies count. cargo xtask layering reads cargo metadata, fails on any dependency that is not strictly downward, and fails when a crate has no layer. It runs first in scripts/ci.sh, so a violation stops CI before anything compiles. To add a crate, put it in LAYERS in that script and in the table above.
Two consequences hold the design together:
- No
TypeIdcrosses a unit. A unit's output is the arena-free data inportable(PortableDecl,ModuleExports). That is whytsox-projectandtsox-dbcan schedule and memoize units without knowing how the arena works, and whytsox-dbneeds from the checker only theCancelToken(it imports nothing frombridge). - The checker does not know about the driver or Salsa.
tsox-checkerruns one unit;tsox-projectdecides the order and parallelism;tsox-dbdecides what has to run again. (See query-layer.)
Known limit: tsox-types depends on oxc_ast and oxc_semantic (symbol and node ids in the arena and the annotation resolver). The type system is independent of the checker's traversal code, not of Oxc.
Features
Features live on the crate whose code they gate, and the root package forwards them.
| Feature | Defined on | Effect |
|---|---|---|
module-resolution (default) | tsox | Pulls in tsox-project, oxc_resolver, rayon; the CLI's project mode |
incremental | tsox | Pulls in tsox-db and tsox-project/incremental; --incremental, --watch |
scratchpad | tsox-base, forwarded by tsox | Bump scratch for one worker |
wasm | tsox | Serialize/Deserialize on the diagnostic types, via tsox-base/wasm. tsox-wasm turns it on |
module-resolution (default), incremental | tsox-cli | The binary's own gates. Each one switches on the tsox feature of the same name, so the CLI code and its tests keep their cfg(feature = ...) |
mimalloc | tsox-cli | mimalloc as the binary's global allocator: cargo build --release -p tsox-cli --features mimalloc |
test-hash-seed | tsox-base | Exposes fxhash::TEST_HASH_SEED outside this crate's own tests. Only from a dev-dependency (tsox-project does) so its determinism tests can vary hash order |
cfg(test) is true only for the crate being tested. Anything a dependent crate's tests need from a lower crate has to be a feature, not cfg(test); the split first broke exactly this (TEST_HASH_SEED, now fixed).
The front-end crates
The CLI, the wasm front end and the tools used to live in the root package. They moved out so the root is only the facade, and each front end depends on nothing but that facade.
- Tests move with the binary they start. Cargo sets
CARGO_BIN_EXE_<name>only for the package that defines the binary, so the six CLI test files moved tocrates/tsox-cli/tests/andharness_launchertocrates/tsox-xtask/tests/. Their test names are unchanged. - The repository root.
harnessandcompare-tscread.harness/andtests/from the repository root, andcorpus_abortsreads.corpus/(fetched bycargo xtask corpus) andtests/corpus/. Each finds the root withPath::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(2): the crates sit two levels down, andancestorskeeps the path asCARGO_MANIFEST_DIRspells it, whichstrip_prefixon tool output relies on (a../..join would not). default-members. A workspace with a root package selects only that package by default.default-members = [".", "crates/tsox-cli", "crates/tsox-xtask"]keepscargo build,cargo build --release --bin tsoxandcargo run --bin harnessworking unchanged, which CI,scripts/harness.shandscripts/compare-local.shuse.tsox-wasmis left out: it builds for a wasm target.- The wasm artifact is renamed. The build now selects the crate, and its output is
tsox_wasm.wasm(it wastsox.wasm):cargo build --profile wasm-release -p tsox-wasm --target wasm32-unknown-unknown, thenwasm-bindgen --target web --out-dir pkg target/wasm32-unknown-unknown/wasm-release/tsox_wasm.wasm. A consumer that importstsox.jsfrom the bundle needs the new name. - The root library is an
rlibonly. It was acdylibtoo, for the wasm build; that artifact now comes fromtsox-wasm. tests/at the root still holds the integration tests that go through the facade, and the shared fixtures and corpora the front-end tests also read.
Commands
cargo build # the tsox CLI, harness and compare-tsc
cargo build --release -p tsox-cli --features mimalloc # release CLI with mimalloc
cargo build --profile wasm-release -p tsox-wasm --target wasm32-unknown-unknown
cargo test --workspace --all-features # every crate's tests and the integration tests
cargo check --workspace --no-default-features # every crate without the optional layers
cargo xtask layering # the dependency rule
bash scripts/ci.sh # the branch gate: fmt, layering, check, test--workspace matters: a bare cargo test runs only the default members (the root, tsox-cli and tsox-xtask), which would skip the unit tests in tsox-base, tsox-types, tsox-checker, tsox-project and tsox-db.