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

feat(compiler)!: interfaces, enums, and public classes must be defined at the top-level #7036

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

Chriscbr
Copy link
Contributor

@Chriscbr Chriscbr commented Aug 20, 2024

Closes #7035
Closes #5542

To encourage more readable code and reduce the number of edge cases we might have to handle in the compiler implementation, we add the constraint that that interfaces, enums, and any exported classes have to be defined at the top level. This requirement is already in place for structs.

It's a bit unclear whether we want to apply the same restriction to classes, since classes can have code inside of them (unlike interfaces, enums, and structs) and you can certainly find plenty of examples where folks define anonymous classes inside functions in other languages, so for now we're continue to allow them, though support for it isn't as rigorously tested. We only require that if you define a class in a local context, it must be private, since it wouldn't be possible to access them in other Wing files.

BREAKING CHANGE: interfaces, enums, and classes marked with "pub" or "internal" are now required to be defined at the top-level of Wing programs. Please let us know if you encounter issues due to this change.

Checklist

  • Title matches Winglang's style guide
  • Description explains motivation and solution
  • Tests added (always)
  • Docs updated (only required for features)
  • Added pr/e2e-full label if this feature requires end-to-end testing

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

@Chriscbr Chriscbr requested a review from a team as a code owner August 20, 2024 22:56
Copy link

Thanks for opening this pull request! 🎉
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 standard library @chriscbr
Wing Console @skyrpex
Wing compiler and language design @chriscbr
VSCode extension and language server @chriscbr
Wing CLI @chriscbr
Documentation @boyney123
Examples @boyney123
Wing Playground @skyrpex

@Chriscbr Chriscbr changed the title feat(compiler): interfaces, enums, and public classes must be defined at the top-level feat(compiler)!: interfaces, enums, and public classes must be defined at the top-level Aug 20, 2024
@monadabot
Copy link
Contributor

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

Last Updated (UTC) 2024-08-20 23:03

@monadabot
Copy link
Contributor

Benchmarks

Comparison to Baseline 🟥⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜
Benchmark Before After Change
version 57ms±1.04 62ms±4.26 +5ms (+8.52%)🟥
hello_world.test.w -t sim 418ms±7.8 410ms±4.08 -8ms (-1.98%)⬜
hello_world.test.w -t tf-aws 1523ms±14.31 1519ms±10.14 -4ms (-0.28%)⬜
jsii_big.test.w -t sim 2987ms±24.25 2976ms±12.2 -11ms (-0.37%)⬜
jsii_big.test.w -t tf-aws 3204ms±24.34 3208ms±20.85 +4ms (+0.12%)⬜
functions_1.test.w -t sim 415ms±5.02 410ms±4.58 -5ms (-1.2%)⬜
functions_1.test.w -t tf-aws 873ms±6.71 867ms±8.24 -6ms (-0.7%)⬜
empty.test.w -t sim 381ms±4.38 372ms±3.33 -9ms (-2.28%)⬜
empty.test.w -t tf-aws 622ms±6.41 621ms±10.46 0ms (-0.03%)⬜
functions_10.test.w -t sim 512ms±9.55 508ms±8.85 -4ms (-0.78%)⬜
functions_10.test.w -t tf-aws 2228ms±12.17 2213ms±20.35 -15ms (-0.66%)⬜
jsii_small.test.w -t sim 395ms±7.1 385ms±5.67 -10ms (-2.47%)⬜
jsii_small.test.w -t tf-aws 644ms±6.77 632ms±5.68 -12ms (-1.81%)⬜

⬜ 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 62ms 57ms 76ms 4ms 6ms
hello_world.test.w -t sim 410ms 403ms 418ms 4ms 6ms
hello_world.test.w -t tf-aws 1519ms 1500ms 1544ms 10ms 14ms
jsii_big.test.w -t sim 2976ms 2951ms 3008ms 12ms 17ms
jsii_big.test.w -t tf-aws 3208ms 3173ms 3251ms 21ms 29ms
functions_1.test.w -t sim 410ms 400ms 420ms 5ms 6ms
functions_1.test.w -t tf-aws 867ms 851ms 888ms 8ms 12ms
empty.test.w -t sim 372ms 365ms 380ms 3ms 5ms
empty.test.w -t tf-aws 621ms 599ms 653ms 10ms 15ms
functions_10.test.w -t sim 508ms 489ms 524ms 9ms 12ms
functions_10.test.w -t tf-aws 2213ms 2172ms 2254ms 20ms 28ms
jsii_small.test.w -t sim 385ms 374ms 399ms 6ms 8ms
jsii_small.test.w -t tf-aws 632ms 622ms 647ms 6ms 8ms
Last Updated (UTC) 2024-08-20 23:08

Copy link
Contributor

mergify bot commented Aug 21, 2024

Thanks for contributing, @Chriscbr! This PR will now be added to the merge queue, or immediately merged if rybickic/top-level-checks is up-to-date with main and the queue is empty.

@mergify mergify bot merged commit eca0508 into main Aug 21, 2024
21 checks passed
@mergify mergify bot deleted the rybickic/top-level-checks branch August 21, 2024 07:37
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.83.0.

@eladb
Copy link
Contributor

eladb commented Aug 27, 2024

+1 not to do this for classes at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants