Repository navigation
fix(lint): type-check every file before rules run under --type-check - #955
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
65fbbe8 to
6f8ab3e
Compare
Performance change vs mainWorkflow run · main Clef gate: Running benchmarks because the decision was unavailable (crates/tsrs_lint/src/engine.rs: patch exceeds the Clef context limit (5766 bytes)). Release builds in fast mode (TSRS_FAST=1) with Hyperfine 2 hardware counters. After warming each binary, alternating main/PR pairs measure wall time at both the fast preset's default checker count and with --singleThreaded, with ten pairs per configuration by default. Instructions come from the single-threaded runs; peak RSS comes from the default-count runs.
Negative means the PR used less; positive means it used more. Deltas are medians of paired PR/main ratios for wall time and instructions. Single-threaded runs reduce scheduling noise; shared CI machines can still add noise to wall time. Measured medians (main → PR)
tsrs-lintRelease
Negative means the PR used less. Wall and CPU time deltas are medians of paired PR/main ratios; peak RSS compares medians. Measured lint medians (main → PR)
|
Summary
With
--type-check, each checker used to type-check a file and then run the rules on it, one file at a time. A rule's type query could then build a type before the checking thattsrs --noEmitdoes. Any error the checker hit there had no location, so it was reported on the tsconfig as a global diagnostic. Checking a later file on the same checker also lost the error, because the type was already cached.run_programnow runs its per-file loop twice: first type-checking only, then rules only, on the same checkers. It collects the program's global diagnostics between the two passes, so diagnostics recorded while answering rule queries are never reported.Example
a.ts(listed, withno-unsafe-enum-assignment):b.ts:tsgo --noEmit/tsrs --noEmitb.ts(2,1): error TS2590tsrs-lint --type-check, beforetsconfig.json:1:1 TS2590tsrs-lint --type-check, afterb.ts(2,1) TS2590The issue's own program,
a.tsalone, now reports nothing, which matchestsgoandtsrs --noEmit.Dropping the global diagnostics that a checker adds while rules run, as the issue suggests, would not be enough:
b.tswould still miss its error.Fixes #941
Real-world case
On t3code-server (a catalog project),
--type-checkon main reportspackages/contracts/tsconfig.json:1:1 TS2590. This branch doesn't, which matchestsgoandtsrs --noEmit: neither reports any error for that project. Apart from that one diagnostic, the output is identical.Performance
The two passes don't repeat work: each file is still type-checked once and linted once. The only added cost is a second trip through the checker pool, and on large projects with
--type-checkthe rules running after every file is checked rather than right after their own file.These numbers compare release
tsrs-lintbuilds of main and this branch with all 61 rules. Wall time and peak RSS are medians of 8 interleaved main/branch pairs on default checkers. Instructions retired are medians of 3 runs with one checker (RAYON_NUM_THREADS=1). Measured on macOS arm64 with/usr/bin/time -l(10 ms wall resolution).--type-check--type-check: the output is byte-identical, and wall time, peak RSS and instructions are within noise.--type-check: there is a small cost, about 1–2% more instructions on the larger projects. On vscode, an earlier 2-pair round measured +0.8% instructions and +2.4% wall time, against +1.7% and +5.4% here, so the wall-time number is noisy. Peak RSS does not change.Where the
--type-checkcost goesI measured instructions and cycles separately for the type-check part and the rules part of each file. This was single-threaded on vscode with
--type-check, two runs each, using temporaryproc_pid_rusageprobes that are not in this PR.The checker does the same work, and type checking costs the same. The rules phase is slower for two reasons:
flowmemo.rs. Now every later file has been checked first, and those entries are no longer usable, so the rules re-walk the flow graph.TSRS_FLOW_MEMO=0), the instruction gap disappears: 122.5G vs 122.1G.TSRS_FLOW_MEMO_BITS=20) keeps the gap at +3.1G, so entries are being invalidated rather than evicted.Making the memo's invalidation finer-grained could recover most of this, but that is a separate checker change.