-
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
[move-vm][closures] Refactor: move abilities and closure mask into core types #15668
base: wrwg/clos_file_format
Are you sure you want to change the base?
Conversation
⏱️ 50m total CI duration on this PR
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
e45e16d
to
f92e339
Compare
34517a1
to
7862e77
Compare
1a207d1
to
9688bde
Compare
7862e77
to
ee49138
Compare
9688bde
to
f2effc9
Compare
ee49138
to
9fbe74f
Compare
third_party/move/move-compiler-v2/src/pipeline/ability_processor.rs
Outdated
Show resolved
Hide resolved
third_party/move/move-ir-compiler/move-bytecode-source-map/src/source_map.rs
Outdated
Show resolved
Hide resolved
} | ||
|
||
impl ClosureMask { | ||
pub const MAX_ARGS: usize = 64; |
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 should be used somewhere? Please add tests to closure operations. They are quite easy to unit tests but also easy to get wrong
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 is an interesting methodological disagreement.
I believe unit tests on this atomic level are counter productive. Better one can read the code and verify/"see" its working, as it is now the case. If the code would be so complex you need unit tests, something wrong with it. (As it was with the version in the previous PR.)
Indeed, the feature will be extensively tested by higher-level tests as it is a basic mechanism used in many places.
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.
PS. Bzgl. MAX_ARGS
, I expect it used by the compiler. In the stack machine of the VM it plays no role because we never check "number of arguments correct", this is implicit via stack balancing.
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.
(2) Regarding number of arguments and MAX_ARGS
: let's document that this is implicit via stack balancing. This helps reviews, security reviews, etc. and if someone else comes working on this code one does not need to spend searching through the codebase for all thus implicit checks.
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.
(1) Regarding unit tests:
I disagree. Unit test exists exactly for this purpose to verify small components work as expected and test corner cases. Good tests act as a spec by itself describing behaviour (there is a reason why TDD was created). Saying "my code works, just read it and see" is not a great practice in my opinion: previous iteration of a mask had a panic on certain inputs - was it expected, unreachable code? These things should be documented and tested explicitly.
For example, since you derive Arbitrary
and say that mask.compose(mask.extract(v, true), mask.extract(v, false)) == v
should be preserved, a simple proptest doing this would be good. Actually, your extract
right now skips elements > 64, so this property does not hold for all v
.
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.
But let's also hear what other folks think: @ziaptos @vgao1996 @runtian-zhou @vineethk
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.
You want me to actually write a test for this code:
let mut mask = self.0;
values
.iter()
.filter(|_| {
let set = mask & 0x1 != 0;
mask >>= 1;
set && collect_captured || !set && !collect_captured
})
.collect()
Sorry, I won't. The code is already the spec.
Unnecessary unit tests are a kind of technical debt . You come back to change structure or semantics, the tests are a drag. This is a series of PRs where things evolve, and the basic concepts are revisited while solving each layer in the stack.
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.
(2) Regarding number of arguments and MAX_ARGS: let's document t
Done
f2effc9
to
3c767c3
Compare
a79fde9
to
719f728
Compare
3c767c3
to
0aa8d5d
Compare
719f728
to
41d027e
Compare
0aa8d5d
to
301ccae
Compare
41d027e
to
8e5b22c
Compare
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.
I would strongly argue in favour of unit testing for the mask, but otherwise looks good
301ccae
to
c879216
Compare
8e5b22c
to
6aa1fbf
Compare
0ebce3a
to
58fbf2b
Compare
6aa1fbf
to
94836d9
Compare
…re types [PR 2/n vm closures] The type `AbilitySet` is required in `MoveTypeLayout`, and the type `ClosureMask` in `MoveValue`. This PRs moves those both types from file_format into the core types crate.
58fbf2b
to
d9a4a9f
Compare
94836d9
to
da757e8
Compare
da757e8
to
c078929
Compare
Description
[PR 2/n vm closures]
The type
AbilitySet
is required inMoveTypeLayout
, and the typeClosureMask
inMoveValue
. This PRs moves those both types from file_format into the core types crate.How Has This Been Tested?
Existing tests
Type of Change
Which Components or Systems Does This Change Impact?