-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move][move-ide] Revise how IDE information is recorded in the compil…
…er (#17864) ## 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:
- Loading branch information
Showing
29 changed files
with
450 additions
and
519 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
external-crates/move/crates/move-analyzer/src/compiler_info.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) The Move Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::collections::{BTreeMap, BTreeSet}; | ||
|
||
use move_compiler::shared::ide as CI; | ||
use move_ir_types::location::Loc; | ||
|
||
#[derive(Default, Debug, Clone)] | ||
pub struct CompilerInfo { | ||
pub macro_info: BTreeMap<Loc, CI::MacroCallInfo>, | ||
pub expanded_lambdas: BTreeSet<Loc>, | ||
pub autocomplete_info: BTreeMap<Loc, CI::AutocompleteInfo>, | ||
} | ||
|
||
impl CompilerInfo { | ||
pub fn new() -> CompilerInfo { | ||
CompilerInfo::default() | ||
} | ||
|
||
pub fn from(info: impl IntoIterator<Item = (Loc, CI::IDEAnnotation)>) -> Self { | ||
let mut result = Self::new(); | ||
result.add_info(info); | ||
result | ||
} | ||
|
||
pub fn add_info(&mut self, info: impl IntoIterator<Item = (Loc, CI::IDEAnnotation)>) { | ||
for (loc, entry) in info { | ||
match entry { | ||
CI::IDEAnnotation::MacroCallInfo(info) => { | ||
// TODO: should we check this is not also an expanded lambda? | ||
// TODO: what if we find two macro calls? | ||
if let Some(_old) = self.macro_info.insert(loc, *info) { | ||
eprintln!("Repeated macro info"); | ||
} | ||
} | ||
CI::IDEAnnotation::ExpandedLambda => { | ||
self.expanded_lambdas.insert(loc); | ||
} | ||
CI::IDEAnnotation::AutocompleteInfo(info) => { | ||
// TODO: what if we find two autocomplete info sets? Intersection may be better | ||
// than union, as it's likely in a lambda body. | ||
if let Some(_old) = self.autocomplete_info.insert(loc, *info) { | ||
eprintln!("Repeated autocomplete info"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn get_macro_info(&mut self, loc: &Loc) -> Option<&CI::MacroCallInfo> { | ||
self.macro_info.get(loc) | ||
} | ||
|
||
pub fn is_expanded_lambda(&mut self, loc: &Loc) -> bool { | ||
self.expanded_lambdas.contains(loc) | ||
} | ||
|
||
pub fn get_autocomplete_info(&mut self, loc: &Loc) -> Option<&CI::AutocompleteInfo> { | ||
self.autocomplete_info.get(loc) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.