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 element access expression writes for divergent write types #55585

Conversation

Andarist
Copy link
Contributor

I noticed this problem yesterday when working on #55576

The problem is that those two should always behave in the same way and they should use the same write type:

prop.foo = value
prop['foo'] = value

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

@@ -7239,8 +7239,8 @@ export function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) {

/** @internal */
export function isRightSideOfAccessExpression(node: Node) {
return isPropertyAccessExpression(node.parent) && node.parent.name === node
|| isElementAccessExpression(node.parent) && node.parent.argumentExpression === node;
return !!node.parent && (isPropertyAccessExpression(node.parent) && node.parent.name === node
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other utils like this one do not have a guard like this so it looks a little bit off. However, .parent is actually nullable - a SourceFile doesn't have a parent. I could guard this before calling this function but personally, I prefer to have it here.

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 tests are borrowed from #54777 , just adjusted to use the element access expressions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

most of the test cases here (but not all) are borrowed from tests/cases/compiler/divergentAccessorsTypes1-6.ts

u1['prop1'] = 42;
u1['prop1'] = "hello";

u1['prop2'] = 42;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that this one should error. See the playground here

I re-verified all of the tests here and everything here behaves in the same way as it behaves for regular property access expressions. So I think that this issue is a separate one and I will try to prepare a follow up PR to fix it.

@rubiesonthesky
Copy link

Will this break cases where prop['foo'] is used to access properties marked as private in class? Or is this more about just the writable part? I'd like to know if this has worked because bug (or missing feature) in compiler or was it intended that you can circumvent the type error.

(I have seen people use this to be able to access private properties in test files without completely turning off ts type check for the line.)

@Andarist
Copy link
Contributor Author

Or is this more about just the writable part?

It's definitely intended to be just about the writable part. If you have any complete example of what you have in mind in regards to private properties then I could take a look at it and re-verify that I don't break something that shouldn't be broken.

@rubiesonthesky
Copy link

If you have any complete example of what you have in mind in regards to private properties then I could take a look at it and re-verify that I don't break something that shouldn't be broken.

Here is one example :)

export class ExampleClass {
    private name = 'Name';
}
const example = new ExampleClass();
const accessedName = example['name'];

@Andarist
Copy link
Contributor Author

I don't think this will be affected by this PR

@jakebailey
Copy link
Member

@typescript-bot test top200
@typescript-bot user test this
@typescript-bot run dt
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 13, 2023

Heya @jakebailey, I've started to run the diff-based top-repos suite on this PR at 46e771a. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 13, 2023

Heya @jakebailey, I've started to run the parallelized Definitely Typed test suite on this PR at 46e771a. You can monitor the build here.

Update: The results are in!

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 13, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 13, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

There were infrastructure failures potentially unrelated to your change:

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

Otherwise...

Everything looks good!

@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,261k (± 0.00%) 300,261k (± 0.00%) ~ 300,250k 300,275k p=1.000 n=6
Parse Time 3.00s (± 0.17%) 3.01s (± 0.17%) ~ 3.00s 3.01s p=0.311 n=6
Bind Time 0.93s (± 0.00%) 0.93s (± 0.00%) ~ 0.93s 0.93s p=1.000 n=6
Check Time 9.33s (± 0.30%) 9.35s (± 0.29%) ~ 9.32s 9.39s p=0.295 n=6
Emit Time 7.64s (± 0.32%) 7.65s (± 0.32%) ~ 7.61s 7.68s p=0.374 n=6
Total Time 20.90s (± 0.20%) 20.94s (± 0.14%) ~ 20.89s 20.98s p=0.169 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 193,936k (± 0.03%) 193,949k (± 0.03%) ~ 193,865k 194,010k p=0.936 n=6
Parse Time 1.58s (± 0.26%) 1.58s (± 0.00%) ~ 1.58s 1.58s p=0.405 n=6
Bind Time 0.80s (± 0.65%) 0.80s (± 0.51%) ~ 0.79s 0.80s p=0.595 n=6
Check Time 9.93s (± 0.46%) 9.95s (± 0.49%) ~ 9.87s 9.99s p=0.627 n=6
Emit Time 2.74s (± 0.19%) 2.74s (± 0.27%) ~ 2.73s 2.75s p=0.241 n=6
Total Time 15.05s (± 0.35%) 15.06s (± 0.30%) ~ 14.99s 15.09s p=0.870 n=6
Monaco - node (v16.17.1, x64)
Memory used 347,195k (± 0.01%) 347,184k (± 0.01%) ~ 347,116k 347,214k p=0.936 n=6
Parse Time 2.69s (± 0.28%) 2.69s (± 0.20%) ~ 2.68s 2.69s p=0.476 n=6
Bind Time 0.99s (± 0.41%) 0.99s (± 0.41%) ~ 0.99s 1.00s p=0.218 n=6
Check Time 7.94s (± 0.42%) 7.94s (± 0.27%) ~ 7.91s 7.96s p=0.744 n=6
Emit Time 4.27s (± 0.27%) 4.26s (± 0.54%) ~ 4.22s 4.29s p=0.681 n=6
Total Time 15.88s (± 0.25%) 15.88s (± 0.18%) ~ 15.84s 15.91s p=1.000 n=6
TFS - node (v16.17.1, x64)
Memory used 301,173k (± 0.01%) 301,184k (± 0.00%) ~ 301,171k 301,203k p=0.377 n=6
Parse Time 2.18s (± 0.34%) 2.18s (± 0.63%) ~ 2.16s 2.20s p=0.357 n=6
Bind Time 1.11s (± 0.37%) 1.11s (± 0.00%) ~ 1.11s 1.11s p=0.405 n=6
Check Time 7.23s (± 0.38%) 7.24s (± 0.40%) ~ 7.20s 7.28s p=0.935 n=6
Emit Time 3.98s (± 0.22%) 3.99s (± 0.26%) ~ 3.97s 4.00s p=0.273 n=6
Total Time 14.50s (± 0.26%) 14.51s (± 0.20%) ~ 14.48s 14.55s p=0.808 n=6
material-ui - node (v16.17.1, x64)
Memory used 479,554k (± 0.00%) 479,528k (± 0.00%) -26k (- 0.01%) 479,505k 479,550k p=0.016 n=6
Parse Time 3.15s (± 0.13%) 3.15s (± 0.16%) ~ 3.14s 3.15s p=0.595 n=6
Bind Time 0.91s (± 0.00%) 0.91s (± 0.00%) ~ 0.91s 0.91s p=1.000 n=6
Check Time 17.91s (± 0.41%) 17.92s (± 0.25%) ~ 17.85s 17.96s p=0.520 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 21.97s (± 0.33%) 21.98s (± 0.21%) ~ 21.91s 22.02s p=0.627 n=6
xstate - node (v16.17.1, x64)
Memory used 542,841k (± 0.01%) 542,863k (± 0.01%) ~ 542,794k 542,986k p=0.689 n=6
Parse Time 3.68s (± 0.14%) 3.69s (± 0.11%) ~ 3.68s 3.69s p=0.112 n=6
Bind Time 1.43s (± 3.57%) 1.46s (± 0.00%) ~ 1.46s 1.46s p=0.074 n=6
Check Time 3.19s (± 2.12%) 3.17s (± 0.24%) ~ 3.16s 3.18s p=1.000 n=6
Emit Time 0.08s (± 4.99%) 0.09s (± 4.62%) +0.01s (+ 8.16%) 0.08s 0.09s p=0.034 n=6
Total Time 8.39s (± 0.41%) 8.41s (± 0.24%) ~ 8.38s 8.44s p=0.372 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,489ms (± 0.10%) 2,494ms (± 0.41%) ~ 2,485ms 2,512ms p=0.624 n=6
Req 2 - geterr 5,967ms (± 0.33%) 5,927ms (± 0.34%) -39ms (- 0.66%) 5,912ms 5,965ms p=0.031 n=6
Req 3 - references 343ms (± 0.64%) 342ms (± 0.45%) ~ 339ms 343ms p=0.618 n=6
Req 4 - navto 278ms (± 0.95%) 276ms (± 0.63%) ~ 274ms 279ms p=0.096 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 81ms (± 4.19%) 82ms (± 7.59%) ~ 76ms 93ms p=0.935 n=6
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,608ms (± 0.12%) 2,612ms (± 0.57%) ~ 2,599ms 2,639ms p=0.872 n=6
Req 2 - geterr 4,776ms (± 0.18%) 4,776ms (± 0.27%) ~ 4,761ms 4,795ms p=0.936 n=6
Req 3 - references 351ms (± 0.23%) 350ms (± 0.39%) ~ 349ms 353ms p=0.325 n=6
Req 4 - navto 269ms (± 0.23%) 270ms (± 1.09%) ~ 268ms 274ms p=0.934 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 78ms (± 0.66%) 78ms (± 1.04%) ~ 77ms 79ms p=0.929 n=6
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,705ms (± 0.20%) 2,707ms (± 0.23%) ~ 2,700ms 2,715ms p=0.518 n=6
Req 2 - geterr 1,957ms (± 1.79%) 1,934ms (± 2.51%) ~ 1,860ms 1,976ms p=0.575 n=6
Req 3 - references 136ms (± 5.57%) 136ms (± 2.07%) ~ 132ms 140ms p=0.294 n=6
Req 4 - navto 360ms (± 1.21%) 359ms (± 0.98%) ~ 355ms 364ms p=0.809 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 323ms (± 1.69%) 315ms (± 1.60%) ~ 311ms 325ms p=0.084 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.72ms (± 0.21%) 156.79ms (± 0.18%) ~ 154.71ms 159.45ms p=0.070 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time 230.46ms (± 0.15%) 231.06ms (± 0.15%) +0.60ms (+ 0.26%) 229.42ms 236.52ms p=0.000 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 235.90ms (± 0.16%) 236.42ms (± 0.12%) +0.53ms (+ 0.22%) 235.22ms 241.81ms p=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time 235.75ms (± 0.11%) 235.61ms (± 0.12%) -0.13ms (- 0.06%) 234.36ms 238.74ms 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

Hey @jakebailey, it looks like the DT test run failed. Please check the log for more details.
You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, it looks like the DT test run failed. Please check the log for more details.
You can check the log here.

@jakebailey
Copy link
Member

@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 13, 2023

Heya @jakebailey, I've started to run the parallelized Definitely Typed test suite on this PR at 46e771a. You can monitor the build here.

Update: The results are in!

@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.

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