Skip to content

Commit 30eda19

Browse files
authored
[move][move-compiler] Provide name suggestions when resolution fails (#24016)
## Description Introduces suggestions for module and alias name resolution in the Move compiler when naming fails. Suggestion is via a filtered list of candidates, with a hand-tuned Levenshtein implementation to try to be somewhat performant when looking for a candidate. There are a lot of heuristics in place around when to suggest a name and what kind, which I am sure can use tuning and adjustment based on usage experience and feedback. ### Smaller changes: * Improved error location reporting in CLI output for duplicate module definitions, giving more precise spans in `args.exp`. * Refactored `aliases.rs` to add clearer sectioning for type definitions, traits, and implementations, and imported additional types for improved clarity and maintainability. * Added a convenience method `module_name` to `ModuleIdent_` for easier access to module names. ## Test plan Tests were changed, and new output was hand-reviewed. Some specific suggestion tests were added. --- ## 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): - [ ] gRPC: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK:
1 parent 7e84566 commit 30eda19

File tree

65 files changed

+1155
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1155
-221
lines changed

crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__additive.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ source: crates/sui/src/upgrade_compatibility/../unit_tests/upgrade_compatibility
33
expression: normalize_path(err.to_string())
44
---
55
error[Compatibility E01007]: missing declaration
6-
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
6+
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:8
77
88
4module upgrades::upgrades {
9-
^^^^^^^^ enum 'EnumToRemove' is missing
9+
^^^^^^^^^^^^^^^^^^ enum 'EnumToRemove' is missing
1010
1111
= Enums cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
1212
= Add missing enum 'EnumToRemove' back to the module 'upgrades'.
1313

1414
error[Compatibility E01007]: missing declaration
15-
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
15+
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:8
1616
1717
4module upgrades::upgrades {
18-
^^^^^^^^ function 'function_to_remove' is missing
18+
^^^^^^^^^^^^^^^^^^ function 'function_to_remove' is missing
1919
2020
= Functions cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
2121
= Add missing function 'function_to_remove' back to the module 'upgrades'.
2222

2323
error[Compatibility E01007]: missing declaration
24-
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
24+
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:8
2525
2626
4 │ module upgrades::upgrades {
27-
^^^^^^^^ struct 'StructToRemove' is missing
27+
^^^^^^^^^^^^^^^^^^ struct 'StructToRemove' is missing
2828
2929
= Structs cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
3030
= Add missing struct 'StructToRemove' back to the module 'upgrades'.

crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__all.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ source: crates/sui/src/upgrade_compatibility/../unit_tests/upgrade_compatibility
33
expression: normalize_path(err.to_string())
44
---
55
error[Compatibility E01001]: missing public declaration
6-
┌─ /fixtures/upgrade_errors/all_v2/sources/UpgradeErrors.move:6:18
6+
┌─ /fixtures/upgrade_errors/all_v2/sources/UpgradeErrors.move:6:8
77
88
6module upgrades::upgrades {
9-
^^^^^^^^ enum 'EnumToBeRemoved' is missing
9+
^^^^^^^^^^^^^^^^^^ enum 'EnumToBeRemoved' is missing
1010
1111
= Enums are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
1212
= Add missing enum 'EnumToBeRemoved' back to the module 'upgrades'.
1313

1414
error[Compatibility E01001]: missing public declaration
15-
┌─ /fixtures/upgrade_errors/all_v2/sources/UpgradeErrors.move:6:18
15+
┌─ /fixtures/upgrade_errors/all_v2/sources/UpgradeErrors.move:6:8
1616
1717
6module upgrades::upgrades {
18-
^^^^^^^^ struct 'StructToBeRemoved' is missing
18+
^^^^^^^^^^^^^^^^^^ struct 'StructToBeRemoved' is missing
1919
2020
= Structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
2121
= Add missing struct 'StructToBeRemoved' back to the module 'upgrades'.

crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__declarations_missing.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ source: crates/sui/src/upgrade_compatibility/../unit_tests/upgrade_compatibility
33
expression: normalize_path(err.to_string())
44
---
55
error[Compatibility E01001]: missing public declaration
6-
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/enum.move:4:18
6+
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/enum.move:4:8
77
88
4module upgrades::enum_ {
9-
^^^^^ enum 'EnumToBeRemoved' is missing
9+
^^^^^^^^^^^^^^^ enum 'EnumToBeRemoved' is missing
1010
1111
= Enums are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
1212
= Add missing enum 'EnumToBeRemoved' back to the module 'enum_'.
1313

1414
error[Compatibility E01001]: missing public declaration
15-
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/func.move:4:18
15+
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/func.move:4:8
1616
1717
4module upgrades::func_ {
18-
^^^^^ public function 'fun_to_be_removed' is missing
18+
^^^^^^^^^^^^^^^ public function 'fun_to_be_removed' is missing
1919
2020
= Public functions are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
2121
= Add missing public function 'fun_to_be_removed' back to the module 'func_'.
@@ -30,10 +30,10 @@ error[Compatibility E01001]: missing public declaration
3030
= Restore the original function's 'public' visibility for function 'fun_to_lose_public'.
3131

3232
error[Compatibility E01001]: missing public declaration
33-
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/struct.move:4:18
33+
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/struct.move:4:8
3434
3535
4 │ module upgrades::struct_ {
36-
^^^^^^^ struct 'StructToBeRemoved' is missing
36+
^^^^^^^^^^^^^^^^^ struct 'StructToBeRemoved' is missing
3737
3838
= Structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
3939
= Add missing struct 'StructToBeRemoved' back to the module 'struct_'.

crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__deponly.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ source: crates/sui/src/upgrade_compatibility/../unit_tests/upgrade_compatibility
33
expression: normalize_path(err.to_string())
44
---
55
error[Compatibility E01010]: new declaration
6-
┌─ /fixtures/upgrade_errors/deponly_errors_v2/sources/UpgradeErrors.move:4:18
6+
┌─ /fixtures/upgrade_errors/deponly_errors_v2/sources/UpgradeErrors.move:4:8
77
88
4module upgrades::upgrades {
9-
^^^^^^^^ New unexpected enum 'NewEnum'.
9+
^^^^^^^^^^^^^^^^^^ New unexpected enum 'NewEnum'.
1010
1111
= Enums cannot be added during a 'dependency only' upgrade.
1212
= Remove the enum 'NewEnum' from its module.
1313

1414
error[Compatibility E01010]: new declaration
15-
┌─ /fixtures/upgrade_errors/deponly_errors_v2/sources/UpgradeErrors.move:4:18
15+
┌─ /fixtures/upgrade_errors/deponly_errors_v2/sources/UpgradeErrors.move:4:8
1616
1717
4module upgrades::upgrades {
18-
^^^^^^^^ New unexpected function 'new_function'.
18+
^^^^^^^^^^^^^^^^^^ New unexpected function 'new_function'.
1919
2020
= Functions cannot be added during a 'dependency only' upgrade.
2121
= Remove the function 'new_function' from its module.

crates/sui/src/unit_tests/snapshots/sui__upgrade_compatibility__upgrade_compatibility_tests__version_mismatch.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
2+
source: crates/sui/src/upgrade_compatibility/../unit_tests/upgrade_compatibility_tests.rs
33
expression: normalize_path(result.unwrap_err().to_string())
44
---
55
error[Compatibility E01008]: file format version downgrade
6-
┌─ /fixtures/upgrade_errors/deponly_errors_v2/sources/UpgradeErrors.move:4:18
6+
┌─ /fixtures/upgrade_errors/deponly_errors_v2/sources/UpgradeErrors.move:4:8
77
88
4module upgrades::upgrades {
9-
^^^^^^^^ Downgrading from file format version 1 to 0 is not supported.
9+
^^^^^^^^^^^^^^^^^^ Downgrading from file format version 1 to 0 is not supported.
1010
1111
= File format version downgrades are not supported.
1212
= Please upgrade to the latest version of the move language tooling.

external-crates/move/crates/move-analyzer/tests/dot_calls.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ source: crates/move-analyzer/tests/ide_testsuite.rs
55
-- test 0 -------------------
66
use line: 3, use_ndx: 0
77
Use: 'Self', start: 19, end: 23
8-
Def: 'M1', line: 0, def char: 17
8+
Def: 'Move2024', line: 0, def char: 7
99
TypeDef: no info
1010
On Hover:
1111
module Move2024::M1
@@ -43,7 +43,7 @@ public fun Move2024::M1::foo(
4343
-- test 4 -------------------
4444
use line: 4, use_ndx: 0
4545
Use: 'M1', start: 29, end: 31
46-
Def: 'M1', line: 0, def char: 17
46+
Def: 'Move2024', line: 0, def char: 7
4747
TypeDef: no info
4848
On Hover:
4949
module Move2024::M1
@@ -81,7 +81,7 @@ public fun Move2024::M1::foo(
8181
-- test 8 -------------------
8282
use line: 27, use_ndx: 0
8383
Use: 'M1_ALIAS', start: 12, end: 20
84-
Def: 'M1', line: 0, def char: 17
84+
Def: 'Move2024', line: 0, def char: 7
8585
TypeDef: no info
8686
On Hover:
8787
module Move2024::M1
@@ -100,7 +100,7 @@ public fun Move2024::M1::bar(
100100
-- test 10 -------------------
101101
use line: 27, use_ndx: 2
102102
Use: 'M1', start: 39, end: 41
103-
Def: 'M1', line: 0, def char: 17
103+
Def: 'Move2024', line: 0, def char: 7
104104
TypeDef: no info
105105
On Hover:
106106
module Move2024::M1
@@ -129,7 +129,7 @@ public fun Move2024::M1::bar(
129129
-- test 13 -------------------
130130
use line: 30, use_ndx: 0
131131
Use: 'M1', start: 16, end: 18
132-
Def: 'M1', line: 0, def char: 17
132+
Def: 'Move2024', line: 0, def char: 7
133133
TypeDef: no info
134134
On Hover:
135135
module Move2024::M1

external-crates/move/crates/move-analyzer/tests/implicit_uses.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public struct Option<Element> has copy, drop, store {
1818
-- test 1 -------------------
1919
use line: 8, use_ndx: 2
2020
Use: 'option', start: 26, end: 32
21-
Def: 'option', line: 4, def char: 12
21+
Def: 'std', line: 4, def char: 7
2222
TypeDef: no info
2323
On Hover:
2424
module option

external-crates/move/crates/move-analyzer/tests/imports.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ source: crates/move-analyzer/tests/ide_testsuite.rs
55
-- test 0 -------------------
66
use line: 2, use_ndx: 0
77
Use: 'M9', start: 16, end: 18
8-
Def: 'M9', line: 5, def char: 16
8+
Def: 'Symbols', line: 5, def char: 7
99
TypeDef: no info
1010
On Hover:
1111
module Symbols::M9
@@ -15,55 +15,55 @@ module Symbols::M9
1515
-- test 1 -------------------
1616
use line: 8, use_ndx: 0
1717
Use: 'M1', start: 17, end: 19
18-
Def: 'M1', line: 0, def char: 16
18+
Def: 'Symbols', line: 0, def char: 7
1919
TypeDef: no info
2020
On Hover:
2121
module Symbols::M1
2222

2323
-- test 2 -------------------
2424
use line: 9, use_ndx: 0
2525
Use: 'M1', start: 17, end: 19
26-
Def: 'M1', line: 0, def char: 16
26+
Def: 'Symbols', line: 0, def char: 7
2727
TypeDef: no info
2828
On Hover:
2929
module Symbols::M1
3030

3131
-- test 3 -------------------
3232
use line: 9, use_ndx: 1
3333
Use: 'ALIAS_M1', start: 23, end: 31
34-
Def: 'M1', line: 0, def char: 16
34+
Def: 'Symbols', line: 0, def char: 7
3535
TypeDef: no info
3636
On Hover:
3737
module Symbols::M1
3838

3939
-- test 4 -------------------
4040
use line: 10, use_ndx: 0
4141
Use: 'M1', start: 18, end: 20
42-
Def: 'M1', line: 0, def char: 16
42+
Def: 'Symbols', line: 0, def char: 7
4343
TypeDef: no info
4444
On Hover:
4545
module Symbols::M1
4646

4747
-- test 5 -------------------
4848
use line: 10, use_ndx: 1
4949
Use: 'BLAH', start: 24, end: 28
50-
Def: 'M1', line: 0, def char: 16
50+
Def: 'Symbols', line: 0, def char: 7
5151
TypeDef: no info
5252
On Hover:
5353
module Symbols::M1
5454

5555
-- test 6 -------------------
5656
use line: 10, use_ndx: 2
5757
Use: 'M2', start: 30, end: 32
58-
Def: 'M2', line: 0, def char: 16
58+
Def: 'Symbols', line: 0, def char: 7
5959
TypeDef: no info
6060
On Hover:
6161
module Symbols::M2
6262

6363
-- test 7 -------------------
6464
use line: 10, use_ndx: 3
6565
Use: 'BLEH', start: 36, end: 40
66-
Def: 'M2', line: 0, def char: 16
66+
Def: 'Symbols', line: 0, def char: 7
6767
TypeDef: no info
6868
On Hover:
6969
module Symbols::M2
@@ -91,15 +91,15 @@ public struct Symbols::M2::SomeOtherStruct has drop {
9191
-- test 10 -------------------
9292
use line: 33, use_ndx: 0
9393
Use: 'M1', start: 21, end: 23
94-
Def: 'M1', line: 0, def char: 16
94+
Def: 'Symbols', line: 0, def char: 7
9595
TypeDef: no info
9696
On Hover:
9797
module Symbols::M1
9898

9999
-- test 11 -------------------
100100
use line: 33, use_ndx: 1
101101
Use: 'ANOTHER_ALIAS_M1', start: 27, end: 43
102-
Def: 'M1', line: 0, def char: 16
102+
Def: 'Symbols', line: 0, def char: 7
103103
TypeDef: no info
104104
On Hover:
105105
module Symbols::M1

external-crates/move/crates/move-analyzer/tests/macros.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ $T
183183
-- test 16 -------------------
184184
use line: 33, use_ndx: 0
185185
Use: 'macros', start: 16, end: 22
186-
Def: 'macros', line: 0, def char: 15
186+
Def: 'Macros', line: 0, def char: 7
187187
TypeDef: no info
188188
On Hover:
189189
module Macros::macros
@@ -314,7 +314,7 @@ ERROR: No use_line 22 in mod_symbols UseDefMap(
314314
col_end: 23,
315315
def_loc: Loc {
316316
file_hash: "6c258978e645dea8faaf2f91e67b30b04a67c3d338d7ad7edb927a49a7291cae",
317-
start: 15,
317+
start: 7,
318318
end: 23,
319319
},
320320
type_def_loc: None,
@@ -362,7 +362,7 @@ ERROR: No use_line 22 in mod_symbols UseDefMap(
362362
col_end: 22,
363363
def_loc: Loc {
364364
file_hash: "6148171bd349df74f3ece996d9b5e08173125155fdeed36451c03a5a33616168",
365-
start: 15,
365+
start: 7,
366366
end: 21,
367367
},
368368
type_def_loc: None,

external-crates/move/crates/move-analyzer/tests/mod_access.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ source: crates/move-analyzer/tests/ide_testsuite.rs
55
-- test 0 -------------------
66
use line: 19, use_ndx: 1
77
Use: 'M9', start: 32, end: 34
8-
Def: 'M9', line: 5, def char: 16
8+
Def: 'Symbols', line: 5, def char: 7
99
TypeDef: no info
1010
On Hover:
1111
module Symbols::M9
@@ -15,7 +15,7 @@ module Symbols::M9
1515
-- test 1 -------------------
1616
use line: 20, use_ndx: 0
1717
Use: 'M9', start: 17, end: 19
18-
Def: 'M9', line: 5, def char: 16
18+
Def: 'Symbols', line: 5, def char: 7
1919
TypeDef: no info
2020
On Hover:
2121
module Symbols::M9
@@ -25,7 +25,7 @@ module Symbols::M9
2525
-- test 2 -------------------
2626
use line: 20, use_ndx: 3
2727
Use: 'M9', start: 55, end: 57
28-
Def: 'M9', line: 5, def char: 16
28+
Def: 'Symbols', line: 5, def char: 7
2929
TypeDef: no info
3030
On Hover:
3131
module Symbols::M9
@@ -35,7 +35,7 @@ module Symbols::M9
3535
-- test 3 -------------------
3636
use line: 23, use_ndx: 2
3737
Use: 'M9', start: 34, end: 36
38-
Def: 'M9', line: 5, def char: 16
38+
Def: 'Symbols', line: 5, def char: 7
3939
TypeDef: no info
4040
On Hover:
4141
module Symbols::M9
@@ -45,7 +45,7 @@ module Symbols::M9
4545
-- test 4 -------------------
4646
use line: 24, use_ndx: 0
4747
Use: 'M9', start: 21, end: 23
48-
Def: 'M9', line: 5, def char: 16
48+
Def: 'Symbols', line: 5, def char: 7
4949
TypeDef: no info
5050
On Hover:
5151
module Symbols::M9
@@ -55,31 +55,31 @@ module Symbols::M9
5555
-- test 5 -------------------
5656
use line: 28, use_ndx: 2
5757
Use: 'M1', start: 34, end: 36
58-
Def: 'M1', line: 0, def char: 16
58+
Def: 'Symbols', line: 0, def char: 7
5959
TypeDef: no info
6060
On Hover:
6161
module Symbols::M1
6262

6363
-- test 6 -------------------
6464
use line: 28, use_ndx: 4
6565
Use: 'ALIAS_M1', start: 51, end: 59
66-
Def: 'M1', line: 0, def char: 16
66+
Def: 'Symbols', line: 0, def char: 7
6767
TypeDef: no info
6868
On Hover:
6969
module Symbols::M1
7070

7171
-- test 7 -------------------
7272
use line: 34, use_ndx: 1
7373
Use: 'ANOTHER_ALIAS_M1', start: 17, end: 33
74-
Def: 'M1', line: 0, def char: 16
74+
Def: 'Symbols', line: 0, def char: 7
7575
TypeDef: no info
7676
On Hover:
7777
module Symbols::M1
7878

7979
-- test 8 -------------------
8080
use line: 34, use_ndx: 3
8181
Use: 'M9', start: 57, end: 59
82-
Def: 'M9', line: 5, def char: 16
82+
Def: 'Symbols', line: 5, def char: 7
8383
TypeDef: no info
8484
On Hover:
8585
module Symbols::M9

0 commit comments

Comments
 (0)