-
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.
use ast::Value equivalence, not enum equality, to do constant folding…
… of constants (#12518) Some apparently different `ast::Value` values may represent the same runtime values (Value::ByteArray(..) and Value::AddressArray(..) values can each also be represented by Value::Vector(..) instead) and some may not be well-defined at compile time (different symbolic addresses could end up the same).
- Loading branch information
1 parent
3246c4a
commit 1b43e0e
Showing
13 changed files
with
458 additions
and
48 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
17 changes: 17 additions & 0 deletions
17
third_party/move/move-compiler-v2/tests/no-simplifier/constant_folding_ristretto.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,17 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0xcafe::Ristretto { | ||
public fun test() { | ||
{ | ||
let non_canonical_highbit: vector<u8> = Vector<u8>(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128); | ||
{ | ||
let non_canonical_highbit_hex: vector<u8> = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128]; | ||
if Eq<vector<u8>>(non_canonical_highbit, non_canonical_highbit_hex) { | ||
Tuple() | ||
} else { | ||
Abort(1) | ||
}; | ||
Tuple() | ||
} | ||
} | ||
} | ||
} // end 0xcafe::Ristretto |
8 changes: 8 additions & 0 deletions
8
third_party/move/move-compiler-v2/tests/no-simplifier/constant_folding_ristretto.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,8 @@ | ||
//# publish --print-bytecode | ||
module 0xcafe::Ristretto { | ||
public fun test() { | ||
let non_canonical_highbit = vector[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128]; | ||
let non_canonical_highbit_hex = x"0000000000000000000000000000000000000000000000000000000000000080"; | ||
assert!(non_canonical_highbit == non_canonical_highbit_hex, 1); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
third_party/move/move-compiler-v2/tests/simplifier/constant_folding_ristretto.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,11 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0xcafe::Ristretto { | ||
public fun test() { | ||
if true { | ||
Tuple() | ||
} else { | ||
Abort(1) | ||
}; | ||
Tuple() | ||
} | ||
} // end 0xcafe::Ristretto |
8 changes: 8 additions & 0 deletions
8
third_party/move/move-compiler-v2/tests/simplifier/constant_folding_ristretto.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,8 @@ | ||
//# publish --print-bytecode | ||
module 0xcafe::Ristretto { | ||
public fun test() { | ||
let non_canonical_highbit = vector[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128]; | ||
let non_canonical_highbit_hex = x"0000000000000000000000000000000000000000000000000000000000000080"; | ||
assert!(non_canonical_highbit == non_canonical_highbit_hex, 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
43 changes: 43 additions & 0 deletions
43
...move/move-compiler-v2/transactional-tests/tests/simplifier/constant_folding_ristretto.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,43 @@ | ||
processed 1 task | ||
|
||
task 0 'publish'. lines 1-8: | ||
|
||
|
||
|
||
==> Compiler v2 delivered same results! | ||
|
||
>>> V1 Compiler { | ||
== BEGIN Bytecode == | ||
// Move bytecode v6 | ||
module cafe.Ristretto { | ||
|
||
|
||
public test() /* def_idx: 0 */ { | ||
B0: | ||
0: Ret | ||
} | ||
} | ||
== END Bytecode == | ||
} | ||
|
||
>>> V2 Compiler { | ||
== BEGIN Bytecode == | ||
// Move bytecode v7 | ||
module cafe.Ristretto { | ||
|
||
|
||
public test() /* def_idx: 0 */ { | ||
B0: | ||
0: LdTrue | ||
1: BrFalse(3) | ||
B1: | ||
2: Branch(5) | ||
B2: | ||
3: LdU64(1) | ||
4: Abort | ||
B3: | ||
5: Ret | ||
} | ||
} | ||
== END Bytecode == | ||
} |
8 changes: 8 additions & 0 deletions
8
...ove/move-compiler-v2/transactional-tests/tests/simplifier/constant_folding_ristretto.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,8 @@ | ||
//# publish --print-bytecode | ||
module 0xcafe::Ristretto { | ||
public fun test() { | ||
let non_canonical_highbit = vector[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128]; | ||
let non_canonical_highbit_hex = x"0000000000000000000000000000000000000000000000000000000000000080"; | ||
assert!(non_canonical_highbit == non_canonical_highbit_hex, 1); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ty/move/move-compiler/transactional-tests/tests/simplifier/constant_folding_ristretto.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,19 @@ | ||
processed 1 task | ||
|
||
task 0 'publish'. lines 1-8: | ||
|
||
|
||
|
||
>>> V1 Compiler { | ||
== BEGIN Bytecode == | ||
// Move bytecode v6 | ||
module cafe.Ristretto { | ||
|
||
|
||
public test() /* def_idx: 0 */ { | ||
B0: | ||
0: Ret | ||
} | ||
} | ||
== END Bytecode == | ||
} |
8 changes: 8 additions & 0 deletions
8
...y/move/move-compiler/transactional-tests/tests/simplifier/constant_folding_ristretto.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,8 @@ | ||
//# publish --print-bytecode | ||
module 0xcafe::Ristretto { | ||
public fun test() { | ||
let non_canonical_highbit = vector[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128]; | ||
let non_canonical_highbit_hex = x"0000000000000000000000000000000000000000000000000000000000000080"; | ||
assert!(non_canonical_highbit == non_canonical_highbit_hex, 1); | ||
} | ||
} |
Oops, something went wrong.