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

Lookup retained type nodes in the node builder using correct, specific SymbolFlags meaning #57887

Conversation

weswigham
Copy link
Member

Fixes #57861

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Mar 21, 2024
Comment on lines +6328 to +6330
(entityName.parent.kind === SyntaxKind.QualifiedName && (entityName.parent as QualifiedName).left === entityName) ||
(entityName.parent.kind === SyntaxKind.PropertyAccessExpression && (entityName.parent as PropertyAccessExpression).expression === entityName) ||
(entityName.parent.kind === SyntaxKind.ElementAccessExpression && (entityName.parent as ElementAccessExpression).expression === entityName)
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if this is even a good thought, but could entityName.parent.left/entityName.parent.expression be yet another one of these nodes has a left/expression that satisfies these rules, e.g. does this need to be recursively unwrapped to check for the innermost thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

These are so if you're the A in A.B, you get a Namespace meaning. Since we always get the leftmost identifier for the lookup, we only ever actually lookup the A. Even in an A.B.C, we only lookup the A. Elsewhere, we use getQualifiedLeftMeaning on the "input" meaning for the whole dotted name to map type/value meaning to a namespace/value meaning, but when we're using this function, we're usually in a state where we don't even have an "input" meaning yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

That this codepath is somewhat bespoke is... unfortunate. It basically has to distill "what meaning is done by a resolveName call where elsewhere in the checker for this node" into a single function, so declaration emit can redo the lookup with alias collection on.

Copy link
Member Author

@weswigham weswigham Mar 21, 2024

Choose a reason for hiding this comment

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

For example, getResolvedSymbol, as used by checkIdentifier (for expression identifiers), uses SymbolFlags.Value | SymbolFlags.ExportValue, while getTypeFromTypeReference uses SymbolFlags.Type* (and SymbolFlags.Namespace for anything left of the last dot), while checkPropertyAccessExpressionOrQualifiedName just expects the LHS namespace to already be resolved and looks up members on it directly, so doesn't concern itself with meanings.

*Unless you're in JSDoc and it gets very complicated with Value meanings mixing in a fallback lookup.

