Repository navigation
Commit 740c377
checker: a circular generic type's variances no longer depend on where, or on which checker, the circularity was first entered
Variances are measured lazily and cached per checker. On a circularity the type being re-entered reads
as unknown, so whatever is measured above it is measured against that assumption, and upstream restarts
only from the smallest symbol of the part of the stack it can see. Entered from different places, two
checkers measured different variances for the same cycle: in structure's tables model,
TableContextInterface came out [in out] on one and [out] on another, so whether TableContextInterface<TRow>
is assignable to TableContextInterface<unknown> depended on which checker owned the file. tsc has the
same order effect, harder (it has no restart at all).
Four parts close it:
- Regions, the way Tarjan's algorithm finds them. Each variance stack entry carries a serial and a low
link. A variance measured while a region is open is provisional for the rest of that region; when the
region's root completes, it commits if the root is the region's smallest symbol, and otherwise
discards the region's variances and measures again from the smallest symbol with nothing below it.
- Relation results go with them. tsc caches a False as "false under assumptions is false without",
which holds for Maybe assumptions but not for a provisional variance, which can be stricter than the
final one. Results cached while the variance stack is open are logged (setRelationResult, at the three
write sites), and a discarding root deletes its slice of the log.
- A marker type is a marker only while its generic is on the variance stack. Markers share the global
marker type parameters, so another generic instantiated with its own markers can produce the identical
type, and the old grow-only set made whether a reference was compared structurally, and so whether a
cycle was seen at all, depend on what had been measured before. A marker of a generic further down the
stack is still compared structurally, and records a dependency on that entry, since it stands in for a
circular reference. The variance annotation check's markers (markerSubTypeForCheck and its pair) always
count.
- Upstream's immediate restart on detecting a circularity stays, since when it happens decides whether a
type resolution sees TS7022 (classVarianceResolveCircularity2, microsoft#52813). It is bounded: a restart of a
symbol already being restarted further up the chain is skipped, a region rooted inside the restart of
its own smallest symbol is kept, and a variance a restart committed is not marked provisional again.
Checked: go vet; the checker tests and the testrunner pass with no baseline moved (go test ./... fails
only internal/astnav and internal/fswatch, as on e65aa4a). On the whole ahra program, tsgo's output is
byte-identical single-threaded and at 4 and 16 checkers, and a per-checker log of every committed
variance found no disagreement across checkers or runs (3 before). In cohere, --no-fix findings are
byte-identical across 1, 4 and 16 checkers on ahra, www-ahra-ai, www-phi-health and api-phi-health; with
the three order-sensitive cast rules on, ahra and www-ahra-ai stop flipping, and the one finding that
moves on all four, TableRoot.tsx:1128:39, moves to adamic/invariant-mutable, the side typescript-eslint
takes. Instructions retired are unchanged within noise on ahra and api-phi-health.
For cohere's #rt071h3.
Co-Authored-By: Ahra <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>1 parent e65aa4a commit 740c377
3 files changed
Lines changed: 264 additions & 105 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
544 | 544 | | |
545 | 545 | | |
546 | 546 | | |
547 | | - | |
548 | | - | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
549 | 553 | | |
550 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
551 | 564 | | |
552 | 565 | | |
553 | 566 | | |
| |||
645 | 658 | | |
646 | 659 | | |
647 | 660 | | |
648 | | - | |
| 661 | + | |
649 | 662 | | |
650 | 663 | | |
651 | 664 | | |
| |||
796 | 809 | | |
797 | 810 | | |
798 | 811 | | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
799 | 816 | | |
800 | 817 | | |
801 | 818 | | |
| |||
0 commit comments