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

Support importing the parent directory - bring "./" #4276

Open
Chriscbr opened this issue Sep 25, 2023 · 4 comments
Open

Support importing the parent directory - bring "./" #4276

Chriscbr opened this issue Sep 25, 2023 · 4 comments
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request 📚 libraries Wing Libraries needs-discussion Further discussion is needed prior to impl

Comments

@Chriscbr
Copy link
Contributor

Feature Spec

It should be possible to reuse other modules classes and public types from the current directory:

// file1.w
class Bar {
  pub bar(): str {
    return "bar";
  }
}

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

class Foo {
  pub bar(bar: self.Bar): str {
    return bar.bar();
  }
}

Use Cases

Reduce the number of bring statements in folders with lots of modules

Implementation Notes

Currently this doesn't work because the compiler sees a cyclic dependency where src/file1.w depends on src/ which depends on src/file1.w.

One possible way to break this dependency cycle could be treat these self-directory imports differently, e.g. so src/file1.w depends on src/#1 and src/#1 is a special node that depends on all of its children files/directories EXCEPT for src/file1.w. (just the first idea off the top of my head, not sure if this is a good one)

Component

Compiler

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@Chriscbr Chriscbr added ✨ enhancement New feature or request 🛠️ compiler Compiler labels Sep 25, 2023
@eladb
Copy link
Contributor

eladb commented Sep 26, 2023

P2/P3

mergify bot pushed a commit that referenced this issue Sep 27, 2023
This pull request adds support for bringing directories. Bringing a directory will make all types defined in the files in a directory accessible through the alias defined by the user:

```
bring "./aws" as aws;
``` 

If a symbol like "Bucket" is defined multiple times inside files at the same hierarchical level of "aws", an error will be raised saying that there are multiple definitions of "Bucket" inside the directory. If the directory contains subdirectories, it will be available through a child namespace inside `aws`. For example, `aws.storage` will contain types from all `aws/storage/*.w` files.

To achieve this, I had to figure out some way to model symbol lookups in a directory, where there might be multiple symbol environments that have to be looked up before finding a symbol. To that end, I changed `Namespace` so instead of storing a single single environment, it stores a vector of symbol environments, as this seemed like the least invasive change.

Future items:
- #4276

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [x] 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](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
@staycoolcall911 staycoolcall911 added the 📚 libraries Wing Libraries label Nov 15, 2023
@Chriscbr Chriscbr added the needs-discussion Further discussion is needed prior to impl label Dec 19, 2023
Copy link

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

Copy link

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

Copy link

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

@github-actions github-actions bot added the Stale label Aug 30, 2024
@Chriscbr Chriscbr removed the Stale label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request 📚 libraries Wing Libraries needs-discussion Further discussion is needed prior to impl
Projects
Status: 🤝 Backlog - handoff to owners
Development

No branches or pull requests

3 participants