winglang / wing

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

feat: `@app` and `@filename` intrinsics #7078

Closed Chriscbr closed 2 months ago

Chriscbr commented 2 months ago

Closes #6058

This PR introduces the @app and @filename intrinsics to the language. @filename is a complement to the existing @dirname intrinsic, and @app provides a way to access the globally accessible app. @app exposes some meta information that can be useful, like whether the app is being compiled as a test or not, and the platform parameter system. In the CDK world, the app is also the "root" of the tree that all resources get added to.

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 2 months 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 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
monadabot commented 2 months ago

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

Last Updated (UTC) 2024-09-06 02:57
Chriscbr commented 2 months ago

Mmm... I thought this wasn't necessary, but I found an example where it still seems like it's load-bearing. Basically, if you compile your Wing app to have multiple tests, this will take on different values, so this is valid:

bring cloud;
bring "constructs" as constructs;
bring expect;

class BucketFactory {
  pub static makeBucket(scope: constructs.IConstruct): cloud.Bucket {
    let bucket = new cloud.Bucket() in scope;
    // apply customizations to bucket...
    return bucket;
  }
}

let bucket = BucketFactory.makeBucket(this);

test "can use bucket" {
  bucket.put("hello", "world");
  expect.equal(bucket.list().length, 1);
}

test "can use other bucket" {
  bucket.put("yo", "sup");
  expect.equal(bucket.list().length, 1);
}

But if you were to change it to:

let bucket = BucketFactory.makeBucket(@app);

Then the test can't be run on AWS, because in preflight it tries creating two buckets with the same scope and name.

I'm not totally sure how to resolve this, so I'll revert a few of the changes and leave in this for now.

monadabot commented 2 months ago

Benchmarks

Comparison to Baseline ⬜🟥⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ | Benchmark | Before | After | Change | | :-- | --: | --: | --: | | version | 55ms±0.69 | 55ms±0.47 | -1ms (-1.12%)⬜ | | functions_10.test.w -t sim | 475ms±17.04 | 497ms±15.06 | +22ms (+4.66%)🟥 | | functions_10.test.w -t tf-aws | 2125ms±27.72 | 2128ms±16.43 | +3ms (+0.13%)⬜ | | jsii_small.test.w -t sim | 368ms±2.5 | 368ms±2.3 | 0ms (-0.03%)⬜ | | jsii_small.test.w -t tf-aws | 591ms±1.95 | 591ms±5 | +0ms (+0.02%)⬜ | | functions_1.test.w -t sim | 397ms±5.13 | 396ms±2.98 | -1ms (-0.34%)⬜ | | functions_1.test.w -t tf-aws | 828ms±8.82 | 818ms±4.44 | -10ms (-1.2%)⬜ | | empty.test.w -t sim | 365ms±4.75 | 359ms±4.18 | -6ms (-1.61%)⬜ | | empty.test.w -t tf-aws | 586ms±4.18 | 584ms±3.67 | -1ms (-0.25%)⬜ | | hello_world.test.w -t sim | 407ms±3.09 | 401ms±3.34 | -6ms (-1.4%)⬜ | | hello_world.test.w -t tf-aws | 1454ms±5.74 | 1445ms±4.74 | -9ms (-0.64%)⬜ | | jsii_big.test.w -t sim | 2917ms±10.26 | 2909ms±7.34 | -8ms (-0.28%)⬜ | | jsii_big.test.w -t tf-aws | 3113ms±12.55 | 3095ms±9.07 | -18ms (-0.57%)⬜ | ⬜ 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|55ms|54ms|56ms|0ms|1ms| |functions_10.test.w -t sim|497ms|476ms|550ms|15ms|21ms| |functions_10.test.w -t tf-aws|2128ms|2092ms|2160ms|16ms|23ms| |jsii_small.test.w -t sim|368ms|362ms|374ms|2ms|3ms| |jsii_small.test.w -t tf-aws|591ms|578ms|604ms|5ms|7ms| |functions_1.test.w -t sim|396ms|390ms|404ms|3ms|4ms| |functions_1.test.w -t tf-aws|818ms|811ms|828ms|4ms|6ms| |empty.test.w -t sim|359ms|347ms|366ms|4ms|6ms| |empty.test.w -t tf-aws|584ms|577ms|593ms|4ms|5ms| |hello_world.test.w -t sim|401ms|394ms|408ms|3ms|5ms| |hello_world.test.w -t tf-aws|1445ms|1431ms|1452ms|5ms|7ms| |jsii_big.test.w -t sim|2909ms|2897ms|2927ms|7ms|10ms| |jsii_big.test.w -t tf-aws|3095ms|3076ms|3109ms|9ms|13ms|
Last Updated (UTC) 2024-09-05 01:05
Chriscbr commented 2 months ago

@eladb missed that, thanks - I added it to the language ref

monadabot commented 2 months ago

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