Skip to content
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

Open
wants to merge 2 commits into
base: wrwg/clos_file_format
Choose a base branch
from

Conversation

wrwg
Copy link
Contributor

@wrwg wrwg commented Jan 4, 2025

Description

[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.

How Has This Been Tested?

Existing tests

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Performance improvement
  • Refactoring
  • Dependency update
  • Documentation update
  • Tests

Which Components or Systems Does This Change Impact?

  • Validator Node
  • Full Node (API, Indexer, etc.)
  • Move/Aptos Virtual Machine
  • Aptos Framework
  • Aptos CLI/SDK
  • Developer Infrastructure
  • Move Compiler
  • Other (specify)

Copy link

trunk-io bot commented Jan 4, 2025

⏱️ 50m total CI duration on this PR
Job Cumulative Duration Recent Runs
rust-move-tests 13m 🟩
rust-move-tests 13m 🟩
rust-move-tests 8m 🟥
rust-cargo-deny 7m 🟩🟩🟩🟩
check-dynamic-deps 3m 🟩🟩🟩🟩
rust-move-tests 2m 🟥
general-lints 2m 🟩🟩🟩🟩
semgrep/ci 1m 🟩🟩🟩🟩
file_change_determinator 46s 🟩🟩🟩🟩
permission-check 12s 🟩🟩🟩🟩
permission-check 12s 🟩🟩🟩🟩
check-branch-prefix 1s 🟩

settingsfeedbackdocs ⋅ learn more about trunk.io

Copy link
Contributor Author

wrwg commented Jan 4, 2025

third_party/move/move-vm/types/src/values/values_impl.rs Outdated Show resolved Hide resolved
}

impl ClosureMask {
pub const MAX_ARGS: usize = 64;
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@wrwg wrwg force-pushed the wrwg/clos_file_format branch from f2effc9 to 3c767c3 Compare January 13, 2025 07:08
@wrwg wrwg force-pushed the wrwg/clos_ability_move branch 2 times, most recently from a79fde9 to 719f728 Compare January 14, 2025 02:32
@wrwg wrwg force-pushed the wrwg/clos_file_format branch from 3c767c3 to 0aa8d5d Compare January 16, 2025 06:43
@wrwg wrwg force-pushed the wrwg/clos_ability_move branch from 719f728 to 41d027e Compare January 16, 2025 06:43
@wrwg wrwg force-pushed the wrwg/clos_file_format branch from 0aa8d5d to 301ccae Compare January 16, 2025 06:44
@wrwg wrwg force-pushed the wrwg/clos_ability_move branch from 41d027e to 8e5b22c Compare January 16, 2025 06:44
Copy link
Contributor

@georgemitenkov georgemitenkov left a 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

@wrwg wrwg force-pushed the wrwg/clos_file_format branch from 301ccae to c879216 Compare January 17, 2025 06:10
@wrwg wrwg force-pushed the wrwg/clos_ability_move branch from 8e5b22c to 6aa1fbf Compare January 17, 2025 06:10
@wrwg wrwg force-pushed the wrwg/clos_file_format branch from 0ebce3a to 58fbf2b Compare January 18, 2025 03:21
@wrwg wrwg force-pushed the wrwg/clos_ability_move branch from 6aa1fbf to 94836d9 Compare January 18, 2025 03:49
…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.
@wrwg wrwg force-pushed the wrwg/clos_file_format branch from 58fbf2b to d9a4a9f Compare January 18, 2025 04:20
@wrwg wrwg force-pushed the wrwg/clos_ability_move branch from 94836d9 to da757e8 Compare January 18, 2025 04:21
@wrwg wrwg force-pushed the wrwg/clos_ability_move branch from da757e8 to c078929 Compare January 18, 2025 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants