Repository navigation
[experiment] fully order independent type checking - #65064
Jake Bailey (jakebailey) wants to merge 62 commits into
Conversation
|
TypeScript Bot (@typescript-bot) test it |
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. There were interesting changes: Branch only errors:
|
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Well, that's a little bleak. |
7eda73a to
1846356
Compare
|
Not sure why top400 didn't come back either |
|
TypeScript Bot (@typescript-bot) test it |
1846356 to
c7ee0b9
Compare
|
Hey Jake Bailey (@jakebailey), this PR is in an unmergable state, so is missing a merge commit to run against; please resolve conflicts and try again. |
|
TypeScript Bot (@typescript-bot) test it |
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. There were interesting changes: Branch only errors:
|
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Now we're talking |
|
Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing Something interesting changed - please have a look. Details
|
c7ee0b9 to
c501b1f
Compare
|
TypeScript Bot (@typescript-bot) test it |
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. There were interesting changes: Branch only errors:
|
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing Something interesting changed - please have a look. Details
|
|
TypeScript Bot (@typescript-bot) test it |
A cycle through return types gave different results depending on where it was entered. Entered at rebuild's return type, re-entering it fails rebuild, so both members report an implicit any. Entered at b's return type, subtype reduction of rebuild's return type finds b in progress and compares as if it returned any, without failing anything, so rebuild returns B and was kept as a participant of the cycle, though computing it from scratch fails. Cycles through the types of symbols are already resolved from the member declared first (see yieldCycle). The same now applies to the return types of declared signatures, both when a cycle re-enters a return type and when it only observes one in progress, so that each order gives the result of resolving the first declared member first (seen in effect's SchemaAST). Contextually checking a function expression infers its return type from its body, and that inference was pushed as a return type resolution of the function's signature. When the body calls a function whose return type depends on the call enclosing the function expression, resolving that call requests the function expression's return type, which, seen in progress, returned any without detecting a cycle, so the enclosing function's return type was inferred from a provisional any instead of reporting the circularity (seen in OmniRoute). The inference now runs without marking the signature in progress, as in TypeScript: the nested request computes the return type itself, reaches the enclosing function, and the cycle is reported on both. The result is cached only if no request has already cached one, the same as when the return type is requested directly. The flag marking a function as contextually checked is set before its return type is inferred, and is TypeScript's guard against re-checking the function from within its own check, so it is never discarded. The inferred return type is now kept whenever the flag is, so that a discarded cycle in between cannot leave the flag without the return type, which made a const assertion in the body readonly when queried before its binding pattern.
Completing contextual signatures before anyone reads them switched parameter assignment from the signature of the function's symbol to the signature built from its declaration. In JavaScript the symbol's signature comes from a @type tag when one is present, and the function's parameters take their types from that tag. Using the declaration's signature wrote the outer contextual types onto those parameters instead, producing errors inside the function body that the tag rules out (seen in webpack). Prefer the tag's signature, as before, and fall back to the declaration's signature otherwise.
An instantiation stopped by the limit on the depth of the whole instantiation names every type that recurs in it, in the order in which they recur. Which type of the cycle the instantiation entered first depends on the results cached before, so checkers that had checked different files named the same cycle starting from different types, and reported the same error twice with different messages (seen in zod, with checkers running concurrently). The names now start from the type declared first, so the message is the same wherever the cycle is entered. The limit on the depth of a single computation already names only the types that computation instantiated, which does not depend on where it was entered, so its messages keep the order in which the types recur.
While the type implied by a binding pattern is computed as the
contextual type of its initializer, references to the pattern's
elements from the elements' defaults are any. The calls and types
computed from them were cached anyway, so asking for the contextual
type of the initializer first left `extra` in
const { kind, payload, extra = kind === "a" ? ... : ... } = u;
as any rather than unknown. TypeScript behaves the same way.
Track the patterns as resolutions in progress rather than a separate
stack, so that a reference returning any marks the computation circular
and the results cached from it are discarded.
(seen in check order fuzzing)
A call resolution hides the resolutions below it, so a symbol whose initializer reaches itself through a call argument is computed again, nested in itself, as in main. The nested computation observes things in progress that the outer one entered: here, a mapped property whose contextual type is skipped, and the reverse mapping whose depth cutoff it reaches. Those mark everything since as circular, so the nested result was discarded, and the outer computation, reaching the same types again outside that context, then failed with a circularity. When everything the nested computation observed in progress was entered by the outermost hidden resolution of the same target, the nested computation is the one that resolution always computes first from scratch, whichever entry led to it, so its result is kept as a cycle participant, as main keeps the first result set. Main also keeps the reverse-mapped property type computed under the depth cutoff, so it types the property as unknown. That result still depends on the cutoff and is discarded, so the property is computed again from scratch afterwards, giving its full type: an improvement over main rather than a match (seen in arktype).
When a query enters a cycle somewhere other than its program-order entry, the cycle yields to its first member and recomputes it with the resolutions below hidden. Two things made that recomputation differ from computing the member first: - The reverse mapping stacks, contextual types and inference contexts of the hidden resolutions stayed visible, so the recomputation saw contexts that a computation from scratch never has. A yield now hides them along with the resolutions and restores them when it ends. - Results were kept as cycle participants only by comparing the outermost cycle head in progress against the resolution. A cycle headed below the yield, which the yield cannot observe, caused the yield root and the hidden re-entries of itself to be discarded, so the member was computed again and genuinely re-entered itself. Each type resolution now tracks the lowest cycle head it observed, and a result is kept when the computations it observed were entered from scratch: by the outer resolution of itself, by the yield it is the root of, or by the outermost measurement of variances. (seen in circularScopeThunkReverseMapped)
Which symbols are referenced, which nodes need deferred or unused checks, and which aliases are referenced are facts about a node that only the check of its file consumes. Recording them as effects made nearly every query result carry effects, so emit and other queries without a check retained and walked a large effect graph: --noCheck emit of VS Code used twice the time and memory of main. Each fact now depends only on its node, and the check reaches every node, so the first computation reaching a fact records it. Write-only names are not uses wherever a name is resolved. The check now also checks methods and accessors in destructuring targets and decorators where they are not valid, which only a query computing their types reached before, and follows referenced import = declarations itself once the file's references are marked, so that following them reports errors regardless of which computation cached them first. Marks are written only by checking, or by a computation a check started that entered a cycle. A query records them on its result, and they are replayed even when its other effects are dropped, as whether a computation reaches the nodes they mark does not depend on the results it read. Following a referenced alias to the aliases it refers to computes, so it happens where the alias is referenced, and the mark only records the aliases found. A test finds marks written anywhere else.
When no overload applies, call resolution caches its result before reporting errors, so that a circular request for the call while they are reported finds it. Discarding that result in a cycle restored the marker put in place when resolution began, leaving the call marked as being resolved. Caching it like the final result clears the marker instead.
Signature help resolves a call from the arguments typed so far, without reporting errors, and string literal completions resolve it with inference from the argument being typed blocked. The results those requests cache depend on that state, which is not part of their keys, so checking that reuses them could infer other types or miss errors. Nothing such a request caches is kept: it runs in a cycle headed below every computation, which ends with the request. The state of such a request, the number of arguments typed so far and the nodes inference is blocked from, is held in a request that exists only while it runs, rather than in fields of the checker that any computation could read.
A checker's memos are not its only state: it also holds the state of the computations in progress, such as the contextual types pushed for the nodes being checked, the resolutions on the stack, and the cycles being resolved. The next request reads anything a request leaves there, so none of it may outlast the request that set it. Every field of Checker is now either listed as the state of the computations in progress, which the test harness checks is at rest after every request it makes, or listed with the reason it is not, as the fields of the memo store and links already are. A few fields kept indices or flags after the computation using them finished, which nothing read: the lowest cycle head observed, the cycle flag of errors collected at the current node, the start of a circularity, of a reverse mapping and of a depth limit. They are now left at rest too.
When a variance measurement reaches a type whose measurement is in progress, the results cached until the outermost measurement finishes may be discarded, in case the measurement did not start at the canonical entry of its circularity. Until then, checking switched to recording: storing the effects of each result to apply later, and accounting for them on every read of a cached result. Few measurements are ever discarded, a handful per project, but recording roughly doubles the cost of the work done in the meantime, and each checker measures the shared types again, so with several checkers it accounts for most of the extra time these changes cost on xstate. So checking keeps applying effects during a variance cycle, except those that discarding the measurement would have to take back: errors, suggestions and deferred diagnostics are held until nothing can discard them, and dropped with the results if the measurement is.
Every memoized computation records its key as in progress and removes it when it finishes, so that re-entering it is caught as a cycle. Nearly every lookup finds nothing, yet the hash table made each computation pay for an insertion and a deletion that shifts probe sequences. Counting keys per slot makes the common case one load and one increment; the rare hit searches the resolution stack, which already holds the keys.
Each memo map kept its own record of the entries being computed: their keys, where on the resolution stack each was, and, once there were many, a count of each key. The checker already counts every other computation in progress and finds it on the resolution stack, so map entries are now counted with the rest by a hash of the map and key, and found on the resolution stack when the count says one may be in progress. A map keeps only the keys themselves, which a resolution has no room for.
…ested Finding a computation in progress searched the whole resolution stack whenever its slot of the resolving table was taken, and marking the computations that read an incomplete result walked the stack above it. With thousands of computations in progress, as in an instantiation that runs away, nearly every slot is taken, so both cost time proportional to the depth on every step, and nesting deeply took quadratic time.
The limit on the depth of the whole instantiation stack failed an instantiation at whatever depth the stack reached, which depends on how much of what it needed was cached before, so whether a finite but deep instantiation failed depended on the order types were checked in. Caching only ever shortens the stack, so an instantiation that would stay below a limit computed from scratch stays below it in any order. The limit is now a guard against runaway instantiations, far above any finite one in real code (the deepest measured, in arktype's tests, nests 189 instantiations computed from scratch), while the limit on each computation still reports deep ones. An instantiation reaching the guard fails as a whole wherever it is computed or reused, so an infinite one fails the same way in any order.
A cycle that passes through a member table in progress is computed again as if the table had been entered first, with everything below the table hidden. The table's own memoized computation sits just below its type resolution, so it was hidden too, and reading the table then failed the recomputation instead of reading the table. Which member of such a cycle failed then depended on where the cycle was entered: a type alias read through an index signature was circular when queried first, and a parameter typed through a class's base was circular when its class was checked first. Fixes 64998 For 61721
A cycle yield recomputes a member of the cycle with the computations in progress hidden. Reading a member table being resolved below the yield failed the recomputation, since the table it would see is whatever part of it has been published. A table that has published nothing is instead resolved again from scratch inside the yield, so there is nothing incomplete to read, and failing there reported a circularity for a property only when its class was checked before its type was queried. Fixes 61711
When a qualified name used as a type does not resolve, the error
suggests typeof if the name resolves as a value, which needs the type
of the value its first identifier refers to. In
declare const n: n.T;
declare namespace n {}
that type is the annotation being resolved. Checking the annotation
first made it the head of the cycle, and the missing member it reports
was dropped along with the other results computed from the incomplete
annotation, so it was reported only when the type of n was queried
first. The type of a value used within its own declaration can depend
on the name being resolved, so no suggestion is made there, and the
missing member is reported in every order, without a circularity error.
For 18163
Reaching the limit on the instantiation stack failed every
instantiation in progress. A computation that resolves part of a type
whenever it is first needed, like the element type of a deferred array
type, is reached inside an instantiation or not depending on who needs
it first, so whether the instantiation needing it failed as a whole
depended on order. In
type A = A[];
const r = ([] as A).flat(Infinity);
r was any[] when the element type of A was resolved first, but any when
the call was checked first. Reaching the limit now fails only the
instantiations in progress in the innermost computation other than of a
cached instantiation, which fail the same way wherever the computation
is reached, so r is any[] in every order, as in TypeScript 6. A result
carrying the error no longer fails an instantiation reading it, as
computing it there would fail only within it.
For 49280
A base constraint keeps how deep its own walk went, so that a walk reusing it can tell whether computing it again there would give up. Comparisons are about to keep the same kind of record for their cached failures, so the record becomes a type of its own, a height, with the checks both need. The multiplication spreading the bits of a key over the high bits, which several tables and filters index by, is likewise written once.
A comparison nested too deeply is truncated: 100 levels deep, where both sides are deeply nested, or where a conditional type is deeply nested on one side. All of these count the comparisons in progress around it, so a result cached by one comparison could be reused inside another that would have truncated the comparisons the result came from, and the result then depended on which comparison ran first. A cached failure, and a cached result that reports reliability flags or depends on a failure through a check that truncation can change, now keeps a summary of the comparisons below it that it depends on: how deep they went on each side, and which recursion identities they pushed. It is reused only where the comparisons in progress, counting the comparison itself, could truncate none of them, and is otherwise compared again in place. Checks that reject types that relate, or pick among types by which relate, record the results they read, and results depending on a comparison assumed related or truncated outside them are not cached, or reused only where as much is pushed onto the stacks. A cycle through such a check, such as an inference constraint check that compares the comparison in progress again, then gives the same answer whichever comparison in it starts first. The recursion identities on the stacks are now kept with counts, which also replaces scanning the stack for every comparison to find deeply nested types. inferFromTypeArgumentsNoInfiniteRecursion no longer reports an excessive depth in any check order, as TypeScript 6.0 does not.
0470523 to
eea2f5e
Compare
|
TypeScript Bot (@typescript-bot) run dt |
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. There were interesting changes: Branch only errors:
|
Whether a comparison is too complex depended on how many of the results it needs were cached by comparisons made before it, so the same assignment could be an error in one check order and not another. Charge each reused result the results that computing it cached, and count a comparison only too complex for those charges again with no result cached, which decides it exactly.
eea2f5e to
bf061ab
Compare
|
Jake Bailey (@jakebailey), the perf run you requested failed. You can check the log here. |
Fixes #17873
Fixes #30982
Fixes #34099
Fixes #38460
Fixes #60453
Fixes #61711
Fixes #61982
Fixes #63949
Fixes #64278
Fixes #64891
Fixes #64998
Fixes #65440
For #18163
For #32063
For #49280
For #52892
For #54921
For #61721
There's too much here to explain, but at a high level, this is a massive change which aims to make the checker entirely order independent, that is, it doesn't matter when you call the checker, which nodes you walk first, if you do or do not pull something, check some other file, helicopter into the wrong part of a cycle, etc, the behavior, diagnostics, everything, will be the same.
Looking at individual commits is my suggested way to look inside, not the entire diff, which will surely crash your browser.
This is all AI driven, so it's a bit hard to unbox (I plan to break this apart since some stuff can be done early), but some interesting tidbits (handwritten by me!)
There's a new
checkOrdertest option, which makes certain tests variant on interesting orderings, like "what if we visit every single node before checking" or "what if we reverse the order of the files" or even "what if we use PRNG to randomly walk nodes and then check". This up front found on the order of 500 failing tests we already had that were secretly order dependent. These were all fuzzed out and kept.There are a significant number of new tests which all show various ordering bugs never before discovered.
The first chunk of the PR are fixing places where code peeked at caches that "happened to be filled" instead of calling the actual function to pull on them.
Then, all of the ID-using code gets removed. At the end everything now has an ID independent ordering based on content, flags, the works. This caught a bunch of places where we were not caching things and ending up with types that were by all rights identical but had different IDs and then were unstable.
The big and scary change is the introduction of a new state management type dubbed "memo". Every single piece of checker state was moved into memos on a sidecar object on the checker (maybe for future sharing??). This memo system keeps track of the current computation, what depends on what else, eliminating basically all flags/bools that track "computed" or "resolved"-ness. This tracking also records side effects, including diagnostics, "referenced" marks, deferred checks, emit helper checks. The result is that if you query via the API and that calculates some error, those same errors will appear later if the checker runs.
With those data structures in place, now all of the cycles can be handled. Once a cycle is discovered, the checker starts logging what it's doing, and throws all of that info away assuming it's been poisoned.
All of the different recursion stacks get pulled into a single memo stack, which is a cool simplification too.
Variance is now a fixpoint algorithm, proceeding in rounds until stability. In practice, it doesn't iterate much.
Instantiation limits also stop being global numbers (since of course, that is order dependent side effect stuff). Instead, things get limited by the amount of work that's been done, and if you then pull on caches related to work, it tallies that work up to error consistently when needed. (I don't think this is fully done yet, though, since there are depth limits that are really hard to get right. Still thinking about that.)
In some cases, cycles still can't be fixed up, and so they're made consistent by doing what we've done previously for these cases, which is to pick a canonical place to restart to at least get it consistent.
Unfortunately, this all has a cost; the end of the PR tries to claw back perf, but at the end of the day, if we do more work tracking, we spend more CPU and memory tracking. It's still an open question whether this can be cheapened any more. But, my hope is that this idea is minimal enough that we could then optimize TS as a whole assuming this order-independence, e.g. work stealing, checker recycling, shared state, maybe even using LRU caches, or dumping data to disk.
But, it could also well be that this is slop and impossible to manage. But I don't want to sit on it anymore and want to see some real world effects.
Also, this is really meant to be rebased, so expect this all to be nasty nasty force pushes all the time as this gets tweaked. Unfortunately right now that's like 125+ commits, so that sucks.
However, I think that this will fix countless issues on the tracker. I have no idea how to evaluate all 5k issues to see if this PR fixes them. But it's gotta be a lot.
Why each remaining break in the extended tests is correct
From the latest runs, on 9d4aa58: DT, user tests, top1000, perf. Each was judged on whether the user code is actually wrong, not on whether the result matches main. The earlier rounds of these runs showed the same set. That perf run also showed a new TS2488 in arktype, a false error from this PR, fixed since; test:
distributiveConstraintOfCircularCheckType.ts.d3-selection, TS2769 atd3-selection-tests.ts:1502(DT): the test passes aTransitionLike<HTMLParagraphElement>where aTransitionLike<HTMLElement>is expected. That is unsound: throughselection().merge, the paragraph selection would accept elements that are not paragraphs. Main reports the same TS2769 when the snippet is checked on its own, and accepts it in the full test only because earlier checking cached a laxer variance.react-relay, TS2344 and TS2322 inrelay-hooks-tests.tsx(DT): the test is unsound, asextraProps: {}and{} | nullflow contravariantly throughComponentClass.getDerivedStateFromProps. Main measures the variances ofEntryPointComponentandEntryPointpartway through their cycle and keeps the wrong answer (independent, though the parameters are used), so it contradicts itself: it acceptsconst whole: EntryPoint<any, any> = ebut rejects the same fore.root. We reject both. Test:varianceCircularConsistency.ts._rebuildandrecurinSchemaAST.ts(user tests, top1000, and the +8 errors in the effect perf scenario): a real cycle._rebuildreturnsthis | A, and subtype reduction relates the class toA, which needs the return type of a method returning the result of_rebuild. Main silently gives one of the twoany, depending on which return type is requested first. TS 6.0 reports these same TS7023s when the class is checked before its use. The fix in effect is a return type annotation. Test:circularReturnTypeSubtypeReductionOrder.ts.compress.js:2544(user tests):value_defisnullnarrowed by truthiness, sonever, and both compilers report an error on the line; only the message differs. Main's TS2322 comes from caching a result computed from an incomplete flow type in a loop. Outside a loop, main reports TS2339 too. Test:narrowedNeverAfterLoopWithAndCondition.ts.ScriptableContextis invariant, soChart<"bar">is not aChart<ChartType>, and(chart: Chart) => voidfitsPlugin<"bar">.beforeDrawin neither direction. Main accepts it only through a variance measured partway through a cycle, and rejects it in other check orders. It is a practical break on a common pattern, but the error is right. Test:varianceCircularityHidesInvariance.ts.AstObject<R3PartialDeclaration>is passed asAstObject<R3DeclareClassMetadata>, an unchecked downcast:AstValueis covariant inTthrough its type brand, andAstObjectreaches it throughgetValue. Main infers the type arguments ofnew AstValue(...)ingetValuefrom its return type, which measuresAstValuefirst;AstObject, measured inside that, seesTonly in references to types in progress, so main records it as independent ofT. Main rejects the same code whenAstObjectis measured first. Test:varianceCircularityEnteredByInference.ts.schemas.d.ctsno longer reports TS5115. That error is main bug TS5115 in published Zod 4.5–4.6 types after #64372 #64605, fixed in main by Read declared members while instantiating base types #65479.tooling/generate-types.jsTS2345 is a real error that main hides because its inference gives up. Main decides that inference is expanding by comparing type IDs, so forflatten(m)withm: string[][]it infersunknown[]orstring[]depending on whether an unrelatedfor...ofwas checked first. We compare by structure and always inferstring[], which exposes the error. Test:inferenceDeeplyNestedCheckOrder.ts.