Skip to content

Fixed declaration emit of object literals withs divergent accessors #55442

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

@Andarist Andarist commented Aug 20, 2023

cc @andrewbranch as divergent setters became allowed since #53417

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 20, 2023
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Comment on lines 58 to 80
export namespace obj1 {
let x: string;
}
export const obj2: {
/**
* my awesome getter
* @returns {string}
*/
get x(): string;
/**
* my awesome setter
* @param {number} a
*/
set x(a: number);
};
export namespace obj3 {
let x_1: string;
export { x_1 as x };
}
export namespace obj4 {
let x_2: number;
export { x_2 as x };
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We might notice that comments are only preserved here in obj2. There is probably a complication related to this here since JSDoc comments here will always refer to @param and @returns and those don't make sense for variable declarations - so should the comment be reconstructed/trimmed in such a case?

Either way, I think that's a separate issue and I would prefer not to work on it here.

const getterDeclaration = getDeclarationOfKind<GetAccessorDeclaration>(propertySymbol, SyntaxKind.GetAccessor)!;
const getterSignature = getSignatureFromDeclaration(getterDeclaration);
typeElements.push(
setCommentRange(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those two are using direct calls to setCommentRange instead of the existing preserveCommentsOn helper. The only added benefit of preserveCommentsOn is that it handles JSDocPropertyTags. However, those only matter when serializing typedefs, as far as I can tell. We are serializing an "inferred" type of the object literal here - its property declarations can't be sourced from @property, right?

@andrewbranch
Copy link
Member

@typescript-bot pack this
@typescript-bot user test this
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 29, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 29, 2023

Heya @andrewbranch, I've started to run the diff-based user code test suite on this PR at 6bc2a84. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 29, 2023

Heya @andrewbranch, I've started to run the regular perf test suite on this PR at 6bc2a84. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 29, 2023

Hey @andrewbranch, 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/157146/artifacts?artifactName=tgz&fileId=05140A6CE48950DF2CADAF345A086D6FE511E951F56B10D1DAE508D246430C0302&fileName=/typescript-5.3.0-insiders.20230829.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]".;

Comment on lines 9747 to 9755
every(getPropertiesOfType(typeToSerialize), p => {
if (!isIdentifierText(symbolName(p), languageVersion)) {
return false;
}
if (!(p.flags & SymbolFlags.Accessor)) {
return true;
}
return getNonMissingTypeOfSymbol(p) === getWriteTypeOfSymbol(p);
});
Copy link
Member

@andrewbranch andrewbranch Aug 29, 2023

Choose a reason for hiding this comment

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

What’s a test that exercises this new code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
System info unknown
Hosts
Scenarios
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
System info unknown
Hosts
Scenarios
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 (v16.17.1, x64)
Execution time 156.04ms (± 0.15%) 156.16ms (± 0.17%) +0.13ms (+ 0.08%) 154.48ms 159.78ms p=0.000 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time 230.73ms (± 0.15%) 231.49ms (± 0.14%) +0.77ms (+ 0.33%) 229.96ms 237.29ms p=0.000 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 235.06ms (± 0.16%) 235.88ms (± 0.10%) +0.82ms (+ 0.35%) 234.79ms 237.61ms p=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time 235.98ms (± 0.15%) 235.68ms (± 0.14%) -0.30ms (- 0.13%) 233.75ms 240.97ms p=0.000 n=600
System info unknown
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 pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@andrewbranch Here are the results of running the user test suite comparing main and refs/pull/55442/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Unknown failure"
  • 2 instances of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

rxjs-src

/mnt/ts_downloads/rxjs-src/build.sh

  • [NEW] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55442/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
  • [MISSING] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)

@jakebailey
Copy link
Member

Uhh, I guess I broke perf.

@jakebailey
Copy link
Member

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 29, 2023

Heya @jakebailey, I've started to run the regular perf test suite on this PR at 6bc2a84. You can monitor the build here.

Update: The results are in!

Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

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

Looks good as long as perf comes back clean

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v16.17.1, x64)
Memory used 300,289k (± 0.01%) 300,277k (± 0.01%) ~ 300,241k 300,295k p=0.378 n=6
Parse Time 3.01s (± 0.25%) 3.00s (± 0.17%) ~ 3.00s 3.01s p=0.247 n=6
Bind Time 0.93s (± 0.00%) 0.93s (± 0.00%) ~ 0.93s 0.93s p=1.000 n=6
Check Time 9.30s (± 0.31%) 9.31s (± 0.18%) ~ 9.29s 9.33s p=0.288 n=6
Emit Time 7.63s (± 0.23%) 7.63s (± 0.28%) ~ 7.60s 7.66s p=0.622 n=6
Total Time 20.87s (± 0.22%) 20.87s (± 0.10%) ~ 20.84s 20.90s p=1.000 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 193,945k (± 0.02%) 193,893k (± 0.03%) ~ 193,815k 193,994k p=0.230 n=6
Parse Time 1.58s (± 0.00%) 1.58s (± 0.00%) ~ 1.58s 1.58s p=1.000 n=6
Bind Time 0.80s (± 0.51%) 0.80s (± 0.65%) ~ 0.79s 0.80s p=0.595 n=6
Check Time 9.90s (± 0.28%) 9.93s (± 0.51%) ~ 9.87s 10.01s p=0.376 n=6
Emit Time 2.73s (± 0.30%) 2.74s (± 0.31%) ~ 2.72s 2.74s p=0.718 n=6
Total Time 15.01s (± 0.17%) 15.04s (± 0.39%) ~ 14.98s 15.13s p=0.573 n=6
Monaco - node (v16.17.1, x64)
Memory used 347,182k (± 0.01%) 347,170k (± 0.01%) ~ 347,118k 347,205k p=0.575 n=6
Parse Time 2.69s (± 0.30%) 2.69s (± 0.41%) ~ 2.67s 2.70s p=0.666 n=6
Bind Time 0.99s (± 0.00%) 0.99s (± 0.00%) ~ 0.99s 0.99s p=1.000 n=6
Check Time 7.93s (± 0.24%) 7.93s (± 0.24%) ~ 7.90s 7.95s p=0.805 n=6
Emit Time 4.26s (± 0.26%) 4.27s (± 0.41%) ~ 4.24s 4.29s p=0.503 n=6
Total Time 15.88s (± 0.17%) 15.88s (± 0.15%) ~ 15.84s 15.91s p=0.808 n=6
TFS - node (v16.17.1, x64)
Memory used 301,165k (± 0.00%) 301,169k (± 0.00%) ~ 301,149k 301,186k p=0.470 n=6
Parse Time 2.17s (± 0.58%) 2.17s (± 0.47%) ~ 2.16s 2.18s p=0.652 n=6
Bind Time 1.11s (± 0.46%) 1.11s (± 0.37%) ~ 1.11s 1.12s p=0.595 n=6
Check Time 7.22s (± 0.58%) 7.23s (± 0.19%) ~ 7.22s 7.25s p=0.285 n=6
Emit Time 3.98s (± 0.65%) 3.99s (± 0.67%) ~ 3.96s 4.02s p=1.000 n=6
Total Time 14.49s (± 0.45%) 14.51s (± 0.23%) ~ 14.47s 14.56s p=0.575 n=6
material-ui - node (v16.17.1, x64)
Memory used 479,470k (± 0.00%) 479,482k (± 0.00%) ~ 479,464k 479,497k p=0.173 n=6
Parse Time 3.15s (± 0.16%) 3.15s (± 0.35%) ~ 3.14s 3.17s p=0.784 n=6
Bind Time 0.91s (± 0.00%) 0.91s (± 0.00%) ~ 0.91s 0.91s p=1.000 n=6
Check Time 17.80s (± 0.31%) 17.82s (± 0.32%) ~ 17.71s 17.87s p=0.687 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 21.86s (± 0.25%) 21.88s (± 0.25%) ~ 21.77s 21.92s p=0.572 n=6
xstate - node (v16.17.1, x64)
Memory used 542,803k (± 0.00%) 542,824k (± 0.01%) ~ 542,784k 542,861k p=0.261 n=6
Parse Time 3.69s (± 0.00%) 3.69s (± 0.28%) ~ 3.68s 3.71s p=0.599 n=6
Bind Time 1.42s (± 4.11%) 1.42s (± 4.11%) ~ 1.34s 1.46s p=1.000 n=6
Check Time 3.22s (± 2.28%) 3.22s (± 2.30%) ~ 3.14s 3.31s p=0.869 n=6
Emit Time 0.08s (± 4.99%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=0.405 n=6
Total Time 8.41s (± 0.25%) 8.40s (± 0.37%) ~ 8.36s 8.44s p=1.000 n=6
System info unknown
Hosts
  • node (v16.17.1, x64)
Scenarios
  • Angular - node (v16.17.1, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Monaco - node (v16.17.1, x64)
  • TFS - node (v16.17.1, x64)
  • material-ui - node (v16.17.1, x64)
  • xstate - node (v16.17.1, 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 (v16.17.1, x64)
Req 1 - updateOpen 2,487ms (± 0.20%) 2,490ms (± 0.16%) ~ 2,483ms 2,494ms p=0.421 n=6
Req 2 - geterr 5,951ms (± 0.29%) 5,935ms (± 0.27%) ~ 5,922ms 5,962ms p=0.092 n=6
Req 3 - references 344ms (± 0.48%) 343ms (± 0.44%) ~ 342ms 346ms p=1.000 n=6
Req 4 - navto 279ms (± 0.94%) 277ms (± 0.27%) ~ 276ms 278ms p=0.150 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 79ms (± 3.84%) 87ms (± 8.97%) ~ 76ms 94ms p=0.122 n=6
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,614ms (± 0.53%) 2,625ms (± 0.67%) ~ 2,606ms 2,645ms p=0.230 n=6
Req 2 - geterr 4,769ms (± 0.14%) 4,777ms (± 0.27%) ~ 4,759ms 4,792ms p=0.332 n=6
Req 3 - references 351ms (± 0.28%) 351ms (± 0.12%) ~ 350ms 351ms p=0.673 n=6
Req 4 - navto 270ms (± 0.31%) 269ms (± 0.38%) ~ 268ms 271ms p=0.672 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 79ms (± 0.65%) 80ms (± 0.69%) ~ 79ms 80ms p=0.640 n=6
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,708ms (± 0.14%) 2,710ms (± 0.09%) ~ 2,707ms 2,713ms p=0.197 n=6
Req 2 - geterr 1,950ms (± 2.33%) 1,959ms (± 2.22%) ~ 1,871ms 1,988ms p=0.936 n=6
Req 3 - references 133ms (± 6.21%) 136ms (± 5.62%) ~ 121ms 141ms p=0.468 n=6
Req 4 - navto 352ms (± 0.29%) 353ms (± 0.42%) ~ 351ms 355ms p=0.616 n=6
Req 5 - completionInfo count 2,071 (± 0.00%) 2,071 (± 0.00%) ~ 2,071 2,071 p=1.000 n=6
Req 5 - completionInfo 319ms (± 2.43%) 321ms (± 2.02%) ~ 312ms 326ms p=0.740 n=6
System info unknown
Hosts
  • node (v16.17.1, x64)
Scenarios
  • CompilerTSServer - node (v16.17.1, x64)
  • Compiler-UnionsTSServer - node (v16.17.1, x64)
  • xstateTSServer - node (v16.17.1, 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 (v16.17.1, x64)
Execution time 156.42ms (± 0.16%) 156.57ms (± 0.17%) +0.15ms (+ 0.10%) 154.70ms 159.97ms p=0.000 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time 230.28ms (± 0.21%) 230.98ms (± 0.14%) +0.70ms (+ 0.30%) 229.36ms 235.52ms p=0.000 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 234.92ms (± 0.11%) 235.76ms (± 0.12%) +0.84ms (+ 0.36%) 234.30ms 242.19ms p=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time 235.87ms (± 0.15%) 235.78ms (± 0.13%) -0.09ms (- 0.04%) 233.98ms 241.32ms p=0.018 n=600
System info unknown
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 pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

set x(a: number);
};
export namespace obj3 {
let x_1: string;
Copy link
Member

Choose a reason for hiding this comment

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

This is going to change because I merged your other jsdoc declaration emit PR, right? I think this is ready to go once it's sync'd, though - perf did come back clean, after all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this was impacted by that other PR. I just synced with main so this should now be mergeable.

@andrewbranch andrewbranch merged commit 7377f5c into microsoft:main Oct 5, 2023
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
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants