Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Unify representation of tuples and other generic types#10466

Merged
ahejlsberg merged 5 commits into
mastermicrosoft/TypeScript:masterfrom
tupleTypeReferencesmicrosoft/TypeScript:tupleTypeReferencesCopy head branch name to clipboard
Aug 22, 2016
Merged

Unify representation of tuples and other generic types#10466
ahejlsberg merged 5 commits into
mastermicrosoft/TypeScript:masterfrom
tupleTypeReferencesmicrosoft/TypeScript:tupleTypeReferencesCopy head branch name to clipboard

Conversation

@ahejlsberg

@ahejlsberg ahejlsberg commented Aug 22, 2016

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

Will this be developed into #5453 ?

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

@weswigham

Copy link
Copy Markdown
Member

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

Comment thread src/compiler/checker.ts
}
else if (type.target.flags & TypeFlags.Tuple) {
writePunctuation(writer, SyntaxKind.OpenBracketToken);
writeTypeList(type.typeArguments.slice(0, getTypeReferenceArity(type)), SyntaxKind.CommaToken);

@sandersn sandersn Aug 22, 2016

Copy link
Copy Markdown
Member

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
Copy Markdown
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

mhegazy commented Aug 22, 2016

Copy link
Copy Markdown
Contributor

👍

@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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.