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

Allowed non-this, non-super code before super call in derived classes with property initializers #29374

Merged
merged 61 commits into from Jan 14, 2022

Conversation

JoshuaKGoldberg
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg commented Jan 11, 2019

Starts on #8277 by allowing the non-this, non-super code to be root-level statements in the constructor. This will now be allowed:

class Base { }
class Derived extends Base {
    public prop = true;
    constructor(public paramProp = true) {
        console.log("Hello, world!");
        super();
    }
}

It feels wrong to put a new forEachChild loop in the checker, though in the vast majority of user files this will be a very quick one. Is there a better way to check for a reference to super or this?

Edit 2/28/2020: I've mostly resolved the merge conflicts introduced by both # private fields & useDefineForClassFields , but I'm not confident my approach is still a valid one. I'd greatly appreciate it if someone could confirm I'm on the right track!
Oh, and gulp runtests passes locally (on Windows). I'll try a Mac to see if there's some odd encoding/whitespace behavior with the failing test... ✔️

Edit 3/11/2021: It seems this is fairly close to merging.

Edit 1/13/2022: I bought this PR a birthday cake for its third birthday. https://twitter.com/JoshuaKGoldberg/status/1481654056422567944

Blue and white cake with text 'Happy 3rd birthday, #29374 Bump for PR review please!' and the TypeScript logo. A tall slice is removed.

Fixes microsoft#8277.

It feels wrong to put a new `forEachChild` loop in the checker, though in the vast majority of user files this will be a very quick one. Is there a better way to check for a reference to `super` or `this`?
src/compiler/checker.ts Outdated Show resolved Hide resolved
src/compiler/utilities.ts Outdated Show resolved Hide resolved
src/compiler/utilities.ts Outdated Show resolved Hide resolved
@weswigham
Copy link
Member

@weswigham weswigham commented Jan 11, 2019

It feels wrong to put a new forEachChild loop in the checker, though in the vast majority of user files this will be a very quick one. Is there a better way to check for a reference to super or this?

TransformFlags.Super | TransformFlags.ContainsSuper for super at least.

src/compiler/utilities.ts Outdated Show resolved Hide resolved
…boundaries

```ts
function () {
    return this;
}
```

It was immediately going to `ts.forEachChild` so the statement itself wasn't being counted as a new `this` scope.
Copy link
Contributor

@ajafff ajafff left a comment

This is getting very complex very fast. I wonder if there's an easier way using the control flow graph?

src/compiler/utilities.ts Outdated Show resolved Hide resolved
src/compiler/checker.ts Outdated Show resolved Hide resolved
src/compiler/utilities.ts Outdated Show resolved Hide resolved
src/compiler/utilities.ts Outdated Show resolved Hide resolved
src/compiler/utilities.ts Outdated Show resolved Hide resolved
As per discussion in the issue, it would be ideal to consider any block that always ends up calling to super() the equivalent of a root-level super() statement. This would be valid:

```ts
foo = 1;
constructor() {
    condition() ? super(1) : super(0);
    this.foo;
}
```

