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

Update use declarations. #266

Merged
merged 3 commits into from
Sep 27, 2021
Merged

Update use declarations. #266

merged 3 commits into from
Sep 27, 2021

Conversation

otrho
Copy link
Contributor

@otrho otrho commented Sep 24, 2021

Closes #187.

Instead of copying and/or merging from namespaces for use declarations we now keep a list of use synonyms. When an unqualified/relative symbol lookup is made the synonyms can be used to find the path to its module.

I added a new test, taken from #187 and it's passing all the existing tests, but I feel like the whole system is still a bit fragile and could probably do with a bit of a refactor, now that we have it fairly stable. In the future we may wish to support partial paths -- e.g., use std::hash and then hash::hash_value(...). While looking at the code I feel like there should be a distinction between a 'module' and a 'namespace', perhaps a namespace maintains a collection of modules. Dunno. This is working for now.

@otrho otrho self-assigned this Sep 24, 2021
@otrho otrho force-pushed the otrho/187_update_use_decls branch from 482fec7 to 1f1dd57 Compare September 24, 2021 09:42
Previously `use` would copy everything from the referenced module into
the current namespace.  This is problematic for special overrides like
our binary operators.

E.g., `==` is translated to `eq()` in the `std::ops::Ord` trait.  If we
copy `std::ops::Ord` to the local namespace (via `use std::ops::Ord;`)
then we're creating an `Ord` impl there instead of in `std::ops` where
they're expected.

This change does not copy anything any more, but rather maintains a list
of the `use` symbol synonyms and whenever they're queried relatively
(without a module path) then the synonym path is used.
@otrho otrho force-pushed the otrho/187_update_use_decls branch from 1f1dd57 to d438d18 Compare September 24, 2021 10:00
@sezna
Copy link
Contributor

sezna commented Sep 27, 2021

perhaps a namespace maintains a collection of modules

Do you mean like this? https://github.com/FuelLabs/sway/blob/master/core_lang/src/semantic_analysis/namespace.rs#L24

@otrho otrho merged commit 47e4201 into master Sep 27, 2021
@otrho otrho deleted the otrho/187_update_use_decls branch September 27, 2021 23:23
@otrho
Copy link
Contributor Author

otrho commented Sep 27, 2021

No, more like there's 1 namespace with an API to manage the collection of all the modules. Maybe it could be encapsulated differently. Doesn't matter, this is working. 👍

@adlerjohn adlerjohn added the compiler General compiler. Should eventually become more specific as the issue is triaged label Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implemented traits for operators are not inserted back into the proper module.
3 participants