Skip to content

Commit

Permalink
[compiler-v2] Showcase fixes for several old issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethk committed Jan 31, 2025
1 parent f246671 commit aa1195c
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

============ disassembled file-format ==================
// Move bytecode v8
module c0ffee.m {


public test(): u64 /* def_idx: 0 */ {
B0:
0: LdU64(2)
1: Call test1(u64): u64
2: LdU64(5)
3: Call test2(u64): u64
4: Add
5: Ret
}
test1(Arg0: u64): u64 /* def_idx: 1 */ {
B0:
0: MoveLoc[0](Arg0: u64)
1: LdU64(1)
2: Add
3: Ret
}
test2(Arg0: u64): u64 /* def_idx: 2 */ {
B0:
0: MoveLoc[0](Arg0: u64)
1: LdU64(2)
2: Add
3: Ret
}
}
============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Example taken from https://github.com/aptos-labs/aptos-core/issues/12404#issuecomment-2004040746
module 0xc0ffee::m {
fun test1(x: u64): u64 {
x + 1
}

fun test2(x: u64): u64 {
x + 2
}

public fun test(): u64 {
test1(2) + test2(5)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

============ disassembled file-format ==================
// Move bytecode v8
module c0ffee.m {


public test(): u64 /* def_idx: 0 */ {
B0:
0: LdU64(2)
1: Call test1(u64): u64
2: LdU64(5)
3: Call test2(u64): u64
4: Add
5: Ret
}
test1(Arg0: u64): u64 /* def_idx: 1 */ {
B0:
0: MoveLoc[0](Arg0: u64)
1: LdU64(1)
2: Add
3: Ret
}
test2(Arg0: u64): u64 /* def_idx: 2 */ {
B0:
0: MoveLoc[0](Arg0: u64)
1: LdU64(2)
2: Add
3: Ret
}
}
============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

============ disassembled file-format ==================
// Move bytecode v8
module c0ffee.m {


public point_add_assign(Arg0: &mut u64, Arg1: &u64): &mut u64 /* def_idx: 0 */ {
L2: loc0: &mut u64
B0:
0: CopyLoc[0](Arg0: &mut u64)
1: FreezeRef
2: MoveLoc[1](Arg1: &u64)
3: LdTrue
4: Call point_add_internal(&u64, &u64, bool): u64
5: MoveLoc[0](Arg0: &mut u64)
6: StLoc[2](loc0: &mut u64)
7: Pop
8: MoveLoc[2](loc0: &mut u64)
9: Ret
}
point_add_internal(Arg0: &u64, Arg1: &u64, Arg2: bool): u64 /* def_idx: 1 */ {
B0:
0: MoveLoc[0](Arg0: &u64)
1: ReadRef
2: MoveLoc[1](Arg1: &u64)
3: ReadRef
4: Add
5: Ret
}
}
============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Code example taken from https://github.com/aptos-labs/aptos-core/issues/12540
module 0xc0ffee::m {
fun point_add_internal(a: &u64, b: &u64, _in_place: bool): u64 {
*a + *b
}

public fun point_add_assign(a: &mut u64, b: &u64): &mut u64 {
point_add_internal(a, b, true);
a
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

============ disassembled file-format ==================
// Move bytecode v8
module c0ffee.m {


public point_add_assign(Arg0: &mut u64, Arg1: &u64): &mut u64 /* def_idx: 0 */ {
B0:
0: CopyLoc[0](Arg0: &mut u64)
1: FreezeRef
2: MoveLoc[1](Arg1: &u64)
3: LdTrue
4: Call point_add_internal(&u64, &u64, bool): u64
5: Pop
6: MoveLoc[0](Arg0: &mut u64)
7: Ret
}
point_add_internal(Arg0: &u64, Arg1: &u64, Arg2: bool): u64 /* def_idx: 1 */ {
B0:
0: MoveLoc[0](Arg0: &u64)
1: ReadRef
2: MoveLoc[1](Arg1: &u64)
3: ReadRef
4: Add
5: Ret
}
}
============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

============ disassembled file-format ==================
// Move bytecode v8
module c0ffee.m {


id_mut<Ty0>(Arg0: &mut Ty0): &mut Ty0 /* def_idx: 0 */ {
B0:
0: MoveLoc[0](Arg0: &mut Ty0)
1: Ret
}
t0() /* def_idx: 1 */ {
L0: loc0: u64
L1: loc1: &mut u64
B0:
0: LdU64(0)
1: StLoc[0](loc0: u64)
2: MutBorrowLoc[0](loc0: u64)
3: StLoc[1](loc1: &mut u64)
4: CopyLoc[1](loc1: &mut u64)
5: Call id_mut<u64>(&mut u64): &mut u64
6: ReadRef
7: MoveLoc[1](loc1: &mut u64)
8: ReadRef
9: Pop
10: Pop
11: Ret
}
}
============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Example taken from https://github.com/aptos-labs/aptos-core/issues/14243
module 0xc0ffee::m {
fun id_mut<T>(r: &mut T): &mut T {
r
}

fun t0() {
let x = &mut 0;
let y = id_mut(x);
*y;
*x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

============ disassembled file-format ==================
// Move bytecode v8
module c0ffee.m {


id_mut<Ty0>(Arg0: &mut Ty0): &mut Ty0 /* def_idx: 0 */ {
B0:
0: MoveLoc[0](Arg0: &mut Ty0)
1: Ret
}
t0() /* def_idx: 1 */ {
L0: loc0: u64
L1: loc1: &mut u64
B0:
0: LdU64(0)
1: StLoc[0](loc0: u64)
2: MutBorrowLoc[0](loc0: u64)
3: StLoc[1](loc1: &mut u64)
4: CopyLoc[1](loc1: &mut u64)
5: Call id_mut<u64>(&mut u64): &mut u64
6: ReadRef
7: Pop
8: MoveLoc[1](loc1: &mut u64)
9: ReadRef
10: Pop
11: Ret
}
}
============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comparison between v1 and v2 failed:
- processed 2 tasks
-
- task 1 'publish'. lines 11-16:
- Error: bug[ICE12001]: BYTECODE GENERATION FAILED
- ┌─ TEMPFILE1:12:18
- │
- 12 │ module 0xc0ffee::dummy2 {
- │ ^^^^^^ IR ERROR: Missing constant definition for CC
-
-
-
+ processed 2 tasks
+
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Example taken from https://github.com/aptos-labs/aptos-core/issues/11022
//# publish
module 0xc0ffee::dummy1 {
const CC: u64 = 1;

public inline fun expose(): u64 {
CC
}
}

//# publish
module 0xc0ffee::dummy2 {
public fun main(): u64 {
0xc0ffee::dummy1::expose()
}
}

0 comments on commit aa1195c

Please sign in to comment.