diff --git a/api/types/src/bytecode.rs b/api/types/src/bytecode.rs index 45908b2e2b7121..f51a8ccfb16e1a 100644 --- a/api/types/src/bytecode.rs +++ b/api/types/src/bytecode.rs @@ -105,7 +105,7 @@ pub trait Bytecode { mutable: true, to: Box::new(self.new_move_type(t.borrow())), }, - SignatureToken::Function { .. } => { + SignatureToken::Function( .. ) => { // TODO(LAMBDA) unimplemented!("signature token function to API MoveType") }, diff --git a/aptos-move/script-composer/src/decompiler.rs b/aptos-move/script-composer/src/decompiler.rs index 861bbe990a6b16..147d976b90ccfe 100644 --- a/aptos-move/script-composer/src/decompiler.rs +++ b/aptos-move/script-composer/src/decompiler.rs @@ -208,7 +208,7 @@ impl LocalState { SignatureToken::Vector(s) => { TypeTag::Vector(Box::new(Self::type_tag_from_sig_token(script, s)?)) }, - SignatureToken::Function { .. } => { + SignatureToken::Function(..) => { // TODO(LAMBDA) bail!("function types not yet implemented for script composer") }, diff --git a/third_party/move/move-binary-format/src/binary_views.rs b/third_party/move/move-binary-format/src/binary_views.rs index f1093d22c45e72..a7c4a8f6600d28 100644 --- a/third_party/move/move-binary-format/src/binary_views.rs +++ b/third_party/move/move-binary-format/src/binary_views.rs @@ -340,10 +340,12 @@ impl<'a> BinaryIndexedView<'a> { Reference(_) | MutableReference(_) => Ok(AbilitySet::REFERENCES), Signer => Ok(AbilitySet::SIGNER), TypeParameter(idx) => Ok(constraints[*idx as usize]), - Vector(ty) => AbilitySet::polymorphic_abilities(AbilitySet::VECTOR, vec![false], vec![ - self.abilities(ty, constraints)?, - ]), - Function { abilities, .. } => Ok(*abilities), + Vector(ty) => AbilitySet::polymorphic_abilities( + AbilitySet::VECTOR, + vec![false], + vec![self.abilities(ty, constraints)?], + ), + Function(_, _, abilities) => Ok(*abilities), Struct(idx) => { let sh = self.struct_handle_at(*idx); Ok(sh.abilities) diff --git a/third_party/move/move-binary-format/src/builders.rs b/third_party/move/move-binary-format/src/builders.rs index 5cacb8e3e62b25..69c6d7889d60a0 100644 --- a/third_party/move/move-binary-format/src/builders.rs +++ b/third_party/move/move-binary-format/src/builders.rs @@ -235,15 +235,11 @@ impl CompiledScriptBuilder { MutableReference(Box::new(self.import_signature_token(module, ty)?)) }, Vector(ty) => Vector(Box::new(self.import_signature_token(module, ty)?)), - Function { - args, - results, - abilities, - } => Function { - args: import_vec(self, args)?, - results: import_vec(self, results)?, - abilities: *abilities, - }, + Function(args, results, abilities) => Function( + import_vec(self, args)?, + import_vec(self, results)?, + *abilities, + ), Struct(idx) => Struct(self.import_struct(module, *idx)?), StructInstantiation(idx, inst_tys) => StructInstantiation( self.import_struct(module, *idx)?, diff --git a/third_party/move/move-binary-format/src/constant.rs b/third_party/move/move-binary-format/src/constant.rs index 1f27d9f259fe3b..3b8d200787a4e1 100644 --- a/third_party/move/move-binary-format/src/constant.rs +++ b/third_party/move/move-binary-format/src/constant.rs @@ -17,7 +17,7 @@ fn sig_to_ty(sig: &SignatureToken) -> Option { SignatureToken::U128 => Some(MoveTypeLayout::U128), SignatureToken::U256 => Some(MoveTypeLayout::U256), SignatureToken::Vector(v) => Some(MoveTypeLayout::Vector(Box::new(sig_to_ty(v.as_ref())?))), - SignatureToken::Function { .. } => { + SignatureToken::Function(..) => { // TODO(LAMBDA): do we need representation in MoveTypeLayout? None }, diff --git a/third_party/move/move-binary-format/src/deserializer.rs b/third_party/move/move-binary-format/src/deserializer.rs index df8236d78eeef7..b5418d12dd4696 100644 --- a/third_party/move/move-binary-format/src/deserializer.rs +++ b/third_party/move/move-binary-format/src/deserializer.rs @@ -1180,11 +1180,11 @@ fn load_signature_token(cursor: &mut VersionedCursor) -> BinaryLoaderResult= args_arity as usize { results.push(tok); if results.len() >= res_arity as usize { - T::Saturated(SignatureToken::Function { + T::Saturated(SignatureToken::Function( args, results, abilities, - }) + )) } else { T::Function { args_arity, diff --git a/third_party/move/move-binary-format/src/file_format.rs b/third_party/move/move-binary-format/src/file_format.rs index 2c1791b853f01d..927fa7b9f6e5bf 100644 --- a/third_party/move/move-binary-format/src/file_format.rs +++ b/third_party/move/move-binary-format/src/file_format.rs @@ -1263,11 +1263,11 @@ pub enum SignatureToken { /// Vector Vector(Box), /// Function, with n argument types and m result types, and an associated ability set. - Function { - args: Vec, - results: Vec, - abilities: AbilitySet, - }, + Function( + Vec, // args + Vec, // results + AbilitySet, // abilities + ), /// User defined type Struct(StructHandleIndex), StructInstantiation(StructHandleIndex, Vec), @@ -1310,7 +1310,7 @@ impl<'a> Iterator for SignatureTokenPreorderTraversalIter<'a> { self.stack.extend(inner_toks.iter().rev()) }, - Function { args, results, .. } => { + Function( args, results, .. ) => { self.stack.extend(args.iter().rev()); self.stack.extend(results.iter().rev()); }, @@ -1348,7 +1348,7 @@ impl<'a> Iterator for SignatureTokenPreorderTraversalIterWithDepth<'a> { .stack .extend(inner_toks.iter().map(|tok| (tok, depth + 1)).rev()), - Function { args, results, .. } => { + Function( args, results, .. ) => { self.stack .extend(args.iter().map(|tok| (tok, depth + 1)).rev()); self.stack @@ -1415,11 +1415,11 @@ impl std::fmt::Debug for SignatureToken { SignatureToken::Address => write!(f, "Address"), SignatureToken::Signer => write!(f, "Signer"), SignatureToken::Vector(boxed) => write!(f, "Vector({:?})", boxed), - SignatureToken::Function { + SignatureToken::Function ( args, results, abilities, - } => { + ) => { write!(f, "Function({:?}, {:?}, {})", args, results, abilities) }, SignatureToken::Reference(boxed) => write!(f, "Reference({:?})", boxed), @@ -1443,7 +1443,7 @@ impl SignatureToken { | Address | Signer | Vector(_) - | Function { .. } + | Function ( .. ) | Struct(_) | StructInstantiation(_, _) | Reference(_) @@ -1482,7 +1482,7 @@ impl SignatureToken { Bool | U8 | U16 | U32 | U64 | U128 | U256 | Address => true, Vector(inner) => inner.is_valid_for_constant(), Signer - | Function { .. } + | Function ( .. ) | Struct(_) | StructInstantiation(_, _) | Reference(_) @@ -1495,7 +1495,7 @@ impl SignatureToken { pub fn is_function(&self) -> bool { use SignatureToken::*; - matches!(self, Function { .. }) + matches!(self, Function ( .. )) } /// Set the index to this one. Useful for random testing. @@ -1546,15 +1546,15 @@ impl SignatureToken { Address => Address, Signer => Signer, Vector(ty) => Vector(Box::new(ty.instantiate(subst_mapping))), - Function { + Function ( args, results, abilities, - } => Function { - args: inst_vec(args), - results: inst_vec(results), - abilities: *abilities, - }, + ) => Function ( + inst_vec(args), + inst_vec(results), + *abilities, + ), Struct(idx) => Struct(*idx), StructInstantiation(idx, struct_type_args) => { StructInstantiation(*idx, inst_vec(struct_type_args)) diff --git a/third_party/move/move-binary-format/src/proptest_types/types.rs b/third_party/move/move-binary-format/src/proptest_types/types.rs index 830dd5c564298f..17e599f3aacb66 100644 --- a/third_party/move/move-binary-format/src/proptest_types/types.rs +++ b/third_party/move/move-binary-format/src/proptest_types/types.rs @@ -71,7 +71,7 @@ impl StDefnMaterializeState { let inner = self.potential_abilities(ty); inner.intersect(AbilitySet::VECTOR) }, - Function { abilities, .. } => *abilities, + Function(_, _, abilities) => *abilities, Struct(idx) => { let sh = &self.struct_handles[idx.0 as usize]; sh.abilities diff --git a/third_party/move/move-binary-format/src/serializer.rs b/third_party/move/move-binary-format/src/serializer.rs index 376ff1dceecc8a..b64cf045ec2ff6 100644 --- a/third_party/move/move-binary-format/src/serializer.rs +++ b/third_party/move/move-binary-format/src/serializer.rs @@ -800,11 +800,11 @@ fn serialize_signature_token_single_node_impl( binary.push(SerializedType::TYPE_PARAMETER as u8)?; serialize_type_parameter_index(binary, *idx)?; }, - SignatureToken::Function { + SignatureToken::Function( args, results, abilities, - } => { + ) => { binary.push(SerializedType::FUNCTION as u8)?; serialize_signature_size(binary, args.len())?; serialize_signature_size(binary, results.len())?; diff --git a/third_party/move/move-bytecode-verifier/bytecode-verifier-tests/src/unit_tests/feature_function_values_tests.rs b/third_party/move/move-bytecode-verifier/bytecode-verifier-tests/src/unit_tests/feature_function_values_tests.rs index 9ff7d9693edf0c..31ed738c6c4a7b 100644 --- a/third_party/move/move-bytecode-verifier/bytecode-verifier-tests/src/unit_tests/feature_function_values_tests.rs +++ b/third_party/move/move-bytecode-verifier/bytecode-verifier-tests/src/unit_tests/feature_function_values_tests.rs @@ -12,21 +12,21 @@ use move_core_types::{identifier::Identifier, vm_status::StatusCode}; fn get_fun_type_bool_to_bool() -> SignatureToken { let bool_token = SignatureToken::Bool; let abilities = AbilitySet::PUBLIC_FUNCTIONS; - SignatureToken::Function { - args: vec![bool_token.clone()], - results: vec![bool_token.clone()], + SignatureToken::Function( + vec![bool_token.clone()], + vec![bool_token.clone()], abilities, - } + ) } fn get_fun_type_nothing_to_bool() -> SignatureToken { let bool_token = SignatureToken::Bool; let abilities = AbilitySet::PUBLIC_FUNCTIONS; - SignatureToken::Function { - args: vec![], - results: vec![bool_token.clone()], + SignatureToken::Function( + vec![], + vec![bool_token.clone()], abilities, - } + ) } #[test] diff --git a/third_party/move/move-bytecode-verifier/invalid-mutations/src/bounds.rs b/third_party/move/move-bytecode-verifier/invalid-mutations/src/bounds.rs index 0d7858b658c7da..9470a6cbf34850 100644 --- a/third_party/move/move-bytecode-verifier/invalid-mutations/src/bounds.rs +++ b/third_party/move/move-bytecode-verifier/invalid-mutations/src/bounds.rs @@ -369,6 +369,6 @@ fn struct_handle(token: &SignatureToken) -> Option { | Signer | Vector(_) | TypeParameter(_) - | Function { .. } => None, + | Function(..) => None, } } diff --git a/third_party/move/move-bytecode-verifier/src/dependencies.rs b/third_party/move/move-bytecode-verifier/src/dependencies.rs index 74d86a40a5783c..1ce3789fa6452f 100644 --- a/third_party/move/move-bytecode-verifier/src/dependencies.rs +++ b/third_party/move/move-bytecode-verifier/src/dependencies.rs @@ -456,16 +456,16 @@ fn compare_types( compare_types(context, ty1, ty2, def_module) }, ( - SignatureToken::Function { - args: args1, - results: result1, - abilities: abilities1, - }, - SignatureToken::Function { - args: args2, - results: result2, - abilities: abilities2, - }, + SignatureToken::Function( + args1, + result1, + abilities1, + ), + SignatureToken::Function( + args2, + result2, + abilities2, + ), ) => { compare_cross_module_signatures(context, args1, args2, def_module)?; compare_cross_module_signatures(context, result1, result2, def_module)?; @@ -504,7 +504,7 @@ fn compare_types( | (SignatureToken::Address, _) | (SignatureToken::Signer, _) | (SignatureToken::Vector(_), _) - | (SignatureToken::Function { .. }, _) + | (SignatureToken::Function(..), _) | (SignatureToken::Struct(_), _) | (SignatureToken::StructInstantiation(_, _), _) | (SignatureToken::Reference(_), _) diff --git a/third_party/move/move-bytecode-verifier/src/features.rs b/third_party/move/move-bytecode-verifier/src/features.rs index e2f898d66d75d6..b2de902b7959d0 100644 --- a/third_party/move/move-bytecode-verifier/src/features.rs +++ b/third_party/move/move-bytecode-verifier/src/features.rs @@ -87,7 +87,7 @@ impl<'a> FeatureVerifier<'a> { if !self.config.enable_function_values { for (idx, signature) in self.code.signatures().iter().enumerate() { for signature_token in signature.0.iter() { - if matches!(signature_token, SignatureToken::Function { .. }) { + if matches!(signature_token, SignatureToken::Function(..)) { return Err(PartialVMError::new(StatusCode::FEATURE_NOT_ENABLED) .at_index(IndexKind::Signature, idx as u16) .with_message("function values feature not enabled".to_string())); diff --git a/third_party/move/move-bytecode-verifier/src/instantiation_loops.rs b/third_party/move/move-bytecode-verifier/src/instantiation_loops.rs index d1a1501d414307..00979d9826e2cc 100644 --- a/third_party/move/move-bytecode-verifier/src/instantiation_loops.rs +++ b/third_party/move/move-bytecode-verifier/src/instantiation_loops.rs @@ -148,7 +148,7 @@ impl<'a> InstantiationLoopChecker<'a> { type_params.insert(*idx); }, Vector(ty) => rec(type_params, ty), - Function { args, results, .. } => { + Function(args, results, ..) => { for ty in args { rec(type_params, ty); } diff --git a/third_party/move/move-bytecode-verifier/src/instruction_consistency.rs b/third_party/move/move-bytecode-verifier/src/instruction_consistency.rs index 752489ff69a899..17c6bf4e6bf64d 100644 --- a/third_party/move/move-bytecode-verifier/src/instruction_consistency.rs +++ b/third_party/move/move-bytecode-verifier/src/instruction_consistency.rs @@ -289,7 +289,7 @@ impl<'a> InstructionConsistency<'a> { ) -> PartialVMResult<()> { let signature = self.resolver.signature_at(sig_index); if let Some(sig_token) = signature.0.first() { - if let SignatureToken::Function { args: params, .. } = sig_token { + if let SignatureToken::Function(params, ..) = sig_token { if count as usize > params.len() { return Err( PartialVMError::new(StatusCode::NUMBER_OF_TYPE_ARGUMENTS_MISMATCH) diff --git a/third_party/move/move-bytecode-verifier/src/reference_safety/mod.rs b/third_party/move/move-bytecode-verifier/src/reference_safety/mod.rs index 651f54078d7849..276e3bae106f08 100644 --- a/third_party/move/move-bytecode-verifier/src/reference_safety/mod.rs +++ b/third_party/move/move-bytecode-verifier/src/reference_safety/mod.rs @@ -250,7 +250,7 @@ fn fun_type( idx: SignatureIndex, ) -> PartialVMResult<(Vec, Vec)> { match verifier.resolver.signature_at(idx).0.first() { - Some(SignatureToken::Function { args, results, .. }) => Ok((args.clone(), results.clone())), + Some(SignatureToken::Function(args, results, ..)) => Ok((args.clone(), results.clone())), _ => Err(PartialVMError::new( StatusCode::VERIFIER_INVARIANT_VIOLATION, )), diff --git a/third_party/move/move-bytecode-verifier/src/signature.rs b/third_party/move/move-bytecode-verifier/src/signature.rs index a89dc52c8d7835..a7b2d4372c9ab5 100644 --- a/third_party/move/move-bytecode-verifier/src/signature.rs +++ b/third_party/move/move-bytecode-verifier/src/signature.rs @@ -372,7 +372,7 @@ impl<'a> SignatureChecker<'a> { } }, - SignatureToken::Function { .. } => { + SignatureToken::Function(..) => { return Err(PartialVMError::new(StatusCode::UNEXPECTED_VERIFIER_ERROR) .with_message("function types not supported".to_string())); }, @@ -429,7 +429,7 @@ impl<'a> SignatureChecker<'a> { Err(PartialVMError::new(StatusCode::INVALID_SIGNATURE_TOKEN) .with_message("reference not allowed".to_string())) }, - Function { .. } => Err(PartialVMError::new(StatusCode::UNEXPECTED_VERIFIER_ERROR) + Function(..) => Err(PartialVMError::new(StatusCode::UNEXPECTED_VERIFIER_ERROR) .with_message("function types not supported".to_string())), Vector(ty) => self.check_signature_token(ty), StructInstantiation(_, type_arguments) => self.check_signature_tokens(type_arguments), @@ -481,7 +481,7 @@ impl<'a> SignatureChecker<'a> { type_parameters, ) }, - SignatureToken::Function { .. } => { + SignatureToken::Function(..) => { Err(PartialVMError::new(StatusCode::UNEXPECTED_VERIFIER_ERROR) .with_message("function types not supported".to_string())) }, diff --git a/third_party/move/move-bytecode-verifier/src/signature_v2.rs b/third_party/move/move-bytecode-verifier/src/signature_v2.rs index f352aee8fe922b..0c4598963f2ad6 100644 --- a/third_party/move/move-bytecode-verifier/src/signature_v2.rs +++ b/third_party/move/move-bytecode-verifier/src/signature_v2.rs @@ -173,11 +173,11 @@ fn check_ty( param_constraints, )?; }, - Function { + Function( args, results, abilities, - } => { + ) => { assert_abilities(*abilities, required_abilities)?; for ty in args.iter().chain(results.iter()) { check_ty( @@ -275,7 +275,7 @@ fn check_phantom_params( match ty { Vector(ty) => check_phantom_params(struct_handles, context, false, ty)?, - Function { args, results, .. } => { + Function(args, results, ..) => { for ty in args.iter().chain(results) { check_phantom_params(struct_handles, context, false, ty)? } @@ -919,7 +919,7 @@ impl<'a, const N: usize> SignatureChecker<'a, N> { checked_early_bind_insts.entry((*idx, *count)) { // Note non-function case is checked in `verify_fun_sig_idx` above. - if let Some(SignatureToken::Function { args, .. }) = + if let Some(SignatureToken::Function(args, ..)) = self.resolver.signature_at(*idx).0.first() { if *count as usize > args.len() { diff --git a/third_party/move/move-bytecode-verifier/src/stack_usage_verifier.rs b/third_party/move/move-bytecode-verifier/src/stack_usage_verifier.rs index 4fb7856670a42e..d60b3bf3c86911 100644 --- a/third_party/move/move-bytecode-verifier/src/stack_usage_verifier.rs +++ b/third_party/move/move-bytecode-verifier/src/stack_usage_verifier.rs @@ -242,7 +242,7 @@ impl<'a> StackUsageVerifier<'a> { // InvokeFunction pops a function and the number of arguments and pushes the results of the // given function type Bytecode::InvokeFunction(idx) => { - if let Some(SignatureToken::Function { args, results, .. }) = + if let Some(SignatureToken::Function(args, results, ..)) = self.resolver.signature_at(*idx).0.first() { ((1 + args.len()) as u64, results.len() as u64) @@ -255,7 +255,7 @@ impl<'a> StackUsageVerifier<'a> { // EarlyBindFunction pops a function value and the captured arguments and returns 1 value Bytecode::EarlyBindFunction(idx, arg_count) => { - if let Some(SignatureToken::Function { args, .. }) = + if let Some(SignatureToken::Function(args, ..)) = self.resolver.signature_at(*idx).0.first() { if args.len() <= *arg_count as usize { diff --git a/third_party/move/move-bytecode-verifier/src/struct_defs.rs b/third_party/move/move-bytecode-verifier/src/struct_defs.rs index a3ce1f606d77ef..3d9fec2e6a62da 100644 --- a/third_party/move/move-bytecode-verifier/src/struct_defs.rs +++ b/third_party/move/move-bytecode-verifier/src/struct_defs.rs @@ -123,7 +123,7 @@ impl<'a> StructDefGraphBuilder<'a> { ) }, T::Vector(inner) => self.add_signature_token(neighbors, cur_idx, inner)?, - T::Function { args, results, .. } => { + T::Function(args, results, ..) => { for t in args.iter().chain(results) { self.add_signature_token(neighbors, cur_idx, t)? } diff --git a/third_party/move/move-bytecode-verifier/src/type_safety.rs b/third_party/move/move-bytecode-verifier/src/type_safety.rs index bf9897f47ea058..ee451e9388feb7 100644 --- a/third_party/move/move-bytecode-verifier/src/type_safety.rs +++ b/third_party/move/move-bytecode-verifier/src/type_safety.rs @@ -307,11 +307,11 @@ fn invoke_function( offset: CodeOffset, expected_ty: &SignatureToken, ) -> PartialVMResult<()> { - let SignatureToken::Function { - args: param_tys, - results: ret_tys, + let SignatureToken::Function( + param_tys, + ret_tys, abilities, - } = expected_ty + ) = expected_ty else { // The signature checker has ensured this is a function safe_assert!(false); @@ -327,10 +327,10 @@ fn invoke_function( .with_message("closure type mismatch".to_owned())); } // Verify that the abilities match - let SignatureToken::Function { - abilities: closure_abilities, - .. - } = closure_ty + let SignatureToken::Function( + _, _, + closure_abilities, + ) = closure_ty else { // Ensured above, but never panic safe_assert!(false); @@ -394,11 +394,11 @@ fn ld_function( verifier.push( meter, instantiate( - &SignatureToken::Function { - args: parameters.0.to_vec(), - results: ret_sign.0.to_vec(), + &SignatureToken::Function( + parameters.0.to_vec(), + ret_sign.0.to_vec(), abilities, - }, + ), type_actuals, ), ) @@ -412,11 +412,11 @@ fn early_bind_function( count: u8, ) -> PartialVMResult<()> { let count = count as usize; - let SignatureToken::Function { - args: param_tys, - results: ret_tys, + let SignatureToken::Function( + param_tys, + ret_tys, abilities, - } = expected_ty + ) = expected_ty else { // The signature checker has ensured this is a function safe_assert!(false); @@ -432,10 +432,10 @@ fn early_bind_function( .with_message("closure type mismatch".to_owned())); } // Verify that the abilities match - let SignatureToken::Function { - abilities: closure_abilities, - .. - } = closure_ty + let SignatureToken::Function( + _, _, + closure_abilities + ) = closure_ty else { // Ensured above, but never panic safe_assert!(false); @@ -461,11 +461,11 @@ fn early_bind_function( return Err(verifier.error(StatusCode::CALL_TYPE_MISMATCH_ERROR, offset)); } } - let result_ty = SignatureToken::Function { - args: (*remaining_param_tys).to_vec(), - results: ret_tys.to_vec(), - abilities: *abilities, - }; + let result_ty = SignatureToken::Function( + (*remaining_param_tys).to_vec(), + ret_tys.to_vec(), + *abilities, + ); verifier.push(meter, result_ty) } @@ -1343,15 +1343,15 @@ fn instantiate(token: &SignatureToken, subst: &Signature) -> SignatureToken { Address => Address, Signer => Signer, Vector(ty) => Vector(Box::new(instantiate(ty, subst))), - Function { + Function ( args, results, abilities, - } => Function { - args: inst_vec(args), - results: inst_vec(results), - abilities: *abilities, - }, + ) => Function ( + inst_vec(args), + inst_vec(results), + *abilities, + ), Struct(idx) => Struct(*idx), StructInstantiation(idx, struct_type_args) => { StructInstantiation(*idx, inst_vec(struct_type_args)) diff --git a/third_party/move/move-compiler/src/interface_generator.rs b/third_party/move/move-compiler/src/interface_generator.rs index 09c4c8379eb987..db4798d321dcb7 100644 --- a/third_party/move/move-compiler/src/interface_generator.rs +++ b/third_party/move/move-compiler/src/interface_generator.rs @@ -272,6 +272,20 @@ fn write_ability_constraint(abs: AbilitySet) -> String { ) } +fn function_value_abilities_to_str(abs: AbilitySet) -> String { + if abs.is_subset(AbilitySet::FUNCTIONS) { + return "".to_string(); + } + format!( + ": {}", + abs.setminus(AbilitySet::FUNCTIONS) + .into_iter() + .map(write_ability) + .collect::>() + .join("+") + ) +} + fn write_ability(ab: Ability) -> String { use crate::parser::ast::Ability_ as A_; match ab { @@ -365,8 +379,13 @@ fn write_signature_token(ctx: &mut Context, t: &SignatureToken) -> String { SignatureToken::Address => "address".to_string(), SignatureToken::Signer => "signer".to_string(), SignatureToken::Vector(inner) => format!("vector<{}>", write_signature_token(ctx, inner)), - SignatureToken::Function { args, results, .. } => { - format!("|{}|{}", tok_list(ctx, args), tok_list(ctx, results)) + SignatureToken::Function(args, results, abilities) => { + format!( + "|{}|{}{}", + tok_list(ctx, args), + tok_list(ctx, results), + function_value_abilities_to_str(*abilities) + ) }, SignatureToken::Struct(idx) => write_struct_handle_type(ctx, *idx), SignatureToken::StructInstantiation(idx, types) => { diff --git a/third_party/move/move-ir-compiler/move-ir-to-bytecode/src/context.rs b/third_party/move/move-ir-compiler/move-ir-to-bytecode/src/context.rs index 3da165cdb01e1c..cd2e1560e9caf6 100644 --- a/third_party/move/move-ir-compiler/move-ir-to-bytecode/src/context.rs +++ b/third_party/move/move-ir-compiler/move-ir-to-bytecode/src/context.rs @@ -768,7 +768,8 @@ impl<'a> Context<'a> { let correct_inner = self.reindex_signature_token(dep, *inner)?; SignatureToken::Vector(Box::new(correct_inner)) }, - SignatureToken::Function { .. } => { + SignatureToken::Function(..) => { + // TODO(LAMBDA) unimplemented!("function types not supported by MoveIR") }, SignatureToken::Reference(inner) => { diff --git a/third_party/move/move-model/src/ty.rs b/third_party/move/move-model/src/ty.rs index d1eedf5ed561c1..5dc9c97a67fd80 100644 --- a/third_party/move/move-model/src/ty.rs +++ b/third_party/move/move-model/src/ty.rs @@ -1394,7 +1394,7 @@ impl Type { .collect(), ) }, - SignatureToken::Function { .. } => { + SignatureToken::Function (..) => { // TODO: implement function conversion unimplemented!("signature token to model type") }, diff --git a/third_party/move/move-vm/runtime/src/loader/type_loader.rs b/third_party/move/move-vm/runtime/src/loader/type_loader.rs index 19099c68c5c4c2..90de57faa2769e 100644 --- a/third_party/move/move-vm/runtime/src/loader/type_loader.rs +++ b/third_party/move/move-vm/runtime/src/loader/type_loader.rs @@ -31,8 +31,8 @@ pub fn intern_type( let inner_type = intern_type(module, inner_tok, struct_name_table)?; Type::Vector(TriompheArc::new(inner_type)) }, - SignatureToken::Function { .. } => { - // TODO: implement closures + SignatureToken::Function(..) => { + // TODO(LAMBDA): implement closures return Err(PartialVMError::new(StatusCode::UNIMPLEMENTED_FEATURE) .with_message("function types in the type loader".to_owned())); }, diff --git a/third_party/move/move-vm/types/src/values/values_impl.rs b/third_party/move/move-vm/types/src/values/values_impl.rs index ffdc8634d2cf1b..c3171cd907588b 100644 --- a/third_party/move/move-vm/types/src/values/values_impl.rs +++ b/third_party/move/move-vm/types/src/values/values_impl.rs @@ -4154,7 +4154,7 @@ impl Value { S::Signer => return None, S::Vector(inner) => L::Vector(Box::new(Self::constant_sig_token_to_layout(inner)?)), // Not yet supported - S::Struct(_) | S::StructInstantiation(_, _) | S::Function { .. } => return None, + S::Struct(_) | S::StructInstantiation(_, _) | S::Function(..) => return None, // Not allowed/Not meaningful S::TypeParameter(_) | S::Reference(_) | S::MutableReference(_) => return None, }) diff --git a/third_party/move/tools/move-bytecode-utils/src/layout.rs b/third_party/move/tools/move-bytecode-utils/src/layout.rs index cfb305dd6b408f..635b154e613780 100644 --- a/third_party/move/tools/move-bytecode-utils/src/layout.rs +++ b/third_party/move/tools/move-bytecode-utils/src/layout.rs @@ -386,7 +386,10 @@ impl TypeLayoutBuilder { ) -> anyhow::Result { use SignatureToken::*; Ok(match s { - Function { .. } => bail!("function types NYI for MoveTypeLayout"), + Function(..) => { + // TODO(LAMBDA) + bail!("function types NYI for MoveTypeLayout") + }, Vector(t) => MoveTypeLayout::Vector(Box::new(Self::build_from_signature_token( m, t, diff --git a/third_party/move/tools/move-disassembler/src/disassembler.rs b/third_party/move/tools/move-disassembler/src/disassembler.rs index 1e4bcc1e3608f2..dcb747e390373a 100644 --- a/third_party/move/tools/move-disassembler/src/disassembler.rs +++ b/third_party/move/tools/move-disassembler/src/disassembler.rs @@ -570,9 +570,6 @@ impl<'a> Disassembler<'a> { type_param_context: &[SourceName], ) -> Result { Ok(match sig_tok { - // TODO: function types - SignatureToken::Function { .. } => unimplemented!("disassembling function sig tokens"), - SignatureToken::Bool => "bool".to_string(), SignatureToken::U8 => "u8".to_string(), SignatureToken::U16 => "u16".to_string(), @@ -632,6 +629,29 @@ impl<'a> Disassembler<'a> { })? .0 .to_string(), + SignatureToken::Function(args, results, abilities) => { + let args_str = args + .into_iter() + .map(|tok| self.disassemble_sig_tok(tok, type_param_context)) + .collect::>>()? + .join(","); + let results_str = results + .into_iter() + .map(|tok| self.disassemble_sig_tok(tok, type_param_context)) + .collect::>>()? + .join(","); + let abilities_str = if abilities.is_subset(AbilitySet::FUNCTIONS) { + "".to_string() + } else { + let ability_vec: Vec<_> = abilities + .setminus(AbilitySet::FUNCTIONS) + .into_iter() + .map(Self::format_ability) + .collect(); + format!(" with {}", ability_vec.join("+")) + }; + format!("|{}|{}{}", args_str, results_str, abilities_str) + }, }) } diff --git a/third_party/move/tools/move-resource-viewer/src/lib.rs b/third_party/move/tools/move-resource-viewer/src/lib.rs index 3e81f50c130769..ba6d7f3eca5151 100644 --- a/third_party/move/tools/move-resource-viewer/src/lib.rs +++ b/third_party/move/tools/move-resource-viewer/src/lib.rs @@ -375,7 +375,7 @@ impl MoveValueAnnotator { SignatureToken::Vector(ty) => { FatType::Vector(Box::new(self.resolve_signature(module, ty, limit)?)) }, - SignatureToken::Function { .. } => { + SignatureToken::Function(..) => { bail!("function types NYI by fat types") }, SignatureToken::Struct(idx) => {