Skip to content

Refactored node builder flags and tests - #59440

Merged
Armando Aguirre (armanio123) merged 11 commits into
microsoft:mainfrom
armanio123:RefactorNodeBuilderFlags
Aug 8, 2024
Merged

Refactored node builder flags and tests#59440
Armando Aguirre (armanio123) merged 11 commits into
microsoft:mainfrom
armanio123:RefactorNodeBuilderFlags

Conversation

@armanio123

@armanio123Armando Aguirre (armanio123) commented Jul 27, 2024

Copy link
Copy Markdown
Contributor

The NodeBuilderFlags enum has shifted more than the allowed signed int32 limit.

This refactors experiments with creating a type and constant using BigInt instead. This approach was discarded becuase of the performance of BigInt, and the limitations the type has.

Added an additional flag InternalNodeBuilderFlags, that releases a couple of bits on NodeBuilderFlag by moving all the internal flags.

Reference to this PR #58475.

@typescript-bot

Copy link
Copy Markdown
Contributor

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure Daniel Rosenwasser (@DanielRosenwasser) and Ryan Cavanaugh (@RyanCavanaugh) are aware of the changes, just as a heads up.

Armando Aguirre Sepulveda added 2 commits July 26, 2024 18:28
@armanio123

Copy link
Copy Markdown
ContributorAuthor

TypeScript Bot (@typescript-bot) test this

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 27, 2024

Copy link
Copy Markdown
Contributor

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

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

@typescript-bot

Copy link
Copy Markdown
Contributor

Armando Aguirre (@armanio123) Here are the results of running the user tests with tsc comparing main and refs/pull/59440/merge:

