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

Avoid incorrectly reusing assertion nodes from property assignments #60576

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Nov 24, 2024

fixes #60573 (a regression from #59282 )

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 24, 2024
@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.

@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Dec 4, 2024
@jakebailey
Copy link
Member

If this fixes #60573, we should definitely add a dts test that shows that things are fixed.

Comment on lines +713 to +714
if (assertionNode && !isConstTypeReference(assertionNode) && resolver.canReuseTypeNodeAnnotation(context, node, assertionNode, symbol)) {
result = serializeExistingTypeNode(assertionNode, context);
Copy link
Member

Choose a reason for hiding this comment

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

I was largely unsure about this given you ask a question about node then use that to work with assertionNode, but this is effectively the same check as:

    function typeFromPropertyAssignment(node: PropertyAssignment | ShorthandPropertyAssignment, symbol: Symbol, context: SyntacticTypeNodeBuilderContext) {
        const typeAnnotation = getEffectiveTypeAnnotationNode(node);
        let result;
        if (typeAnnotation && resolver.canReuseTypeNodeAnnotation(context, node, typeAnnotation, symbol)) {
            result = serializeExistingTypeNode(typeAnnotation, context);
        }

So I definitely like this change more than the initial version.

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 4, 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/60576/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 34 34 ~ ~ ~ p=1.000 n=6
Symbols 62,363 62,363 ~ ~ ~ p=1.000 n=6
Types 50,395 50,395 ~ ~ ~ p=1.000 n=6
Memory used 194,233k (± 0.95%) 194,267k (± 0.97%) ~ 193,042k 196,713k p=0.748 n=6
Parse Time 1.30s (± 1.15%) 1.31s (± 0.68%) ~ 1.30s 1.32s p=0.456 n=6
Bind Time 0.72s 0.72s ~ ~ ~ p=1.000 n=6
Check Time 9.78s (± 0.36%) 9.79s (± 0.46%) ~ 9.72s 9.85s p=0.872 n=6
Emit Time 2.73s (± 0.38%) 2.73s (± 0.65%) ~ 2.71s 2.76s p=0.805 n=6
Total Time 14.53s (± 0.29%) 14.54s (± 0.41%) ~ 14.48s 14.64s p=0.936 n=6
angular-1 - node (v18.15.0, x64)
Errors 37 37 ~ ~ ~ p=1.000 n=6
Symbols 947,936 947,936 ~ ~ ~ p=1.000 n=6
Types 410,955 410,955 ~ ~ ~ p=1.000 n=6
Memory used 1,226,007k (± 0.00%) 1,226,016k (± 0.00%) ~ 1,225,935k 1,226,080k p=0.575 n=6
Parse Time 6.63s (± 0.55%) 6.64s (± 0.52%) ~ 6.58s 6.68s p=0.871 n=6
Bind Time 1.89s (± 0.22%) 1.89s (± 0.58%) ~ 1.88s 1.91s p=1.000 n=6
Check Time 32.00s (± 0.34%) 31.96s (± 0.33%) ~ 31.87s 32.15s p=0.517 n=6
Emit Time 15.22s (± 0.37%) 15.18s (± 0.31%) ~ 15.10s 15.22s p=0.167 n=6
Total Time 55.74s (± 0.25%) 55.66s (± 0.25%) ~ 55.48s 55.86s p=0.471 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,501,823 2,501,823 ~ ~ ~ p=1.000 n=6
Types 909,645 909,645 ~ ~ ~ p=1.000 n=6
Memory used 2,319,287k (± 0.00%) 2,319,273k (± 0.00%) ~ 2,319,207k 2,319,317k p=0.378 n=6
Parse Time 9.30s (± 0.18%) 9.30s (± 0.23%) ~ 9.28s 9.33s p=0.514 n=6
Bind Time 2.16s (± 0.83%) 2.15s (± 0.97%) ~ 2.12s 2.18s p=0.452 n=6
Check Time 74.95s (± 0.23%) 74.98s (± 0.37%) ~ 74.57s 75.42s p=0.936 n=6
Emit Time 0.28s 0.28s (± 3.53%) ~ 0.27s 0.29s p=0.652 n=6
Total Time 86.69s (± 0.21%) 86.72s (± 0.32%) ~ 86.31s 87.17s p=0.686 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,225,287 1,225,287 ~ ~ ~ p=1.000 n=6
Types 266,555 266,555 ~ ~ ~ p=1.000 n=6
Memory used 2,354,218k (± 0.03%) 2,354,129k (± 0.02%) ~ 2,353,675k 2,354,651k p=0.810 n=6
Parse Time 5.23s (± 0.59%) 5.25s (± 0.44%) ~ 5.23s 5.29s p=0.683 n=6
Bind Time 1.77s (± 1.57%) 1.78s (± 1.56%) ~ 1.76s 1.83s p=0.746 n=6
Check Time 35.19s (± 0.65%) 35.19s (± 0.44%) ~ 35.07s 35.49s p=0.873 n=6
Emit Time 2.97s (± 1.21%) 3.02s (± 3.00%) ~ 2.95s 3.19s p=0.630 n=6
Total Time 45.17s (± 0.53%) 45.25s (± 0.55%) ~ 45.10s 45.74s p=0.298 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,225,287 1,225,287 ~ ~ ~ p=1.000 n=6
Types 266,555 266,555 ~ ~ ~ p=1.000 n=6
Memory used 2,907,885k (±12.87%) 2,786,589k (±14.24%) ~ 2,423,271k 3,150,329k p=0.298 n=6
Parse Time 6.97s (± 1.41%) 6.91s (± 2.01%) ~ 6.77s 7.08s p=0.575 n=6
Bind Time 2.16s (± 1.67%) 2.16s (± 1.82%) ~ 2.10s 2.20s p=1.000 n=6
Check Time 42.73s (± 0.76%) 42.80s (± 0.52%) ~ 42.60s 43.21s p=1.000 n=6
Emit Time 3.48s (± 2.40%) 3.57s (± 5.02%) ~ 3.40s 3.83s p=0.575 n=6
Total Time 55.37s (± 0.76%) 55.43s (± 0.53%) ~ 55.01s 55.91s p=0.810 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 262,259 262,259 ~ ~ ~ p=1.000 n=6
Types 106,616 106,616 ~ ~ ~ p=1.000 n=6
Memory used 439,871k (± 0.01%) 439,875k (± 0.01%) ~ 439,813k 439,921k p=0.748 n=6
Parse Time 3.54s (± 0.52%) 3.52s (± 0.69%) ~ 3.50s 3.56s p=0.164 n=6
Bind Time 1.31s (± 0.89%) 1.31s (± 0.89%) ~ 1.30s 1.33s p=1.000 n=6
Check Time 18.96s (± 0.50%) 18.87s (± 0.36%) ~ 18.79s 18.98s p=0.093 n=6
Emit Time 1.52s (± 1.56%) 1.54s (± 0.89%) ~ 1.52s 1.56s p=0.191 n=6
Total Time 25.33s (± 0.45%) 25.24s (± 0.25%) ~ 25.16s 25.34s p=0.173 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 70 70 ~ ~ ~ p=1.000 n=6
Symbols 226,062 226,062 ~ ~ ~ p=1.000 n=6
Types 94,488 94,488 ~ ~ ~ p=1.000 n=6
Memory used 371,772k (± 0.07%) 371,606k (± 0.05%) ~ 371,472k 371,958k p=0.173 n=6
Parse Time 2.92s (± 1.14%) 2.88s (± 1.45%) ~ 2.82s 2.94s p=0.199 n=6
Bind Time 1.58s (± 0.74%) 1.59s (± 1.01%) ~ 1.57s 1.61s p=0.285 n=6
Check Time 16.53s (± 0.41%) 16.48s (± 0.16%) ~ 16.44s 16.50s p=0.327 n=6
Emit Time 0.00s (±244.70%) 0.00s ~ ~ ~ p=0.405 n=6
Total Time 21.03s (± 0.32%) 20.96s (± 0.28%) ~ 20.89s 21.04s p=0.108 n=6
vscode - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 3,197,663 3,197,663 ~ ~ ~ p=1.000 n=6
Types 1,099,162 1,099,162 ~ ~ ~ p=1.000 n=6
Memory used 3,271,365k (± 0.01%) 3,271,502k (± 0.01%) ~ 3,271,145k 3,272,144k p=0.173 n=6
Parse Time 14.08s (± 0.49%) 14.11s (± 0.53%) ~ 14.02s 14.23s p=0.688 n=6
Bind Time 4.54s (± 0.37%) 4.52s (± 0.28%) -0.02s (- 0.44%) 4.51s 4.54s p=0.048 n=6
Check Time 88.17s (± 1.86%) 87.70s (± 1.90%) ~ 86.28s 90.15s p=0.689 n=6
Emit Time 28.27s (± 2.92%) 27.60s (± 8.67%) ~ 22.81s 29.12s p=1.000 n=6
Total Time 135.07s (± 0.95%) 133.93s (± 1.01%) ~ 131.70s 135.77s p=0.173 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 288,751 288,751 ~ ~ ~ p=1.000 n=6
Types 117,157 117,157 ~ ~ ~ p=1.000 n=6
Memory used 441,035k (± 0.03%) 441,029k (± 0.03%) ~ 440,839k 441,224k p=1.000 n=6
Parse Time 4.06s (± 0.83%) 4.08s (± 0.78%) ~ 4.03s 4.12s p=0.376 n=6
Bind Time 1.76s (± 2.28%) 1.77s (± 1.82%) ~ 1.74s 1.82s p=0.687 n=6
Check Time 18.90s (± 0.75%) 18.92s (± 0.55%) ~ 18.72s 19.00s p=1.000 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.72s (± 0.64%) 24.77s (± 0.48%) ~ 24.57s 24.91s p=0.810 n=6
xstate-main - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 552,390 552,390 ~ ~ ~ p=1.000 n=6
Types 185,096 185,096 ~ ~ ~ p=1.000 n=6
Memory used 492,463k (± 0.02%) 492,518k (± 0.01%) ~ 492,450k 492,614k p=0.936 n=6
Parse Time 3.41s (± 1.01%) 3.41s (± 0.86%) ~ 3.36s 3.45s p=0.935 n=6
Bind Time 1.18s (± 0.69%) 1.17s (± 1.03%) ~ 1.15s 1.18s p=1.000 n=6
Check Time 19.55s (± 1.11%) 19.66s (± 2.43%) ~ 19.34s 20.62s p=0.810 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.14s (± 0.88%) 24.25s (± 2.00%) ~ 23.95s 25.22s p=1.000 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

@jakebailey
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 4, 2024

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

Command Status Results
pack this ✅ Started

Comment on lines +31 to +34
//// [declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.d.ts]
export declare const unwrapped: {
prop1: "hello";
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jakebailey here is the requested dts test

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.

Yeah, this looks solid now. It'd probably be relevant to ask what output this limits under isolatedDeclarations, but... 🤷‍♂️ it kinda is what it is.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@jakebailey
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 4, 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 Dec 4, 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/164278/artifacts?artifactName=tgz&fileId=579FD5D10F806287DEC373A9533F60476A5F5163C508B9047F1A00060D2FA2A002&fileName=/typescript-5.8.0-insiders.20241204.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.8.0-pr-60576-12".;

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@jakebailey jakebailey merged commit 676d329 into microsoft:main Dec 4, 2024
32 checks passed
@jakebailey
Copy link
Member

@typescript-bot cherry-pick this to release-5.7

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 4, 2024

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

Command Status Results
cherry-pick this to release-5.7 ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

Hey, @jakebailey! I've created #60679 for you.

DanielRosenwasser pushed a commit that referenced this pull request Dec 11, 2024
…e-5.7 (#60679)

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
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
Status: Done
Development

Successfully merging this pull request may close these issues.

Type assertion regression in TypeScript 5.7
5 participants