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

Fixed an out-of-order quick info issue with contextual rest parameter #57580

Merged
merged 3 commits into from
Mar 12, 2024

Conversation

Andarist
Copy link
Contributor

No description provided.

@@ -85,7 +85,7 @@
// return curry(getStylingByKeys, 2)(mergedStyling, ...args);
// ^^^^
// | ----------------------------------------------------------------------
// | (parameter) args: any
// | (parameter) args: []
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 the correct display that we can see when hovering at this location in the playground (after the playgrounds gets typechecked first): TS playground. If we make an edit and quickly hover over this location we can sometimes "catch" this any being displayed since then the quick info request happens before computing semantic diagnostics and this is exactly what this test is doing.

@@ -49585,7 +49590,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_have_an_initializer);
}
}
else if (isOptionalParameter(parameter)) {
else if (hasEffectiveQuestionToken(parameter)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

isOptionalParameter calls getMinArgumentCount for parameters with initializers and that in turn calls getTypeOfSymbol on rest parameters. This led to anyType being returned by reportCircularityError since the circularity was caused by this getTypeOfSymbol called again for something that was just being computed through out-of-order request

I spent some time on this and to the best of my knowledge - this particular function (checkGrammarParameterList) doesn't even have to consult that type. A parameter with an initializer is always treated as required (unless it's last) - and the main purpose of checking this here is to set seenOptionalParameter to potentially error on a required parameter that follows an optional one. This still happens but this error is mainly based on the syntactic~ optionality so it should be OK to just call hasEffectiveQuestionToken here.

I think that avoiding this extra type resolution from a grammar check function should be preferred - but I didn't recheck with all of the other existing grammar checks to see if this is a hard rule today or not.

Copy link
Member

Choose a reason for hiding this comment

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

checkGrammar* should in general not get types. So I think this is an improvement.

A parameter with an initializer is always treated as required

Shouldn't it be treated as optional by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't it be treated as optional by default?

I worded this terribly here. I think I've meant that it's always treated as required when followed by a required parameter:

function fn1(a: string, b = '', c = 0) {} // b is optional
function fn2(a: string, b = '', ...args: any[]) {} // b is optional
function fn3(a: string, b = '', c: number) {} // b is required

@@ -10518,7 +10517,7 @@ export function canHaveExportModifier(node: Node): node is Extract<HasModifiers,
}