if (!isDeclarationName(node)) {
introducesError = true;
}
}
else {
context.tracker.trackSymbol(sym, context.enclosingDeclaration, SymbolFlags.All);
context.tracker.trackSymbol(sym, context.enclosingDeclaration, meaning);
Copy link
Member Author

Choose a reason for hiding this comment

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

Just as an FYI to anyone who wants to know why this is the fix for the issue, this call here passes the symbol off to the declaration emitter, which then does a isSymbolAccessible with shouldComputeAliasesToMakeVisible set to true (unlike the speculative one above, where it's false), and uses that alias list to determine what to preserve in the output. When the meaning is inaccurate, you get the wrong symbol from the resolveEntityName lookup, and collect the wrong set of aliases.

@weswigham
Copy link
Member Author

@DanielRosenwasser I guess this fixes a 5.4 regression, so is a candidate for a patch?

@weswigham
Copy link
Member Author

@typescript-bot run dt
@typescript-bot test top100
@typescript-bot user test this
@typescript-bot perf test public

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2024

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

Command Status Results
run dt ✅ Started ✅ Results
test top100 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
perf test public ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

Hey @weswigham, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

@weswigham
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 (v20.5.1, x64)
Memory used 192,149k (± 1.03%) 191,468k (± 1.01%) ~ 190,211k 193,970k p=0.575 n=6
Parse Time 1.38s (± 1.16%) 1.38s (± 1.09%) ~ 1.37s 1.41s p=0.675 n=6
Bind Time 0.75s (± 2.14%) 0.75s (± 1.37%) ~ 0.74s 0.77s p=0.720 n=6
Check Time 9.05s (± 0.30%) 9.00s (± 0.56%) ~ 8.96s 9.09s p=0.063 n=6
Emit Time 2.67s (± 0.77%) 2.66s (± 1.00%) ~ 2.63s 2.69s p=0.687 n=6
Total Time 13.86s (± 0.20%) 13.81s (± 0.35%) -0.05s (- 0.36%) 13.74s 13.89s p=0.042 n=6
mui-docs - node (v20.5.1, x64)
Memory used 1,754,517k (± 0.00%) 1,754,517k (± 0.00%) ~ 1,754,483k 1,754,563k p=0.936 n=6
Parse Time 6.81s (± 0.49%) 6.81s (± 0.22%) ~ 6.80s 6.84s p=0.805 n=6
Bind Time 2.29s (± 7.23%) 2.40s (± 0.82%) ~ 2.38s 2.43s p=0.327 n=6
Check Time 53.31s (± 0.71%) 53.35s (± 0.41%) ~ 53.12s 53.67s p=1.000 n=6
Emit Time 0.12s (± 4.18%) 0.13s (± 4.38%) ~ 0.12s 0.13s p=0.640 n=6
Total Time 62.54s (± 0.51%) 62.69s (± 0.35%) ~ 62.46s 63.02s p=0.423 n=6
self-build-src - node (v20.5.1, x64)
Memory used 2,656,223k (± 2.74%) 2,609,586k (± 2.81%) ~ 2,561,623k 2,704,395k p=0.810 n=6
Parse Time 5.27s (± 0.92%) 5.26s (± 0.84%) ~ 5.22s 5.32s p=0.810 n=6
Bind Time 2.01s (± 0.81%) 2.03s (± 0.40%) ~ 2.02s 2.04s p=0.184 n=6
Check Time 32.44s (± 0.20%) 32.43s (± 0.25%) ~ 32.34s 32.53s p=0.936 n=6
Emit Time 2.64s (± 4.06%) 2.62s (± 2.31%) ~ 2.56s 2.70s p=0.748 n=6
Total Time 42.39s (± 0.40%) 42.37s (± 0.33%) ~ 42.19s 42.52s p=0.689 n=6
self-compiler - node (v20.5.1, x64)
Memory used 414,718k (± 0.02%) 414,769k (± 0.02%) ~ 414,658k 414,856k p=0.230 n=6
Parse Time 2.89s (± 0.73%) 2.89s (± 0.92%) ~ 2.84s 2.92s p=0.935 n=6
Bind Time 1.13s (± 0.79%) 1.13s (± 0.74%) ~ 1.13s 1.15s p=0.437 n=6
Check Time 14.26s (± 0.16%) 14.27s (± 0.34%) ~ 14.22s 14.36s p=0.935 n=6
Emit Time 0.99s (± 1.74%) 1.00s (± 1.37%) ~ 0.98s 1.02s p=0.564 n=6
Total Time 19.27s (± 0.23%) 19.29s (± 0.20%) ~ 19.25s 19.36s p=0.467 n=6
vscode - node (v20.5.1, x64)
Memory used 2,931,643k (± 0.00%) 2,931,636k (± 0.00%) ~ 2,931,593k 2,931,687k p=0.936 n=6
Parse Time 10.98s (± 0.13%) 10.97s (± 0.16%) ~ 10.94s 10.99s p=0.250 n=6
Bind Time 3.53s (± 0.42%) 3.53s (± 0.29%) ~ 3.52s 3.55s p=0.803 n=6
Check Time 59.16s (± 0.30%) 59.00s (± 0.17%) ~ 58.89s 59.18s p=0.054 n=6
Emit Time 20.28s (± 3.59%) 19.97s (± 4.35%) ~ 18.84s 20.67s p=0.873 n=6
Total Time 93.94s (± 0.85%) 93.47s (± 0.99%) ~ 92.29s 94.27s p=0.128 n=6
webpack - node (v20.5.1, x64)
Memory used 411,517k (± 0.01%) 411,488k (± 0.01%) ~ 411,452k 411,541k p=0.336 n=6
Parse Time 3.38s (± 0.51%) 3.38s (± 0.61%) ~ 3.36s 3.42s p=0.682 n=6
Bind Time 1.47s (± 0.43%) 1.47s (± 0.37%) ~ 1.47s 1.48s p=0.201 n=6
Check Time 13.37s (± 0.24%) 13.36s (± 0.12%) ~ 13.34s 13.39s p=0.936 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 18.22s (± 0.14%) 18.22s (± 0.16%) ~ 18.19s 18.26s p=0.870 n=6
System info unknown
Hosts
  • node (v20.5.1, x64)
Scenarios
  • Compiler-Unions - node (v20.5.1, x64)
  • mui-docs - node (v20.5.1, x64)
  • self-build-src - node (v20.5.1, x64)
  • self-compiler - node (v20.5.1, x64)
  • vscode - node (v20.5.1, x64)
  • webpack - node (v20.5.1, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@weswigham Here are the results of running the top-repos suite comparing main and refs/pull/57887/merge:

Everything looks good!

@weswigham weswigham merged commit 91cecdc into microsoft:main Mar 21, 2024
25 checks passed
@weswigham weswigham deleted the fix-declaration-emit-imports-referenced-by-retained-nodes branch March 21, 2024 18:49
@jakebailey
Copy link
Member

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2024

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

Command Status Results
cherry-pick this to release-5.4 ✅ Started ❌ Results

@typescript-bot
Copy link
Collaborator

Hey, @jakebailey! I was unable to cherry-pick this PR.

Check the logs at: https://github.com/microsoft/TypeScript/actions/runs/8380436348

@jakebailey
Copy link
Member

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 21, 2024

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

Command Status Results
cherry-pick this to release-5.4 ✅ Started ❌ Results

@typescript-bot
Copy link
Collaborator

Hey, @jakebailey! I was unable to cherry-pick this PR.

Check the logs at: https://github.com/microsoft/TypeScript/actions/runs/8381864069

jakebailey pushed a commit to jakebailey/TypeScript that referenced this pull request Mar 21, 2024
@jakebailey
Copy link
Member

The cherry-pick for this onto the release branch is... big? #57898

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5.4 omits certain import * as ... statements from .d.ts
4 participants