forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler-v2] More concise visibility declarations (aptos-labs#14417)
The syntax `public(friend) fun` and `public(package) fun` is unnecessary verbose. Taken over from Rust, perhaps in Rust `pub(crate) fn` is OK, but Move does add to much noise. This PR suggests to introduce the syntax `package fun` and `friend fun`. Those read naturally and are also in this in other languages. (E.g. C#).
- Loading branch information
Showing
11 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
third_party/move/move-compiler-v2/tests/checking-lang-v1/direct_visibility.exp
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,19 @@ | ||
|
||
Diagnostics: | ||
error: unsupported language construct | ||
┌─ tests/checking-lang-v1/direct_visibility.move:2:5 | ||
│ | ||
2 │ package fun f() {} | ||
│ ^^^^^^^ Move 2 language construct is not enabled: direct `package` declaration | ||
|
||
error: unsupported language construct | ||
┌─ tests/checking-lang-v1/direct_visibility.move:7:5 | ||
│ | ||
7 │ friend fun f() {} | ||
│ ^^^^^^ Move 2 language construct is not enabled: direct `friend` declaration | ||
|
||
error: unsupported language construct | ||
┌─ tests/checking-lang-v1/direct_visibility.move:11:5 | ||
│ | ||
11 │ friend fun f() { | ||
│ ^^^^^^ Move 2 language construct is not enabled: direct `friend` declaration |
15 changes: 15 additions & 0 deletions
15
third_party/move/move-compiler-v2/tests/checking-lang-v1/direct_visibility.move
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,15 @@ | ||
module 0x815::a { | ||
package fun f() {} | ||
} | ||
|
||
module 0x815::b { | ||
friend 0x815::c; | ||
friend fun f() {} | ||
} | ||
|
||
module 0x815::c { | ||
friend fun f() { | ||
0x815::a::f(); | ||
0x815::b::f(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
third_party/move/move-compiler-v2/tests/checking/visibility-checker/direct_visibility.exp
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,22 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x815::b { | ||
friend fun f() { | ||
Tuple() | ||
} | ||
} // end 0x815::b | ||
module 0x815::a { | ||
friend fun f() { | ||
Tuple() | ||
} | ||
friend fun g() { | ||
Tuple() | ||
} | ||
} // end 0x815::a | ||
module 0x815::c { | ||
public fun f() { | ||
a::f(); | ||
a::g(); | ||
b::f(); | ||
Tuple() | ||
} | ||
} // end 0x815::c |
17 changes: 17 additions & 0 deletions
17
third_party/move/move-compiler-v2/tests/checking/visibility-checker/direct_visibility.move
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,17 @@ | ||
module 0x815::a { | ||
package fun f() {} | ||
public(package) fun g(){} | ||
} | ||
|
||
module 0x815::b { | ||
friend 0x815::c; | ||
friend fun f() {} | ||
} | ||
|
||
module 0x815::c { | ||
public fun f() { | ||
0x815::a::f(); | ||
0x815::a::g(); | ||
0x815::b::f(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...d_party/move/move-compiler-v2/tests/checking/visibility-checker/direct_visibility_err.exp
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,10 @@ | ||
|
||
Diagnostics: | ||
error: function `0x815::b::f` cannot be called from function `0x815::c::f` because module `0x815::c` is not a `friend` of `0x815::b` | ||
┌─ tests/checking/visibility-checker/direct_visibility_err.move:2:16 | ||
│ | ||
2 │ friend fun f() {} | ||
│ ^ callee | ||
· | ||
7 │ 0x815::b::f(); | ||
│ ------------- called here |
9 changes: 9 additions & 0 deletions
9
..._party/move/move-compiler-v2/tests/checking/visibility-checker/direct_visibility_err.move
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,9 @@ | ||
module 0x815::b { | ||
friend fun f() {} | ||
} | ||
|
||
module 0x815::c { | ||
public fun f() { | ||
0x815::b::f(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
..._party/move/move-compiler-v2/tests/checking/visibility-checker/direct_visibility_err2.exp
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,9 @@ | ||
|
||
Diagnostics: | ||
error: duplicate declaration, item, or annotation | ||
┌─ tests/checking/visibility-checker/direct_visibility_err2.move:2:13 | ||
│ | ||
2 │ package friend fun f() {} | ||
│ ------- ^^^^^^ Duplicate visibility modifier | ||
│ │ | ||
│ Visibility modifier previously given here |
3 changes: 3 additions & 0 deletions
3
...party/move/move-compiler-v2/tests/checking/visibility-checker/direct_visibility_err2.move
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,3 @@ | ||
module 0x815::a { | ||
package friend fun f() {} | ||
} |
10 changes: 10 additions & 0 deletions
10
..._party/move/move-compiler-v2/tests/checking/visibility-checker/direct_visibility_err3.exp
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,10 @@ | ||
|
||
Diagnostics: | ||
error: unexpected token | ||
┌─ tests/checking/visibility-checker/direct_visibility_err3.move:2:13 | ||
│ | ||
2 │ package 0x815::a; | ||
│ ^^^^^ | ||
│ │ | ||
│ Unexpected '0x815' | ||
│ Expected a module member: 'spec', 'use', 'friend', 'const', 'fun', 'inline', or 'struct' |
3 changes: 3 additions & 0 deletions
3
...party/move/move-compiler-v2/tests/checking/visibility-checker/direct_visibility_err3.move
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,3 @@ | ||
module 0x815::b { | ||
package 0x815::a; | ||
} |
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