Repository navigation
[experiment] order independence + dynamic checkers / work stealing - #65367
Jake Bailey (jakebailey) wants to merge 78 commits into
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
33e4a7b to
50d7631
Compare
|
TypeScript Bot (@typescript-bot) run dt |
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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
|
50d7631 to
2a565a2
Compare
|
TypeScript Bot (@typescript-bot) perf test this faster |
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2a565a2 to
f59a1e8
Compare
|
TypeScript Bot (@typescript-bot) perf test this faster |
|
Jake Bailey (@jakebailey) Here are the results of running the top 1000 repos 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: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
b8c46ea to
60ca9ed
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:
|
A mapped type resolves its constraint eagerly so that errors in the constraint are reported at the mapped type. It did so only when the type was created, so when the type was first created while checking another node, the mapped type itself never reported those errors.
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, except that the members whose return types a relation requested are resolved before the others. A relation compares a return type in progress as any and never fails it, so entering the cycle at such a member is the order that fails the least, and the members relations request are the same wherever the cycle is entered. Resolving the member declared first made both methods of a class in effect's SchemaAST circular, where TypeScript, entering the cycle at the other method, reports nothing. An instantiation of a signature resolves its return type as part of the signature it instantiates, so the two count as one member, and the instantiation the relation requested is the one resolved first. The declared signature is resolved within that instantiation, sees it in progress, and its result is discarded, so it is resolved again from scratch; otherwise a later request of it re-enters the cycle and fails both members. Strict subtype reduction compared a return type in progress as any, which is a strict subtype of nothing but any, so whether a union kept a member depended on which return type was requested first. It now assumes such a return type related, as a comparison assumes of the pair of types it is comparing when it recurs. 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. Analyzing control flow checks whether a call is an assertion, which reads the declared type of the name called through. Finding that type in progress made the call not an assertion without failing anything, so which members of the cycle were circular depended on where it was entered. Such a cycle now fails as re-entering it would, resolved from the member declared first (seen in 50200). A call whose arguments are related while its own return type is inferred re-enters a hidden resolution of itself, which fails, falling back to the longest earlier candidate as when no overload matches. That candidate's return type can be assignable where the failing one's is not, so the call reported nothing and kept a recovery type it did not fail as. It now falls back to the candidate the error is reported against, and reports that no overload matches in every order (seen in lexical). For 55069
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). A return type is kept so only where a cycle yield computes it first. Nested in the recomputation of another member of a cycle, which resolving the members that relations request first makes possible, it is part of that member's computation, and keeping it as the outer one's result let the return type requested first decide whether a method was circular.
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) # Conflicts: # tsc/internal/checker/checker.go
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 effects of what such a request computes are discarded with its results: a result computed again by checking would otherwise replay errors found in the state of the request. The types at loop junctions, which a cycle keeps when it discards the rest, are not kept past the request either. Signature help creates its items from the candidates within the request, as printing them computes members of the types inferred for them, which can resolve the call again. 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 type alias found circular within such a request gets the error type as its declared type, which is the same identity whatever computes it, so it is discarded with the error reported for it, to be computed again where the error is kept. Keeping it would leave checking with the circular alias and no error (seen in 58068). Fixes 43948 Fixes 62183
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. Only the computations a search can find, those of memo cells counted as in progress, are linked from their slots. A computation re-entering one in progress runs again without being counted, and linking it as well let a runaway re-entry of one key build a chain that every search for the key walked to the end (seen in 63040).
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
A variance measurement must give the same variances wherever it is first requested. The outermost measurement hid the type resolutions in progress below it, but memoized computations in progress stayed visible. When a query reached the return type of a method first, the measurement of its class re-entered the subtype reduction of that return type in progress below, treated it as a cycle and discarded the variances and the reduced type, so the method's return type depended on whether the class or the method was checked first. The outermost measurement is now a cycle yield, which hides every computation in progress below it, together with the contextual types, inference contexts and depth limits they entered.
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.
(seen in 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.
Inside a cycle in progress, the innermost such computation can be one
re-entered just below the limit, whose own instantiations are finite.
Failing only it let the rest of the cycle go on at the limit, failing
computations that are finite and taking exponential time on recursions
with two branches. The computation that fails is now the one at the
head of the cycle, as the results computed in a cycle are kept or
discarded together.
A conditional type instantiation already known to fail was cached as
the error type before its failure was reported, so the instantiations
reusing it reported nothing and failed nothing. It now ends as other
instantiations do, and no instantiation known to fail is cached (seen
in fuzzing instantiationStackLimitCheckOrder and
recursiveConditionalCrash4).
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.
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, once per comparison, 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. The charge is kept in the spare upper bits of each cached result. A map of charges kept apart from the results held an entry for about half of them, which raised memory use by more than half (seen in 63854).
A cycle of interfaces extending each other kept different base types depending on which interface's base types were resolved first: the one entered first lost its base, and the others kept theirs. Asking for the members of one interface before checking the declarations could leave another without the properties it inherits. Resolve such a cycle from the class or interface declared first, as cycles through the types of symbols and the return types of signatures already are. Resolving the cycle's first member may resolve the base types the cycle re-entered, which are then kept, and a computation of base types resumed after the cycle resolved them keeps that result rather than adding its own.
The declared members of a class or interface are marked resolved before their index signatures are, as the types of those may refer back to the type. Resolving the members of the type while its declared members were still in progress, as checking the inherited properties of an interface with several bases does, or as resolving the members of its reference with its this type does, read the declared members without noticing the re-entry. The members were then resolved for good without the index signature, and keyof the type cached without it. Both keyof the type and whether its index signature existed depended on whether the type was checked before its members were otherwise needed, and so, with several checkers, on how files were assigned to them. Re-entering the declared members is a cycle like re-entering any other computation in progress, so results derived from the incomplete members are computed again once they are complete. Fixes 65543
An error that computing a cached result reports at the node being checked is reported at every node whose check reaches the result, as it would be had that node been checked first. A union type and its first constituent start at the same position, and both reach the result of resolving the constituent, so such an error was reported twice at one position, over spans of different lengths that are not deduplicated. The error is reported at the outermost type node starting where the node being checked starts. (seen in 64384)
Holding a check's effects during variance cycles leaves results with effects still to replay, and a few keep them for long, for example when the only read that would replay them was discarded with a variance measurement. While any result had pending effects, every read of a cached result took the slow path that looks for them, so a single one slowed all the checking after it (seen in xstate). The keys of results given pending effects are now kept in a filter, and a read takes the slow path only for a key that may have them.
Files are assigned to checkers up front, so the checker with the most work left finishes last while the others sit idle. Results no longer depend on which checker checks a file or which files it checked before, so a checker that runs out of files can take one from another without changing any output. Each checker still starts with the files assigned to it, keeping the locality of the assignment, and takes the file another checker would reach last. A file stays associated with the checker that checked it, so later requests for it reuse that checker's caches.
The checker count was fixed at 4 because which checker checked a file could change the results, so changing it changed the output. That is no longer the case, and with checkers taking files from each other it only trades time for memory, so the default can follow the machine. Checking is fastest with about one checker per CPU, until the work every checker duplicates (library and shared types) outweighs the parallelism another checker adds. Measured on 4 and 8 CPUs, one checker per logical CPU was fastest for nearly every project, hyperthreads included; on 20 CPUs, 8 checkers were fastest for most projects, and only very large programs gained up to 12-16. So the default is one checker per CPU, up to 8, rising with the square root of the checked work up to 16, and no more than one per 32 checked files, but at least the 4 of before when there are as many CPUs. Files whose checking is skipped, such as declaration files under skipLibCheck, count for nothing. Build mode divides the CPUs among the projects it builds concurrently, but never gives a project fewer than the 4 checkers of before, since projects that depend on each other are built one at a time.
331da4c to
01b814d
Compare
This is #65064 + more dynamic checker counts + work stealing between checkers, as this should actually be safe now.