forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move][move-2024] Add match fix for typing around literal switches, p…
…lus tests (MystenLabs#19133) ## Description This addresses a bug where `abort` was causing mistyped literal arm binders in match compilation. It also addresses some false-positive dead code complaints that I discovered while fixing the bug up. Longer-term, it would be nice to eliminate temp binders of the form `#%1: _|_ = unreachable` from HLIR generation so that CFGIR can invariantly ensure none exist, catching these sorts of issues, but due to multiple-binding forms `(x, y, z) = (abort 0, abort 1, abort 2)` and the current structure of the pass, that is work left for another day. ## Test plan Several more tests to cover these cases, though still never enough. --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API:
- Loading branch information
Showing
22 changed files
with
231 additions
and
20 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/lit_abort.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 @@ | ||
processed 3 tasks |
19 changes: 19 additions & 0 deletions
19
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/lit_abort.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,19 @@ | ||
//# init --edition 2024.beta | ||
|
||
//# publish | ||
module 0x42::m { | ||
public fun from_index(index: u64): u64 { | ||
match (index) { | ||
0 => 1, | ||
1 => 2, | ||
2 => 3, | ||
_ => abort 0, | ||
} | ||
} | ||
|
||
public fun run() { | ||
assert!(from_index(2) == 3) | ||
} | ||
} | ||
|
||
//# run 0x42::m::run |
1 change: 1 addition & 0 deletions
1
...rnal-crates/move/crates/move-compiler-transactional-tests/tests/matching/struct_abort.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 @@ | ||
processed 3 tasks |
19 changes: 19 additions & 0 deletions
19
...nal-crates/move/crates/move-compiler-transactional-tests/tests/matching/struct_abort.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,19 @@ | ||
//# init --edition 2024.beta | ||
|
||
//# publish | ||
module 0x42::m { | ||
public struct S has drop { x: u64 } | ||
|
||
public fun from_index(s: S): u64 { | ||
match (s) { | ||
S { x: 0} => 1, | ||
_ => abort 0, | ||
} | ||
} | ||
|
||
public fun run() { | ||
assert!(from_index(S { x: 0 }) == 1) | ||
} | ||
} | ||
|
||
//# run 0x42::m::run |
1 change: 1 addition & 0 deletions
1
...-crates/move/crates/move-compiler-transactional-tests/tests/matching/true_false_abort.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 @@ | ||
processed 3 tasks |
17 changes: 17 additions & 0 deletions
17
...crates/move/crates/move-compiler-transactional-tests/tests/matching/true_false_abort.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,17 @@ | ||
//# init --edition 2024.beta | ||
|
||
//# publish | ||
module 0x42::m { | ||
public fun test(value: bool): u64 { | ||
match (value) { | ||
true => abort 0, | ||
false => 0, | ||
} | ||
} | ||
|
||
public fun run() { | ||
assert!(test(false) == 0) | ||
} | ||
} | ||
|
||
//# run 0x42::m::run |
1 change: 1 addition & 0 deletions
1
.../move/crates/move-compiler-transactional-tests/tests/matching/true_false_nested_abort.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 @@ | ||
processed 3 tasks |
17 changes: 17 additions & 0 deletions
17
...move/crates/move-compiler-transactional-tests/tests/matching/true_false_nested_abort.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,17 @@ | ||
//# init --edition 2024.beta | ||
|
||
//# publish | ||
module 0x42::m { | ||
public fun test(value: bool): u64 { | ||
match (value) { | ||
true => match (value) { true => abort 0, false => abort 0 }, | ||
false => match (value) { true => abort 0, false => 1 }, | ||
} | ||
} | ||
|
||
public fun run() { | ||
assert!(test(false) == 1) | ||
} | ||
} | ||
|
||
//# run 0x42::m::run |
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
8 changes: 8 additions & 0 deletions
8
external-crates/move/crates/move-compiler/tests/move_2024/hlir/abort_pair.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,8 @@ | ||
warning[W09005]: dead or unreachable code | ||
┌─ tests/move_2024/hlir/abort_pair.move:4:6 | ||
│ | ||
4 │ (abort 0, abort 0) | ||
│ ^^^^^^^ Expected a value. Any code surrounding or after this expression will not be reached | ||
│ | ||
= This warning can be suppressed with '#[allow(dead_code)]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
5 changes: 5 additions & 0 deletions
5
external-crates/move/crates/move-compiler/tests/move_2024/hlir/abort_pair.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,5 @@ | ||
module 0x42::m; | ||
|
||
public fun test(): (u64, u64) { | ||
(abort 0, abort 0) | ||
} |
5 changes: 5 additions & 0 deletions
5
external-crates/move/crates/move-compiler/tests/move_2024/hlir/determine_error.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,5 @@ | ||
module 0x42::m; | ||
|
||
public fun report_from_value(code: u64) { | ||
if (code < 10) abort 0 else abort 1 | ||
} |
9 changes: 9 additions & 0 deletions
9
external-crates/move/crates/move-compiler/tests/move_2024/hlir/nested_if_abort.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::m; | ||
|
||
fun test() { | ||
if (true) { | ||
if (true) abort 0 else abort 0 | ||
} else { | ||
if (true) abort 0 else abort 0 | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
external-crates/move/crates/move-compiler/tests/move_2024/hlir/nested_if_abort_statement.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,16 @@ | ||
warning[W09005]: dead or unreachable code | ||
┌─ tests/move_2024/hlir/nested_if_abort_statement.move:5:9 | ||
│ | ||
5 │ if (true) abort 0 else abort 0 | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected a value. Any code surrounding or after this expression will not be reached | ||
│ | ||
= This warning can be suppressed with '#[allow(dead_code)]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
warning[W09005]: dead or unreachable code | ||
┌─ tests/move_2024/hlir/nested_if_abort_statement.move:7:9 | ||
│ | ||
7 │ if (true) abort 0 else abort 0 | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected a value. Any code surrounding or after this expression will not be reached | ||
│ | ||
= This warning can be suppressed with '#[allow(dead_code)]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
10 changes: 10 additions & 0 deletions
10
...rnal-crates/move/crates/move-compiler/tests/move_2024/hlir/nested_if_abort_statement.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,10 @@ | ||
module 0x42::m; | ||
|
||
fun test(): u64 { | ||
let x: u64 = if (true) { | ||
if (true) abort 0 else abort 0 | ||
} else { | ||
if (true) abort 0 else abort 0 | ||
}; | ||
x | ||
} |
17 changes: 17 additions & 0 deletions
17
external-crates/move/crates/move-compiler/tests/move_2024/hlir/true_false_nested_abort.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,17 @@ | ||
//# init --edition 2024.beta | ||
|
||
//# publish | ||
module 0x42::m { | ||
public fun test(value: bool): u64 { | ||
match (value) { | ||
true => match (value) { true => abort 0, false => abort 0 }, | ||
false => match (value) { true => abort 0, false => 1 }, | ||
} | ||
} | ||
|
||
public fun run() { | ||
assert!(test(false) == 1) | ||
} | ||
} | ||
|
||
//# run 0x42::m::run |
19 changes: 19 additions & 0 deletions
19
external-crates/move/crates/move-compiler/tests/move_2024/matching/lit_abort.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,19 @@ | ||
//# init --edition 2024.beta | ||
|
||
//# publish | ||
module 0x42::m { | ||
public fun from_index(index: u64): u64 { | ||
match (index) { | ||
0 => 1, | ||
1 => 2, | ||
2 => 3, | ||
_ => abort 0, | ||
} | ||
} | ||
|
||
public fun run() { | ||
assert!(from_index(2) == 3) | ||
} | ||
} | ||
|
||
//# run 0x42::m::run |
19 changes: 19 additions & 0 deletions
19
external-crates/move/crates/move-compiler/tests/move_2024/matching/struct_abort.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,19 @@ | ||
//# init --edition 2024.beta | ||
|
||
//# publish | ||
module 0x42::m { | ||
public struct S has drop { x: u64 } | ||
|
||
public fun from_index(s: S): u64 { | ||
match (s) { | ||
S { x: 0} => 1, | ||
_ => abort 0, | ||
} | ||
} | ||
|
||
public fun run() { | ||
assert!(from_index(S { x: 0 }) == 1) | ||
} | ||
} | ||
|
||
//# run 0x42::m::run |
17 changes: 17 additions & 0 deletions
17
external-crates/move/crates/move-compiler/tests/move_2024/matching/true_false_abort.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,17 @@ | ||
//# init --edition 2024.beta | ||
|
||
//# publish | ||
module 0x42::m { | ||
public fun test(value: bool): u64 { | ||
match (value) { | ||
true => abort 0, | ||
false => 0, | ||
} | ||
} | ||
|
||
public fun run() { | ||
assert!(test(false) == 0) | ||
} | ||
} | ||
|
||
//# run 0x42::m::run |
17 changes: 17 additions & 0 deletions
17
...al-crates/move/crates/move-compiler/tests/move_2024/matching/true_false_nested_abort.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,17 @@ | ||
//# init --edition 2024.beta | ||
|
||
//# publish | ||
module 0x42::m { | ||
public fun test(value: bool): u64 { | ||
match (value) { | ||
true => match (value) { true => abort 0, false => abort 0 }, | ||
false => match (value) { true => abort 0, false => 1 }, | ||
} | ||
} | ||
|
||
public fun run() { | ||
assert!(test(false) == 1) | ||
} | ||
} | ||
|
||
//# run 0x42::m::run |