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.
| # | Decision | Reason | Reopen when |
|---|---|---|---|
| 1 | DeclKey is identity, SigHash is version | A signature inside the id changes the id of every referrer on each edit, which defeats early cutoff | Never expected; the rest of the key scheme rests on it |
| 2 | Aliases are transparent wrapper nodes (Named) | A side table keyed by id is what forces set() and make_unique today | Measurement shows the wrapper costs more than the table it replaces |
| 3 | Union display order is first writer wins, in a side table | Identity stays canonical and messages keep the written order, closest to tsc | The tsc comparison shows order mismatches that matter |
| 4 | A 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 incomplete | One 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-settlement | A shared arena per component becomes cheap because of other type-system work, or cycles that do not settle turn up in real projects |
| 5 | Hash function is XXH3-128 | Already a dependency, and fast | Input must be treated as adversarial |
| 6 | The hash is computed lazily, at an export boundary | Most types never leave their file | A test shows lazy and eager hashing disagree |
| 7 | Salsa is pinned at =0.28.5 | It is what the query layer builds on, and the behaviours it relies on are pinned by tests | The behaviours pinned in crates/tsox-db/src/incremental.rs stop holding on an upgrade |
| 8 | A module key follows the rule in "The module key, in one place" below | An 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 |
| 9 | FileId is a run-local index, sorted by canonical path | Output order must not depend on discovery order, and ids must not be stored | Never expected; it only works if no key uses it |
| 10 | Intersection identity is ordered, deduplicated by id, never sorted | Call-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 |
| 11 | Intersection reduction has two levels: ids and wrappers at construction, bodies lazily | A decision that read a body while a declaration was unresolved would bake a wrong answer into the intern table | Never expected; it is the placeholder bug turned around |
| 12 | A product of union sizes of 100,000 or more is TS2590 | Same cap as tsc. Reported as TSR1701, mapped to TS2590 (d3662d7), where it used to become the error type silently | A budget on recursive work needs it lower (see safety-net-and-limits) |
| 13 | A new Type variant goes at the end of the enum | Adding 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 nothing | Never expected to matter again |
| 14 | A bare return f(...) inside f is not a return-type read | tsc 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 returns | Inferring 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) |
| 15 | Units start on a dependency count, and results are read by unit index | A 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 run | The export tables are merged in an order that depends on finishing order, which means publication has to be ordered by unit index first |
| 16 | The project driver runs on the ready queue, from frozen globals, and a second pass only when the first found something global | A 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 file | On 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 |
| 17 | The 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 other | The 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.wasm | A 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
Project : path relative to the project root, "/" separators
Package : package name, version, path inside the package
External : absolute canonical pathA 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.