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: generate types for extern declarations #5967

Merged
merged 7 commits into from
Mar 18, 2024
Merged

feat: generate types for extern declarations #5967

merged 7 commits into from
Mar 18, 2024

Conversation

MarkMcCulloh
Copy link
Contributor

Closes #5868 (except the static part, but that's not critical for the use-case)

Compiling a wing project will now generate .d.ts files for the contract between wing and extern files. These .d.ts files are fully self-contained.

The code for this looks similar to existing dtsification code, but there are couple important distinctions that made it feel useful to separate it:

  1. The new code only access to type information rather than the original ASTs
  2. The new code is intentionally generating types in the same file as needed instead of producing references

Misc:

Note that this may be a breaking change: extern types must be consistent. So in one class you refer to an extern as returning a str and in another it returns a Json, that will now be a compiler error.

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 @eladb
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 Mar 17, 2024

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

Last Updated (UTC) 2024-03-17 20:32

@monadabot
Copy link
Contributor

monadabot commented Mar 17, 2024

Benchmarks

Comparison to Baseline 🟥🟥⬜⬜🟥⬜🟥⬜🟥⬜⬜🟥⬜
Benchmark Before After Change
version 58ms±0.6 61ms±0.72 +3ms (+4.63%)🟥
empty.test.w -t sim 487ms±4 499ms±3.34 +11ms (+2.35%)🟥
empty.test.w -t tf-aws 713ms±3.94 729ms±10.42 +16ms (+2.23%)⬜
hello_world.test.w -t sim 530ms±9.3 536ms±5.27 +7ms (+1.23%)⬜
hello_world.test.w -t tf-aws 1661ms±4.82 1691ms±10.62 +31ms (+1.84%)🟥
functions_10.test.w -t sim 600ms±8.09 608ms±10.06 +8ms (+1.37%)⬜
functions_10.test.w -t tf-aws 2249ms±18.87 2295ms±10.01 +46ms (+2.04%)🟥
jsii_small.test.w -t sim 509ms±4.54 506ms±6.37 -3ms (-0.52%)⬜
jsii_small.test.w -t tf-aws 719ms±4.66 735ms±5.89 +15ms (+2.12%)🟥
jsii_big.test.w -t sim 2923ms±10.23 2960ms±56.71 +38ms (+1.29%)⬜
jsii_big.test.w -t tf-aws 3158ms±29.95 3146ms±28.67 -12ms (-0.36%)⬜
functions_1.test.w -t sim 521ms±3.83 536ms±6.84 +16ms (+3%)🟥
functions_1.test.w -t tf-aws 957ms±5.67 964ms±7.64 +7ms (+0.74%)⬜

⬜ 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 61ms 59ms 62ms 1ms 1ms
empty.test.w -t sim 499ms 492ms 506ms 3ms 5ms
empty.test.w -t tf-aws 729ms 718ms 768ms 10ms 15ms
hello_world.test.w -t sim 536ms 523ms 544ms 5ms 7ms
hello_world.test.w -t tf-aws 1691ms 1669ms 1721ms 11ms 15ms
functions_10.test.w -t sim 608ms 584ms 631ms 10ms 14ms
functions_10.test.w -t tf-aws 2295ms 2280ms 2327ms 10ms 14ms
jsii_small.test.w -t sim 506ms 494ms 522ms 6ms 9ms
jsii_small.test.w -t tf-aws 735ms 718ms 746ms 6ms 8ms
jsii_big.test.w -t sim 2960ms 2909ms 3181ms 57ms 79ms
jsii_big.test.w -t tf-aws 3146ms 3102ms 3227ms 29ms 40ms
functions_1.test.w -t sim 536ms 522ms 547ms 7ms 10ms
functions_1.test.w -t tf-aws 964ms 944ms 986ms 8ms 11ms
Last Updated (UTC) 2024-03-17 20:37

@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 Mar 17, 2024
@MarkMcCulloh MarkMcCulloh removed the ⚠️ pr/review-mutation PR has been mutated and will not auto-merge. Clear this label if the changes look good! label Mar 17, 2024
@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 Mar 17, 2024
@MarkMcCulloh MarkMcCulloh added 🧪 pr/e2e-full and removed 🧪 pr/e2e-full ⚠️ pr/review-mutation PR has been mutated and will not auto-merge. Clear this label if the changes look good! labels Mar 17, 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.

Cooooool

examples/tests/valid/dynamo.ts Show resolved Hide resolved
examples/tests/valid/subdir/util.ts Show resolved Hide resolved
Copy link
Contributor

mergify bot commented Mar 18, 2024

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

mergify bot added a commit that referenced this pull request Mar 18, 2024
mergify bot added a commit that referenced this pull request Mar 18, 2024
@mergify mergify bot merged commit 75b30ad into main Mar 18, 2024
25 checks passed
@mergify mergify bot deleted the mark/ts-inflight branch March 18, 2024 13:24
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.61.13.

@@ -4,7 +4,7 @@ class MyResource {
api: cloud.Api;
url: str;

extern "./url_utils.js" pub static inflight isValidUrl(url: str): bool;
extern "./url_utils.ts" pub static inflight isValidUrl(url: str): bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

@MarkMcCulloh Just checking, so we've decided to officially support *.ts files? Should we note this in the documentation or language spec somewhere? (I'm cool with the choice, just wanna check if we're tracking it somewhere :^))

pub fn is_extern_file(file: &Utf8PathBuf) -> bool {
if let Some(ext) = file.extension() {
match ext {
"js" | "cjs" | "mjs" | "jsx" | "ts" | "cts" | "mts" | "tsx" => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Who woulda thunk a single language would result in so many file extensions / formats

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

Successfully merging this pull request may close these issues.

TypeScript inflights (Enhanced extern)
4 participants