-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler crashes with 'Allocation failed' error after using mapped type #13681
Comments
@rbuckton can you take a look. |
I couldn't repro this with the latest build of typescript, but I may have missed something along the way. There were tons of build errors reported, so maybe the crash is avoided because of earlier errors. |
@dsehnal does the crash still happen with |
@sandersn Yes it does happen on 2.3.0-dev.20170406. Oddly enough, in 2.2.2 it works but takes unreasonably long (13s for the "Bootstrap" component vs ~2.5-5s for the other ones while having comparable amount of code). To reproduce it in
under the |
Moving the line definitely got rid of the errors, but Viewer and Examples still completes for me (in 34 seconds). Bootstrap takes 26 seconds though. Let me try on a Windows machine...and also with 2.1.7. |
Well, I think that I must have hit some degenerate path with the way I used the mapped type. Or maybe it's something that when fixed speeds up the compilation in general. I am on Windows 10. Originally, I got the error in Node 6.9 and when I tested it yesterday, it was present in 7.6 as well. |
Well, I got a consistent repro. In Viewer/PDBe/SequenceAnnotation.ts, a line like I'm still looking for the point where the compiler gets trapped in the comparison of the two types. |
Here's a standalone repro.
|
Here's a bit more progress. It turns out the code should actually fail with an error: In other words, Entity.Any should not be comparable to more specialised entity types. However, the code path in |
@sandersn But I am comparing the "types" of the entities (where the "type" is a factory of sorts for the given entity), not the entities themselves, therefore the error message does not make much sense to me. Or am I missing something? |
Well, Type<Annotation['props']>
Type<N<{ n: number }>['props']>
BaseType<N<N<{ n: number }>>['props']>
BaseType<N<{ n: number }>> Then when the checker compares Notably, when I lower the recursion overflow limit in |
I might be totally off here, but could this be related to the variance of the type parameters? I've run into an issue in the next iteration of the "transform tree" data structure I am using in LiteMol. Basically I wanted to achieve what in C# would look like interface Transform<in A, out B, P> { .... } My first attempt was to try export interface Transform<A extends Entity.Any, B extends Entity.Any, P> {
'@sourceType'?: A,
'@targetType'?: B
} But I was getting "X is not assignable to Y" type of errors which sounds kind of similar to "X and Y are not comparable". I assume this is because the compiler assumed A and B are bi-variant when trying to compare different instances of the (Tho a bit unrelated, eventually, I figured out I need to use export interface Transform<A extends Entity.Any, B extends Entity.Any, P> {
'@typeAnnotation'?: (src: A['kind'], params: P) => B['kind'],
} and the whole interface then behaves as the C# version.) Where I am going with this: The compiler tries to compare types So maybe a solution would be to memoize which type pairs have already been compared? |
Well, yes, basically. When
|
Can you try |
Yes, this seems to fix it for checkout c075025 (after using "any" type for the newly introduced type errors because 2.4's typechecker seems to be stricter/more correct) and the compile time takes ~2.6s on my machine. On the latest version of my project, there is no significant time difference between 2.4 ( |
TypeScript Version: 2.1.5 and nightly (2.2.0-dev.20170125)
Node Version: 6.9.4 64-bit (probably not relevant)
Code
I have changed type annotation in my code from
to
Here is the change in the full context.
I did the change because using the original approach
resulted in loosing typename in typedoc documentation.
Instead, I decided to use
Expected behavior:
The code compiles and does not crash.
Actual behavior:
Code takes extremely long to compile or crashes.
If I modify the code to
the problem goes away. (I am using
T & any
because I am using the noUnusedLocals flag and would have to change more code).Steps to reproduce:
Compiles without problems:
Crashes on "Viewer and Examples" task and takes too long on "Bootstrap" task:
The error I am getting is:
The text was updated successfully, but these errors were encountered: