-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[7][15/n][enums/Move] Add flavor to serialized compiled module for versions >= 7 #17706
Merged
tzakian
merged 2 commits into
tzakian/move-enums-sui-tests
from
tzakian/move-enums-flavor-version
May 24, 2024
Merged
Changes from all commits
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
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
664 changes: 332 additions & 332 deletions
664
crates/sui-adapter-transactional-tests/tests/upgrade/type_names.exp
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
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 |
---|---|---|
|
@@ -19,6 +19,57 @@ use std::{ | |
mem::size_of, | ||
}; | ||
|
||
// Static assertions about the encoding of the flavor into the version of the binary format. | ||
const _: () = { | ||
let x = BinaryFlavor::shift_and_flavor(0u32); | ||
// Make sure that the flavoring is added in the correct position in the u32. | ||
// It should always be `0x05XX_XXXX` where `XX_XXXX` is the version digits. | ||
assert!(x == 0x0500_0000u32); | ||
// Make sure that the flavoring is extracted correctly. | ||
assert!(BinaryFlavor::mask_and_shift_to_unflavor(x) == BinaryFlavor::SUI_FLAVOR); | ||
}; | ||
|
||
/// Encoding of a the flavor into the version of the binary format for versions >= 7. | ||
pub struct BinaryFlavor; | ||
impl BinaryFlavor { | ||
pub const FLAVOR_MASK: u32 = 0xFF00_0000; | ||
pub const VERSION_MASK: u32 = 0x00FF_FFFF; | ||
// The Sui flavor is 0x05 | ||
pub const SUI_FLAVOR: u8 = 0x05; | ||
const SHIFT_AMOUNT: u8 = 24; | ||
Comment on lines
+35
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there is a more-canonical way to do this in Rust, since we're doing it a few places now. |
||
|
||
pub fn encode_version(unflavored_version: u32) -> u32 { | ||
if unflavored_version <= VERSION_6 { | ||
return unflavored_version; | ||
} | ||
|
||
debug_assert!(unflavored_version & Self::VERSION_MASK == unflavored_version); | ||
Self::shift_and_flavor(unflavored_version) | ||
} | ||
|
||
pub fn decode_version(flavored_version: u32) -> u32 { | ||
if flavored_version <= VERSION_6 { | ||
return flavored_version; | ||
} | ||
flavored_version & Self::VERSION_MASK | ||
} | ||
|
||
pub fn decode_flavor(flavored_version: u32) -> Option<u8> { | ||
if flavored_version <= VERSION_6 { | ||
return None; | ||
} | ||
Some(Self::mask_and_shift_to_unflavor(flavored_version)) | ||
} | ||
|
||
const fn mask_and_shift_to_unflavor(flavored: u32) -> u8 { | ||
((flavored & Self::FLAVOR_MASK) >> Self::SHIFT_AMOUNT) as u8 | ||
} | ||
|
||
const fn shift_and_flavor(unflavored: u32) -> u32 { | ||
(Self::SUI_FLAVOR as u32) << Self::SHIFT_AMOUNT | unflavored | ||
} | ||
} | ||
|
||
/// Constant values for the binary format header. | ||
/// | ||
/// The binary header is magic + version info + table count. | ||
|
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
2 changes: 1 addition & 1 deletion
2
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_binder.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...rates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_mut_ref.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...rates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_no_drop.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...al-crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_ref.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...-crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_twice.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...ove/crates/move-compiler-transactional-tests/tests/matching/abc_match_value_wildcard.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...-crates/move/crates/move-compiler-transactional-tests/tests/matching/at_pattern_copy.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...-crates/move/crates/move-compiler-transactional-tests/tests/matching/at_pattern_drop.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...l-crates/move/crates/move-compiler-transactional-tests/tests/matching/at_pattern_lit.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...crates/move/crates/move-compiler-transactional-tests/tests/matching/at_pattern_reuse.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...rnal-crates/move/crates/move-compiler-transactional-tests/tests/matching/bad_guard_1.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...rnal-crates/move/crates/move-compiler-transactional-tests/tests/matching/bad_guard_2.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/basic.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...nal-crates/move/crates/move-compiler-transactional-tests/tests/matching/bind_subject.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/const_at.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...l-crates/move/crates/move-compiler-transactional-tests/tests/matching/const_in_guard.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...l-crates/move/crates/move-compiler-transactional-tests/tests/matching/const_matching.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...-crates/move/crates/move-compiler-transactional-tests/tests/matching/const_mut_guard.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
|
||
//# publish | ||
|
2 changes: 1 addition & 1 deletion
2
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/const_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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...nal-crates/move/crates/move-compiler-transactional-tests/tests/matching/const_result.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/const_self.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/drop_ref.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...es/move/crates/move-compiler-transactional-tests/tests/matching/enum_no_tyargs_match.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...-crates/move/crates/move-compiler-transactional-tests/tests/matching/enum_poly_match.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
...rates/move/crates/move-compiler-transactional-tests/tests/matching/exhaustive_struct.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
2 changes: 1 addition & 1 deletion
2
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/fib.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//# init --edition development | ||
//# init --edition 2024.alpha | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
Is it worth naming this for easier debugging if the assertions ever fail?
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.
Probably not, but I'll add some more comments!