Repository navigation
Make checker behavior order independent - #65293
Jake Bailey (jakebailey) wants to merge 9 commits into
Conversation
e8dc435 to
7afb732
Compare
7afb732 to
a7534e3
Compare
The checker caches nearly everything it computes, and many results depend on what happened to be cached when they were computed: which file was checked first, which types an editor asked for before requesting diagnostics, whether a file was emitted before it was checked. The check order tests and fuzzer show hundreds of such differences on main. As long as they exist, checkers cannot share results, a cached result cannot be dropped and recomputed later, and concurrent checking needs separate checkers with fixed file assignments to stay deterministic. The goal is a checker that behaves like a pure function with a cache: the answer to any query is the answer of computing it from scratch. The cached state of a checker moves to a memo store, leaving the Checker with only the state of the computation in progress. Every cached result is a memo: a cell, a keyed map, or a check-once set. Reading one records it as a dependency of the computation in progress. Computing a result can produce more than the result: diagnostics, reference marks for unused checks, deferred nodes, required emit helpers. When a query computed a result first, those effects were either reported for code checking never visits or lost when checking reused the result. A query now records them on the result instead, along with the results it reused, and checking replays them, exactly once, when it reuses the result, as if it had computed it. Effects produced outside any memoized computation belong only to the query and are dropped. Circularities are where most of the order dependence lives. A computation that re-enters one in progress sees a provisional state, so whatever is cached until the outermost computation of the cycle finishes depends on where the cycle was entered. Those results are now discarded when it finishes, and recomputed when next requested. The computations in progress when the cycle was detected keep their fallbacks, as each reaches the cycle when computed from scratch too. Results that define identity, such as declared types and instantiations, are kept, so no second, distinct result can exist. Main detects many re-entries silently, through markers and probes rather than the resolution stack; those now go through the resolution stack too, so their cycles are seen. Where a cycle's result depends on which member was entered, the cycle is resolved from a canonical entry, the member declared first, as when checking in program order: cycles through the types of symbols, mutually dependent member tables and module tables, and type parameter defaults. Variances of circular types are measured with TypeScript's rule from the canonical type of each strongly connected component, so that they no longer depend on which type was measured first. Instantiation depth is measured from the start of each memoized computation, and a reused result adds none, so whether a result reaches the depth limit does not depend on what was cached. The count limit, which only stops runaway instantiations, still counts per statement or expression, and starts again for each outermost computation; its error is reported once, where it is reached. Smaller fixes needed for the same reason are part of this change: errors for accessor pairs are reported by each accessor without a flag, type alias type parameters are read through the declared type, name lookups that cannot match a late-bound member do not resolve late-bound members, symbols derived from the same declaration are ordered without ids, awaited types that refer back to themselves fail as a cycle, and relation complexity overflows are reported in every comparison that needs them.
A declared type parameter with a circular constraint is circular no matter how it is used, and checking its declaration reports it. Which use happened to resolve the constraint before that is an accident of check order, so pointing at it as the origin of the cycle made the diagnostic depend on that order. Only an instantiated type parameter has a cycle that originates at a use.
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, 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 what was 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 what 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 what was cached from it is 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 what that one 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 what it observed was 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)
a7534e3 to
d31d179
Compare
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review. Note You can configure setup steps for Copilot code review separately from Copilot cloud agent with a |
There was a problem hiding this comment.
🟡 Changes recommended
Critical type-checking regressions retain a false missing-property diagnostic, accept structurally incompatible assignments, and select an inapplicable overload that hides an invalid assignment.
2 open issues
1 file not reviewed
tsc/internal/api/enum_values_generated.go: Generated file
What changed in this PR
These changes support the order-independent checker work in #65064 by adapting checker integration points to memo-backed state and updating regression coverage.
Changes:
- Makes checker consumers, serialization, and emit-reference tracking memo-aware.
- Adds regressions for contextual typing, cyclic member resolution, and JavaScript assignments.
- Updates diagnostic, type, symbol, declaration, and incremental baselines; removes an obsolete object flag.
Validation: Static review only; builds and tests were not run.
| File | Description |
|---|---|
| tsc/testdata/tests/cases/compiler/lateBoundMutualMemberTables.ts | Updated as part of this pull request. |
| tsc/testdata/tests/cases/compiler/jsExpandoIndexedAssignmentDiagnostic.ts | Updated as part of this pull request. |
| tsc/testdata/tests/cases/compiler/contextualReturnTypeInSpreadArgument.ts | Updated as part of this pull request. |
| tsc/testdata/tests/cases/compiler/contextualCheckReentryAfterParameters.ts | Updated as part of this pull request. |
| tsc/testdata/tests/cases/compiler/contextualCheckInDiscardedCycle.ts | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/tsc/incremental/global-diagnostics-produced-during-semantic-checking.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/conformance/templateLiteralTypes1.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/conformance/recursiveMappedTypes.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/conformance/privateNameNestedClassFieldShadowing(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/conformance/importTag13(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/conformance/dependentDestructuredVariablesReferenceInDeclaration1(checkorder=typesfirst).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/conformance/dependentDestructuredVariablesReferenceInDeclaration1(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.symbols | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/varianceCircularConsistency.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/unusedLocalsOnFunctionDeclarationWithinFunctionDeclaration1(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/typeParameterWithInvalidConstraintType.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/typeParameterHasSelfAsConstraint(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/templateLiteralTypeExcessiveLength(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/templateLiteralTypeExcessiveLength(checkorder=default).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/relationDeeplyNestedCheckOrder.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/relationComplexityError(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/relationComplexityError(checkorder=default).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyExportEqualsWithOtherExportsImportOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyExportEqualsWithOtherExportsImportOrder.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyExportEqualsWithOtherExportsCheckOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyExportEqualsWithOtherExportsCheckOrder.symbols | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyExportEqualsWithOtherExportsCheckOrder.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNonExportedMemberOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNonExportedMemberOrder.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrderReexportedTypes.symbols | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrderReexportedTypes.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrderReexportedTypes.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrder.symbols | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrder.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrder.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsExportStarDeclarationCollisionOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsExportStarDeclarationCollisionOrder.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsExportStarCollisionOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsExportStarCollisionOrder.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitVariableMatchesInScopeOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitVariableMatchesInScopeOrder.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitUmdGlobalAliasesOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitUmdGlobalAliasesOrder.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitSharedCheckerOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitRenamedExportOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitRenamedExportOrder.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitLateBoundIndexSignatureSiblingsOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitLateBoundIndexSignatureSiblingsOrder.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitExternalModuleContainerIndexOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitExternalModuleContainerIndexOrder.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitExportEqualsQualifiedNameOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitExportEqualsQualifiedNameOrder.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/namespaceMembersResolutionOrderExportStar.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/namespaceMembersResolutionOrderExportStar.symbols | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/namespaceMembersResolutionOrderExportStar.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/namespaceMembersResolutionOrderExportStar.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/limitDeepInstantiations(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/limitDeepInstantiations(checkorder=default).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/lateBoundMutualMemberTables.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/lateBoundMutualMemberTables.symbols | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/lateBoundMutualMemberTables.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/lateBoundMutualMemberTables.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/keyofGenericExtendingClassDoubleLayer.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/jsxIntrinsicElementsExtendsRecord(checkorder=typesfirst).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/jsxIntrinsicElementsExtendsRecord(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/jsxImportSourceNonPragmaComment(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.symbols | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/jsExpandoIndexedAssignmentDiagnostic.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/jsdocTypeTagOnContextuallyTypedFunction.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/jsdocTypeTagOnContextuallyTypedFunction.symbols | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/jsdocTypeTagOnContextuallyTypedFunction.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/incorrectRecursiveMappedTypeConstraint.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/excessivelyLargeTupleSpread(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/dependentDestructuringBindingElementInitializer(checkorder=typesfirst).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/declarationEmitExternalModuleContainerIndexDeclarationOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/declarationEmitExternalModuleContainerIndexDeclarationOrder.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/contextualReturnTypeInSpreadArgument.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/contextualReturnTypeInSpreadArgument.symbols | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/contextualReturnTypeInSpreadArgument.js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/contextualCheckInDiscardedCycle.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/contextualCheckInDiscardedCycle.symbols | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/classVarianceResolveCircularity2.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/classVarianceResolveCircularity2.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/circularScopeThunkReverseMapped(checkorder=typesfirst).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/circularScopeThunkReverseMapped(checkorder=default).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/circularReturnTypeSubtypeReductionOrder.types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/circularReturnTypeSubtypeReductionOrder.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/circularInlineMappedGenericTupleTypeNoCrash(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/circularInlineMappedGenericTupleTypeNoCrash(checkorder=default).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/circularIndexedPropertyInstantiation.errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/circularAccessorAnnotations(checkorder=typesfirst).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderStableInstantiationErrors(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderStableInstantiationErrors(checkorder=reverse).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderStableInstantiationErrors(checkorder=default).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderSpreadCycle(checkorder=typesfirst).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderSpreadCycle(checkorder=typesfirst).js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderSpreadCycle(checkorder=reverse).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderSpreadCycle(checkorder=reverse).js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderSpreadCycle(checkorder=isolated).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderSpreadCycle(checkorder=isolated).js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderSpreadCycle(checkorder=default).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderSpreadCycle(checkorder=default).js | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderEmitBeforeCheck(checkorder=isolated).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderEmitBeforeCheck(checkorder=default).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderCircularDefaults(checkorder=typesfirst).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderCircularDefaults(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderCircularDefaults(checkorder=isolated).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderCircularDefaults(checkorder=isolated).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderCircularDefaults(checkorder=default).types | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderCircularDefaults(checkorder=default).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderCircularConstraint(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderCircularConstraint(checkorder=reverse).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderCircularConstraint(checkorder=default).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderAwaitedCycle(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderAwaitedCycle(checkorder=reverse).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/checkOrderAwaitedCycle(checkorder=default).errors.txt | Updated as part of this pull request. |
| tsc/testdata/baselines/reference/compiler/bigintArbirtraryIdentifier(checkorder=typesfirst).errors.txt | Updated as part of this pull request. |
| tsc/internal/execute/tsctests/tsc_test.go | Updated as part of this pull request. |
| tsc/internal/checker/utilities.go | Updated as part of this pull request. |
| tsc/internal/checker/tracer.go | Updated as part of this pull request. |
| tsc/internal/checker/symbolaccessibility.go | Updated as part of this pull request. |
| tsc/internal/checker/services.go | Updated as part of this pull request. |
| tsc/internal/checker/printer.go | Updated as part of this pull request. |
| tsc/internal/checker/nodebuilderimpl.go | Updated as part of this pull request. |
| tsc/internal/checker/nodebuilder_hover.go | Updated as part of this pull request. |
| tsc/internal/checker/links.go | Updated as part of this pull request. |
| tsc/internal/checker/inference.go | Updated as part of this pull request. |
| tsc/internal/checker/grammarchecks.go | Updated as part of this pull request. |
| tsc/internal/checker/emitresolver.go | Updated as part of this pull request. |
| tsc/internal/ast/utilities.go | Updated as part of this pull request. |
| tsc/internal/ast/symbol.go | Updated as part of this pull request. |
| tsc/internal/api/enum_values_generated.go | Updated as part of this pull request. |
| packages/typescript/enums/objectFlags.js | Updated as part of this pull request. |
| packages/typescript/enums/objectFlags.d.ts | Updated as part of this pull request. |
Review effort: Balanced
| @@ -0,0 +1,29 @@ | |||
| lateBoundMutualMemberTables.ts(6,8): error TS2339: Property 'by' does not exist on type 'B<"b">'. | |||
| lateBoundMutualMemberTables.ts(11,8): error TS2339: Property 'b' does not exist on type 'A<"a">'. | |||
| >pick(new Foo(this)).foo : string | ||
| >pick(new Foo(this)) : B | ||
| >pick(new Foo(this)).foo : any | ||
| >pick(new Foo(this)) : A |

This is the final part of #65064, adding all of the new infra to make the checker insensitive to orderings
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.
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.