wing
wing copied to clipboard
fix(compiler): cannot lift a class that extends a cloud resource
The issue with extending classes from the SDK's TypeScript source code is related to how inheritance works at runtime.
Each inflight client implementation needs to be constructed with target-specific arguments. For example, to support cloud.Bucket on AWS, the SDK has a TypeScript class with all of the inflight methods of the Bucket, and its implementation uses the AWS SDK. Importantly, for the class to work an ARN for the Bucket needs to be provided to the class's constructor. This is a piece of information defined in preflight. (Some resources need multiple pieces of preflight information).
How do we ensure the ARN is passed when the class is constructed? Currently, each preflight defines an _toInflight() method which creates a JavaScript string which instantiates the class and hardcodes in the necessary arguments.
But suppose we have a class MyBucket that extends Bucket. To instantiate such a class, we'd need to instantiate MyBucket with both the preflight fields needed by MyBucket AND the preflight fields needed by Bucket, and ensure that the super() call in MyBucket's constructor passes the appropriate arguments to Bucket's constructor.
To support this, we're now exposing a new method in the TypeScript source code named _liftedFields() which can be overridden by classes inside our TypeScript SDK implementation to specify what arguments they need when they're instantiated. This does not have any user-facing effect.
Fixes #4203
Checklist
- [ ] Title matches Winglang's style guide
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added
pr/e2e-fulllabel 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.
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 |
Console preview environment is available at https://wing-console-pr-6490.fly.dev :rocket:
Last Updated (UTC) 2024-07-24 19:14
Benchmarks
Comparison to Baseline ⬜⬜⬜⬜⬜⬜⬜🟥🟥⬜⬜⬜⬜
| Benchmark | Before | After | Change |
|---|---|---|---|
| version | 57ms±0.55 | 58ms±0.54 | +1ms (+1.19%)⬜ |
| empty.test.w -t sim | 380ms±19.7 | 376ms±4.81 | -4ms (-1.1%)⬜ |
| empty.test.w -t tf-aws | 612ms±3.62 | 626ms±6.16 | +15ms (+2.37%)⬜ |
| hello_world.test.w -t sim | 412ms±8.51 | 422ms±10.66 | +10ms (+2.39%)⬜ |
| hello_world.test.w -t tf-aws | 1496ms±6.7 | 1532ms±9.8 | +36ms (+2.38%)⬜ |
| jsii_big.test.w -t sim | 2951ms±7.86 | 3007ms±12.74 | +56ms (+1.9%)⬜ |
| jsii_big.test.w -t tf-aws | 3167ms±10.82 | 3227ms±12.81 | +61ms (+1.91%)⬜ |
| functions_1.test.w -t sim | 406ms±5.21 | 419ms±5.96 | +13ms (+3.09%)🟥 |
| functions_1.test.w -t tf-aws | 851ms±4.7 | 877ms±5.05 | +26ms (+3.01%)🟥 |
| functions_10.test.w -t sim | 506ms±4.81 | 519ms±9.3 | +13ms (+2.55%)⬜ |
| functions_10.test.w -t tf-aws | 2195ms±8.99 | 2222ms±20.69 | +27ms (+1.25%)⬜ |
| jsii_small.test.w -t sim | 376ms±3.15 | 379ms±6.42 | +2ms (+0.61%)⬜ |
| jsii_small.test.w -t tf-aws | 618ms±4.08 | 619ms±4.39 | +0ms (+0.08%)⬜ |
⬜ 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 | 58ms | 57ms | 59ms | 1ms | 1ms |
| empty.test.w -t sim | 376ms | 364ms | 388ms | 5ms | 7ms |
| empty.test.w -t tf-aws | 626ms | 615ms | 641ms | 6ms | 9ms |
| hello_world.test.w -t sim | 422ms | 407ms | 460ms | 11ms | 15ms |
| hello_world.test.w -t tf-aws | 1532ms | 1514ms | 1556ms | 10ms | 14ms |
| jsii_big.test.w -t sim | 3007ms | 2980ms | 3031ms | 13ms | 18ms |
| jsii_big.test.w -t tf-aws | 3227ms | 3201ms | 3256ms | 13ms | 18ms |
| functions_1.test.w -t sim | 419ms | 407ms | 433ms | 6ms | 8ms |
| functions_1.test.w -t tf-aws | 877ms | 862ms | 885ms | 5ms | 7ms |
| functions_10.test.w -t sim | 519ms | 500ms | 542ms | 9ms | 13ms |
| functions_10.test.w -t tf-aws | 2222ms | 2168ms | 2260ms | 21ms | 29ms |
| jsii_small.test.w -t sim | 379ms | 362ms | 395ms | 6ms | 9ms |
| jsii_small.test.w -t tf-aws | 619ms | 610ms | 629ms | 4ms | 6ms |
Last Updated (UTC) 2024-07-24 19:20
excited about this one :) nice work.
It looks like the approach in this PR is missing one or two pieces -- it adds some code that calls "typeForFqn" to obtain the target-specific versions of classes. But this "typeForFqn" function isn't accessible from some places in preflight JavaScript like static methods because typeForFqn is currently associated with the app. (And, the app requires a root construct to be passed to it, whose code might require "typeForFqn"...). I opened a PR a while back for trying to unwind this cycle here (https://github.com/winglang/wing/pull/6099) so I'm going to try and work on that PR and see if having that problem solved will help us here.
Hi,
This PR has not seen activity in 20 days. Therefore, we are marking the PR as stale for now. It will be closed after 7 days. If you need help with the PR, do not hesitate to reach out in the winglang community Discord. Feel free to re-open this PR when it is still relevant and ready to be worked on again. Thanks!
Spec tests run: https://github.com/winglang/wing/actions/runs/10066164789
Thanks for contributing, @Chriscbr! This PR will now be added to the merge queue, or immediately merged if rybickic/extend-resources is up-to-date with main and the queue is empty.
Congrats! :rocket: This was released in Wing 0.79.13.