-
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] Pattern matching for struct variants (aka enum types)
This implements the Move 2 `match` expression on stackless bytecode level. The PR consists of the following parts: 1. *Extending the Bytecode* There are a few new bytecode operations: ``` dest := TestVariant(struct_id, variant, src) dest := PackVariant(struct_id, variant, srcs) dests := UnpackVariant(struct_id, variant, src) dest := BorrowFieldVariant(struct_id, variant, field, src) ``` The `TestVariant` and `BorrowFieldVariant` operations expect references to the variant struct. The `UnpackVariant` and `BorrowFieldVariant` operations abort if the `src` value is not a value of the given variant. Notably, there are no new control flow operations, and the remaining part of the stackless bytecode framework should operate without changes. This may change in the future if we introduce a new branch instruction for switching over variants. 2. *Translating Matches* Matches are translated into cascades of test & branch instructions. The translation is complicated by the need for 'probing' whether a value can be matched before it is consumed. See for discussion in the code how this problem is solved. The current translation is manually reviewed via the baseline output, but it will not be fully tested before we are able to run e2e tests with VM execution. (Future PRs.) 3. *Checking Match Coverage* Even though we generate robust match code which is resilient against addition of new match variants by explicit `abort` if there is no match, at compile time complete match coverage is required. Checking for this is non-trivial because of the sequential, imperative semantics of matching. See documentation in the code. 4. *Other* There are some only indirectlyu related changes in this PR. To implement non-destructive matches with conditions, it appeared handy to have `*&x` to be equivalent to `x`. This seems to be general useful and is AFAICT also in Rust. Also, the new pattern translation is a bit more efficient also in the `let` case, leading to some changes in baseline files.
- Loading branch information
Showing
26 changed files
with
2,810 additions
and
1,036 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/bug_bbb75fa.v2_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 4 tasks |
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
941 changes: 828 additions & 113 deletions
941
third_party/move/move-compiler-v2/src/bytecode_generator.rs
Large diffs are not rendered by default.
Oops, something went wrong.
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
6 changes: 0 additions & 6 deletions
6
third_party/move/move-compiler-v2/tests/ability-check/v1-signer/read_ref_transitive.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
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
Oops, something went wrong.