Expand type references recursively in cache key #18207
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This means that
A<B<T, C<U>>>
will include the keys forB
andC
now.Fixes the secondary cause of #17716 — when comparing
Bluebird<string>
toBluebird<string>
, the compilation ends up using two versions of Bluebird. And it turns out Bluebird is a very large type, and nearly every method returns another instance of Bluebird. This causes the compiler to run out of memory and crash. With this fix, compilation finishes in 2.9 seconds compared to 0.9 seconds when package deduping work correctly, skipping the structuralBluebird <-> Bluebird
comparison.The fix works because many of Bluebird's methods return
Bluebird<T[]>
. So extendinggetTypeReferenceId
to understand arrays allows caching to perform better. The intuition is that if we don't learn anything by relatingA<T> ==> B<T>
when already relatingA<U> ==> B<U>
, then we also don't learn anything by relatingA<T[]> ==> B<T[]>
when already relatingA<U[]> ==> B<U[]>
.This technique, in fact, generalises to any depth of nested type references. that is a type argument of a type reference. So if we are already relating
Foo<Bar<T, Baz<V>>> ==> Qux<Quid<T, Quam<V>>>
then we will skipFoo<Bar<U, Baz<W>>> ==> Qux<Quid<U, Quam<W>>>
.This works by generating the same key in
getTypeReferenceId
. I add one additional case that checks if a type argument is itself a type reference with generic arguments. If so, thengetTypeReferenceId
calls itself recursively on that type argument.Note that we could limit the depth of the expansion when generating the key by adding a depth parameter to
getTypeReferenceId
.