-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Compiler-v2] fix receiver call with index notation #15239
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
176 changes: 176 additions & 0 deletions
176
third_party/move/move-compiler-v2/tests/checking/receiver/calls_index.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,176 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x42::m { | ||
struct T { | ||
w: W, | ||
} | ||
struct S { | ||
t: T, | ||
} | ||
struct W { | ||
x: u64, | ||
} | ||
struct Wrapper<T> { | ||
inner: T, | ||
} | ||
private fun boo(v: vector<S>,w: W) { | ||
m::merge(Borrow(Mutable)(select m::T.w<T>(select m::S.t<S>(vector::borrow_mut<S>(Borrow(Mutable)(v), 0)))), w) | ||
} | ||
private fun boo_(v: vector<S>,w: W) { | ||
m::merge(Borrow(Mutable)(select m::T.w<T>(select m::S.t<S>(vector::borrow_mut<S>(Borrow(Mutable)(v), 0)))), w) | ||
} | ||
private fun boo_greater(v: vector<S>,w: W): bool { | ||
m::greater(Borrow(Immutable)(select m::T.w<T>(select m::S.t<S>(vector::borrow<S>(Borrow(Immutable)(v), 0)))), w) | ||
} | ||
private fun boo_greater_(v: vector<S>,w: W): bool { | ||
m::greater(Freeze(false)(Borrow(Mutable)(select m::T.w<T>(select m::S.t<S>(vector::borrow_mut<S>(Borrow(Mutable)(v), 0))))), w) | ||
} | ||
private fun boo_greater_2(v: vector<W>,w: W): bool { | ||
m::greater(vector::borrow<W>(Borrow(Immutable)(v), 0), w) | ||
} | ||
private fun boo_greater_2_(v: vector<W>,w: W): bool { | ||
m::greater(vector::borrow<W>(Borrow(Immutable)(v), 0), w) | ||
} | ||
private fun dispatch<T>(account: address): T | ||
acquires Wrapper(*) | ||
{ | ||
m::unwrap<T>(BorrowGlobal(Immutable)<Wrapper<T>>(account)) | ||
} | ||
private fun foo(account: address,w: W) | ||
acquires S(*) | ||
{ | ||
m::merge(Borrow(Mutable)(select m::T.w<T>(select m::S.t<S>(BorrowGlobal(Mutable)<S>(account)))), w) | ||
} | ||
private fun foo_(account: address,w: W) | ||
acquires S(*) | ||
{ | ||
m::merge(Borrow(Mutable)(select m::T.w<T>(select m::S.t<S>(BorrowGlobal(Mutable)<S>(account)))), w) | ||
} | ||
private fun foo_2(account: address,w: W) | ||
acquires W(*) | ||
{ | ||
m::merge(BorrowGlobal(Mutable)<W>(account), w) | ||
} | ||
private fun foo_3(account: address,w: W) | ||
acquires W(*) | ||
{ | ||
m::merge(BorrowGlobal(Mutable)<W>(account), w) | ||
} | ||
private fun foo_greater(account: address,w: W): bool | ||
acquires S(*) | ||
{ | ||
m::greater(Borrow(Immutable)(select m::T.w<T>(select m::S.t<S>(BorrowGlobal(Immutable)<S>(account)))), w) | ||
} | ||
private fun foo_greater_(account: address,w: W): bool | ||
acquires S(*) | ||
{ | ||
m::greater(Freeze(false)(Borrow(Mutable)(select m::T.w<T>(select m::S.t<S>(BorrowGlobal(Mutable)<S>(account))))), w) | ||
} | ||
private fun foo_greater_2(account: address,w: W): bool | ||
acquires S(*) | ||
{ | ||
m::greater(BorrowGlobal(Immutable)<W>(account), w) | ||
} | ||
private fun greater(self: &W,s: W): bool { | ||
Gt<u64>(select m::W.x<&W>(self), select m::W.x<W>(s)) | ||
} | ||
private fun merge(self: &mut W,s: W) { | ||
{ | ||
let $t2: u64 = select m::W.x<W>(s); | ||
{ | ||
let $t1: &mut u64 = Borrow(Mutable)(select m::W.x<&mut W>(self)); | ||
$t1 = Add<u64>(Deref($t1), $t2) | ||
} | ||
}; | ||
Tuple() | ||
} | ||
private fun unwrap<T>(self: &Wrapper<T>): T { | ||
select m::Wrapper.inner<&Wrapper<T>>(self) | ||
} | ||
} // end 0x42::m | ||
|
||
// -- Sourcified model before bytecode pipeline | ||
module 0x42::m { | ||
struct T has drop, store, key { | ||
w: W, | ||
} | ||
struct S has drop, key { | ||
t: T, | ||
} | ||
struct W has drop, store, key { | ||
x: u64, | ||
} | ||
struct Wrapper<T: copy> has copy, drop, store, key { | ||
inner: T, | ||
} | ||
fun boo(v: vector<S>, w: W) { | ||
merge(&mut 0x1::vector::borrow_mut<S>(&mut v, 0).t.w, w) | ||
} | ||
fun boo_(v: vector<S>, w: W) { | ||
merge(&mut 0x1::vector::borrow_mut<S>(&mut v, 0).t.w, w) | ||
} | ||
fun boo_greater(v: vector<S>, w: W): bool { | ||
greater(&0x1::vector::borrow<S>(&v, 0).t.w, w) | ||
} | ||
fun boo_greater_(v: vector<S>, w: W): bool { | ||
greater(/*freeze*/&mut 0x1::vector::borrow_mut<S>(&mut v, 0).t.w, w) | ||
} | ||
fun boo_greater_2(v: vector<W>, w: W): bool { | ||
greater(0x1::vector::borrow<W>(&v, 0), w) | ||
} | ||
fun boo_greater_2_(v: vector<W>, w: W): bool { | ||
greater(0x1::vector::borrow<W>(&v, 0), w) | ||
} | ||
fun dispatch<T: copy + store>(account: address): T | ||
acquires Wrapper | ||
{ | ||
unwrap<T>(borrow_global<Wrapper<T>>(account)) | ||
} | ||
fun foo(account: address, w: W) | ||
acquires S | ||
{ | ||
merge(&mut borrow_global_mut<S>(account).t.w, w) | ||
} | ||
fun foo_(account: address, w: W) | ||
acquires S | ||
{ | ||
merge(&mut borrow_global_mut<S>(account).t.w, w) | ||
} | ||
fun foo_2(account: address, w: W) | ||
acquires W | ||
{ | ||
merge(borrow_global_mut<W>(account), w) | ||
} | ||
fun foo_3(account: address, w: W) | ||
acquires W | ||
{ | ||
merge(borrow_global_mut<W>(account), w) | ||
} | ||
fun foo_greater(account: address, w: W): bool | ||
acquires S | ||
{ | ||
greater(&borrow_global<S>(account).t.w, w) | ||
} | ||
fun foo_greater_(account: address, w: W): bool | ||
acquires S | ||
{ | ||
greater(/*freeze*/&mut borrow_global_mut<S>(account).t.w, w) | ||
} | ||
fun foo_greater_2(account: address, w: W): bool | ||
acquires S | ||
{ | ||
greater(borrow_global<W>(account), w) | ||
} | ||
fun greater(self: &W, s: W): bool { | ||
self.x > s.x | ||
} | ||
fun merge(self: &mut W, s: W) { | ||
{ | ||
let $t2 = s.x; | ||
let $t1 = &mut self.x; | ||
*$t1 = *$t1 + $t2 | ||
}; | ||
} | ||
fun unwrap<T: copy>(self: &Wrapper<T>): T { | ||
self.inner | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
third_party/move/move-compiler-v2/tests/checking/receiver/calls_index.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,85 @@ | ||
module 0x42::m { | ||
|
||
struct S has key, drop { t: T } | ||
|
||
struct T has key, store, drop { | ||
w: W | ||
} | ||
|
||
struct W has key, store, drop { | ||
x: u64 | ||
} | ||
|
||
fun merge(self: &mut W, s: W) { | ||
self.x += s.x; | ||
} | ||
|
||
fun foo(account: address, w: W) acquires S { | ||
S[account].t.w.merge(w) | ||
} | ||
|
||
fun foo_2(account: address, w: W) acquires W { | ||
W[account].merge(w) | ||
} | ||
|
||
fun foo_3(account: address, w: W) acquires W { | ||
borrow_global_mut<W>(account).merge(w) | ||
} | ||
|
||
fun boo(v: vector<S>, w: W) { | ||
v[0].t.w.merge(w) | ||
} | ||
|
||
fun foo_(account: address, w: W) acquires S { | ||
(&mut S[account].t.w).merge(w) | ||
} | ||
|
||
fun boo_(v: vector<S>, w: W) { | ||
(&mut v[0].t.w).merge(w) | ||
} | ||
|
||
fun greater(self: &W, s: W): bool { | ||
self.x > s.x | ||
} | ||
|
||
fun foo_greater(account: address, w: W): bool acquires S { | ||
S[account].t.w.greater(w) | ||
} | ||
|
||
fun foo_greater_2(account: address, w: W): bool acquires S { | ||
W[account].greater(w) | ||
} | ||
|
||
fun boo_greater(v: vector<S>, w: W): bool { | ||
v[0].t.w.greater(w) | ||
} | ||
|
||
fun boo_greater_2(v: vector<W>, w: W): bool { | ||
v[0].greater(w) | ||
} | ||
|
||
fun foo_greater_(account: address, w: W): bool acquires S { | ||
(&mut S[account].t.w).greater(w) | ||
} | ||
|
||
fun boo_greater_(v: vector<S>, w: W): bool { | ||
(&mut v[0].t.w).greater(w) | ||
} | ||
|
||
fun boo_greater_2_(v: vector<W>, w: W): bool { | ||
(&v[0]).greater(w) | ||
} | ||
|
||
struct Wrapper<T: copy> has drop, key, store, copy { | ||
inner: T | ||
} | ||
|
||
fun unwrap<T: copy>(self: &Wrapper<T>): T { | ||
self.inner | ||
} | ||
|
||
fun dispatch<T: store + copy>(account: address): T acquires Wrapper { | ||
Wrapper<T>[account].unwrap() | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
third_party/move/move-compiler-v2/tests/checking/receiver/calls_index_errors.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: undeclared receiver function `merge_non_receiver` for type `W` | ||
┌─ tests/checking/receiver/calls_index_errors.move:22:9 | ||
│ | ||
22 │ S[account].t.w.merge_non_receiver(w) | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: the function takes `&mut` but `&` was provided | ||
┌─ tests/checking/receiver/calls_index_errors.move:26:9 | ||
│ | ||
26 │ (&S[account].t.w).merge(w) | ||
│ ^^^^^^^^^^^^^^^^^ | ||
|
||
error: the function takes `&mut` but `&` was provided | ||
┌─ tests/checking/receiver/calls_index_errors.move:30:9 | ||
│ | ||
30 │ (&v[0].t.w).merge(w) | ||
│ ^^^^^^^^^^^ |
33 changes: 33 additions & 0 deletions
33
third_party/move/move-compiler-v2/tests/checking/receiver/calls_index_errors.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::m { | ||
|
||
struct S has key, drop { t: T } | ||
|
||
struct T has store, drop { | ||
w: W | ||
} | ||
|
||
struct W has store, drop { | ||
x: u64 | ||
} | ||
|
||
fun merge(self: &mut W, s: W) { | ||
self.x += s.x; | ||
} | ||
|
||
fun merge_non_receiver(self1: &mut W, s: W) { | ||
self1.x += s.x; | ||
} | ||
|
||
fun foo_non_receiver(account: address, w: W) acquires S { | ||
S[account].t.w.merge_non_receiver(w) | ||
} | ||
|
||
fun foo_(account: address, w: W) acquires S { | ||
(&S[account].t.w).merge(w) | ||
} | ||
|
||
fun boo_(v: vector<S>, w: W) { | ||
(&v[0].t.w).merge(w) | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
third_party/move/move-compiler-v2/transactional-tests/tests/no-v1-comparison/index.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 |
---|---|---|
@@ -1 +1 @@ | ||
processed 25 tasks | ||
processed 29 tasks |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add the following test case (or similar) that tests:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done