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

Don't rename imported Main module that only imports names #3710

Merged
merged 5 commits into from
Sep 16, 2022

Conversation

hubertp
Copy link
Contributor

@hubertp hubertp commented Sep 14, 2022

Pull Request Description

Turns that if you import a two-part import we had special code that would a) add Main submodule b) add an explicit rename.

b) is problematic because sometimes we only want to import specific names.
E.g.,

from Bar.Foo import Bar, Baz

would be translated to

from Bar.Foo.Main as Foo import Bar, Baz

and it should only be translated to

from Bar.Foo.Main import Bar, Baz

This change detects this scenario and does not add renames in that case.

Fixes 183276486.

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the
    Scala,
    Java,
    and
    Rust
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH
      ./run ide build and ./run ide watch.

@hubertp hubertp changed the title Don't rename module that only import names Don't rename imported Main module that only imports names Sep 14, 2022
@hubertp
Copy link
Contributor Author

hubertp commented Sep 14, 2022

@JaroslavTulach I don't think @kazcw needs to be aware of this one. This is added in a later compiler phase. Current parser gives correct IR.

@hubertp
Copy link
Contributor Author

hubertp commented Sep 14, 2022

/cc @jdunkerley since you discovered it.

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

Technical approval - I find the import system of Enso too confusing to judge what is right or wrong.

@hubertp hubertp force-pushed the wip/hubert/ambiguous-imports-183276486 branch 2 times, most recently from aad5647 to e936ef4 Compare September 15, 2022 12:19
@hubertp hubertp added the CI: Ready to merge This PR is eligible for automatic merge label Sep 15, 2022
@hubertp hubertp force-pushed the wip/hubert/ambiguous-imports-183276486 branch from e936ef4 to ea1ef9f Compare September 15, 2022 13:48
@radeusgd
Copy link
Member

Btw. after we made it so that from X.Y import Z does not bring Y into scope, should we even keep the form from X.Y as W import Z? I assume that the explicit rename makes it bring the W into scope - but shouldn't we just make this form illegal? If you want to bring into scope, you should add a separate import import X.Y as W, and the from imports should be used only for importing symbols from within a scope - so that each import form would have only one responsibility.

@kazcw
Copy link
Contributor

kazcw commented Sep 16, 2022

@radeusgd I'll be removing that syntax from the new parser, discussion here: #3710 (comment)

@hubertp hubertp force-pushed the wip/hubert/ambiguous-imports-183276486 branch from 98ac4b8 to 0c979cf Compare September 16, 2022 10:29
Turns that if you import a two-part import we had special code that
would a) add Main submodule b) add an explicit rename.

b) is problematic because sometimes we only want to import specific
names.
E.g.,
```
from Bar.Foo import Bar, Baz
```
would be translated to
```
from Bar.Foo.Main as Foo import Bar, Baz
```
and it should only be translated to
```
from Bar.Foo.Main import Bar, Baz
```

This change detects this scenario and does not add renames in that case.
Don't add rename when importing/exporting all names as well.
We now require those to be written by hand.
@hubertp hubertp force-pushed the wip/hubert/ambiguous-imports-183276486 branch from 0c979cf to 2399827 Compare September 16, 2022 12:22
@mergify mergify bot merged commit 0e5df93 into develop Sep 16, 2022
@mergify mergify bot deleted the wip/hubert/ambiguous-imports-183276486 branch September 16, 2022 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants