Skip to content
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

Infer from annotated parameters of context sensitive functions in the first inference pass #56460

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Nov 19, 2023

fixes #56459
fixes #60047
fixes #60648

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 19, 2023
@typescript-bot typescript-bot removed the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 29, 2023
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Nov 29, 2023
@Andarist
Copy link
Contributor Author

@jakebailey could you run the extended test suite here? :)

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 24, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests with tsc comparing main and refs/pull/56460/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

@jakebailey
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
Compiler-Unions - node (v18.15.0, x64)
Errors 30 30 ~ ~ ~ p=1.000 n=6
Symbols 62,340 62,340 ~ ~ ~ p=1.000 n=6
Types 50,378 50,378 ~ ~ ~ p=1.000 n=6
Memory used 193,997k (± 0.90%) 195,147k (± 0.90%) ~ 192,687k 196,341k p=0.298 n=6
Parse Time 1.57s (± 1.19%) 1.57s (± 0.40%) ~ 1.56s 1.58s p=0.677 n=6
Bind Time 0.86s (± 0.60%) 0.86s (± 1.20%) ~ 0.85s 0.87s p=0.204 n=6
Check Time 11.38s (± 0.28%) 11.35s (± 0.38%) ~ 11.28s 11.40s p=0.414 n=6
Emit Time 3.24s (± 1.09%) 3.25s (± 0.81%) ~ 3.21s 3.28s p=0.747 n=6
Total Time 17.05s (± 0.33%) 17.04s (± 0.15%) ~ 17.00s 17.08s p=1.000 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 7 ~ ~ ~ p=1.000 n=6
Symbols 947,102 947,104 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 410,738 410,744 +6 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 1,224,025k (± 0.00%) 1,223,983k (± 0.00%) ~ 1,223,925k 1,224,065k p=0.128 n=6
Parse Time 6.60s (± 0.54%) 6.59s (± 0.78%) ~ 6.54s 6.67s p=0.422 n=6
Bind Time 1.87s (± 0.22%) 1.87s ~ ~ ~ p=0.405 n=6
Check Time 31.28s (± 0.31%) 31.34s (± 0.12%) ~ 31.29s 31.38s p=0.376 n=6
Emit Time 15.07s (± 0.76%) 15.04s (± 0.44%) ~ 14.95s 15.12s p=0.748 n=6
Total Time 54.82s (± 0.25%) 54.83s (± 0.14%) ~ 54.72s 54.91s p=1.000 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,521,651 2,521,572 -79 (- 0.00%) ~ ~ p=0.001 n=6
Types 936,037 936,022 -15 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 2,351,741k (± 0.00%) 2,351,774k (± 0.00%) ~ 2,351,703k 2,351,859k p=0.298 n=6
Parse Time 9.29s (± 0.24%) 9.28s (± 0.33%) ~ 9.24s 9.32s p=0.518 n=6
Bind Time 2.14s (± 0.42%) 2.14s (± 0.35%) ~ 2.13s 2.15s p=0.798 n=6
Check Time 73.38s (± 0.66%) 73.55s (± 0.41%) ~ 73.02s 73.79s p=0.378 n=6
Emit Time 0.28s (± 2.70%) 0.27s (± 2.77%) ~ 0.26s 0.28s p=0.195 n=6
Total Time 85.09s (± 0.57%) 85.24s (± 0.38%) ~ 84.68s 85.51s p=0.470 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,249,990 1,249,995 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Types 264,937 264,936 -1 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 2,403,943k (± 0.04%) 2,404,184k (± 0.04%) ~ 2,403,094k 2,405,323k p=0.936 n=6
Parse Time 5.14s (± 0.87%) 5.10s (± 0.95%) ~ 5.05s 5.18s p=0.126 n=6
Bind Time 1.90s (± 0.72%) 1.90s (± 0.43%) ~ 1.89s 1.91s p=0.933 n=6
Check Time 34.90s (± 0.46%) 35.00s (± 0.43%) ~ 34.90s 35.30s p=0.126 n=6
Emit Time 3.06s (± 5.00%) 3.05s (± 4.75%) ~ 2.93s 3.26s p=0.809 n=6
Total Time 45.02s (± 0.52%) 45.08s (± 0.40%) ~ 44.85s 45.33s p=0.810 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,249,990 1,249,995 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Types 264,937 264,936 -1 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 2,479,239k (± 0.02%) 2,478,244k (± 0.01%) -996k (- 0.04%) 2,477,876k 2,478,497k p=0.031 n=6
Parse Time 5.29s (± 0.80%) 5.30s (± 0.97%) ~ 5.23s 5.36s p=0.748 n=6
Bind Time 1.72s (± 0.48%) 1.72s (± 0.57%) ~ 1.71s 1.73s p=0.862 n=6
Check Time 35.22s (± 0.35%) 35.34s (± 0.72%) ~ 35.06s 35.78s p=0.423 n=6
Emit Time 3.03s (± 5.73%) 3.00s (± 0.69%) ~ 2.98s 3.03s p=0.520 n=6
Total Time 45.28s (± 0.40%) 45.38s (± 0.63%) ~ 45.12s 45.85s p=0.689 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 260,917 260,916 -1 (- 0.00%) ~ ~ p=0.001 n=6
Types 106,357 106,356 -1 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 436,535k (± 0.04%) 436,686k (± 0.04%) ~ 436,450k 436,905k p=0.173 n=6
Parse Time 3.45s (± 0.89%) 3.46s (± 1.17%) ~ 3.40s 3.51s p=0.936 n=6
Bind Time 1.31s (± 0.39%) 1.31s (± 0.57%) ~ 1.30s 1.32s p=0.784 n=6
Check Time 18.15s (± 0.34%) 18.14s (± 0.29%) ~ 18.08s 18.21s p=0.810 n=6
Emit Time 1.53s (± 2.08%) 1.52s (± 1.64%) ~ 1.49s 1.56s p=0.872 n=6
Total Time 24.44s (± 0.26%) 24.43s (± 0.26%) ~ 24.32s 24.50s p=1.000 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 68 ~ ~ ~ p=1.000 n=6
Symbols 225,916 225,916 ~ ~ ~ p=1.000 n=6
Types 94,414 94,414 ~ ~ ~ p=1.000 n=6
Memory used 370,896k (± 0.03%) 370,975k (± 0.03%) ~ 370,800k 371,119k p=0.298 n=6
Parse Time 2.76s (± 0.42%) 2.74s (± 1.15%) ~ 2.70s 2.78s p=0.369 n=6
Bind Time 1.57s (± 1.90%) 1.57s (± 0.87%) ~ 1.56s 1.59s p=0.935 n=6
Check Time 15.83s (± 0.34%) 15.84s (± 0.30%) ~ 15.79s 15.90s p=0.747 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.16s (± 0.39%) 20.15s (± 0.36%) ~ 20.06s 20.24s p=1.000 n=6
vscode - node (v18.15.0, x64)
Errors 1 1 ~ ~ ~ p=1.000 n=6
Symbols 3,099,008 3,098,997 -11 (- 0.00%) ~ ~ p=0.001 n=6
Types 1,068,764 1,068,755 -9 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 3,196,196k (± 0.01%) 3,196,336k (± 0.00%) ~ 3,196,260k 3,196,367k p=0.810 n=6
Parse Time 13.88s (± 0.40%) 13.88s (± 0.49%) ~ 13.80s 13.97s p=0.873 n=6
Bind Time 4.33s (± 0.25%) 4.33s (± 0.62%) ~ 4.30s 4.37s p=1.000 n=6
Check Time 81.57s (± 0.39%) 81.71s (± 0.30%) ~ 81.38s 81.98s p=0.297 n=6
Emit Time 22.40s (± 1.72%) 22.26s (± 0.29%) ~ 22.18s 22.37s p=0.575 n=6
Total Time 122.17s (± 0.37%) 122.18s (± 0.20%) ~ 121.87s 122.47s p=1.000 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 278,920 278,921 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 113,837 113,837 ~ ~ ~ p=1.000 n=6
Memory used 428,440k (± 0.02%) 428,437k (± 0.02%) ~ 428,319k 428,509k p=1.000 n=6
Parse Time 4.89s (± 0.44%) 4.89s (± 0.46%) ~ 4.86s 4.92s p=0.935 n=6
Bind Time 2.12s (± 0.75%) 2.13s (± 0.77%) ~ 2.11s 2.15s p=0.616 n=6
Check Time 21.87s (± 0.42%) 21.96s (± 0.63%) ~ 21.71s 22.11s p=0.199 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 28.88s (± 0.34%) 28.98s (± 0.57%) ~ 28.68s 29.15s p=0.229 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 540,027 540,075 +48 (+ 0.01%) ~ ~ p=0.001 n=6
Types 181,292 181,342 +50 (+ 0.03%) ~ ~ p=0.001 n=6
Memory used 483,516k (± 0.01%) 483,534k (± 0.01%) ~ 483,463k 483,624k p=0.810 n=6
Parse Time 4.01s (± 0.26%) 4.02s (± 0.47%) ~ 3.99s 4.04s p=1.000 n=6
Bind Time 1.42s (± 0.57%) 1.43s (± 0.85%) ~ 1.41s 1.44s p=0.677 n=6
Check Time 22.86s (± 0.22%) 22.84s (± 0.28%) ~ 22.76s 22.94s p=0.629 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 28.29s (± 0.21%) 28.28s (± 0.19%) ~ 28.22s 28.34s p=0.746 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 400 repos with tsc comparing main and refs/pull/56460/merge:

