-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] [Compiler-V2] Package Visibility (#13680)
* extend parser * impl package visibility * bug fix * trivial: remove commented code * doc * doc * doc * rename * doc * doc * refactor * rename * linter * add tests * bug fix * update tests * refactor * remove package keyword * make package a contextual keyword * unreachable! to panic! * linter * err msg * typo * refactor * add tests * add tests * remove outdated exp file * format * linter * gate public(package) * add v1 exp * update test * update tests * revert * update doc * change is_target to is_primary target and impl of in_same_package * remove file * revert to is_target & bug fix & update tests * linter * add tests * switch to is_primary_target * renaming * format * remove in_same_package * format --------- Co-authored-by: Zekun Wang <[email protected]>
- Loading branch information
Showing
52 changed files
with
699 additions
and
40 deletions.
There are no files selected for viewing
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
9 changes: 9 additions & 0 deletions
9
..._party/move/move-compiler-v2/tests/checking/visibility-checker/parser_package_keyword.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 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x42::package { | ||
friend fun package(package: u8): u8 { | ||
{ | ||
let package: u8 = Add<u8>(package, 1); | ||
package | ||
} | ||
} | ||
} // end 0x42::package |
6 changes: 6 additions & 0 deletions
6
...party/move/move-compiler-v2/tests/checking/visibility-checker/parser_package_keyword.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,6 @@ | ||
module 0x42::package { | ||
public(package) fun package(package: u8): u8 { | ||
let package = package + 1; | ||
package | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_invalid.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,23 @@ | ||
|
||
Diagnostics: | ||
error: Cannot use both package and friend visibility in the same module | ||
┌─ tests/visibility-checker/mix_friend_package_visibility_invalid.move:7:3 | ||
│ | ||
3 │ public(package) fun foo() { | ||
│ --------------- package visibility declared here | ||
· | ||
7 │ public(friend) fun bar() { | ||
│ ^^^^^^^^^^^^^^ | ||
│ │ | ||
│ friend visibility declared here | ||
|
||
error: Cannot use both package and friend visibility in the same module | ||
┌─ tests/visibility-checker/mix_friend_package_visibility_invalid.move:15:3 | ||
│ | ||
15 │ public(friend) fun foo() { | ||
│ ^^^^^^^^^^^^^^ | ||
│ │ | ||
│ friend visibility declared here | ||
· | ||
19 │ public(package) fun bar() { | ||
│ --------------- package visibility declared here |
23 changes: 23 additions & 0 deletions
23
...move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_invalid.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,23 @@ | ||
address 0x42 { | ||
module A { | ||
public(package) fun foo() { | ||
|
||
} | ||
|
||
public(friend) fun bar() { | ||
|
||
} | ||
} | ||
} | ||
|
||
address 0x43 { | ||
module A { | ||
public(friend) fun foo() { | ||
|
||
} | ||
|
||
public(package) fun bar() { | ||
|
||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ty/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_valid.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,12 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x42::B { | ||
friend fun foo() { | ||
Tuple() | ||
} | ||
} // end 0x42::B | ||
module 0x42::A { | ||
friend fun foo() { | ||
B::foo(); | ||
Tuple() | ||
} | ||
} // end 0x42::A |
13 changes: 13 additions & 0 deletions
13
...y/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_valid.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,13 @@ | ||
// It's ok to use (public)friend and public(package) in different modules | ||
|
||
module 0x42::A { | ||
public(friend) fun foo() { | ||
0x42::B::foo(); | ||
} | ||
} | ||
|
||
module 0x42::B { | ||
public(package) fun foo() { | ||
|
||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
third_party/move/move-compiler-v2/tests/visibility-checker/package_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,33 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x42::A { | ||
friend fun bar() { | ||
Tuple() | ||
} | ||
private fun foo() { | ||
Tuple() | ||
} | ||
} // end 0x42::A | ||
module 0x42::B { | ||
use 0x42::A; // resolved as: 0x42::A | ||
public fun bar() { | ||
A::bar() | ||
} | ||
friend fun foo() { | ||
A::bar() | ||
} | ||
private fun baz() { | ||
A::bar() | ||
} | ||
} // end 0x42::B | ||
module 0x42::C { | ||
use 0x42::B; // resolved as: 0x42::B | ||
public fun bar() { | ||
B::foo() | ||
} | ||
friend fun foo() { | ||
B::foo() | ||
} | ||
private fun baz() { | ||
B::foo() | ||
} | ||
} // end 0x42::C |
36 changes: 36 additions & 0 deletions
36
third_party/move/move-compiler-v2/tests/visibility-checker/package_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,36 @@ | ||
module 0x42::A { | ||
fun foo() {} | ||
public(package) fun bar() {} | ||
} | ||
|
||
module 0x42::B { | ||
use 0x42::A; | ||
|
||
public(package) fun foo() { | ||
A::bar() | ||
} | ||
|
||
public fun bar() { | ||
A::bar() | ||
} | ||
|
||
fun baz() { | ||
A::bar() | ||
} | ||
} | ||
|
||
module 0x42::C { | ||
use 0x42::B; | ||
|
||
public(package) fun foo() { | ||
B::foo() | ||
} | ||
|
||
public fun bar() { | ||
B::foo() | ||
} | ||
|
||
fun baz() { | ||
B::foo() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...arty/move/move-compiler-v2/tests/visibility-checker/package_visibility_already_friend.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,29 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x42::C { | ||
friend fun bar() { | ||
Tuple() | ||
} | ||
friend fun foo() { | ||
C::bar() | ||
} | ||
} // end 0x42::C | ||
module 0x42::A { | ||
friend fun bar() { | ||
Tuple() | ||
} | ||
private fun foo() { | ||
Tuple() | ||
} | ||
} // end 0x42::A | ||
module 0x42::B { | ||
use 0x42::A; // resolved as: 0x42::A | ||
public fun bar() { | ||
A::bar() | ||
} | ||
friend fun foo() { | ||
A::bar() | ||
} | ||
private fun baz() { | ||
A::bar() | ||
} | ||
} // end 0x42::B |
33 changes: 33 additions & 0 deletions
33
...rty/move/move-compiler-v2/tests/visibility-checker/package_visibility_already_friend.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,33 @@ | ||
module 0x42::A { | ||
// check we don't add duplicate `friend 0x42::B;` | ||
// during the transformation | ||
friend 0x42::B; | ||
fun foo() {} | ||
public(package) fun bar() {} | ||
} | ||
|
||
module 0x42::B { | ||
use 0x42::A; | ||
|
||
public(package) fun foo() { | ||
A::bar() | ||
} | ||
|
||
public fun bar() { | ||
A::bar() | ||
} | ||
|
||
fun baz() { | ||
A::bar() | ||
} | ||
} | ||
|
||
module 0x42::C { | ||
public(package) fun foo() { | ||
bar() | ||
} | ||
|
||
public(package) fun bar() { | ||
|
||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_cycle.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: invalid 'module' declaration | ||
┌─ tests/visibility-checker/package_visibility_cycle.move:3:9 | ||
│ | ||
3 │ 0x42::B::foo() | ||
│ ^^^^^^^^^^^^ '0x42::B' uses '0x42::A'. This 'use' relationship creates a dependency cycle. | ||
· | ||
9 │ 0x42::A::foo() | ||
│ ------------ '0x42::A' uses '0x42::B' |
11 changes: 11 additions & 0 deletions
11
third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_cycle.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,11 @@ | ||
module 0x42::A { | ||
public(package) fun foo() { | ||
0x42::B::foo() | ||
} | ||
} | ||
|
||
module 0x42::B { | ||
public(package) fun foo() { | ||
0x42::A::foo() | ||
} | ||
} |
Oops, something went wrong.