Expand type references recursively in cache key#18207
Merged
Merged
Conversation
This means that `A<B<T, C<U>>>` will include the keys for `B` and `C` now.
4 is the limit.
ahejlsberg
requested changes
Sep 5, 2017
Member
ahejlsberg
left a comment
There was a problem hiding this comment.
Approved with the requested change.
|
|
||
| function isTypeReferenceWithGenericArguments(type: Type) { | ||
| return getObjectFlags(type) & ObjectFlags.Reference && some((<TypeReference>type).typeArguments, isUnconstrainedTypeParameter); | ||
| function isTypeReferenceWithGenericArguments(type: Type): type is TypeReference { |
Member
There was a problem hiding this comment.
Technically this is not correct. A type might be a type reference even if this function returns false.
Member
Author
There was a problem hiding this comment.
Oops, I forgot that 'type is TypeReference' implies that type is not TypeReference if the return value is false.
I forgot that 'f(x): x is T' implies that x is *not* T if f returns false.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 forBandCnow.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 <-> Bluebirdcomparison.The fix works because many of Bluebird's methods return
Bluebird<T[]>. So extendinggetTypeReferenceIdto 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, thengetTypeReferenceIdcalls 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.