winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.77k stars 189 forks source link

fix(compiler): closure transform generated `parent_this` even when not used #6531

Closed yoav-steinberg closed 1 month ago

yoav-steinberg commented 1 month ago

This is a small code cleanup as part of addressing #4925.

We only generate the parent_this variable used in generated closure classes when needed. If the inflight closure never accesses this then we don't generated parent_this. The code avoids traversing into inner classes inside the closure when searching for this accesses, making it a bit cleaner and more efficient.

This relates to #4925 because it solves the problem of accessing this (for assignment into parent_this) before the super() call in a ctor.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Wing Cloud Contribution License.

github-actions[bot] commented 1 month ago

Thanks for opening this pull request! :tada: Please consult the contributing guidelines for details on how to contribute to this project. If you need any assistance, don't hesitate to ping the relevant owner over Discord.

Topic Owner
Wing SDK and utility APIs @chriscbr
Wing Console @ainvoner, @skyrpex, @polamoros
JSON, structs, primitives and collections @hasanaburayyan
Platforms and plugins @hasanaburayyan
Frontend resources (website, react, etc) @tsuf239
Language design @chriscbr
VSCode extension and language server @markmcculloh
Compiler architecture, inflights, lifting @yoav-steinberg
Wing Testing Framework @tsuf239
Wing CLI @markmcculloh
Build system, dev environment, releases @markmcculloh
Library Ecosystem @chriscbr
Documentation @hasanaburayyan
SDK test suite @tsuf239
Examples @hasanaburayyan
Wing Playground @eladcon
monadabot commented 1 month ago

Console preview environment is available at https://wing-console-pr-6531.fly.dev :rocket:

Last Updated (UTC) 2024-05-22 10:43
monadabot commented 1 month ago

Benchmarks

Comparison to Baseline 🟥⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ | Benchmark | Before | After | Change | | :-- | --: | --: | --: | | version | 57ms±0.43 | 59ms±2.94 | +2ms (+3.51%)🟥 | | functions_10.test.w -t sim | 497ms±27.12 | 494ms±10.75 | -3ms (-0.57%)⬜ | | functions_10.test.w -t tf-aws | 2033ms±14.54 | 2041ms±7.93 | +8ms (+0.38%)⬜ | | hello_world.test.w -t sim | 402ms±4.61 | 406ms±11.78 | +4ms (+1.05%)⬜ | | hello_world.test.w -t tf-aws | 1426ms±10.66 | 1442ms±14.16 | +16ms (+1.12%)⬜ | | functions_1.test.w -t sim | 397ms±4.93 | 402ms±6.7 | +5ms (+1.16%)⬜ | | functions_1.test.w -t tf-aws | 817ms±5.98 | 825ms±6.23 | +7ms (+0.9%)⬜ | | jsii_big.test.w -t sim | 2795ms±14.64 | 2795ms±9.47 | 0ms (-0.01%)⬜ | | jsii_big.test.w -t tf-aws | 3007ms±13.11 | 3016ms±11.77 | +9ms (+0.3%)⬜ | | empty.test.w -t sim | 361ms±3.93 | 369ms±3.8 | +8ms (+2.15%)⬜ | | empty.test.w -t tf-aws | 597ms±5.12 | 597ms±6.56 | 0ms (-0.04%)⬜ | | jsii_small.test.w -t sim | 372ms±4.45 | 378ms±4.17 | +6ms (+1.5%)⬜ | | jsii_small.test.w -t tf-aws | 612ms±5.01 | 612ms±2.57 | +0ms (+0.04%)⬜ | ⬜ Within 1.5 standard deviations 🟩 Faster, Above 1.5 standard deviations 🟥 Slower, Above 1.5 standard deviations _Benchmarks may vary outside of normal expectations, especially when running in GitHub Actions CI._
Results |name|mean|min|max|moe|sd| |----|----|----|----|----|----| |version|59ms|56ms|71ms|3ms|4ms| |functions_10.test.w -t sim|494ms|480ms|530ms|11ms|15ms| |functions_10.test.w -t tf-aws|2041ms|2022ms|2056ms|8ms|11ms| |hello_world.test.w -t sim|406ms|390ms|445ms|12ms|16ms| |hello_world.test.w -t tf-aws|1442ms|1417ms|1489ms|14ms|20ms| |functions_1.test.w -t sim|402ms|384ms|415ms|7ms|9ms| |functions_1.test.w -t tf-aws|825ms|810ms|842ms|6ms|9ms| |jsii_big.test.w -t sim|2795ms|2781ms|2825ms|9ms|13ms| |jsii_big.test.w -t tf-aws|3016ms|2977ms|3044ms|12ms|16ms| |empty.test.w -t sim|369ms|363ms|378ms|4ms|5ms| |empty.test.w -t tf-aws|597ms|586ms|611ms|7ms|9ms| |jsii_small.test.w -t sim|378ms|369ms|388ms|4ms|6ms| |jsii_small.test.w -t tf-aws|612ms|607ms|619ms|3ms|4ms|
Last Updated (UTC) 2024-05-22 10:38
mergify[bot] commented 1 month ago

Thanks for contributing, @yoav-steinberg! This PR will now be added to the merge queue, or immediately merged if yoav/parent_this_only_when_needed is up-to-date with main and the queue is empty.

monadabot commented 1 month ago

Congrats! :rocket: This was released in Wing 0.74.7.