-
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 bugs around compilation of vector code #9636
Merged
Changes from 1 commit
Commits
Show all changes
2 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
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) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
third_party/move/move-compiler-v2/transactional-tests/tests/control_flow/sorter.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 2 tasks | ||
|
||
==> Compiler v2 delivered same results! | ||
brmataptos marked this conversation as resolved.
Show resolved
Hide resolved
|
73 changes: 73 additions & 0 deletions
73
third_party/move/move-compiler-v2/transactional-tests/tests/control_flow/sorter.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,73 @@ | ||
//# publish | ||
module 0x42::heap { | ||
use std::vector; | ||
|
||
fun create1(): vector<u64> { | ||
vector<u64>[3, 2, 1, 5, 8, 4] | ||
} | ||
|
||
fun create2(): vector<u64> { | ||
vector<u64>[1, 2, 3, 4, 5, 8] | ||
} | ||
|
||
fun vcopy(x: &vector<u64>): vector<u64> { | ||
let y : vector<u64> = vector::empty<u64>(); | ||
let i : u64 = 0; | ||
let l : u64 = vector::length<u64>(x); | ||
while (i < l) { | ||
vector::push_back<u64>(&mut y, *vector::borrow<u64>(x, i)); | ||
i = i + 1; | ||
}; | ||
y | ||
} | ||
|
||
fun sort(x: &mut vector<u64>) { | ||
let i: u64 = 0; | ||
while (i < vector::length<u64>(x)) { | ||
let j: u64 = i + 1; | ||
while (j < vector::length<u64>(x)) { | ||
if (*vector::borrow<u64>(x, i) > *vector::borrow<u64>(x, j)) { | ||
vector::swap<u64>(x, i, j) | ||
}; | ||
j = j + 1; | ||
}; | ||
i = i + 1; | ||
} | ||
} | ||
|
||
fun array_equals(x: &vector<u64>, y: &vector<u64>): bool { | ||
let l1: u64 = vector::length<u64>(x); | ||
let l2: u64 = vector::length<u64>(y); | ||
if (l1 != l2) { | ||
return false | ||
}; | ||
let i: u64 = 0; | ||
while (i < l1) { | ||
if (*vector::borrow<u64>(x, i) != *vector::borrow<u64>(y, i)) { | ||
return false | ||
}; | ||
i = i + 1; | ||
}; | ||
true | ||
} | ||
|
||
public fun main() { | ||
let x: vector<u64> = create1(); | ||
let y: vector<u64> = create2(); | ||
let z: vector<u64> = vcopy(&x); | ||
assert!(array_equals(&x, &z), 23); | ||
assert!(array_equals(&y, &y), 29); | ||
sort(&mut x); | ||
assert!(array_equals(&y, &x), 31); | ||
assert!(array_equals(&x, &y), 29); | ||
assert!(!array_equals(&x, &z), 31); | ||
} | ||
} | ||
|
||
//# run | ||
script { | ||
use 0x42::heap::main; | ||
fun mymain() { | ||
main(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
third_party/move/move-compiler-v2/transactional-tests/tests/evaluation_order/arg_order.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 2 tasks | ||
|
||
==> Compiler v2 delivered same results! |
18 changes: 18 additions & 0 deletions
18
third_party/move/move-compiler-v2/transactional-tests/tests/evaluation_order/arg_order.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,18 @@ | ||
//# publish | ||
module 0x42::test { | ||
public fun two_args(x: u64, b: bool): u64 { | ||
if (b) { | ||
x | ||
} else { | ||
0 | ||
} | ||
} | ||
} | ||
|
||
//# run | ||
script { | ||
use 0x42::test::two_args; | ||
fun mymain() { | ||
assert!(two_args(42, true) == 42, 1); | ||
} | ||
} |
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
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.
what is the advantage of this C style errors versus Rust errors?
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.
This actually neither or, its an error with source location information added to the compilers global environment, which can contain many of them. Its marked as 'internal' because it is unexpected. Nevertheless will be reported with possible errors at the source.
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.
+possible other errors at the source