This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Compiler-v2] Relax check on whether a local can be written (#12890)
* fix * release GitOrigin-RevId: e5d6d257eefdf9530ce6eb5129e2f6cbbbea8b88
- Loading branch information
1 parent
0920342
commit 64f5086
Showing
9 changed files
with
146 additions
and
0 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
2 changes: 2 additions & 0 deletions
2
language/move-compiler-v2/tests/reference-safety/write_ref_dest.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,2 @@ | ||
|
||
============ bytecode verification succeeded ======== |
19 changes: 19 additions & 0 deletions
19
language/move-compiler-v2/tests/reference-safety/write_ref_dest.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,19 @@ | ||
module 0x42::m { | ||
|
||
fun foo(x: &vector<u64>): (vector<u64>, u64) { | ||
(*x, 0) | ||
} | ||
|
||
|
||
fun test_call() { | ||
let y = vector[]; | ||
(y, _) = foo(&y); | ||
assert!(y == vector[], 0); | ||
} | ||
|
||
fun test_assign() { | ||
let y = vector[1]; | ||
(y, _) = (*&y, 1); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
language/move-compiler-v2/tests/reference-safety/write_ref_dest.no-opt.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,2 @@ | ||
|
||
============ bytecode verification succeeded ======== |
21 changes: 21 additions & 0 deletions
21
language/move-compiler-v2/tests/reference-safety/write_ref_dest_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,21 @@ | ||
|
||
Diagnostics: | ||
error: cannot assign to borrowed local `_y` | ||
┌─ tests/reference-safety/write_ref_dest_err.move:18:19 | ||
│ | ||
17 │ let z = &_y; | ||
│ --- previous local borrow | ||
18 │ (_y, _) = foo(&_y); | ||
│ ^^^^^^^^ attempted to assign here | ||
19 │ *z; | ||
│ -- conflicting reference `z` used here | ||
|
||
error: cannot assign to borrowed local `_y` | ||
┌─ tests/reference-safety/write_ref_dest_err.move:25:9 | ||
│ | ||
24 │ let z = &_y; | ||
│ --- previous local borrow | ||
25 │ _y = vector[2]; | ||
│ ^^^^^^^^^^^^^^ attempted to assign here | ||
26 │ *z; | ||
│ -- conflicting reference `z` used here |
29 changes: 29 additions & 0 deletions
29
language/move-compiler-v2/tests/reference-safety/write_ref_dest_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,29 @@ | ||
module 0x42::m { | ||
|
||
struct S has key, drop { | ||
|
||
} | ||
|
||
fun g(s: &S): &S { | ||
s | ||
} | ||
|
||
fun foo(x: &vector<u64>): (vector<u64>, u64) { | ||
(*x, 0) | ||
} | ||
|
||
fun test_call() { | ||
let _y = vector[1]; | ||
let z = &_y; | ||
(_y, _) = foo(&_y); | ||
*z; | ||
} | ||
|
||
fun test_assign() { | ||
let _y = vector[1]; | ||
let z = &_y; | ||
_y = vector[2]; | ||
*z; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
language/move-compiler-v2/tests/reference-safety/write_ref_dest_err.no-opt.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,21 @@ | ||
|
||
Diagnostics: | ||
error: cannot assign to borrowed local `_y` | ||
┌─ tests/reference-safety/write_ref_dest_err.move:18:19 | ||
│ | ||
17 │ let z = &_y; | ||
│ --- previous local borrow | ||
18 │ (_y, _) = foo(&_y); | ||
│ ^^^^^^^^ attempted to assign here | ||
19 │ *z; | ||
│ -- conflicting reference `z` used here | ||
|
||
error: cannot assign to borrowed local `_y` | ||
┌─ tests/reference-safety/write_ref_dest_err.move:25:9 | ||
│ | ||
24 │ let z = &_y; | ||
│ --- previous local borrow | ||
25 │ _y = vector[2]; | ||
│ ^^^^^^^^^^^^^^ attempted to assign here | ||
26 │ *z; | ||
│ -- conflicting reference `z` used here |
3 changes: 3 additions & 0 deletions
3
language/move-compiler-v2/transactional-tests/tests/misc/write_ref_dest.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,3 @@ | ||
processed 3 tasks | ||
|
||
==> Compiler v2 delivered same results! |
25 changes: 25 additions & 0 deletions
25
language/move-compiler-v2/transactional-tests/tests/misc/write_ref_dest.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,25 @@ | ||
//# publish | ||
module 0x42::m { | ||
|
||
fun foo(x: &vector<u64>): (vector<u64>, u64) { | ||
(*x, 0) | ||
} | ||
|
||
|
||
fun test_call() { | ||
let y = vector[]; | ||
(y, _) = foo(&y); | ||
assert!(y == vector[], 0); | ||
} | ||
|
||
fun test_assign() { | ||
let y = vector[1]; | ||
(y, _) = (*&y, 1); | ||
assert!(y == vector[1], 0); | ||
} | ||
|
||
} | ||
|
||
//# run 0x42::m::test_call --check-runtime-types | ||
|
||
//# run 0x42::m::test_assign --check-runtime-types |