Skip to content

Commit 045d564

Browse files
committed
[move compiler] [CSE Step 3] add test cases for CSE
1 parent b1833ab commit 045d564

19 files changed

+5007
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module 0x99::FiledAccess {
2+
struct Inner has copy, drop {
3+
value: u64,
4+
}
5+
6+
struct Outer has copy, drop {
7+
inner: Inner,
8+
}
9+
10+
fun get_value(outer: &Outer): u64 {
11+
outer.inner.value
12+
}
13+
14+
fun set_value(outer: &mut Outer, new_value: u64) {
15+
outer.inner.value = new_value;
16+
}
17+
18+
// `arg1.inner.value` cannot be reused due to the mutation between the two accesses
19+
fun test_field_access(arg1: Outer, arg2: u64): u64 {
20+
let x = arg1.inner.value;
21+
arg1.inner.value += 1;
22+
x + arg2 + arg1.inner.value
23+
}
24+
25+
// `arg1.inner.value` cannot be reused due to the mutation between the two accesses
26+
fun test_field_access_ref(arg1: Outer, arg2: u64): u64 {
27+
let x = arg1.inner.value;
28+
let ref = &mut arg1.inner.value;
29+
*ref += 1;
30+
x + arg2 + arg1.inner.value
31+
}
32+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
============ disassembled file-format ==================
3+
// Bytecode version v9
4+
module 0x99::FiledAccess
5+
struct Inner has copy + drop
6+
value: u64
7+
8+
struct Outer has copy + drop
9+
inner: Inner
10+
11+
// Function definition at index 0
12+
fun get_value(l0: &Outer): u64
13+
move_loc l0
14+
borrow_field Outer, inner
15+
borrow_field Inner, value
16+
read_ref
17+
ret
18+
19+
// Function definition at index 1
20+
fun set_value(l0: &mut Outer, l1: u64)
21+
local l2: &mut u64
22+
move_loc l0
23+
mut_borrow_field Outer, inner
24+
mut_borrow_field Inner, value
25+
st_loc l2
26+
move_loc l1
27+
// @5
28+
move_loc l2
29+
write_ref
30+
ret
31+
32+
// Function definition at index 2
33+
fun test_field_access(l0: Outer, l1: u64): u64
34+
local l2: &mut u64
35+
borrow_loc l0
36+
borrow_field Outer, inner
37+
borrow_field Inner, value
38+
read_ref
39+
mut_borrow_loc l0
40+
// @5
41+
mut_borrow_field Outer, inner
42+
mut_borrow_field Inner, value
43+
st_loc l2
44+
copy_loc l2
45+
read_ref
46+
// @10
47+
ld_u64 1
48+
add
49+
move_loc l2
50+
write_ref
51+
move_loc l1
52+
// @15
53+
add
54+
borrow_loc l0
55+
borrow_field Outer, inner
56+
borrow_field Inner, value
57+
read_ref
58+
// @20
59+
add
60+
ret
61+
62+
// Function definition at index 3
63+
fun test_field_access_ref(l0: Outer, l1: u64): u64
64+
local l2: &mut u64
65+
borrow_loc l0
66+
borrow_field Outer, inner
67+
borrow_field Inner, value
68+
read_ref
69+
mut_borrow_loc l0
70+
// @5
71+
mut_borrow_field Outer, inner
72+
mut_borrow_field Inner, value
73+
st_loc l2
74+
copy_loc l2
75+
read_ref
76+
// @10
77+
ld_u64 1
78+
add
79+
move_loc l2
80+
write_ref
81+
move_loc l1
82+
// @15
83+
add
84+
borrow_loc l0
85+
borrow_field Outer, inner
86+
borrow_field Inner, value
87+
read_ref
88+
// @20
89+
add
90+
ret
91+
92+
93+
============ bytecode verification succeeded ========

0 commit comments

Comments
 (0)