Everything looks good!

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Armando Aguirre (@armanio123), the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Armando Aguirre (@armanio123)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-Unions - node (v18.15.0, x64)
Errors3030~~~p=1.000 n=6
Symbols62,15362,153~~~p=1.000 n=6
Types50,24250,242~~~p=1.000 n=6
Memory used192,432k (± 0.09%)193,734k (± 0.96%)+1,302k (+ 0.68%)192,386k196,190kp=0.030 n=6
Parse Time1.32s (± 0.75%)1.31s (± 0.92%)~1.29s1.32sp=0.391 n=6
Bind Time0.72s (± 0.72%)0.71s (± 0.77%)~0.71s0.72sp=0.640 n=6
Check Time9.59s (± 0.44%)9.62s (± 0.33%)~9.58s9.67sp=0.172 n=6
Emit Time2.78s (± 0.48%)2.78s (± 0.67%)~2.75s2.80sp=0.617 n=6
Total Time14.41s (± 0.32%)14.43s (± 0.31%)~14.39s14.51sp=0.418 n=6
angular-1 - node (v18.15.0, x64)
Errors77~~~p=1.000 n=6
Symbols945,532945,532~~~p=1.000 n=6
Types409,507409,507~~~p=1.000 n=6
Memory used1,221,163k (± 0.00%)1,221,181k (± 0.00%)~1,221,104k1,221,215kp=0.230 n=6
Parse Time6.57s (± 0.25%)6.64s (± 0.87%)+0.07s (+ 1.01%)6.59s6.75sp=0.008 n=6
Bind Time1.85s (± 0.22%)1.86s (± 0.28%)~1.85s1.86sp=0.112 n=6
Check Time31.05s (± 0.35%)31.07s (± 0.37%)~30.97s31.28sp=0.873 n=6
Emit Time15.02s (± 0.50%)14.99s (± 0.46%)~14.87s15.06sp=0.748 n=6
Total Time54.49s (± 0.29%)54.56s (± 0.24%)~54.46s54.81sp=1.000 n=6
mui-docs - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols2,437,2532,437,253~~~p=1.000 n=6
Types1,004,0971,004,097~~~p=1.000 n=6
Memory used2,426,284k (± 0.01%)2,426,249k (± 0.00%)~2,426,159k2,426,374kp=0.378 n=6
Parse Time8.50s (± 0.51%)8.45s (± 0.14%)-0.06s (- 0.67%)8.43s8.46sp=0.005 n=6
Bind Time2.11s (± 0.57%)2.11s (± 0.65%)~2.09s2.12sp=0.339 n=6
Check Time75.67s (± 1.40%)75.11s (± 0.33%)~74.60s75.27sp=0.575 n=6
Emit Time0.28s (± 1.86%)0.28s (± 1.86%)~0.27s0.28sp=1.000 n=6
Total Time86.56s (± 1.22%)85.94s (± 0.28%)~85.45s86.10sp=0.230 n=6
self-build-src - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,227,7581,227,821+63 (+ 0.01%)~~p=0.001 n=6
Types265,136265,006-130 (- 0.05%)~~p=0.001 n=6
Memory used2,346,580k (± 0.03%)2,347,526k (± 0.02%)+946k (+ 0.04%)2,346,927k2,348,125kp=0.031 n=6
Parse Time4.96s (± 0.76%)5.03s (± 0.65%)+0.06s (+ 1.28%)4.99s5.08sp=0.036 n=6
Bind Time1.90s (± 0.61%)1.89s (± 0.40%)~1.88s1.90sp=0.150 n=6
Check Time34.61s (± 0.36%)34.53s (± 0.43%)~34.27s34.66sp=0.229 n=6
Emit Time3.30s (± 0.85%)3.34s (± 0.86%)~3.32s3.38sp=0.127 n=6
Total Time44.79s (± 0.33%)44.80s (± 0.31%)~44.56s44.94sp=0.810 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,227,7581,227,821+63 (+ 0.01%)~~p=0.001 n=6
Types265,136265,006-130 (- 0.05%)~~p=0.001 n=6
Memory used2,420,479k (± 0.04%)2,420,875k (± 0.01%)~2,420,517k2,421,353kp=0.230 n=6
Parse Time6.25s (± 1.19%)6.19s (± 0.69%)~6.15s6.26sp=0.128 n=6
Bind Time2.03s (± 0.40%)2.07s (± 1.25%)+0.04s (+ 1.97%)2.04s2.11sp=0.008 n=6
Check Time41.17s (± 0.76%)41.16s (± 0.38%)~41.02s41.42sp=0.575 n=6
Emit Time4.05s (± 3.63%)4.06s (± 1.03%)~4.01s4.11sp=0.471 n=6
Total Time53.53s (± 0.73%)53.50s (± 0.25%)~53.37s53.70sp=0.936 n=6
self-compiler - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols255,951255,989+38 (+ 0.01%)~~p=0.001 n=6
Types104,957104,970+13 (+ 0.01%)~~p=0.001 n=6
Memory used427,801k (± 0.02%)428,082k (± 0.05%)+281k (+ 0.07%)427,908k428,468kp=0.005 n=6
Parse Time3.35s (± 0.65%)3.35s (± 0.41%)~3.34s3.38sp=0.413 n=6
Bind Time1.32s (± 1.31%)1.31s (± 1.96%)~1.27s1.33sp=0.683 n=6
Check Time17.94s (± 0.16%)18.06s (± 0.35%)+0.12s (+ 0.64%)17.99s18.15sp=0.005 n=6
Emit Time1.65s (± 1.15%)1.70s (± 1.53%)+0.04s (+ 2.73%)1.66s1.73sp=0.013 n=6
Total Time24.26s (± 0.05%)24.41s (± 0.37%)+0.16s (+ 0.64%)24.33s24.53sp=0.005 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors3535~~~p=1.000 n=6
Symbols224,931224,931~~~p=1.000 n=6
Types94,14694,146~~~p=1.000 n=6
Memory used370,180k (± 0.05%)370,218k (± 0.03%)~370,019k370,326kp=1.000 n=6
Parse Time2.77s (± 0.50%)2.76s (± 0.81%)~2.73s2.79sp=0.618 n=6
Bind Time1.58s (± 0.67%)1.58s (± 0.62%)~1.57s1.59sp=0.315 n=6
Check Time15.66s (± 0.45%)15.63s (± 0.45%)~15.57s15.73sp=0.518 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time20.00s (± 0.36%)19.97s (± 0.33%)~19.89s20.05sp=0.572 n=6
vscode - node (v18.15.0, x64)
Errors1111~~~p=1.000 n=6
Symbols2,986,8392,986,839~~~p=1.000 n=6
Types1,027,4681,027,468~~~p=1.000 n=6
Memory used3,110,683k (± 0.00%)3,110,635k (± 0.00%)~3,110,558k3,110,714kp=0.230 n=6
Parse Time13.87s (± 0.34%)13.85s (± 0.55%)~13.75s13.94sp=0.574 n=6
Bind Time4.32s (± 1.58%)4.31s (± 2.01%)~4.27s4.49sp=0.167 n=6
Check Time79.27s (± 0.40%)79.26s (± 0.52%)~78.86s79.86sp=0.936 n=6
Emit Time20.46s (± 0.34%)20.42s (± 0.66%)~20.29s20.60sp=0.423 n=6
Total Time117.93s (± 0.32%)117.83s (± 0.38%)~117.32s118.34sp=0.689 n=6
webpack - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols267,567267,567~~~p=1.000 n=6
Types109,077109,077~~~p=1.000 n=6
Memory used412,412k (± 0.01%)412,534k (± 0.02%)+122k (+ 0.03%)412,485k412,690kp=0.005 n=6
Parse Time3.83s (± 0.74%)3.82s (± 0.83%)~3.78s3.86sp=0.627 n=6
Bind Time1.71s (± 0.32%)1.71s (± 0.44%)~1.70s1.72sp=0.476 n=6
Check Time16.83s (± 0.40%)16.88s (± 0.32%)~16.81s16.96sp=0.228 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time22.38s (± 0.35%)22.41s (± 0.28%)~22.30s22.47sp=0.377 n=6
xstate-main - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols511,807511,807~~~p=1.000 n=6
Types162,090162,090~~~p=1.000 n=6
Memory used449,159k (± 0.07%)449,208k (± 0.09%)~448,705k449,530kp=0.471 n=6
Parse Time3.16s (± 0.53%)3.17s (± 1.01%)~3.12s3.21sp=0.572 n=6
Bind Time1.16s (± 0.71%)1.16s (± 0.54%)~1.15s1.17sp=0.599 n=6
Check Time17.12s (± 0.54%)17.17s (± 0.43%)~17.09s17.30sp=0.298 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time21.44s (± 0.42%)21.50s (± 0.29%)~21.45s21.60sp=0.228 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)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot

