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

fix(compiler)!: no way to detect if an interface implements a preflight class #6197

Merged
merged 29 commits into from
Apr 12, 2024

Conversation

yoav-steinberg
Copy link
Contributor

@yoav-steinberg yoav-steinberg commented Apr 10, 2024

Fixes #5872

Add a phase modifier inflight support to interface definitions. Now all preflight interfaces implicitly implement std.IResouce the same way that prefligth classes implicitly implement std.Resource. We can now explicitly qualify these interfaces with the lift() builtin and we can get qualification errors if an inflight variable is being used to access such an object (same as classes).

Note that inflight interfaces can be defined preflight with the keywork and all their methods will be implicitly inflight. Interfaces defined inflight are always inflight interfaces. Preflight interfaces may extend inflight interfaces, but not the other way around.

JSII imported interfaces are, at least for now, always preflight interfaces.

Breaking change:
Since inflight interfaces are new, code using interfaces in inflight that were defined in preflight scope will need to add the inflight modifier to those interfaces or the compiler will complain that you're trying to access an unknown preflight object:

inflight IMyIface { // Explicitly mark this interface as inflight so it can be used in inflight code without worrying about lifting
  do(): void; // No need to specify `do` is an inflight method, it's implicit from the interface type.
}
inflight () => {
  x: IMyIface = ....;
  x.do(); // This would be a qualification error without the above fix.
}

Other fixes

  • Fixed span in diagnostic of wrongly typed methods implementing an interface, previously the span pointed to the implementing class instead of the specific method inside that class that mismatches the interface definition.
  • Cleaned up some dead code.

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.

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 assistence, don't hesitate to ping the relevant owner over Slack.

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
Copy link
Contributor

monadabot commented Apr 10, 2024

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

Last Updated (UTC) 2024-04-12 06:27

@monadabot
Copy link
Contributor

monadabot commented Apr 10, 2024

Benchmarks

Comparison to Baseline ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟥⬜⬜⬜
Benchmark Before After Change
version 59ms±0.6 60ms±0.52 +1ms (+1.66%)⬜
functions_1.test.w -t sim 388ms±4.2 396ms±3.83 +7ms (+1.91%)⬜
functions_1.test.w -t tf-aws 834ms±6.38 844ms±9.74 +11ms (+1.28%)⬜
hello_world.test.w -t sim 392ms±5.71 398ms±7.62 +6ms (+1.62%)⬜
hello_world.test.w -t tf-aws 1524ms±18.89 1533ms±13.4 +9ms (+0.6%)⬜
jsii_big.test.w -t sim 2803ms±11.59 2815ms±14.44 +12ms (+0.44%)⬜
jsii_big.test.w -t tf-aws 3022ms±7.38 3026ms±14.53 +4ms (+0.12%)⬜
functions_10.test.w -t sim 477ms±11.05 483ms±10.75 +6ms (+1.17%)⬜
functions_10.test.w -t tf-aws 2159ms±12.41 2172ms±11.6 +12ms (+0.57%)⬜
jsii_small.test.w -t sim 363ms±2.42 371ms±3.55 +8ms (+2.11%)🟥
jsii_small.test.w -t tf-aws 602ms±5.24 611ms±5.13 +9ms (+1.45%)⬜
empty.test.w -t sim 356ms±3.07 363ms±4.74 +7ms (+2%)⬜
empty.test.w -t tf-aws 593ms±3.18 602ms±6.79 +9ms (+1.43%)⬜

⬜ 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 60ms 59ms 61ms 1ms 1ms
functions_1.test.w -t sim 396ms 387ms 403ms 4ms 5ms
functions_1.test.w -t tf-aws 844ms 829ms 875ms 10ms 14ms
hello_world.test.w -t sim 398ms 387ms 426ms 8ms 11ms
hello_world.test.w -t tf-aws 1533ms 1512ms 1582ms 13ms 19ms
jsii_big.test.w -t sim 2815ms 2793ms 2850ms 14ms 20ms
jsii_big.test.w -t tf-aws 3026ms 2996ms 3059ms 15ms 20ms
functions_10.test.w -t sim 483ms 460ms 499ms 11ms 15ms
functions_10.test.w -t tf-aws 2172ms 2151ms 2195ms 12ms 16ms
jsii_small.test.w -t sim 371ms 363ms 378ms 4ms 5ms
jsii_small.test.w -t tf-aws 611ms 600ms 623ms 5ms 7ms
empty.test.w -t sim 363ms 354ms 377ms 5ms 7ms
empty.test.w -t tf-aws 602ms 589ms 616ms 7ms 10ms
Last Updated (UTC) 2024-04-12 06:32

@monadabot monadabot added the ⚠️ pr/review-mutation PR has been mutated and will not auto-merge. Clear this label if the changes look good! label Apr 10, 2024
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing some tests?

libs/wingc/src/type_check.rs Outdated Show resolved Hide resolved
libs/wingc/src/type_check.rs Outdated Show resolved Hide resolved
libs/wingc/src/type_check.rs Outdated Show resolved Hide resolved
@yoav-steinberg yoav-steinberg marked this pull request as ready for review April 11, 2024 11:12
@yoav-steinberg yoav-steinberg requested a review from a team as a code owner April 11, 2024 11:12
@yoav-steinberg yoav-steinberg changed the title fix(compiler): no way to detect if an interface implements a preflight class fix!(compiler): no way to detect if an interface implements a preflight class Apr 11, 2024
@yoav-steinberg yoav-steinberg changed the title fix!(compiler): no way to detect if an interface implements a preflight class fix(compiler)!: no way to detect if an interface implements a preflight class Apr 11, 2024
monadabot and others added 3 commits April 11, 2024 08:15
Signed-off-by: monada-bot[bot] <monabot@monada.co>
Signed-off-by: monada-bot[bot] <monabot@monada.co>
@monadabot
Copy link
Contributor

❌ Unstable Self-Mutation ❌

Self-mutation has run twice in a row. There may be a something non-deterministic in the build or test process.
Check the last mutation commit (b95e22e) for suspicious changes.
This is typically caused by:

  • Absolute paths
  • Timestamps
  • Random values
  • Flakey tests (relying on one of the above)

@yoav-steinberg yoav-steinberg removed the ⚠️ pr/review-mutation PR has been mutated and will not auto-merge. Clear this label if the changes look good! label Apr 11, 2024
Copy link
Contributor

@Chriscbr Chriscbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

docs/docs/03-language-reference.md Outdated Show resolved Hide resolved
examples/tests/invalid/interface.test.w Show resolved Hide resolved
Co-authored-by: Chris Rybicki <chrisr@monada.co>
Copy link
Contributor

mergify bot commented Apr 12, 2024

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

@mergify mergify bot merged commit 4e5335a into main Apr 12, 2024
15 checks passed
@mergify mergify bot deleted the yoav/phased_interfaces branch April 12, 2024 06:33
Copy link
Contributor

@staycoolcall911 staycoolcall911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great cleanup!

libs/wingc/src/type_check.rs Show resolved Hide resolved
libs/wingc/src/type_check.rs Show resolved Hide resolved
examples/tests/invalid/package.json Show resolved Hide resolved
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.70.0.

mergify bot pushed a commit to winglang/winglibs that referenced this pull request Apr 12, 2024
Use the new `inflight interface` modifier introduced by winglang/wing#6197.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No qualification error when accessing a preflight object via interface
5 participants