...as it would compile to the equivalent of:
```ts
function () {
    condition() ? super(1) : super(0);
    this.foo = 1;
    this.foo;
}

That change would a bit more intense and I'm very timid, so leaving it out of this PR. In the meantime the requirement is that the super() statement must itself be root-level.
src/compiler/utilities.ts Outdated Show resolved Hide resolved
@RyanCavanaugh
Copy link
Member

@RyanCavanaugh RyanCavanaugh commented Jan 25, 2019

cc @ahejlsberg for review

@JoshuaKGoldberg
Copy link
Contributor Author

@JoshuaKGoldberg JoshuaKGoldberg commented Apr 2, 2019

Ping @ahejlsberg - is there anything that needs to be done here? It'd be nice to have this in 😄

@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.6.0 milestone Jul 12, 2019
@JoshuaKGoldberg
Copy link
Contributor Author

@JoshuaKGoldberg JoshuaKGoldberg commented Jul 16, 2019

Correction: ping, @weswigham?

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jan 13, 2022

Heya @rbuckton, I've started to run the perf test suite on this PR at 39d9901. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jan 13, 2022

Heya @rbuckton, I've started to run the parallelized community code test suite on this PR at 39d9901. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jan 13, 2022

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

Here they are:

Comparison Report - main..29374

Metric main 29374 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 355,006k (± 0.02%) 355,104k (± 0.02%) +98k (+ 0.03%) 354,991k 355,257k
Parse Time 1.96s (± 0.64%) 1.95s (± 1.00%) -0.01s (- 0.41%) 1.92s 2.01s
Bind Time 0.85s (± 0.43%) 0.85s (± 1.39%) +0.01s (+ 0.71%) 0.83s 0.89s
Check Time 5.56s (± 0.78%) 5.54s (± 0.34%) -0.02s (- 0.34%) 5.49s 5.57s
Emit Time 5.91s (± 0.51%) 5.91s (± 0.47%) +0.01s (+ 0.12%) 5.86s 6.00s
Total Time 14.27s (± 0.50%) 14.26s (± 0.34%) -0.01s (- 0.08%) 14.13s 14.40s
Compiler-Unions - node (v10.16.3, x64)
Memory used 204,160k (± 0.03%) 204,198k (± 0.02%) +38k (+ 0.02%) 204,103k 204,302k
Parse Time 0.79s (± 0.76%) 0.78s (± 0.76%) -0.00s (- 0.13%) 0.77s 0.80s
Bind Time 0.52s (± 1.28%) 0.52s (± 1.18%) -0.00s (- 0.38%) 0.51s 0.53s
Check Time 7.87s (± 0.36%) 7.83s (± 0.45%) -0.03s (- 0.41%) 7.78s 7.93s
Emit Time 2.47s (± 0.99%) 2.46s (± 1.26%) -0.01s (- 0.20%) 2.40s 2.55s
Total Time 11.64s (± 0.35%) 11.60s (± 0.35%) -0.04s (- 0.32%) 11.52s 11.69s
Monaco - node (v10.16.3, x64)
Memory used 342,598k (± 0.02%) 342,584k (± 0.02%) -15k (- 0.00%) 342,439k 342,749k
Parse Time 1.49s (± 0.41%) 1.48s (± 0.70%) -0.01s (- 0.47%) 1.46s 1.51s
Bind Time 0.75s (± 0.60%) 0.74s (± 0.67%) -0.00s (- 0.40%) 0.73s 0.75s
Check Time 5.53s (± 0.62%) 5.51s (± 0.50%) -0.01s (- 0.25%) 5.44s 5.56s
Emit Time 3.22s (± 1.40%) 3.21s (± 1.02%) -0.01s (- 0.25%) 3.17s 3.30s
Total Time 10.98s (± 0.36%) 10.95s (± 0.31%) -0.03s (- 0.24%) 10.90s 11.06s
TFS - node (v10.16.3, x64)
Memory used 305,650k (± 0.04%) 305,634k (± 0.02%) -15k (- 0.00%) 305,447k 305,794k
Parse Time 1.20s (± 0.67%) 1.20s (± 0.39%) +0.00s (+ 0.17%) 1.19s 1.21s
Bind Time 0.71s (± 1.02%) 0.71s (± 0.67%) -0.00s (- 0.70%) 0.70s 0.72s
Check Time 5.06s (± 0.47%) 5.03s (± 0.56%) -0.03s (- 0.55%) 4.96s 5.11s
Emit Time 3.37s (± 1.11%) 3.38s (± 0.90%) +0.01s (+ 0.42%) 3.30s 3.43s
Total Time 10.34s (± 0.41%) 10.32s (± 0.41%) -0.02s (- 0.17%) 10.23s 10.44s
material-ui - node (v10.16.3, x64)
Memory used 471,411k (± 0.02%) 471,494k (± 0.02%) +83k (+ 0.02%) 471,272k 471,694k
Parse Time 1.77s (± 0.60%) 1.78s (± 0.33%) +0.01s (+ 0.62%) 1.77s 1.79s
Bind Time 0.66s (± 0.72%) 0.66s (± 0.61%) +0.00s (+ 0.30%) 0.65s 0.67s
Check Time 14.26s (± 0.59%) 14.16s (± 0.43%) -0.10s (- 0.71%) 14.07s 14.33s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.69s (± 0.54%) 16.60s (± 0.38%) -0.09s (- 0.53%) 16.51s 16.77s
xstate - node (v10.16.3, x64)
Memory used 569,345k (± 0.02%) 569,393k (± 0.02%) +48k (+ 0.01%) 569,201k 569,615k
Parse Time 2.55s (± 0.45%) 2.56s (± 0.27%) +0.00s (+ 0.08%) 2.54s 2.57s
Bind Time 1.00s (± 0.58%) 1.01s (± 0.49%) +0.00s (+ 0.30%) 1.00s 1.02s
Check Time 1.50s (± 0.33%) 1.50s (± 0.73%) +0.01s (+ 0.47%) 1.47s 1.52s
Emit Time 0.07s (± 0.00%) 0.07s (± 0.00%) 0.00s ( 0.00%) 0.07s 0.07s
Total Time 5.12s (± 0.33%) 5.13s (± 0.15%) +0.01s (+ 0.20%) 5.11s 5.15s
Angular - node (v12.1.0, x64)
Memory used 332,853k (± 0.03%) 332,960k (± 0.03%) +107k (+ 0.03%) 332,725k 333,109k
Parse Time 1.95s (± 0.52%) 1.95s (± 0.62%) +0.01s (+ 0.26%) 1.92s 1.98s
Bind Time 0.82s (± 0.82%) 0.82s (± 0.71%) 0.00s ( 0.00%) 0.81s 0.83s
Check Time 5.35s (± 0.59%) 5.35s (± 0.36%) +0.00s (+ 0.04%) 5.31s 5.41s
Emit Time 6.17s (± 0.58%) 6.15s (± 0.58%) -0.02s (- 0.28%) 6.08s 6.24s
Total Time 14.28s (± 0.40%) 14.27s (± 0.32%) -0.01s (- 0.06%) 14.14s 14.36s
Compiler-Unions - node (v12.1.0, x64)
Memory used 191,512k (± 0.14%) 191,801k (± 0.03%) +289k (+ 0.15%) 191,685k 191,922k
Parse Time 0.78s (± 0.71%) 0.78s (± 0.77%) -0.00s (- 0.26%) 0.76s 0.79s
Bind Time 0.53s (± 0.98%) 0.53s (± 0.84%) -0.00s (- 0.56%) 0.52s 0.54s
Check Time 7.34s (± 0.65%) 7.29s (± 0.30%) -0.05s (- 0.69%) 7.24s 7.35s
Emit Time 2.49s (± 1.01%) 2.47s (± 0.83%) -0.02s (- 0.60%) 2.45s 2.54s
Total Time 11.14s (± 0.61%) 11.07s (± 0.38%) -0.07s (- 0.64%) 11.00s 11.20s
Monaco - node (v12.1.0, x64)
Memory used 325,640k (± 0.03%) 325,574k (± 0.02%) -65k (- 0.02%) 325,394k 325,695k
Parse Time 1.46s (± 1.11%) 1.46s (± 0.94%) +0.00s (+ 0.07%) 1.44s 1.50s
Bind Time 0.73s (± 0.65%) 0.73s (± 1.04%) -0.00s (- 0.14%) 0.71s 0.74s
Check Time 5.39s (± 0.46%) 5.39s (± 0.48%) +0.00s (+ 0.06%) 5.34s 5.45s
Emit Time 3.22s (± 0.86%) 3.22s (± 0.62%) -0.00s (- 0.03%) 3.19s 3.28s
Total Time 10.80s (± 0.30%) 10.80s (± 0.37%) +0.00s (+ 0.01%) 10.72s 10.89s
TFS - node (v12.1.0, x64)
Memory used 290,384k (± 0.01%) 290,313k (± 0.01%) -71k (- 0.02%) 290,222k 290,396k
Parse Time 1.22s (± 0.84%) 1.22s (± 0.91%) -0.00s (- 0.25%) 1.20s 1.25s
Bind Time 0.69s (± 1.36%) 0.69s (± 0.80%) -0.00s (- 0.14%) 0.68s 0.71s
Check Time 4.96s (± 0.32%) 4.97s (± 0.28%) +0.01s (+ 0.22%) 4.94s 4.99s
Emit Time 3.41s (± 0.50%) 3.46s (± 0.81%) +0.05s (+ 1.50%) 3.41s 3.56s
Total Time 10.28s (± 0.26%) 10.33s (± 0.28%) +0.06s (+ 0.54%) 10.29s 10.44s
material-ui - node (v12.1.0, x64)
Memory used 450,246k (± 0.02%) 450,229k (± 0.02%) -17k (- 0.00%) 450,003k 450,343k
Parse Time 1.78s (± 0.47%) 1.77s (± 0.45%) -0.01s (- 0.73%) 1.76s 1.79s
Bind Time 0.64s (± 0.74%) 0.64s (± 1.17%) -0.01s (- 0.93%) 0.62s 0.65s
Check Time 12.77s (± 0.80%) 12.73s (± 0.49%) -0.03s (- 0.25%) 12.60s 12.87s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.19s (± 0.69%) 15.14s (± 0.46%) -0.05s (- 0.32%) 14.99s 15.30s
xstate - node (v12.1.0, x64)
Memory used 535,368k (± 0.01%) 538,884k (± 1.44%) +3,516k (+ 0.66%) 535,254k 570,178k
Parse Time 2.50s (± 0.77%) 2.49s (± 0.54%) -0.01s (- 0.60%) 2.45s 2.51s
Bind Time 1.04s (± 0.59%) 1.04s (± 1.02%) -0.00s (- 0.19%) 1.02s 1.06s
Check Time 1.44s (± 0.62%) 1.43s (± 0.40%) -0.01s (- 0.76%) 1.42s 1.44s
Emit Time 0.07s (± 0.00%) 0.07s (± 0.00%) 0.00s ( 0.00%) 0.07s 0.07s
Total Time 5.05s (± 0.31%) 5.03s (± 0.36%) -0.02s (- 0.46%) 4.98s 5.07s
Angular - node (v14.15.1, x64)
Memory used 331,295k (± 0.01%) 331,302k (± 0.01%) +7k (+ 0.00%) 331,256k 331,360k
Parse Time 1.95s (± 0.74%) 1.95s (± 0.76%) -0.00s (- 0.20%) 1.93s 1.99s
Bind Time 0.86s (± 0.60%) 0.86s (± 0.42%) +0.00s (+ 0.35%) 0.86s 0.87s
Check Time 5.41s (± 0.40%) 5.43s (± 0.51%) +0.01s (+ 0.26%) 5.35s 5.47s
Emit Time 6.19s (± 0.58%) 6.21s (± 0.70%) +0.01s (+ 0.21%) 6.11s 6.32s
Total Time 14.42s (± 0.40%) 14.44s (± 0.53%) +0.02s (+ 0.15%) 14.30s 14.62s
Compiler-Unions - node (v14.15.1, x64)
Memory used 193,289k (± 0.38%) 192,812k (± 0.49%) -477k (- 0.25%) 190,352k 193,639k
Parse Time 0.81s (± 0.74%) 0.81s (± 0.87%) +0.00s (+ 0.37%) 0.80s 0.83s
Bind Time 0.55s (± 0.66%) 0.55s (± 0.81%) -0.00s (- 0.36%) 0.54s 0.56s
Check Time 7.43s (± 0.55%) 7.45s (± 0.64%) +0.02s (+ 0.32%) 7.36s 7.57s
Emit Time 2.46s (± 0.85%) 2.49s (± 0.82%) +0.02s (+ 0.97%) 2.45s 2.54s
Total Time 11.25s (± 0.36%) 11.30s (± 0.46%) +0.05s (+ 0.44%) 11.17s 11.40s
Monaco - node (v14.15.1, x64)
Memory used 324,480k (± 0.00%) 324,438k (± 0.00%) -42k (- 0.01%) 324,404k 324,463k
Parse Time 1.50s (± 0.63%) 1.51s (± 0.88%) +0.01s (+ 0.66%) 1.48s 1.54s
Bind Time 0.76s (± 0.48%) 0.76s (± 0.45%) +0.00s (+ 0.13%) 0.75s 0.76s
Check Time 5.35s (± 0.64%) 5.36s (± 0.31%) +0.00s (+ 0.07%) 5.31s 5.39s
Emit Time 3.27s (± 0.68%) 3.25s (± 0.87%) -0.01s (- 0.40%) 3.17s 3.31s
Total Time 10.88s (± 0.48%) 10.88s (± 0.44%) +0.00s (+ 0.01%) 10.74s 10.96s
TFS - node (v14.15.1, x64)
Memory used 289,281k (± 0.01%) 289,207k (± 0.01%) -74k (- 0.03%) 289,152k 289,241k
Parse Time 1.23s (± 0.69%) 1.24s (± 0.82%) +0.01s (+ 0.49%) 1.21s 1.25s
Bind Time 0.73s (± 0.79%) 0.74s (± 0.68%) +0.00s (+ 0.27%) 0.73s 0.75s
Check Time 4.95s (± 0.52%) 4.97s (± 0.51%) +0.02s (+ 0.34%) 4.92s 5.02s
Emit Time 3.50s (± 0.63%) 3.55s (± 0.59%) +0.05s (+ 1.49%) 3.48s 3.58s
Total Time 10.41s (± 0.30%) 10.49s (± 0.35%) +0.08s (+ 0.77%) 10.39s 10.54s
material-ui - node (v14.15.1, x64)
Memory used 448,303k (± 0.06%) 448,451k (± 0.00%) +148k (+ 0.03%) 448,418k 448,479k
Parse Time 1.82s (± 0.55%) 1.83s (± 0.50%) +0.01s (+ 0.33%) 1.81s 1.86s
Bind Time 0.68s (± 0.59%) 0.68s (± 0.54%) -0.00s (- 0.44%) 0.67s 0.68s
Check Time 12.90s (± 0.80%) 12.79s (± 0.52%) -0.11s (- 0.87%) 12.64s 12.97s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.40s (± 0.66%) 15.29s (± 0.47%) -0.11s (- 0.72%) 15.16s 15.50s
xstate - node (v14.15.1, x64)
Memory used 533,047k (± 0.00%) 533,100k (± 0.01%) +53k (+ 0.01%) 533,041k 533,182k
Parse Time 2.55s (± 0.58%) 2.56s (± 0.41%) +0.00s (+ 0.16%) 2.54s 2.58s
Bind Time 1.15s (± 1.09%) 1.15s (± 0.67%) -0.01s (- 0.52%) 1.14s 1.17s
Check Time 1.48s (± 0.75%) 1.49s (± 0.55%) +0.00s (+ 0.20%) 1.47s 1.50s
Emit Time 0.07s (± 0.00%) 0.07s (± 0.00%) 0.00s ( 0.00%) 0.07s 0.07s
Total Time 5.27s (± 0.43%) 5.27s (± 0.38%) +0.00s (+ 0.04%) 5.24s 5.33s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory8 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v10.16.3, x64)
  • xstate - node (v12.1.0, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 29374 10
Baseline main 10

Developer Information:

Download Benchmark

@JoshuaKGoldberg JoshuaKGoldberg requested a review from rbuckton Jan 13, 2022
@pkoch
Copy link

@pkoch pkoch commented Jan 14, 2022

@rbuckton Is there anything else that @JoshuaKGoldberg can do to move this forward?

@rbuckton
Copy link
Member

@rbuckton rbuckton commented Jan 14, 2022

@typescript-bot user test this inline

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jan 14, 2022

Heya @rbuckton, I'm starting to run the inline community code test suite on this PR at 1b3dd6d. Hold tight - I'll update this comment with the log link once the build has been queued.

@rbuckton
Copy link
Member

@rbuckton rbuckton commented Jan 14, 2022

@rbuckton Is there anything else that @JoshuaKGoldberg can do to move this forward?

Nope, it looks ready to go actually, and just in time for 4.6 beta.

PR Backlog automation moved this from Waiting on author to Needs merge Jan 14, 2022
@rbuckton rbuckton merged commit b7fee7f into microsoft:main Jan 14, 2022
10 checks passed
PR Backlog automation moved this from Needs merge to Done Jan 14, 2022
@JoshuaKGoldberg JoshuaKGoldberg deleted the non-this-super-before-super branch Jan 14, 2022
@JoshuaKGoldberg
Copy link
Contributor Author

@JoshuaKGoldberg JoshuaKGoldberg commented Jan 14, 2022

Fantastic, thanks so much for the reviews & merge @rbuckton!

If any issues come out of this change I'm available to try to fix, if that's helpful.

@NaveedAhmadHematmal
Copy link

@NaveedAhmadHematmal NaveedAhmadHematmal commented Jan 14, 2022

The longest-living PR I have ever seen. 😳

@lukescott
Copy link

@lukescott lukescott commented Jan 20, 2022

YES!!! Thank you!🎉 🎉 🎉

@callumok2004
Copy link

@callumok2004 callumok2004 commented Jan 22, 2022

🥳🎉🎉

@iJungleboy
Copy link

@iJungleboy iJungleboy commented Mar 7, 2022

Amazing work and perseverance. Awesome!

@EstopaceMA
Copy link

@EstopaceMA EstopaceMA commented Mar 18, 2022

Man! Awesome. The perseverance! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug
Projects
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

None yet