Copy link
Copy Markdown
Contributor

Armando Aguirre (@armanio123) Here are the results of running the top 400 repos with tsc comparing main and refs/pull/59440/merge:

Everything looks good!

@jakebailey

Copy link
Copy Markdown
Member

#59282 gives back a node flag, can we not just wait for that?

Comment threadsrc/compiler/types.ts Outdated
@armanio123

Copy link
Copy Markdown
ContributorAuthor

#59282 gives back a node flag, can we not just wait for that?

I was planning on adding a new flag to it, that's how I noticed this issue. So even if we reduce the number of flags, we're going to be dealing with this limitation.

Armando Aguirre Sepulveda added 3 commits July 29, 2024 17:57
Comment threadsrc/compiler/transformers/declarations.ts Outdated
@armanio123

Copy link
Copy Markdown
ContributorAuthor

Refactored as suggested during the design meeting. There's a couple of tests that looks suspicious to me so I appreciate extra set of eyes on them.

@jakebailey

Copy link
Copy Markdown
Member

Yeah, I suspect there's a bug lurking in there; most of the baseline changes are unexpected.

Comment threadsrc/compiler/checker.ts
@jakebailey

Copy link
Copy Markdown
Member

Skimming the code locally, though, I can't find the place where things may have gone wrong... It all seems correct to me.

