Skip to content

Infer fixed-size tuples from infer type parameters with extends clauses at variadic positions #51157

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 9 commits into from
Jan 3, 2023

Conversation

Andarist
Copy link
Contributor

Fixes #51138

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Oct 12, 2022
Comment on lines 23330 to 23338
if (elementFlags[startLength] & elementFlags[startLength + 1] & ElementFlags.Variadic && isTupleType(source)) {
// Middle of target is [...T, ...U] and source is tuple type
const impliedArity = getInferenceInfoForType(elementTypes[startLength])?.impliedArity;
if (impliedArity !== undefined) {
// Infer slices from source based on implied arity of T.
inferFromTypes(sliceTupleType(source, startLength, endLength + sourceArity - impliedArity), elementTypes[startLength]);
inferFromTypes(sliceTupleType(source, startLength + impliedArity, endLength), elementTypes[startLength + 1]);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this case was already here, it just got indented more since I put all 3 cases (1 old, 2 new ones) within the if (middleLength === 2) block

Comment on lines 23358 to 23359
const trailingSlice = createTupleType(getTypeArguments(source).slice(startIndex, endIndex), source.target.elementFlags.slice(startIndex, endIndex),
/*readonly*/ false, source.target.labeledElementDeclarations && source.target.labeledElementDeclarations.slice(startIndex, endIndex));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is based on the content of the sliceTupleType. However, I wasn't able to reuse that function as the purpose of this slice is different here and sliceTupleType wouldn't work for it - I didn't find another instance of such a "trailing slice" in the codebase so I've just inlined the thing here and adjusted for the needs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To give more context behind this - I can't reuse sliceTupleType as it creates array types when index > target.fixedLength:
https://github.dev/microsoft/TypeScript/blob/acf854b636e0b8e5a12c3f9951d4edfa0fa73bcd/src/compiler/checker.ts#L15758-L15764

So it's not a literal "slice" - it's not just slicing between the startIndex and endIndex - it also performs a type conversion conditionally.

If not that condition, I could reuse the sliceTupleType here as follows:

const impliedArity = constraint.target.fixedLength;
const targetEndLength = getEndElementCount(target.target, ElementFlags.Fixed);

inferFromTypes(sliceTupleType(source, sourceArity - targetEndLength - impliedArity, targetEndLength), elementTypes[startLength + 1]);

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

I think this looks pretty good, though it'll need a sync to main, and some extended test suites run, just in case.

# Conflicts:
#	src/compiler/checker.ts
@Andarist
Copy link
Contributor Author

Andarist commented Nov 7, 2022

@weswigham I've synced this with main. You can trigger those extended test suites now.

@Andarist Andarist requested review from weswigham and removed request for gabritto November 7, 2022 22:42
@weswigham
Copy link
Member

@typescript-bot pack this
@typescript-bot user test this
@typescript-bot test this
@typescript-bot run dt
@typescript-bot test top100
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 8, 2022

Heya @weswigham, I've started to run the perf test suite on this PR at f6840d5. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 8, 2022

Heya @weswigham, I've started to run the extended test suite on this PR at f6840d5. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

Heya @weswigham, I'm starting to run the diff-based user code test suite on this PR at f6840d5. Hold tight - I'll update this comment with the log link once the build has been queued.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 8, 2022

Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at f6840d5. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 8, 2022

Heya @weswigham, I've started to run the tarball bundle task on this PR at f6840d5. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

Heya @weswigham, I'm starting to run the diff-based top-repos suite on this PR at f6840d5. Hold tight - I'll update this comment with the log link once the build has been queued.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 8, 2022

Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/137831/artifacts?artifactName=tgz&fileId=8D2233403759AA0726D4FC331C971B4C72B2671875DB8E4C9FF5A44A5B23509002&fileName=/typescript-5.0.0-insiders.20221108.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

@typescript-bot
Copy link
Collaborator

@weswigham
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - main..51157
Metric main 51157 Delta Best Worst
Angular - node (v18.10.0, x64)
Memory used 341,140k (± 0.01%) 341,132k (± 0.02%) -7k (- 0.00%) 340,943k 341,263k
Parse Time 1.57s (± 0.77%) 1.55s (± 0.77%) -0.01s (- 0.83%) 1.53s 1.59s
Bind Time 0.54s (± 0.89%) 0.54s (± 1.30%) +0.00s (+ 0.37%) 0.53s 0.56s
Check Time 4.04s (± 0.53%) 4.01s (± 0.54%) -0.03s (- 0.67%) 3.94s 4.04s
Emit Time 4.28s (± 0.94%) 4.27s (± 0.81%) -0.02s (- 0.35%) 4.22s 4.39s
Total Time 10.42s (± 0.47%) 10.37s (± 0.49%) -0.05s (- 0.48%) 10.29s 10.52s
Compiler-Unions - node (v18.10.0, x64)
Memory used 189,893k (± 0.65%) 188,810k (± 1.00%) -1,082k (- 0.57%) 184,874k 190,581k
Parse Time 0.62s (± 1.29%) 0.62s (± 1.10%) -0.01s (- 0.96%) 0.61s 0.64s
Bind Time 0.33s (± 0.91%) 0.33s (± 1.67%) +0.00s (+ 1.22%) 0.32s 0.35s
Check Time 5.02s (± 0.69%) 4.97s (± 0.81%) -0.05s (- 0.96%) 4.90s 5.08s
Emit Time 1.52s (± 0.67%) 1.53s (± 1.07%) +0.01s (+ 0.92%) 1.49s 1.56s
Total Time 7.49s (± 0.52%) 7.44s (± 0.65%) -0.04s (- 0.56%) 7.35s 7.56s
Monaco - node (v18.10.0, x64)
Memory used 320,533k (± 0.01%) 320,541k (± 0.02%) +8k (+ 0.00%) 320,426k 320,678k
Parse Time 1.18s (± 2.01%) 1.16s (± 1.18%) -0.01s (- 1.19%) 1.13s 1.20s
Bind Time 0.49s (± 1.43%) 0.49s (± 1.59%) -0.00s (- 0.41%) 0.47s 0.50s
Check Time 3.84s (± 0.68%) 3.85s (± 0.53%) +0.01s (+ 0.31%) 3.80s 3.90s
Emit Time 2.25s (± 1.08%) 2.25s (± 1.33%) +0.00s (+ 0.09%) 2.21s 2.31s
Total Time 7.77s (± 0.71%) 7.76s (± 0.52%) -0.01s (- 0.08%) 7.68s 7.85s
TFS - node (v18.10.0, x64)
Memory used 283,842k (± 0.24%) 283,448k (± 0.22%) -394k (- 0.14%) 282,654k 284,764k
Parse Time 0.98s (± 1.61%) 0.96s (± 1.13%) -0.02s (- 1.74%) 0.94s 0.99s
Bind Time 0.44s (± 1.18%) 0.45s (± 6.35%) +0.01s (+ 1.82%) 0.43s 0.56s
Check Time 3.78s (± 0.62%) 3.78s (± 0.43%) -0.01s (- 0.13%) 3.75s 3.82s
Emit Time 2.19s (± 1.16%) 2.19s (± 0.64%) -0.00s (- 0.05%) 2.16s 2.23s
Total Time 7.40s (± 0.61%) 7.37s (± 0.54%) -0.02s (- 0.28%) 7.30s 7.47s
material-ui - node (v18.10.0, x64)
Memory used 435,999k (± 0.02%) 436,000k (± 0.01%) +1k (+ 0.00%) 435,908k 436,155k
Parse Time 1.34s (± 1.36%) 1.34s (± 0.93%) -0.00s (- 0.22%) 1.31s 1.36s
Bind Time 0.49s (± 1.96%) 0.49s (± 2.29%) +0.00s (+ 1.03%) 0.45s 0.51s
Check Time 10.32s (± 0.82%) 10.32s (± 0.60%) +0.00s (+ 0.01%) 10.19s 10.42s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 12.15s (± 0.60%) 12.15s (± 0.48%) +0.00s (+ 0.01%) 12.04s 12.27s
xstate - node (v18.10.0, x64)
Memory used 518,696k (± 0.01%) 518,656k (± 0.01%) -41k (- 0.01%) 518,605k 518,723k
Parse Time 1.92s (± 0.58%) 1.93s (± 0.78%) +0.01s (+ 0.42%) 1.90s 1.97s
Bind Time 0.78s (± 3.00%) 0.78s (± 3.00%) +0.01s (+ 0.90%) 0.72s 0.83s
Check Time 1.04s (± 0.57%) 1.05s (± 0.94%) +0.01s (+ 1.16%) 1.02s 1.07s
Emit Time 0.05s (± 0.00%) 0.05s (± 0.00%) 0.00s ( 0.00%) 0.05s 0.05s
Total Time 3.79s (± 0.83%) 3.82s (± 0.84%) +0.02s (+ 0.63%) 3.75s 3.88s
Angular - node (v16.17.1, x64)
Memory used 340,543k (± 0.02%) 340,541k (± 0.02%) -2k (- 0.00%) 340,359k 340,629k
Parse Time 1.88s (± 0.73%) 1.89s (± 0.51%) +0.01s (+ 0.32%) 1.87s 1.91s
Bind Time 0.64s (± 0.56%) 0.65s (± 0.68%) +0.01s (+ 1.24%) 0.64s 0.66s
Check Time 5.14s (± 0.71%) 5.16s (± 0.41%) +0.02s (+ 0.33%) 5.09s 5.20s
Emit Time 5.09s (± 1.15%) 5.12s (± 0.80%) +0.03s (+ 0.53%) 5.02s 5.22s
Total Time 12.76s (± 0.72%) 12.82s (± 0.46%) +0.06s (+ 0.49%) 12.69s 12.95s
Compiler-Unions - node (v16.17.1, x64)
Memory used 187,228k (± 0.52%) 187,598k (± 0.61%) +370k (+ 0.20%) 186,546k 190,042k
Parse Time 0.79s (± 0.71%) 0.80s (± 0.75%) +0.01s (+ 1.02%) 0.79s 0.81s
Bind Time 0.42s (± 0.71%) 0.42s (± 0.53%) +0.00s (+ 0.24%) 0.41s 0.42s
Check Time 6.06s (± 0.65%) 6.03s (± 0.52%) -0.03s (- 0.48%) 5.96s 6.09s
Emit Time 1.89s (± 0.59%) 1.89s (± 0.85%) -0.00s (- 0.11%) 1.84s 1.93s
Total Time 9.15s (± 0.55%) 9.13s (± 0.45%) -0.02s (- 0.21%) 9.03s 9.21s
Monaco - node (v16.17.1, x64)
Memory used 319,828k (± 0.01%) 319,871k (± 0.01%) +43k (+ 0.01%) 319,797k 319,960k
Parse Time 1.43s (± 0.85%) 1.43s (± 0.77%) +0.00s (+ 0.28%) 1.40s 1.45s
Bind Time 0.59s (± 0.76%) 0.59s (± 0.50%) +0.00s (+ 0.68%) 0.59s 0.60s
Check Time 4.86s (± 0.49%) 4.88s (± 0.34%) +0.01s (+ 0.27%) 4.83s 4.91s
Emit Time 2.72s (± 0.53%) 2.73s (± 0.74%) +0.01s (+ 0.37%) 2.69s 2.78s
Total Time 9.60s (± 0.36%) 9.63s (± 0.30%) +0.03s (+ 0.29%) 9.57s 9.70s
TFS - node (v16.17.1, x64)
Memory used 282,286k (± 0.01%) 282,290k (± 0.01%) +4k (+ 0.00%) 282,260k 282,340k
Parse Time 1.16s (± 0.76%) 1.17s (± 0.86%) +0.01s (+ 1.21%) 1.16s 1.20s
Bind Time 0.65s (± 4.43%) 0.66s (± 3.86%) +0.01s (+ 0.92%) 0.58s 0.70s
Check Time 4.74s (± 0.53%) 4.76s (± 0.51%) +0.02s (+ 0.40%) 4.68s 4.80s
Emit Time 2.74s (± 2.33%) 2.79s (± 2.36%) +0.05s (+ 1.90%) 2.66s 2.91s
Total Time 9.29s (± 0.93%) 9.38s (± 0.86%) +0.09s (+ 0.96%) 9.19s 9.56s
material-ui - node (v16.17.1, x64)
Memory used 435,309k (± 0.00%) 435,287k (± 0.00%) -22k (- 0.00%) 435,240k 435,331k
Parse Time 1.64s (± 0.63%) 1.65s (± 0.37%) +0.01s (+ 0.67%) 1.63s 1.66s
Bind Time 0.50s (± 0.99%) 0.50s (± 0.95%) +0.01s (+ 1.41%) 0.49s 0.51s
Check Time 11.80s (± 0.78%) 11.92s (± 0.74%) +0.13s (+ 1.07%) 11.71s 12.14s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 13.93s (± 0.70%) 14.07s (± 0.65%) +0.14s (+ 1.01%) 13.86s 14.29s
xstate - node (v16.17.1, x64)
Memory used 516,238k (± 0.01%) 516,242k (± 0.01%) +4k (+ 0.00%) 516,158k 516,444k
Parse Time 2.31s (± 0.46%) 2.32s (± 0.42%) +0.01s (+ 0.48%) 2.30s 2.34s
Bind Time 0.86s (± 3.14%) 0.85s (± 1.61%) -0.01s (- 0.82%) 0.83s 0.88s
Check Time 1.35s (± 0.80%) 1.35s (± 0.65%) -0.00s (- 0.15%) 1.33s 1.36s
Emit Time 0.06s (± 0.00%) 0.06s (± 0.00%) 0.00s ( 0.00%) 0.06s 0.06s
Total Time 4.58s (± 0.59%) 4.58s (± 0.46%) -0.00s (- 0.02%) 4.54s 4.64s
Angular - node (v14.15.1, x64)
Memory used 334,028k (± 0.01%) 334,057k (± 0.00%) +29k (+ 0.01%) 334,023k 334,075k
Parse Time 2.05s (± 0.54%) 2.05s (± 0.44%) 0.00s ( 0.00%) 2.03s 2.07s
Bind Time 0.70s (± 1.40%) 0.70s (± 0.95%) -0.00s (- 0.28%) 0.69s 0.72s
Check Time 5.47s (± 0.31%) 5.50s (± 0.41%) +0.03s (+ 0.46%) 5.44s 5.56s
Emit Time 5.19s (± 0.43%) 5.20s (± 0.63%) +0.01s (+ 0.27%) 5.13s 5.31s
Total Time 13.41s (± 0.20%) 13.45s (± 0.31%) +0.03s (+ 0.25%) 13.35s 13.54s
Compiler-Unions - node (v14.15.1, x64)
Memory used 182,248k (± 0.55%) 181,871k (± 0.41%) -377k (- 0.21%) 181,290k 184,846k
Parse Time 0.89s (± 0.95%) 0.89s (± 0.58%) -0.00s (- 0.22%) 0.88s 0.90s
Bind Time 0.46s (± 0.80%) 0.46s (± 1.08%) 0.00s ( 0.00%) 0.45s 0.47s
Check Time 6.29s (± 0.64%) 6.31s (± 0.32%) +0.01s (+ 0.22%) 6.27s 6.34s
Emit Time 2.04s (± 1.40%) 2.04s (± 1.30%) +0.00s (+ 0.15%) 1.99s 2.11s
Total Time 9.68s (± 0.45%) 9.70s (± 0.43%) +0.02s (+ 0.18%) 9.62s 9.80s
Monaco - node (v14.15.1, x64)
Memory used 314,616k (± 0.01%) 314,604k (± 0.01%) -12k (- 0.00%) 314,546k 314,682k
Parse Time 1.56s (± 0.44%) 1.57s (± 0.73%) +0.01s (+ 0.58%) 1.55s 1.60s
Bind Time 0.63s (± 0.54%) 0.64s (± 0.78%) +0.00s (+ 0.32%) 0.63s 0.65s
Check Time 5.20s (± 0.46%) 5.18s (± 0.44%) -0.01s (- 0.27%) 5.14s 5.24s
Emit Time 2.87s (± 0.52%) 2.88s (± 1.06%) +0.02s (+ 0.56%) 2.83s 2.97s
Total Time 10.26s (± 0.25%) 10.27s (± 0.39%) +0.01s (+ 0.14%) 10.18s 10.35s
TFS - node (v14.15.1, x64)
Memory used 279,337k (± 0.01%) 279,311k (± 0.01%) -26k (- 0.01%) 279,247k 279,368k
Parse Time 1.34s (± 1.37%) 1.34s (± 1.74%) +0.00s (+ 0.07%) 1.31s 1.42s
Bind Time 0.59s (± 0.84%) 0.59s (± 0.38%) +0.00s (+ 0.51%) 0.58s 0.59s
Check Time 5.06s (± 0.36%) 5.06s (± 0.29%) +0.01s (+ 0.14%) 5.04s 5.09s
Emit Time 3.04s (± 0.62%) 3.07s (± 0.91%) +0.03s (+ 1.09%) 3.02s 3.12s
Total Time 10.02s (± 0.37%) 10.06s (± 0.28%) +0.04s (+ 0.40%) 9.99s 10.12s
material-ui - node (v14.15.1, x64)
Memory used 430,754k (± 0.01%) 430,724k (± 0.00%) -30k (- 0.01%) 430,699k 430,764k
Parse Time 1.87s (± 0.73%) 1.88s (± 0.55%) +0.01s (+ 0.53%) 1.86s 1.90s
Bind Time 0.53s (± 0.84%) 0.53s (± 0.63%) -0.00s (- 0.38%) 0.52s 0.54s
Check Time 12.19s (± 0.50%) 12.16s (± 0.38%) -0.03s (- 0.21%) 12.07s 12.32s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 14.59s (± 0.46%) 14.57s (± 0.33%) -0.02s (- 0.13%) 14.48s 14.73s
xstate - node (v14.15.1, x64)
Memory used 504,443k (± 0.01%) 504,479k (± 0.01%) +35k (+ 0.01%) 504,431k 504,660k
Parse Time 2.65s (± 0.52%) 2.64s (± 0.62%) -0.01s (- 0.23%) 2.59s 2.67s
Bind Time 0.84s (± 0.56%) 0.85s (± 0.96%) +0.01s (+ 0.83%) 0.83s 0.87s
Check Time 1.47s (± 0.75%) 1.47s (± 0.46%) -0.01s (- 0.41%) 1.45s 1.48s
Emit Time 0.07s (± 0.00%) 0.07s (± 0.00%) 0.00s ( 0.00%) 0.07s 0.07s
Total Time 5.03s (± 0.33%) 5.02s (± 0.43%) -0.01s (- 0.18%) 4.98s 5.06s
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-131-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v18.10.0, x64)
  • Angular - node (v16.17.1, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v18.10.0, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v18.10.0, x64)
  • Monaco - node (v16.17.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v18.10.0, x64)
  • TFS - node (v16.17.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v18.10.0, x64)
  • material-ui - node (v16.17.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v18.10.0, x64)
  • xstate - node (v16.17.1, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 51157 10
Baseline main 10

TSServer

Comparison Report - main..51157
Metric main 51157 Delta Best Worst
Compiler-UnionsTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 1,052ms (± 0.83%) 1,060ms (± 0.79%) +8ms (+ 0.73%) 1,041ms 1,075ms
Req 2 - geterr 2,559ms (± 0.74%) 2,561ms (± 1.00%) +2ms (+ 0.07%) 2,493ms 2,610ms
Req 3 - references 165ms (± 0.80%) 167ms (± 0.41%) +1ms (+ 0.85%) 165ms 168ms
Req 4 - navto 139ms (± 0.63%) 138ms (± 0.60%) -1ms (- 0.43%) 137ms 140ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 62ms (± 4.40%) 61ms (± 2.71%) -1ms (- 1.45%) 57ms 64ms
CompilerTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 1,099ms (± 0.55%) 1,111ms (± 0.82%) +12ms (+ 1.12%) 1,080ms 1,123ms
Req 2 - geterr 1,572ms (± 0.64%) 1,572ms (± 0.80%) +0ms (+ 0.01%) 1,555ms 1,612ms
Req 3 - references 169ms (± 0.46%) 170ms (± 0.78%) +1ms (+ 0.35%) 166ms 173ms
Req 4 - navto 157ms (± 7.24%) 158ms (± 6.95%) +1ms (+ 0.32%) 151ms 202ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 53ms (± 2.07%) 54ms (± 2.97%) +1ms (+ 1.70%) 50ms 59ms
xstateTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 1,523ms (± 0.58%) 1,530ms (± 0.60%) +7ms (+ 0.43%) 1,510ms 1,550ms
Req 2 - geterr 554ms (± 0.97%) 557ms (± 0.66%) +3ms (+ 0.52%) 548ms 564ms
Req 3 - references 59ms (± 1.82%) 59ms (± 2.36%) +0ms (+ 0.68%) 57ms 63ms
Req 4 - navto 197ms (± 0.95%) 199ms (± 0.55%) +2ms (+ 1.12%) 197ms 201ms
Req 5 - completionInfo count 3,149 (± 0.00%) 3,149 (± 0.00%) 0 ( 0.00%) 3,149 3,149
Req 5 - completionInfo 211ms (± 1.64%) 213ms (± 1.57%) +2ms (+ 0.95%) 203ms 221ms
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 1,306ms (± 0.69%) 1,308ms (± 0.38%) +2ms (+ 0.14%) 1,299ms 1,323ms
Req 2 - geterr 3,165ms (± 0.76%) 3,179ms (± 0.63%) +14ms (+ 0.45%) 3,140ms 3,228ms
Req 3 - references 190ms (± 0.98%) 194ms (± 0.87%) +4ms (+ 2.26%) 189ms 197ms
Req 4 - navto 151ms (± 0.62%) 151ms (± 0.63%) +0ms (+ 0.07%) 150ms 154ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 59ms (± 2.81%) 59ms (± 2.47%) -1ms (- 1.18%) 56ms 62ms
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 1,399ms (± 0.77%) 1,392ms (± 0.69%) -7ms (- 0.49%) 1,372ms 1,418ms
Req 2 - geterr 2,067ms (± 0.53%) 2,075ms (± 0.32%) +8ms (+ 0.40%) 2,061ms 2,091ms
Req 3 - references 200ms (± 0.50%) 201ms (± 0.74%) +1ms (+ 0.70%) 199ms 206ms
Req 4 - navto 165ms (± 1.02%) 166ms (± 0.93%) +1ms (+ 0.79%) 163ms 170ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 58ms (± 2.85%) 59ms (± 2.61%) +1ms (+ 0.86%) 55ms 61ms
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 1,826ms (± 0.56%) 1,837ms (± 0.47%) +11ms (+ 0.59%) 1,817ms 1,860ms
Req 2 - geterr 717ms (± 0.45%) 714ms (± 0.52%) -3ms (- 0.47%) 705ms 723ms
Req 3 - references 68ms (± 1.14%) 68ms (± 1.49%) -0ms (- 0.44%) 65ms 70ms
Req 4 - navto 199ms (± 0.94%) 198ms (± 1.03%) -1ms (- 0.25%) 194ms 203ms
Req 5 - completionInfo count 3,149 (± 0.00%) 3,149 (± 0.00%) 0 ( 0.00%) 3,149 3,149
Req 5 - completionInfo 252ms (± 0.80%) 253ms (± 0.79%) +1ms (+ 0.36%) 250ms 258ms
Compiler-UnionsTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 1,447ms (± 0.77%) 1,452ms (± 0.29%) +5ms (+ 0.34%) 1,442ms 1,462ms
Req 2 - geterr 3,399ms (± 0.82%) 3,391ms (± 0.65%) -8ms (- 0.24%) 3,340ms 3,447ms
Req 3 - references 205ms (± 0.62%) 206ms (± 0.96%) +1ms (+ 0.39%) 203ms 212ms
Req 4 - navto 161ms (± 1.02%) 162ms (± 1.33%) +2ms (+ 1.12%) 159ms 169ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 68ms (± 5.85%) 64ms (± 7.61%) 🟩-4ms (- 5.75%) 57ms 73ms
CompilerTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 1,524ms (± 0.45%) 1,532ms (± 0.41%) +8ms (+ 0.52%) 1,520ms 1,545ms
Req 2 - geterr 2,239ms (± 0.34%) 2,256ms (± 0.44%) +18ms (+ 0.78%) 2,225ms 2,272ms
Req 3 - references 212ms (± 1.55%) 214ms (± 1.01%) +1ms (+ 0.66%) 209ms 219ms
Req 4 - navto 172ms (± 0.86%) 176ms (± 0.69%) +3ms (+ 1.92%) 173ms 178ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 60ms (± 6.44%) 64ms (± 8.21%) +4ms (+ 7.39%) 56ms 73ms
xstateTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 2,002ms (± 0.46%) 2,013ms (± 0.52%) +11ms (+ 0.55%) 1,993ms 2,038ms
Req 2 - geterr 739ms (± 0.43%) 737ms (± 0.24%) -2ms (- 0.20%) 733ms 742ms
Req 3 - references 71ms (± 1.58%) 71ms (± 1.02%) +1ms (+ 0.99%) 70ms 73ms
Req 4 - navto 219ms (± 0.75%) 217ms (± 0.54%) -2ms (- 0.69%) 214ms 219ms
Req 5 - completionInfo count 3,149 (± 0.00%) 3,149 (± 0.00%) 0 ( 0.00%) 3,149 3,149
Req 5 - completionInfo 269ms (± 1.57%) 273ms (± 2.31%) +4ms (+ 1.45%) 265ms 288ms
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-131-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.15.1, x64)
Scenarios
  • Compiler-UnionsTSServer - node (v18.10.0, x64)
  • Compiler-UnionsTSServer - node (v16.17.1, x64)
  • Compiler-UnionsTSServer - node (v14.15.1, x64)
  • CompilerTSServer - node (v18.10.0, x64)
  • CompilerTSServer - node (v16.17.1, x64)
  • CompilerTSServer - node (v14.15.1, x64)
  • xstateTSServer - node (v18.10.0, x64)
  • xstateTSServer - node (v16.17.1, x64)
  • xstateTSServer - node (v14.15.1, x64)
Benchmark Name Iterations
Current 51157 10
Baseline main 10

Startup

Comparison Report - main..51157
Metric main 51157 Delta Best Worst
tsc-startup - node (v16.17.1, x64)
Execution time 117.03ms (± 0.40%) 119.15ms (± 0.56%) +2.11ms (+ 1.81%) 115.73ms 124.94ms
tsserver-startup - node (v16.17.1, x64)
Execution time 198.35ms (± 0.36%) 198.94ms (± 0.34%) +0.58ms (+ 0.29%) 195.76ms 206.99ms
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 187.69ms (± 0.34%) 188.04ms (± 0.34%) +0.35ms (+ 0.19%) 184.43ms 199.70ms
typescript-startup - node (v16.17.1, x64)
Execution time 174.19ms (± 0.35%) 173.69ms (± 0.33%) -0.50ms (- 0.29%) 171.21ms 180.88ms
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-131-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v16.17.1, x64)
Scenarios
  • tsc-startup - node (v16.17.1, x64)
  • tsserver-startup - node (v16.17.1, x64)
  • tsserverlibrary-startup - node (v16.17.1, x64)
  • typescript-startup - node (v16.17.1, x64)
Benchmark Name Iterations
Current 51157 10
Baseline main 10

Developer Information:

Download Benchmark

Copy link
Member

@gabritto gabritto left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I left some comments about missing things, but everything else looks great. If you can add what's missing, then I think we'll be good to merge this. 😊

if (constraint && isTupleType(constraint) && !constraint.target.hasRestElement) {
const impliedArity = constraint.target.fixedLength;
inferFromTypes(sliceTupleType(source, startLength, sourceArity - (startLength + impliedArity)), elementTypes[startLength]);
}
Copy link
Member

Choose a reason for hiding this comment

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

I believe we also need to infer into the rest element here, if the source arity allows (i.e. there are left over elements after inferring into the tuple constraint). Right now, we're only inferring into the variadic type, so we don't infer into the rest element in a case like this:

type SubTup2Variadic2<T extends unknown[]> = T extends [
    ...infer B extends [any, any],
    ...(infer C)[]
]
    ? [...B, ...[C]]
    : never;

type SubTup2Variadic2Test = SubTup2Variadic2<[a: 0, b: 1, ...c: number[]]>; // Currently [0, 1, unknown], should be [0, 1, number]

const impliedArity = constraint.target.fixedLength;
const endIndex = sourceArity - getEndElementCount(target.target, ElementFlags.Fixed);
const startIndex = endIndex - impliedArity;
const trailingSlice = createTupleType(getTypeArguments(source).slice(startIndex, endIndex), source.target.elementFlags.slice(startIndex, endIndex),
Copy link
Member

Choose a reason for hiding this comment

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

Is there some reason to use createTupleType instead of sliceTupleType here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've mentioned this here but perhaps without going much into the relevant details.

Right now... I'm not exactly sure why I had to do it but I had some reason as I've used sliceTyupleType in other branches and I've called it out in the comment that I wasn't able to use it here. I can try to refresh my memory on this one later and provide the appropriate details

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the requested clarification here: #51157 (comment)

const trailingSlice = createTupleType(getTypeArguments(source).slice(startIndex, endIndex), source.target.elementFlags.slice(startIndex, endIndex),
/*readonly*/ false, source.target.labeledElementDeclarations && source.target.labeledElementDeclarations.slice(startIndex, endIndex));
inferFromTypes(trailingSlice, elementTypes[startLength + 1]);
}
Copy link
Member

Choose a reason for hiding this comment

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

Same as in the case above, we should also infer into the rest type if possible, for cases like this:

type SubTup2TrailingVariadic2<T extends unknown[]> = T extends [
    ...(infer C)[],
    ...infer B extends [any, any],
]
    ? [C, ...B]
    : never;

type SubTup2TrailingVariadic2Test = SubTup2TrailingVariadic2<[...a: number[], b: 1, c: 2]>; // Currently [unknown, 1, 2], should be [number, 1, 2].

@Andarist
Copy link
Contributor Author

@gabritto thank you for the additional test cases! I will take a look into supporting them in the coming days.

@Andarist
Copy link
Contributor Author

@gabritto I pushed out the requested improvements (inferring for the rest elements appearing with the variadic elements with those fixed-size tuple constraints). Could you take another look and re-review it?

@Andarist Andarist requested review from gabritto and removed request for weswigham December 26, 2022 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Inferred subtuple types in extends expression not narrowed if variadic (i.e. has a rest element)
4 participants