/** @internal */
export function isOptionalJSDocPropertyLikeTag(node: Node): node is JSDocPropertyLikeTag {
export function isOptionalJSDocPropertyLikeTag(node: Node): boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I'm not mistaken this function wasn't proving that the input is JSDocPropertyLikeTag - some extra checks on a variable with JSDocPropertyLikeTag type were done here and it could still return false for it. So this wasn't a correct return type annotation

Copy link
Member

Choose a reason for hiding this comment

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

It's certainly not the first type guard we've had which has lied for convenience's sake. But it doesn't seem like it really helped here.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Seems correct to me?

@sandersn sandersn added this to Not started in PR Backlog Mar 8, 2024
@sandersn sandersn moved this from Not started to Needs merge in PR Backlog Mar 11, 2024
@@ -49585,7 +49590,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_have_an_initializer);
}
}
else if (isOptionalParameter(parameter)) {
else if (hasEffectiveQuestionToken(parameter)) {
Copy link
Member

Choose a reason for hiding this comment

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

checkGrammar* should in general not get types. So I think this is an improvement.

A parameter with an initializer is always treated as required

Shouldn't it be treated as optional by default?

@sandersn
Copy link
Member

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 11, 2024

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

Command Status Results
perf test this ✅ Started

@sandersn sandersn added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 11, 2024
@jakebailey
Copy link
Member

I broke the perf pipeline for PRs accidentally, rerunning

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 11, 2024

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

Command Status Results
perf test this ✅ Started 👀 Results

@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
Angular - node (v18.15.0, x64)
Memory used 295,578k (± 0.01%) 295,603k (± 0.00%) +24k (+ 0.01%) 295,588k 295,615k p=0.031 n=6
Parse Time 2.66s (± 0.00%) 2.67s (± 0.19%) +0.01s (+ 0.25%) 2.66s 2.67s p=0.025 n=6
Bind Time 0.83s (± 0.76%) 0.83s (± 0.62%) ~ 0.82s 0.83s p=0.386 n=6
Check Time 8.23s (± 0.10%) 8.21s (± 0.55%) ~ 8.16s 8.28s p=0.462 n=6
Emit Time 7.15s (± 0.28%) 7.15s (± 0.37%) ~ 7.11s 7.18s p=0.806 n=6
Total Time 18.87s (± 0.16%) 18.85s (± 0.25%) ~ 18.79s 18.92s p=0.295 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 192,670k (± 0.91%) 192,084k (± 0.72%) ~ 191,419k 194,905k p=0.575 n=6
Parse Time 1.36s (± 1.29%) 1.35s (± 0.77%) ~ 1.33s 1.36s p=0.059 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.32s (± 0.32%) 9.29s (± 0.19%) ~ 9.27s 9.31s p=0.064 n=6
Emit Time 2.60s (± 0.29%) 2.61s (± 0.48%) ~ 2.60s 2.63s p=0.301 n=6
Total Time 14.00s (± 0.15%) 13.97s (± 0.16%) -0.03s (- 0.23%) 13.94s 14.00s p=0.034 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,313k (± 0.01%) 347,332k (± 0.01%) ~ 347,315k 347,375k p=0.336 n=6
Parse Time 2.48s (± 0.54%) 2.48s (± 0.69%) ~ 2.46s 2.50s p=1.000 n=6
Bind Time 0.93s (± 0.44%) 0.93s (± 0.56%) ~ 0.92s 0.93s p=0.595 n=6
Check Time 6.97s (± 0.53%) 6.94s (± 0.32%) ~ 6.92s 6.98s p=0.169 n=6
Emit Time 4.08s (± 0.77%) 4.07s (± 0.25%) ~ 4.05s 4.08s p=0.745 n=6
Total Time 14.45s (± 0.25%) 14.41s (± 0.16%) ~ 14.37s 14.44s p=0.125 n=6
TFS - node (v18.15.0, x64)
Memory used 302,769k (± 0.01%) 302,763k (± 0.00%) ~ 302,743k 302,777k p=0.575 n=6
Parse Time 2.01s (± 0.60%) 2.01s (± 0.87%) ~ 1.98s 2.03s p=1.000 n=6
Bind Time 1.00s (± 0.98%) 1.01s (± 1.32%) ~ 1.00s 1.03s p=0.340 n=6
Check Time 6.34s (± 0.29%) 6.32s (± 0.45%) ~ 6.29s 6.37s p=0.091 n=6
Emit Time 3.60s (± 0.55%) 3.60s (± 0.48%) ~ 3.57s 3.62s p=0.742 n=6
Total Time 12.95s (± 0.20%) 12.93s (± 0.36%) ~ 12.84s 12.97s p=0.571 n=6
material-ui - node (v18.15.0, x64)
Memory used 511,243k (± 0.00%) 511,258k (± 0.00%) ~ 511,224k 511,278k p=0.229 n=6
Parse Time 2.66s (± 0.51%) 2.66s (± 0.51%) ~ 2.63s 2.67s p=1.000 n=6
Bind Time 0.98s (± 1.06%) 0.99s (± 0.52%) ~ 0.98s 0.99s p=0.070 n=6
Check Time 17.30s (± 0.49%) 17.36s (± 0.65%) ~ 17.25s 17.51s p=0.261 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.94s (± 0.42%) 21.00s (± 0.56%) ~ 20.89s 21.15s p=0.295 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,789,418k (± 0.00%) 1,789,419k (± 0.00%) ~ 1,789,391k 1,789,450k p=0.872 n=6
Parse Time 6.62s (± 0.38%) 6.65s (± 0.40%) ~ 6.63s 6.70s p=0.063 n=6
Bind Time 2.39s (± 0.17%) 2.39s (± 0.22%) ~ 2.39s 2.40s p=0.595 n=6
Check Time 59.06s (± 0.55%) 58.99s (± 0.29%) ~ 58.73s 59.21s p=0.873 n=6
Emit Time 0.17s (± 3.32%) 0.17s (± 2.42%) ~ 0.16s 0.17s p=0.282 n=6
Total Time 68.25s (± 0.46%) 68.20s (± 0.25%) ~ 67.93s 68.39s p=0.936 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,395,120k (± 0.03%) 2,395,019k (± 0.01%) ~ 2,394,755k 2,395,396k p=0.575 n=6
Parse Time 5.03s (± 0.93%) 5.05s (± 1.19%) ~ 4.95s 5.11s p=0.574 n=6
Bind Time 1.90s (± 0.96%) 1.90s (± 0.77%) ~ 1.88s 1.91s p=0.607 n=6
Check Time 33.70s (± 0.08%) 33.65s (± 0.40%) ~ 33.48s 33.83s p=0.810 n=6
Emit Time 2.68s (± 1.34%) 2.70s (± 0.66%) ~ 2.68s 2.73s p=0.470 n=6
Total Time 43.32s (± 0.09%) 43.32s (± 0.30%) ~ 43.16s 43.53s p=1.000 n=6
self-compiler - node (v18.15.0, x64)
Memory used 414,695k (± 0.01%) 414,683k (± 0.01%) ~ 414,607k 414,731k p=0.936 n=6
Parse Time 2.80s (± 2.12%) 2.80s (± 1.29%) ~ 2.75s 2.85s p=0.470 n=6
Bind Time 1.09s (± 5.77%) 1.07s (± 0.38%) ~ 1.06s 1.07s p=1.000 n=6
Check Time 15.18s (± 0.26%) 15.19s (± 0.34%) ~ 15.13s 15.25s p=0.685 n=6
Emit Time 1.13s (± 1.04%) 1.14s (± 1.21%) ~ 1.12s 1.15s p=0.461 n=6
Total Time 20.20s (± 0.25%) 20.19s (± 0.21%) ~ 20.14s 20.25s p=1.000 n=6
vscode - node (v18.15.0, x64)
Memory used 2,867,432k (± 0.00%) 2,867,423k (± 0.00%) ~ 2,867,369k 2,867,483k p=0.748 n=6
Parse Time 10.76s (± 0.21%) 10.75s (± 0.25%) ~ 10.73s 10.79s p=0.418 n=6
Bind Time 3.44s (± 0.43%) 3.44s (± 0.22%) ~ 3.43s 3.45s p=0.620 n=6
Check Time 61.02s (± 0.33%) 60.88s (± 0.35%) ~ 60.65s 61.08s p=0.518 n=6
Emit Time 16.26s (± 0.62%) 16.38s (± 0.55%) ~ 16.28s 16.54s p=0.066 n=6
Total Time 91.48s (± 0.22%) 91.45s (± 0.23%) ~ 91.13s 91.68s p=0.809 n=6
webpack - node (v18.15.0, x64)
Memory used 399,643k (± 0.01%) 399,582k (± 0.01%) ~ 399,514k 399,625k p=0.108 n=6
Parse Time 3.23s (± 0.47%) 3.23s (± 0.41%) ~ 3.21s 3.25s p=0.514 n=6
Bind Time 1.41s (± 1.71%) 1.42s (± 0.96%) ~ 1.40s 1.44s p=0.622 n=6
Check Time 14.06s (± 0.24%) 14.00s (± 0.22%) -0.06s (- 0.45%) 13.95s 14.03s p=0.020 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 18.70s (± 0.21%) 18.65s (± 0.20%) ~ 18.61s 18.72s p=0.053 n=6
xstate - node (v18.15.0, x64)
Memory used 513,169k (± 0.01%) 513,170k (± 0.01%) ~ 513,098k 513,300k p=1.000 n=6
Parse Time 3.27s (± 0.32%) 3.28s (± 0.25%) ~ 3.27s 3.29s p=0.546 n=6
Bind Time 1.54s (± 0.41%) 1.54s (± 0.27%) ~ 1.53s 1.54s p=0.673 n=6
Check Time 2.85s (± 0.37%) 2.85s (± 0.81%) ~ 2.83s 2.89s p=1.000 n=6
Emit Time 0.08s (± 4.99%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=0.405 n=6
Total Time 7.74s (± 0.21%) 7.75s (± 0.25%) ~ 7.74s 7.79s p=0.568 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,350ms (± 0.75%) 2,350ms (± 0.85%) ~ 2,319ms 2,372ms p=0.936 n=6
Req 2 - geterr 5,539ms (± 1.30%) 5,504ms (± 1.01%) ~ 5,469ms 5,614ms p=0.423 n=6
Req 3 - references 323ms (± 0.47%) 331ms (± 1.16%) +8ms (+ 2.48%) 323ms 334ms p=0.015 n=6
Req 4 - navto 275ms (± 1.19%) 275ms (± 0.59%) ~ 272ms 276ms p=0.675 n=6
Req 5 - completionInfo count 1,357 (± 0.00%) 1,357 (± 0.00%) ~ 1,357 1,357 p=1.000 n=6
Req 5 - completionInfo 88ms (± 6.47%) 80ms (± 4.88%) 🟩-8ms (- 8.56%) 77ms 88ms p=0.018 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,511ms (± 0.97%) 2,517ms (± 0.64%) ~ 2,495ms 2,539ms p=0.748 n=6
Req 2 - geterr 4,201ms (± 1.56%) 4,162ms (± 2.07%) ~ 4,090ms 4,272ms p=0.630 n=6
Req 3 - references 334ms (± 1.25%) 337ms (± 1.52%) ~ 332ms 342ms p=0.328 n=6
Req 4 - navto 284ms (± 0.53%) 285ms (± 0.41%) ~ 284ms 287ms p=0.566 n=6
Req 5 - completionInfo count 1,519 (± 0.00%) 1,519 (± 0.00%) ~ 1,519 1,519 p=1.000 n=6
Req 5 - completionInfo 82ms (± 7.70%) 86ms (± 7.71%) ~ 77ms 90ms p=0.366 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,607ms (± 0.51%) 2,609ms (± 0.50%) ~ 2,597ms 2,633ms p=0.936 n=6
Req 2 - geterr 1,768ms (± 1.66%) 1,730ms (± 2.98%) ~ 1,657ms 1,793ms p=0.230 n=6
Req 3 - references 119ms (± 8.49%) 121ms (± 8.40%) ~ 106ms 128ms p=0.255 n=6
Req 4 - navto 370ms (± 0.77%) 373ms (± 0.63%) ~ 370ms 376ms p=0.193 n=6
Req 5 - completionInfo count 2,079 (± 0.00%) 2,079 (± 0.00%) ~ 2,079 2,079 p=1.000 n=6
Req 5 - completionInfo 309ms (± 1.37%) 304ms (± 1.51%) -5ms (- 1.73%) 299ms 310ms p=0.036 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 153.40ms (± 0.15%) 153.34ms (± 0.13%) -0.06ms (- 0.04%) 152.43ms 156.59ms p=0.008 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 229.71ms (± 0.15%) 229.47ms (± 0.16%) -0.24ms (- 0.10%) 228.07ms 232.34ms p=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 222.40ms (± 0.15%) 222.39ms (± 0.15%) ~ 220.96ms 224.84ms p=0.930 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 221.71ms (± 0.17%) 221.81ms (± 0.17%) +0.10ms (+ 0.05%) 220.43ms 224.73ms p=0.011 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
No open projects
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants