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

[move 2024] Combine namespaces for expansion lookup #14978

Merged
merged 15 commits into from
Dec 8, 2023

Conversation

cgswords
Copy link
Contributor

@cgswords cgswords commented Nov 22, 2023

Description

This adds a Move 2024 path resolution mechanism to expansion, which revises name chain resolution to combine address, module, and member namespaces. In addition, it adds ::<addr>::<module> and ::<addr>::<module>::<member> forms to alias-dodge when necessary.

This is toward getting ready to add enums to the name chain space.

Test Plan

New and updated tests, subject to feature gating.


If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

Copy link

vercel bot commented Nov 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 1, 2023 3:47am
sui-typescript-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 1, 2023 3:47am
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) Visit Preview Dec 1, 2023 3:47am
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Dec 1, 2023 3:47am
mysten-ui ⬜️ Ignored (Inspect) Visit Preview Dec 1, 2023 3:47am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Dec 1, 2023 3:47am

@cgswords cgswords changed the title [move-compiler] Combine namespaces for expansion lookup [move 2024] Combine namespaces for expansion lookup Nov 30, 2023
}

// Parse the beginning of an access, either an address or an identifier with a specific description
fn parse_leading_name_access_<'a, F: FnOnce() -> &'a str>(
context: &mut Context,
global_name: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should make the variant GlobalName instead of AddressName then? I think either is fine really, the name GlobalName entered my head as an alternative, and then I saw it in the flag here :)

Copy link
Contributor Author

@cgswords cgswords Dec 1, 2023

Choose a reason for hiding this comment

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

I will split the difference and call it a GlobalAddress.

}
} else if let Some(previous) = self.previous.as_mut() {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. We might want to make this a loop because... Rust 😡
  2. Have you observed a noticeable perf difference with this? Probably not since this is likely... what? like 5 lists deep?
  3. How will this work with locals? Will I have to push a new scope on at each let binding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. We might want to make this a loop because... Rust 😡

Ah, sure thing.

  1. Have you observed a noticeable perf difference with this? Probably not since this is likely... what? like 5 lists deep?

First, yeah, it never gets too deep. Second, the previous implementation cloned the whole map every time it pushed a new scope, so I think this will still be a perf win. Third, if it is ever slow we can do path compression: if we ever look something up in a previous, we can update all the intermediary tables to also hold that information, amortizing it to O(1) lookup (at the cost of space).

  1. How will this work with locals? Will I have to push a new scope on at each let binding?

You will only need to push scopes when entering new blocks, because any lets (or uses) in that block should "fall out" of scope on exit. (Technically, we only need to do this for blocks that have let bindings or use statements in them.) Otherwise, a let should shadow the previous definition, so we just add it to the innermost scope (replacing anything already there).

//**************************************************************************************************
// Context
//**************************************************************************************************

type ModuleMembers = BTreeMap<Name, ModuleMemberKind>;

struct Context<'env, 'map> {
module_members: UniqueMap<ModuleIdent, ModuleMembers>,
// NB: We carry a few things separately because we need to split them out during path resolution to
Copy link
Contributor

Choose a reason for hiding this comment

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

NB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Fancy

Comment on lines 401 to 405
top_level_address(
&mut context.defn_context,
/* suggest_declaration */ true,
a,
),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, maybe bind this to a local to reduce some amount of indenting

Copy link
Contributor

@tnowacki tnowacki left a comment

Choose a reason for hiding this comment

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

Sorry for not getting back to this sooner. I'm approving especially since we plan on making changes to this later

@cgswords cgswords merged commit 094d511 into main Dec 8, 2023
@cgswords cgswords deleted the cgswords/combined_namespaces branch December 8, 2023 04:09
gdanezis pushed a commit that referenced this pull request Dec 15, 2023
## Description 

This adds a Move 2024 path resolution mechanism to expansion, which
revises name chain resolution to combine address, module, and member
namespaces. In addition, it adds `::<addr>::<module>` and
`::<addr>::<module>::<member>` forms to alias-dodge when necessary.

This is toward getting ready to add enums to the name chain space.

## Test Plan 

New and updated tests, subject to feature gating.

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
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.

2 participants