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): multi-file Wing applications #3512

Merged
merged 19 commits into from
Jul 20, 2023
Merged

feat(compiler): multi-file Wing applications #3512

merged 19 commits into from
Jul 20, 2023

Conversation

Chriscbr
Copy link
Contributor

@Chriscbr Chriscbr commented Jul 17, 2023

Introduce a basic form of multi-file Wing projects through the bring keyword. To use classes, interfaces, enums, or structs from another Wing file, bring a file with a path that ends in .w, and assign it to an alias:

bring "./other-file.w" as shared;

new shared.Store();

This initial implementation follows a (naive) strategy of recursively instantiating the parser to create a large AST. This has some limitations -- for example it's not possible for two Wing files to reuse the same third Wing file -- but this still gives users a lot more refactoring power for building Wing apps. #3511 is the main follow-up issue for addressing this.

Closes #476

Follow up:

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 Monada Contribution License.

@Chriscbr Chriscbr requested a review from a team as a code owner July 17, 2023 23:34
@Chriscbr Chriscbr changed the title feat(compiler): support multi-file Wing projects feat(compiler): support multi-file Wing applications Jul 17, 2023
@Chriscbr Chriscbr changed the title feat(compiler): support multi-file Wing applications feat(compiler): multi-file Wing applications Jul 17, 2023
@Chriscbr Chriscbr marked this pull request as draft July 17, 2023 23:39
@Chriscbr
Copy link
Contributor Author

@MarkMcCulloh raised an important issue which is that before shipping this, we should aim to have a solution which prevents imports from having side effects. For example, with this PR the following code would be valid:

// file1.w
bring "./file2.w" as file2;

// file2.w
bring cloud;

let global_bucket = new cloud.Bucket();
class B {
  // uses global_bucket
}

However, notice that bringing file2.w into the first file has the side effect of creating a bucket in the user's application, even though no classes from that module actually gets constructed (such as B). In some past discussions it's been brought up that only the entrypoint Wing file should have an implicit scope, so I'd like to see if there's a way to incorporate that here.

@eladb
Copy link
Contributor

eladb commented Jul 18, 2023

prevents imports from having side effects. For example, with this PR the following code would be valid.

Totally. We discussed this a few times. Non-entrypoint files should not allow any root-level statements, only type declarations (class, enum, interface and struct).

In the future (let's open a tracking issue) we want to support constants as root level statements in non-entrypoint files - let statements with an immutable data type (primitives or immutable collections).

I think we can do this as a quick follow up to this PR if it gets hairy, but let's make sure to prioritize it.

libs/wingc/src/fold.rs Show resolved Hide resolved
libs/wingc/src/jsify.rs Show resolved Hide resolved
examples/tests/valid/bring_local.w Show resolved Hide resolved
@Chriscbr Chriscbr marked this pull request as ready for review July 18, 2023 16:30
Signed-off-by: monada-bot[bot] <monabot@monada.co>
@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 Jul 18, 2023
Signed-off-by: monada-bot[bot] <monabot@monada.co>
Signed-off-by: monada-bot[bot] <monabot@monada.co>
Signed-off-by: monada-bot[bot] <monabot@monada.co>
Signed-off-by: monada-bot[bot] <monabot@monada.co>
Signed-off-by: monada-bot[bot] <monabot@monada.co>
Signed-off-by: monada-bot[bot] <monabot@monada.co>
@Chriscbr Chriscbr requested a review from eladb July 20, 2023 17:46
Signed-off-by: monada-bot[bot] <monabot@monada.co>
@Chriscbr Chriscbr removed the ⚠️ pr/review-mutation PR has been mutated and will not auto-merge. Clear this label if the changes look good! label Jul 20, 2023
@mergify
Copy link
Contributor

mergify bot commented Jul 20, 2023

Thank you for contributing! Your pull request will be updated from dev and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

mergify bot added a commit that referenced this pull request Jul 20, 2023
@mergify mergify bot merged commit e2b3dc7 into dev Jul 20, 2023
12 checks passed
@mergify mergify bot deleted the bring-local branch July 20, 2023 18:47
@staycoolcall911
Copy link
Contributor

This is incredible! So needed...

@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.24.41.

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.

Module System - Imports (bring): local .w files
5 participants