Comment threadsrc/compiler/types.ts
Comment threadtests/cases/fourslash/completionsClassMemberImportTypeNodeParameter2.ts Outdated
@@ -222,7 +223,7 @@ export function addNewNodeForMemberSymbol(
case SyntaxKind.PropertyDeclaration:
let flags = NodeBuilderFlags.NoTruncation;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesn't need AllowUnresolvedNames like the code below?

Sort of wondering if all old users of NoTruncation need that flag, but maybe we shouldn't add ones where we don't think it should matter except those where we would have set it manually...

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Currently is not needed to pass the test cases. Thought we might be missing some, because adding it doesn't change any of them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right, our test suite is just not always exhaustive, so I suspect that there are some lurking bugs without this flag for these auto-import / codefix cases, given those seem to in other cases depend on this flag

Comment threadsrc/services/codefixes/helpers.ts Outdated
contextNode,
scriptTarget,
NodeBuilderFlags.NoTruncation,
/*internalFlags*/ undefined,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes me wonder if we are missing a test with an unresolved name for those who call this code. (Specifically fixAddMissingMember)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I agree, that's the same thing I just responded to your last comment.

@jakebaileyJake Bailey (jakebailey) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall this now seems good, though the title needs to be updated to not say it's an experiment, and I do think we may need to be adding the unresolved name thing in a couple of places that maybe we just don't have tests for?

I think that the tests that fail without the change to createSignatureDeclarationFromSignature may need to be recreated as tests which make the other cases where NoTruncation failed also fail without AllowUnresolvedNames.

@armanio123Armando Aguirre (armanio123) changed the title Experiment: Refactored node builder flags and testsRefactored node builder flags and testsAug 6, 2024
@armanio123

Copy link
Copy Markdown
ContributorAuthor

If I understand the AllowUnresolvedNames flag correctly this tests cases should not use any correct? If so, there's no reason to add the flag as we don't handle it.

interfaceA{foo: import("./doesntexist.js").Foo;getbar(): import("./doesntexist.js").Foo;}classBimplementsA{|<--Triggercompletionhere}

Completion returns:

foo: any;// This should have been `foo: import("./doesntexist.js").Foo;`getbar(): any {// and this `get bar(): import("./doesntexist.js").Foo;`thrownewError("Method not implemented.");}

@jakebailey

Copy link
Copy Markdown
Member

I would expect those to not spit out any, no, though I'm confused because it sounds like you're saying it spits out any when the flag is set?

@armanio123

Armando Aguirre (armanio123) commented Aug 7, 2024

Copy link
Copy Markdown
ContributorAuthor

That's correct, we spit out any regardless if the flag is set or not. Most likely we don't handle the flag on this code path.

@jakebailey

Copy link
Copy Markdown
Member

If you don't want to write a test for those other branches, can we just put that flag back on the places that used to have NoTruncation to maintain the existing behavior?

@armanio123

Copy link
Copy Markdown
ContributorAuthor

Yeah, I was going to propose the same as I don't know how to create all of the necessary tests. I'm going to put the flag in everyplace I find NoTruncation.

Comment threadsrc/compiler/checker.ts Outdated
function typeToString(type: Type, enclosingDeclaration?: Node, flags: TypeFormatFlags = TypeFormatFlags.AllowUniqueESSymbolType | TypeFormatFlags.UseAliasDefinedOutsideCurrentScope, writer: EmitTextWriter = createTextWriter("")): string {
const noTruncation = compilerOptions.noErrorTruncation || flags & TypeFormatFlags.NoTruncation;
const typeNode = nodeBuilder.typeToTypeNode(type, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | (noTruncation ? NodeBuilderFlags.NoTruncation : 0));
const typeNode = nodeBuilder.typeToTypeNode(type, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | (noTruncation ? NodeBuilderFlags.NoTruncation : NodeBuilderFlags.None), noTruncation ? InternalNodeBuilderFlags.AllowUnresolvedNames : InternalNodeBuilderFlags.None);

@armanio123Armando Aguirre (armanio123)Aug 8, 2024

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

This scenario seems weird to me as it depends on NoTruncation being set in TypeFormatFlags. Nonetheless, this is the current behavior, so I decided to change it but let me know if you disagree and I can rollback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hm, I think it's a little weird, though I guess it's also true that nobody would have ever intentionally set AllowUnresolvedNames here because that was never a valid TypeFormatFlag.

Sort of leaning towards not doing this one and seeing what happens? I assume no test changes here either.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

They don't change. Actually, the latest commit doesn't change any of the tests. I'll rollback this line.

@jakebaileyJake Bailey (jakebailey) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this seems alright now, though it would be nice if we could figure out the rest.

Given we just added a flag everywhere, curious what Wesley Wigham (@weswigham) thinks, but it should at least maintain our old behavior which I feel is pretty safe.

@armanio123
Armando Aguirre (armanio123) merged commit 5f79e16 into microsoft:mainAug 8, 2024
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@armanio123@typescript-bot@jakebailey@weswigham@sandersn