Skip to content

Unify representation of tuples and other generic types #10466

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

Merged
merged 5 commits into from
Aug 22, 2016

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Aug 22, 2016

With this PR we unify the internal representation of tuple types and other generic types. Tuple types are now represented as regular type references to synthesized generic types of the form:

interface Tuple<T0, T1, T2, ...> extends Array<T0 | T1 | T2 | ...> { 0: T0, 1: T1, 2: T2, ... }

With these changes it is no longer necessary to special case tuple types throughout the type checker. All of the optimizations we have in place for regular generic type references now also apply to tuple types.

Fixes #10431. The compile time for the example drops from 1.2s to 0.08s with --lib es5 and from 30.5s to 0.11s with --lib es6.

@HerringtonDarkholme
Copy link
Contributor

Will this be developed into #5453 ?

Synthesized generic types and tuple types looks much like variadic kinds.

@weswigham
Copy link
Member

I quite like the changes in the error baselines. Feels neater.

@@ -2214,6 +2211,11 @@ namespace ts {
writePunctuation(writer, SyntaxKind.OpenBracketToken);
writePunctuation(writer, SyntaxKind.CloseBracketToken);
}
else if (type.target.flags & TypeFlags.Tuple) {
writePunctuation(writer, SyntaxKind.OpenBracketToken);
writeTypeList(type.typeArguments.slice(0, getTypeReferenceArity(type)), SyntaxKind.CommaToken);
Copy link
Member

@sandersn sandersn Aug 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why copy this list? Or are there extra type arguments that slice omits? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a generic type has a this parameter other than itself it is represented as an extra type parameter.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 22, 2016

👍

@ahejlsberg ahejlsberg merged commit 3fb0840 into master Aug 22, 2016
@ahejlsberg ahejlsberg deleted the tupleTypeReferences branch August 22, 2016 22:30
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants