Skip to content

Fixed type parameter leak in union calls with mixed type parameter presence #57371

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

Conversation

Andarist
Copy link
Contributor

fixes #57356

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Feb 11, 2024
@@ -13540,6 +13540,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
result.compositeSignatures = concatenate(left.compositeKind !== TypeFlags.Intersection && left.compositeSignatures || [left], [right]);
if (paramMapper) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the gist of the issue was that first 2 calls with type params were unionized here (so paramMapper was created and attached to became left.mapper in the next iteration) but then that composite signature was unionized with one without the type params so the left.mapper wasn't attached to the result (because paramMapper was not created this time)

@@ -13540,6 +13540,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
result.compositeSignatures = concatenate(left.compositeKind !== TypeFlags.Intersection && left.compositeSignatures || [left], [right]);
if (paramMapper) {
result.mapper = left.compositeKind !== TypeFlags.Intersection && left.mapper && left.compositeSignatures ? combineTypeMappers(left.mapper, paramMapper) : paramMapper;
}
else if (left.compositeKind !== TypeFlags.Intersection && left.mapper && left.compositeSignatures) {
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 whole function is very similar to combineSignaturesOfIntersectionMembers so I thought that there might be a similar problem there but so far I couldn't create a test case that would manifest an issue there.

It's also worth noting that both of those functions check left.compositeKind but it's never the "other one" in the existing test suite (in combineSignaturesOfIntersectionMembers we never witness left.compositeKind === TypeFlags.Union and in combineSignaturesOfUnionMembers we never witness left.compositeKind === TypeFlags.Intersection). So either some tests are missing or those branches are unused.

@Andarist Andarist force-pushed the fix-type-param-leak-union-signature branch from 8f10bf7 to a4f0d66 Compare February 11, 2024 09:50
@weswigham
Copy link
Member

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2024

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2024

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2024

Heya @weswigham, I've started to run the diff-based top-repos suite on this PR at a4f0d66. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2024

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2024

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/159833/artifacts?artifactName=tgz&fileId=C8A9595F66800C629D865536766573392E2F7CB901DD45921CED66BF327B1D7A02&fileName=/typescript-5.4.0-insiders.20240212.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/pr-build@5.4.0-pr-57371-5".;

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
mui-docs - node (v20.5.1, x64)
Memory used 2,382,586k (± 0.00%) 2,382,612k (± 0.01%) ~ 2,382,395k 2,382,899k p=0.521 n=6
Parse Time 12.24s (± 2.30%) 12.16s (± 0.58%) ~ 12.06s 12.25s p=1.000 n=6
Bind Time 2.67s (± 0.94%) 2.67s (± 0.73%) ~ 2.65s 2.70s p=0.808 n=6
Check Time 96.90s (± 0.98%) 97.99s (± 1.49%) ~ 96.37s 100.62s p=0.173 n=6
Emit Time 0.31s (± 1.32%) 0.31s (± 1.32%) ~ 0.30s 0.31s p=1.000 n=6
Total Time 112.12s (± 0.86%) 113.13s (± 1.26%) ~ 111.54s 115.68s p=0.173 n=6
self-build-src - node (v20.5.1, x64)
Memory used 2,639,803k (± 5.36%) 2,581,515k (± 0.03%) ~ 2,580,775k 2,582,539k p=0.230 n=6
Parse Time 5.07s (± 1.15%) 5.07s (± 0.95%) ~ 4.98s 5.11s p=0.471 n=6
Bind Time 1.99s (± 0.83%) 1.99s (± 0.59%) ~ 1.97s 2.00s p=0.682 n=6
Check Time 32.08s (± 0.22%) 32.17s (± 0.33%) ~ 32.10s 32.38s p=0.173 n=6
Emit Time 2.74s (± 2.14%) 2.79s (± 2.41%) ~ 2.69s 2.88s p=0.199 n=6
Total Time 41.89s (± 0.20%) 42.03s (± 0.20%) +0.14s (+ 0.34%) 41.93s 42.12s p=0.020 n=6
self-compiler - node (v20.5.1, x64)
Memory used 418,456k (± 0.02%) 418,424k (± 0.02%) ~ 418,334k 418,536k p=0.689 n=6
Parse Time 2.90s (± 0.61%) 2.89s (± 0.51%) ~ 2.87s 2.91s p=0.118 n=6
Bind Time 1.14s (± 0.45%) 1.14s (± 0.66%) ~ 1.13s 1.15s p=0.784 n=6
Check Time 14.14s (± 0.19%) 14.16s (± 0.32%) ~ 14.10s 14.21s p=0.629 n=6
Emit Time 1.04s (± 1.49%) 1.04s (± 1.18%) ~ 1.03s 1.06s p=0.340 n=6
Total Time 19.22s (± 0.27%) 19.22s (± 0.25%) ~ 19.16s 19.28s p=0.936 n=6
vscode - node (v20.5.1, x64)
Memory used 2,874,843k (± 0.00%) 2,874,871k (± 0.00%) ~ 2,874,831k 2,874,928k p=0.810 n=6
Parse Time 10.86s (± 0.21%) 10.84s (± 0.30%) ~ 10.79s 10.88s p=0.411 n=6
Bind Time 3.46s (± 0.35%) 3.46s (± 0.64%) ~ 3.44s 3.50s p=0.684 n=6
Check Time 57.97s (± 0.63%) 57.70s (± 0.31%) ~ 57.51s 57.96s p=0.298 n=6
Emit Time 17.01s (± 8.63%) 16.41s (± 0.35%) ~ 16.34s 16.48s p=0.521 n=6
Total Time 89.31s (± 1.58%) 88.42s (± 0.17%) ~ 88.19s 88.57s p=0.149 n=6
webpack - node (v20.5.1, x64)
Memory used 397,204k (± 0.01%) 397,200k (± 0.01%) ~ 397,138k 397,244k p=1.000 n=6
Parse Time 3.39s (± 0.43%) 3.39s (± 0.31%) ~ 3.37s 3.40s p=0.805 n=6
Bind Time 1.45s (± 0.81%) 1.45s (± 0.95%) ~ 1.43s 1.46s p=0.742 n=6
Check Time 13.10s (± 0.33%) 13.10s (± 0.19%) ~ 13.08s 13.13s p=1.000 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 17.94s (± 0.24%) 17.94s (± 0.14%) ~ 17.91s 17.98s p=1.000 n=6
System info unknown
Hosts
  • node (v20.5.1, x64)
Scenarios
  • mui-docs - node (v20.5.1, x64)
  • self-build-src - node (v20.5.1, x64)
  • self-compiler - node (v20.5.1, x64)
  • vscode - node (v20.5.1, x64)
  • webpack - node (v20.5.1, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

Hey @weswigham, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@typescript-bot
Copy link
Collaborator

@weswigham Here are the results of running the top-repos suite comparing main and refs/pull/57371/merge:

Everything looks good!

@weswigham weswigham merged commit 0b4966a into microsoft:main Feb 12, 2024
@Andarist Andarist deleted the fix-type-param-leak-union-signature branch February 12, 2024 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unbound type parameter leak when calling union of methods in some circumstances
3 participants