Skip to content

Decisions ​

Architecture case study: what the design decided, why, and what would reopen each decision.

This page is the short list of decisions the design took, so a later change can check itself against them. Each decision stays as it is until the condition in the last column happens. The longer account of each area is in architecture and the case studies it links to.

#DecisionReasonReopen when
1DeclKey is identity, SigHash is versionA signature inside the id changes the id of every referrer on each edit, which defeats early cutoffNever expected; the rest of the key scheme rests on it
2Aliases are transparent wrapper nodes (Named)A side table keyed by id is what forces set() and make_unique todayMeasurement shows the wrapper costs more than the table it replaces
3Union display order is first writer wins, in a side tableIdentity stays canonical and messages keep the written order, closest to tscThe tsc comparison shows order mismatches that matter
4A cycle is one unit. Its members are checked again in rounds, each reading the previous round's snapshot, until what they export stops changing or the bound runs out. A cycle that does not settle is marked incompleteOne arena per component would let members see each other directly, but it would change how types are stored and how recursive references are held, which is the type system's design and not the project driver's. Repeating the check keeps each member in its own arena and keeps the unit a clean contract: scheduling, settlement, publication and failure isolation are all per component. The bound is one round per member plus a spare, never fewer than four (cycle_round_cap); see cycles-and-settlementA shared arena per component becomes cheap because of other type-system work, or cycles that do not settle turn up in real projects
5Hash function is XXH3-128Already a dependency, and fastInput must be treated as adversarial
6The hash is computed lazily, at an export boundaryMost types never leave their fileA test shows lazy and eager hashing disagree
7Salsa is pinned at =0.28.5It is what the query layer builds on, and the behaviours it relies on are pinned by testsThe behaviours pinned in crates/tsox-db/src/incremental.rs stop holding on an upgrade
8A module key follows the rule in "The module key, in one place" belowAn id has to survive moving the project and a different install layout. Implemented in crates/tsox-base/src/keys.rs (45b6098)A platform test shows two spellings of one file get two keys
9FileId is a run-local index, sorted by canonical pathOutput order must not depend on discovery order, and ids must not be storedNever expected; it only works if no key uses it
10Intersection identity is ordered, deduplicated by id, never sortedCall-signature order depends on member order, and callability needs a body that may not exist yet. tsc does the same (probed on 5.9.3; the comparison tooling is now on 6.0.3)A fixture shows overload order through intersections is not needed
11Intersection reduction has two levels: ids and wrappers at construction, bodies lazilyA decision that read a body while a declaration was unresolved would bake a wrong answer into the intern tableNever expected; it is the placeholder bug turned around
12A product of union sizes of 100,000 or more is TS2590Same cap as tsc. Reported as TSR1701, mapped to TS2590 (d3662d7), where it used to become the error type silentlyA budget on recursive work needs it lower (see safety-net-and-limits)
13A new Type variant goes at the end of the enumAdding Intersection after Union changed an unrelated diagnostic count from 5 to 1. The cause was a digest collision between two literals, not the order; it was fixed in 91454fa and nothing depends on the order any more. The variant still goes last, which costs nothingNever expected to matter again
14A bare return f(...) inside f is not a return-type readtsc leaves a call to the function itself out of the return type, so return gcd(b, a % b) has no error under tsc 6.0.3 and gets none here. A self call inside a larger expression (n * f(n - 1)), as an argument of another call, or through a second function is still a read and still gets TS7023. The inferred type of the bare call stays the placeholder any, where tsc gives the type of the other returnsInferring the return type ignores the bare call the way tsc does, which needs an answer for a function that returns only itself (tsc gives never)
15Units start on a dependency count, and results are read by unit indexA layer barrier makes a unit wait for the slowest unit of its layer. The scheduler starts a unit when the last unit it waits for finishes, a unit reads only those results, and the outcomes come back indexed by unit, so nothing depends on finishing order. A panic or a cancel is recorded per unit and dependents still runThe export tables are merged in an order that depends on finishing order, which means publication has to be ordered by unit index first
16The project driver runs on the ready queue, from frozen globals, and a second pass only when the first found something globalA layer barrier made a file wait for the slowest file of its layer, and every file was checked twice, because the test for a second pass asked whether the UMD table was empty and the table had an entry for every file. A file now runs as soon as the components it imports have finished and reads only what those published, by file, plus a value for the whole pass that is built before the pass starts (ambient modules, augmentations, UMD namespaces and the declarations behind them). The second pass runs only when the first produced a UMD alias, an augmentation, or an ambient module outside a provider fileOn the 10,083 corpus files as one project the output is byte-identical to the layered driver, and the run went from about 2.3 s to about 1.0 s. A unit must never read a file it does not wait for, which holds by how keys are made and is not checked at run time. An unsettled cycle used to get the budget twice by accident, so with a deliberately tiny bound its files may now keep an unresolved-annotation warning, never a missing-name error
17The checker is a workspace of twelve crates: six layers with a one-way dependency order, a tsox facade, an IR skeleton, and a top layer of front ends, emit and tools (tsox-cli, tsox-lsp, tsox-wasm, tsox-emit, tsox-xtask) that depend on none of each otherThe layers already existed in the code (identities, type system, semantic model, single-file checker, project driver, query layer). Crate boundaries make the order a compile-time rule instead of a habit, so the checker cannot learn about the scheduler or Salsa, and no TypeId crosses a unit. The order is tsox-base < tsox-types < tsox-model < tsox-checker < tsox-project < tsox-db < tsox < tsox-ir < tsox-cli, tsox-lsp, tsox-wasm, tsox-emit, tsox-xtask, checked by cargo xtask layering in CI, dev-dependencies included. Test-only hooks a dependent needs from a lower crate are features (test-hash-seed), because cfg(test) is true only for the crate under test. The front ends left the root package so it is only the facade; the integration tests that start a binary (CARGO_BIN_EXE_*, set only for the package that defines it) moved with it, and default-members keeps cargo build --bin tsox, target/release/tsox and the scripts and CI that use them unchanged. The wasm artifact is now tsox_wasm.wasmA front end needs its own release cadence or a dependency the others should not carry, or the facade grows an API only one front end uses. Then that front end can be published separately

The module key, in one place ​

text
Project   : path relative to the project root, "/" separators
Package   : package name, version, path inside the package
External  : absolute canonical path

A file under node_modules is a Package file when its nearest package.json has both a name and a version, and an External file when none does. A workspace package or a linked package resolves outside node_modules, so it is a Project file. Nothing in a key comes from a FileId, the absolute root or a timestamp.

The cost is accepted and written down: two copies of one name and version with different contents, one patched in place, share a key.

What this changes in the code ​

Decision 9 is the first one that does. ModuleGraph::build still walks the project with discovery ids, but only until the walk ends. It then sorts the discovered paths and renumbers every file and every edge target, so the ids it publishes follow path order and no longer depend on the order the entries were given in. ProjectFiles itself is unchanged and still hands out ids in the order it is asked.

Decisions 5 and 8 are implemented in crates/tsox-base/src/keys.rs and crates/tsox-base/src/stable_hash.rs. How the keys are used is in cross-file-types, and the reasoning behind decision 4 is in cycles-and-settlement.

MIT OR Apache-2.0