-
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.
[compiler v2] Fix bugs around compilation of vector code (#9636)
* [compiler v2] Fix bugs around compilation of vector code This fixes a few bugs and closes #9629 - Usage of precompiled stdlib in transactional tests: v2 compiler currently (and probably never) supports precompiled modules, working around this - Stack-based bytecode generator created wrong target on generic function calls - Needed to make implicit conversion from `&mut` to `&` explicit in generated bytecode via Freeze operation Added some additional tests while debugging this. * Adding a new option `--print-bytecode` which can be provided to the `//# publish` and `//# run` transactional test runner command. This is the applied (for now) to the `sorter` test case only. Also introduced logic to map well-known vector functions to the associated builtin opcodes.
- Loading branch information
Showing
14 changed files
with
998 additions
and
21 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
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
46 changes: 46 additions & 0 deletions
46
third_party/move/move-compiler-v2/tests/bytecode-generator/reference_conversion.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,46 @@ | ||
// ---- Model Dump | ||
module 0x42::reference_conversion { | ||
private fun deref(r: &u64) { | ||
Deref(r) | ||
} | ||
private fun use_it() { | ||
{ | ||
let x: u64 = 42; | ||
{ | ||
let r: &mut u64 = Borrow(Mutable)(x); | ||
r = 43; | ||
reference_conversion::deref(r) | ||
} | ||
} | ||
} | ||
} // end 0x42::reference_conversion | ||
|
||
============ initial bytecode ================ | ||
|
||
[variant baseline] | ||
fun reference_conversion::deref($t0: &u64): u64 { | ||
var $t1: u64 | ||
0: $t1 := read_ref($t0) | ||
1: return $t1 | ||
} | ||
|
||
|
||
[variant baseline] | ||
fun reference_conversion::use_it(): u64 { | ||
var $t0: u64 | ||
var $t1: u64 | ||
var $t2: u64 | ||
var $t3: &mut u64 | ||
var $t4: &mut u64 | ||
var $t5: u64 | ||
var $t6: &u64 | ||
0: $t2 := 42 | ||
1: $t1 := move($t2) | ||
2: $t4 := borrow_local($t1) | ||
3: $t3 := move($t4) | ||
4: $t5 := 43 | ||
5: write_ref($t3, $t5) | ||
6: $t6 := freeze_ref($t3) | ||
7: $t0 := reference_conversion::deref($t6) | ||
8: return $t0 | ||
} |
15 changes: 15 additions & 0 deletions
15
third_party/move/move-compiler-v2/tests/bytecode-generator/reference_conversion.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,15 @@ | ||
module 0x42::reference_conversion { | ||
|
||
fun deref(r: &u64): u64 { | ||
*r | ||
} | ||
|
||
fun use_it(): u64 { | ||
let x = 42; | ||
let r = &mut x; | ||
*r = 43; | ||
deref(r) | ||
} | ||
|
||
|
||
} |
58 changes: 58 additions & 0 deletions
58
third_party/move/move-compiler-v2/tests/file-format-generator/generic_call.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,58 @@ | ||
============ initial bytecode ================ | ||
|
||
[variant baseline] | ||
fun Test::foo($t0: u64): u64 { | ||
var $t1: u64 | ||
0: $t1 := Test::identity<u64>($t0) | ||
1: return $t1 | ||
} | ||
|
||
|
||
[variant baseline] | ||
fun Test::identity<#0>($t0: #0): #0 { | ||
var $t1: #0 | ||
0: $t1 := move($t0) | ||
1: return $t1 | ||
} | ||
|
||
============ after LiveVarAnalysisProcessor: ================ | ||
|
||
[variant baseline] | ||
fun Test::foo($t0: u64): u64 { | ||
var $t1: u64 | ||
# live vars: $t0 | ||
0: $t1 := Test::identity<u64>($t0) | ||
# live vars: $t1 | ||
1: return $t1 | ||
} | ||
|
||
|
||
[variant baseline] | ||
fun Test::identity<#0>($t0: #0): #0 { | ||
var $t1: #0 | ||
# live vars: $t0 | ||
0: $t1 := move($t0) | ||
# live vars: $t1 | ||
1: return $t1 | ||
} | ||
|
||
|
||
============ disassembled file-format ================== | ||
// Move bytecode v6 | ||
module 42.Test { | ||
|
||
|
||
foo(Arg0: u64): u64 { | ||
B0: | ||
0: MoveLoc[0](Arg0: u64) | ||
1: Call identity<u64>(u64): u64 | ||
2: Ret | ||
} | ||
identity<Ty0>(Arg0: Ty0): Ty0 { | ||
B0: | ||
0: MoveLoc[0](Arg0: Ty0) | ||
1: StLoc[1](loc0: Ty0) | ||
2: MoveLoc[1](loc0: Ty0) | ||
3: Ret | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
third_party/move/move-compiler-v2/tests/file-format-generator/generic_call.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,9 @@ | ||
module 0x42::Test { | ||
fun identity<T>(x: T): T { | ||
x | ||
} | ||
|
||
fun foo(x: u64): u64 { | ||
identity(x) | ||
} | ||
} |
Oops, something went wrong.