Everything looks good!

@jakebailey
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 25, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
pack this ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 25, 2024

Hey @jakebailey, 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/163721/artifacts?artifactName=tgz&fileId=38CAD1B2C67CA2FCC8B4A76C2D66BE653CFF98531EB9AA4C10F06CC22114767B02&fileName=/typescript-5.7.0-insiders.20240925.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.7.0-pr-56460-9".;

Comment on lines 38920 to 38925
if (checkMode & CheckMode.Inferential) {
const contextualSignature = getContextualSignature(node);
if (contextualSignature) {
inferFromAnnotatedParameters(node, contextualSignature, getInferenceContext(node)!);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Is it not a little weird for getInferenceContext and inferFromAnnotatedParameters to get called here? I'm not finding other examples where we're doing this sort of thing outside of a function intended to contextually check (which this function is not, contextuallyCheckFunctionExpressionOrObjectLiteralMethod is).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, this might be the first time this is called like it but the placement of those calls here is what fixes the bug conceptually - as in, for the added test cases it's important to infer before contextually checking those functions

Contextual check of functions can fix "requested" inference type parameters and that creates an ordering issue for #56459 as the parameter type "request" can happen before inferFromAnnotatedParameters even has a chance to be called on the other function that comes later in the source code.

And the similar problem happens when it comes to #60047 . The conditional type asks for the inferred type of the type parameter and since by that time the inferFromAnnotatedParameters was not called it resolves to its constraint. Then the arguments fail to be typechecked against current parameter types in getSignatureApplicabilityError so the algorithm returns, never reaching the second inference pass that starts to include context-sensitive parameters.

So if those issues are meant to be fixed it's absolutely necessary to call inferFromAnnotatedParameters within the first inference pass and that doesn't check context-sensitive functions, that's deferred to the second inference pass. I don't see how to even attempt to fix this in any other way given the known limitations around context-sensitive expressions and their associated implementation details

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
Status: Waiting on reviewers
4 participants