Skip to content

Commit

Permalink
Document ClosureMask::MAX_ARGUMENTS
Browse files Browse the repository at this point in the history
  • Loading branch information
wrwg committed Jan 23, 2025
1 parent 15de777 commit 6dd70e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 11 additions & 2 deletions third_party/move/move-core/types/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ impl fmt::Display for ClosureMask {
}

impl ClosureMask {
/// The maximal number of arguments which can be handled by a closure mask.
/// A captured argument's position in the argument list must be lower than
/// this number. Notice that this property is implicit in the bytecode:
/// a PACK_CLOSURE instruction will never pop more arguments from the
/// stack than this number.
pub const MAX_ARGS: usize = 64;

pub fn new(mask: u64) -> Self {
Expand All @@ -38,10 +43,14 @@ impl ClosureMask {
/// Apply a closure mask to a list of elements, returning only those
/// where position `i` is set in the mask (if `collect_captured` is true) or not
/// set (otherwise).
pub fn extract<'a, T>(&self, values: &'a [T], collect_captured: bool) -> Vec<&'a T> {
pub fn extract<'a, T>(
&self,
values: impl IntoIterator<Item = &'a T>,
collect_captured: bool,
) -> Vec<&'a T> {
let mut mask = self.0;
values
.iter()
.into_iter()
.filter(|_| {
let set = mask & 0x1 != 0;
mask >>= 1;
Expand Down
5 changes: 3 additions & 2 deletions third_party/move/move-vm/runtime/src/storage/ty_tag_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@ mod tests {
use super::*;
use crate::config::VMConfig;
use claims::{assert_err, assert_none, assert_ok, assert_ok_eq, assert_some};
use move_binary_format::file_format::{AbilitySet, StructTypeParameter};
use move_binary_format::file_format::StructTypeParameter;
use move_core_types::{
account_address::AccountAddress, identifier::Identifier, language_storage::ModuleId,
ability::AbilitySet, account_address::AccountAddress, identifier::Identifier,
language_storage::ModuleId,
};
use move_vm_types::loaded_data::runtime_types::{
AbilityInfo, StructIdentifier, StructLayout, StructType, TypeBuilder,
Expand Down

0 comments on commit 6dd70e7

Please sign in to comment.