Repository navigation
Order types, symbols, and nodes by content instead of by ID - #65621
Jake Bailey (jakebailey) wants to merge 15 commits into
Conversation
|
TypeScript Bot (@typescript-bot) run dt |
|
Hey Jake Bailey (@jakebailey), it looks like the DT test run failed. Please check the log for more details. |
|
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 1000 repos with tsc comparing Something interesting changed - please have a look. Details
|
7bb107b to
439b0d7
Compare
|
TypeScript Bot (@typescript-bot) run dt |
|
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. |
439b0d7 to
a353a79
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:
|
|
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 1000 repos with tsc comparing Something interesting changed - please have a look. Details
|
a353a79 to
6d334c8
Compare
|
TypeScript Bot (@typescript-bot) run dt |
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. Everything looks the same! |
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
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 1000 repos with tsc comparing Something interesting changed - please have a look. Details
|
6d334c8 to
76d94ad
Compare
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. Everything looks the same! |
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
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 1000 repos with tsc comparing Everything looks good! |
76d94ad to
94dc636
Compare
|
TypeScript Bot (@typescript-bot) test it |
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. Everything looks the same! |
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
2d9432b to
7138620
Compare
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
These tests are added before the changes they cover, so that each change shows in their baselines.
isDeeplyNestedType counts only occurrences of a recursion identity newer than the previous one, using type ids for "newer", so whether a comparison gave up as deeply nested depended on which code had been checked before. It now compares generations: a type's generation is one more than the highest generation of the types it was built from. An occurrence of a higher generation was built by the recursion and counts. One of a lower generation is a nested type argument or member, and counts only if it is a conditional type, an indexed access, or another type that evaluating a step can make with fewer layers, and the previous occurrence was not built from it. A copy of the previous union or intersection with the same constituents, such as one that lost its alias, is the same level of nesting (seen in BlockNote and type-fest), unless both have aliases, whose type arguments can keep growing while the constituents stay the same (seen in tambo). Comparing the RpcStub types of capnweb, which form a variance circularity, recurses through deeply nested instantiations, and reached the instantiation limit before this (seen in cloudflare-os). Fixes 17873 Fixes 34099 Fixes 60453 Fixes 64757
CompareTypes orders the constituents of unions, and so printed types,
union deduplication, and everything derived from them. Many types it
cannot tell apart fell through to the type id, which follows creation
order, so these results depended on which code had been checked before.
Most such ties were copies: checking the same expression again
(inference passes, overload resolution, contextual re-checks) created a
new type with identical content every time.
Types that are the same by content are now interned, so the same
inputs yield the same type whenever and however often they are
computed:
- object literal types;
- spread results and the property symbols they synthesize;
- widened, regular, and padded copies of object literals;
- object rest types;
- types implied by binding patterns;
- intersections with the same constituents, flags, and alias.
Interned object types are keyed by their members in table order, so
spreads such as { ...a, ...b } and { ...b, ...a } stay distinct and
each keeps its own property order.
Types that remain distinct are ordered by how they were derived:
- type parameters sharing a symbol (tuple elements, clones made for
signature and mapped type instantiation, distributive and
restrictive copies) by the kind of copy, then by their origin and
the instantiation they were made for;
- fresh and regular literal types, array literal types after the
references they were cloned from, and object literal copies by the
flags they were created with;
- object literal, rest, and binding pattern types by the declarations
and names of their members;
- tuple targets by their label declarations;
- indexed access types by their access flags.
The pseudo-type printer reused the declared type of an inferred
property assignment when the expression's widened type matched, but
that type is widened without the context of its object literal and
can differ from the real one. It is now reused only when equivalent.
Interning lets a comparison reuse a cached relation result that would
otherwise have been computed again for a fresh copy of a type. A result
computed while the return type of a signature still being resolved
reads as any holds only until that return type is known, so it is no
longer cached. Otherwise, relating the arguments of a call whose return
type is being inferred from them caches a success, and the call no
longer reports that no overload matches (seen in lexical).
compareNodes ordered nodes of a file by position only, so distinct nodes starting together, such as a source file and its first statement or adjacent missing nodes, compared as equal, and sorting them kept whichever order they were found in. They are now ordered as they appear in the tree, so that a node compares equal only to itself.
Symbols the checker derives from a declared one, such as the members of mapped types or readonly copies of object literal properties, share its declaration and name, so compareSymbols ordered them by symbol id. Symbol ids are assigned in the order symbols are first used, which depends on which code was checked before. They are now ordered by whether they are transient and by their check flags first.
Object types derived from others, such as spreads and widened copies,
are interned by their member symbols in member table order and by
their index signatures. Object literal types are interned by the
flags, name types, and types of their members. Both were ordered only
by the declarations, optionality, and types of their members. A spread
over a union can make types that differ only in the order of their
members, such as { ...a, ...b } and { ...b, ...a }, and these were left
to the type id. Widened copies of types implied by binding patterns
have no symbol and were not ordered by their members at all.
They are now ordered by everything they are interned by, the member
symbols last, so that a type compares equal only to itself.
The instantiations of a conditional type are cached on its root, but distributive and tail-recursive evaluation create deferred conditional types without that cache, so the same deferred conditional type, with the same root, mappings, and alias, could be created more than once. Such copies can be told apart only by type id, which follows the order in which code was checked. Deferred conditional types are now interned by their root, the content of their mapper, and their alias. Those made for a constraint stay apart from the others, as the instantiation caches of a conditional type already keep them: evaluating a conditional type for a constraint can include its true branch where evaluating it otherwise would not. Sharing the deferred types made for one with the other reused the comparisons reached from them, and checking calls with SetOptional of generic keys then exceeded the instantiation depth limit (seen in type-fest). Instantiations of InferData and UnpackKeyValue, whose recursion is bounded, are no longer reported as infinitely circular when inferred through a closure (boundedRecursiveTypeInferredThroughClosure).
Symbols the checker makes from others, such as the properties a spread merges or copies, the members of mapped types, instantiated symbols, and the copies of a module symbol made for each import of it, share the declaration, name, and flags of the symbol they are made from, and were ordered by symbol id, which follows the order in which symbols are first used. They are now ordered by the symbols, types, and imports they are made from, which are recorded when they are created. The symbols made for unresolved names share their name, and are ordered by the unresolved names that qualify them, as Bidi.Event and Protocol.Cdp.Event are when neither module is found (seen in puppeteer and DefinitelyTyped).
The type of a module with a synthetic default import is a spread under a type literal symbol, and widening it makes a copy with the same symbol. Neither is an object literal, so nothing but their type ids distinguished them. Unnamed object types are now also ordered by the flags recording how they were created.
Instantiations of distinct object literal types made by the same declaration, such as the copies a call makes when it infers from an argument twice, were ordered only by their mappers. Instantiations with mappers of the same content then compared as equal and fell back to the type id (seen in t3code). They are now ordered by the type they instantiate first.
Inferring from string literals to keyof T infers to T from an object type with an any-typed property per literal, which was made anew every time, so inferring from the same literals twice yielded types that could be told apart only by type id (seen in tanstack-router). They are now interned by the literals and whether the source includes string.
The members of a type implied by a binding pattern have no declarations, so types implied by two patterns with the same names, and their widened copies, could be told apart only by their member symbols, which were ordered by symbol id (seen in vscode). Each member now records the binding element declaring it, as TypeScript's checker does, and is ordered by that element. Types that record the pattern implying them are also ordered by that pattern before their members.
compareTypeMappers compared simple, array, and merged mappers by their mappings and treated all others as equal. Symbols instantiated through composite mappers with different mappings then compared as equal and fell back to the symbol id (seen in sentry). Composite mappers are now compared by the two mappers they compose, and deferred conditional types are interned by them too.
Spreading a union of one object type and empty objects makes an object type with the properties of the object type made optional. A new type with new properties was made every time, so spreading the same union twice yielded types that could be told apart only by their properties' symbol ids (seen in tanstack-router). They are now interned by the object type and whether the spread is readonly.
Type ids follow the order in which types are created, and symbol ids the order in which symbols are first used, both of which depend on which code was checked before. Ordering by them made union order, printed types, and everything derived from them depend on check order. Types and symbols are now ordered by their content, so that a value compares equal only to itself and a sorted list of them is a set by identity. Reaching the id fallback means two distinct values cannot be told apart, and is now an assertion failure, except for the types created with the checker, such as the intrinsic types and the variance markers, whose order of creation is fixed.
7138620 to
cd37f45
Compare
Fixes #17873
Fixes #34099
Fixes #60453
Fixes #64757
This is the second part of #65064, removing ordering by ID, which can apply to main.
Types, symbols, and nodes were ordered by their IDs whenever their content tied. IDs follow creation order, so union order, printed types, and everything derived from them depended on which code was checked first. Everything is now ordered by content, flags, and how it was derived, and types that are identical by content are interned into one type. Falling back to IDs now panics, except for the built-in types the checker creates in a fixed order. This caught a bunch of places where we were not caching things and ended up with types that were by all rights identical but had different IDs.