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][move-ide] Revise how IDE information is recorded in the compiler #17864

Merged
merged 4 commits into from
May 29, 2024

Conversation

cgswords
Copy link
Contributor

@cgswords cgswords commented May 22, 2024

Description

This PR moves how we record IDE information to communicate it to the Move Analyzer. It is now accrued on the CompilationEnv (modulo some care in typing to handle type elaboration) and can be added through methods there. The goal is to set up an extensible way to track IDE information in the future, tying it to location information.

This change has also caused us to change how we compute spans for dotted expression terms: previously, we would make the expression with the call's span in order to report failures to autoborrow to point at the call site (instead of just the subject term). This caused recurring through location information in the analyzer to enter an infinite loop in the macro case, as the subject term shared the location of the overall macro call and recursion into the subject term on the macro information looped forever. This diff introduces a solution to this issue by more-carefully computing spans for subject terms so that they remain pointing at the actual subject term, and plumbs the call location through dotted expression handling to retain good error reporting for the method case. It also introduces a very small change to handle location reporting for */&/&mut usage for type errors.

Test plan

All tests still pass.


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

@cgswords cgswords requested a review from awelc May 22, 2024 00:53
Copy link

vercel bot commented May 22, 2024

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

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2024 0:17am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 0:17am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 0:17am
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 0:17am

Copy link
Contributor

@awelc awelc left a comment

Choose a reason for hiding this comment

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

Left some comments and some cleanup would be necessary but overall looks good

#[derive(Debug, Clone)]
pub struct ExpEntry {
/// Location of the recorded info
pub loc: Loc,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a different location than the one used as key of the exp_info map (e.g., indicates a different, more precise location inside of the expression)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's just duplicated here for sanity.

@@ -3769,12 +3765,12 @@ fn method_call(
edotted.for_autocomplete = true;
let err_ty = context.error_type(loc);
let dot_output =
resolve_exp_dotted(context, DottedUsage::Borrow(false), loc, edotted);
resolve_exp_dotted(context, DottedUsage::Borrow(false), edotted.loc, edotted);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this related or unrelated fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the span stuff is quite related. I'll provide a write-up in the mian PR when I publish it for review.

}

/// For use in the compiler, to ease recording IDE information.
pub enum ExpInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like ExpEntry and ExpInfo encode the same type of information. Can we just use one rather than using ExpInfo in the compiler and (at least seemingly) translating it almost immediately into ExpEntry?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this is likely the cleanest thing we can do. Since the actual information live on the CompilationEnv take a Diagnostics to report ICEs, the only alternative would be to re-expose the entire interface for every information form on that environment, e.g.,

pub fun set_ide_exp_macro_call_info(&mut self, call_info: ide::MacroCallInfo) {
  ...
}

pub fun set_ide_exp_expanded_lambda(&mut self) {
  ...
}

pub fun set_ide_exp_autocomplete_dot_information(&mut self) {
  ...
}

The current approach avoids this by essentially baking this dispatch into the ExpInfo. I'm happy to change this if you want, but I think the overall usage and maintenance will become clumsier.

@cgswords cgswords enabled auto-merge (squash) May 29, 2024 00:14
…7889)

## Description 

This adds autocomplete information collection to the `IDEInfo` form.

## Test plan 

Testing is difficult without the analyzer calling it with a location,
but I anticipate working with Adam on that over the next few days.

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
@cgswords cgswords requested a review from awelc May 29, 2024 00:15
@cgswords cgswords merged commit a1ce332 into main May 29, 2024
48 checks passed
@cgswords cgswords deleted the cgswords/ide_info branch May 29, 2024 00:40
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.

3 participants