Skip to content

Commit

Permalink
[trivial] minor naming fixes (#13029)
Browse files Browse the repository at this point in the history
Rename VM types to correctly differentiate between arguments, parameters and types.
  • Loading branch information
georgemitenkov authored May 15, 2024
1 parent df57548 commit 6cdd4c2
Show file tree
Hide file tree
Showing 89 changed files with 382 additions and 417 deletions.
2 changes: 1 addition & 1 deletion api/src/tests/transaction_vector_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn type_tag_strategy() -> impl Strategy<Value = TypeTag> {
address: addr,
module: Identifier::new(module).unwrap(),
name: Identifier::new(name).unwrap(),
type_params: t_vec,
type_args: t_vec,
}))}),
]
})
Expand Down
12 changes: 6 additions & 6 deletions api/types/src/move_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ impl From<StructTag> for MoveStructTag {
address: tag.address.into(),
module: tag.module.into(),
name: tag.name.into(),
generic_type_params: tag.type_params.into_iter().map(MoveType::from).collect(),
generic_type_params: tag.type_args.into_iter().map(MoveType::from).collect(),
}
}
}
Expand All @@ -425,7 +425,7 @@ impl From<&StructTag> for MoveStructTag {
address: tag.address.into(),
module: IdentifierWrapper::from(&tag.module),
name: IdentifierWrapper::from(&tag.name),
generic_type_params: tag.type_params.iter().map(MoveType::from).collect(),
generic_type_params: tag.type_args.iter().map(MoveType::from).collect(),
}
}
}
Expand Down Expand Up @@ -469,7 +469,7 @@ impl TryFrom<MoveStructTag> for StructTag {
address: tag.address.into(),
module: tag.module.into(),
name: tag.name.into(),
type_params: tag
type_args: tag
.generic_type_params
.into_iter()
.map(|p| p.try_into())
Expand Down Expand Up @@ -1469,7 +1469,7 @@ mod tests {
address: address("0x1"),
module: identifier("Home"),
name: identifier("ABC"),
type_params: vec![TypeTag::Address, TypeTag::Struct(Box::new(account))],
type_args: vec![TypeTag::Address, TypeTag::Struct(Box::new(account))],
}
}

Expand All @@ -1478,7 +1478,7 @@ mod tests {
address: address("0x1"),
module: identifier("account"),
name: identifier("Base"),
type_params: vec![
type_args: vec![
TypeTag::U128,
TypeTag::Vector(Box::new(TypeTag::U64)),
TypeTag::Vector(Box::new(TypeTag::Struct(Box::new(type_struct("String"))))),
Expand All @@ -1492,7 +1492,7 @@ mod tests {
address: address("0x1"),
module: identifier("type"),
name: identifier(t),
type_params: vec![],
type_args: vec![],
}
}

Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion aptos-move/aptos-vm-types/src/resource_group_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn test_group_size_same_as_bcs() {
address: PeerId::ONE,
module: Identifier::new("a").unwrap(),
name: Identifier::new(format!("a_{}", j)).unwrap(),
type_params: vec![],
type_args: vec![],
},
reused_vec.slice(0..j),
);
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/aptos-vm-types/src/tests/test_change_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ fn test_roundtrip_to_storage_change_set() {
address: AccountAddress::ONE,
module: ident_str!("foo").into(),
name: ident_str!("Foo").into(),
type_params: vec![],
type_args: vec![],
};
let test_module_id = ModuleId::new(AccountAddress::ONE, ident_str!("bar").into());

Expand Down
6 changes: 3 additions & 3 deletions aptos-move/aptos-vm-types/src/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub(crate) fn mock_tag_0() -> StructTag {
address: AccountAddress::ONE,
module: Identifier::new("a").unwrap(),
name: Identifier::new("a").unwrap(),
type_params: vec![TypeTag::U8],
type_args: vec![TypeTag::U8],
}
}

Expand All @@ -137,7 +137,7 @@ pub(crate) fn mock_tag_1() -> StructTag {
address: AccountAddress::ONE,
module: Identifier::new("abcde").unwrap(),
name: Identifier::new("fgh").unwrap(),
type_params: vec![TypeTag::U64],
type_args: vec![TypeTag::U64],
}
}

Expand All @@ -146,7 +146,7 @@ pub(crate) fn mock_tag_2() -> StructTag {
address: AccountAddress::ONE,
module: Identifier::new("abcdex").unwrap(),
name: Identifier::new("fghx").unwrap(),
type_params: vec![TypeTag::U128],
type_args: vec![TypeTag::U128],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ mod test {
address: AccountAddress::ONE,
module: Identifier::new("a").unwrap(),
name: Identifier::new("a").unwrap(),
type_params: vec![TypeTag::U8],
type_args: vec![TypeTag::U8],
}
}

Expand All @@ -411,7 +411,7 @@ mod test {
address: AccountAddress::ONE,
module: Identifier::new("abcde").unwrap(),
name: Identifier::new("fgh").unwrap(),
type_params: vec![TypeTag::U64],
type_args: vec![TypeTag::U64],
}
}

Expand All @@ -420,7 +420,7 @@ mod test {
address: AccountAddress::ONE,
module: Identifier::new("abcdex").unwrap(),
name: Identifier::new("fghx").unwrap(),
type_params: vec![TypeTag::U128],
type_args: vec![TypeTag::U128],
}
}

Expand Down
6 changes: 3 additions & 3 deletions aptos-move/aptos-vm/src/move_vm_ext/write_op_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ mod tests {
address: AccountAddress::ONE,
module: Identifier::new("a").unwrap(),
name: Identifier::new("a").unwrap(),
type_params: vec![TypeTag::U8],
type_args: vec![TypeTag::U8],
}
}

Expand All @@ -374,7 +374,7 @@ mod tests {
address: AccountAddress::ONE,
module: Identifier::new("abcde").unwrap(),
name: Identifier::new("fgh").unwrap(),
type_params: vec![TypeTag::U64],
type_args: vec![TypeTag::U64],
}
}

Expand All @@ -383,7 +383,7 @@ mod tests {
address: AccountAddress::ONE,
module: Identifier::new("abcdex").unwrap(),
name: Identifier::new("fghx").unwrap(),
type_params: vec![TypeTag::U128],
type_args: vec![TypeTag::U128],
}
}

Expand Down
22 changes: 9 additions & 13 deletions aptos-move/aptos-vm/src/verifier/transaction_arg_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ pub fn validate_combine_signer_and_txn_args(
are_struct_constructors_enabled: bool,
) -> Result<Vec<Vec<u8>>, VMStatus> {
// entry function should not return
if !func.return_.is_empty() {
if !func.return_tys.is_empty() {
return Err(VMStatus::error(
StatusCode::INVALID_MAIN_FUNCTION_SIGNATURE,
None,
));
}
let mut signer_param_cnt = 0;
// find all signer params at the beginning
for ty in func.parameters.iter() {
for ty in func.param_tys.iter() {
match ty {
Type::Signer => signer_param_cnt += 1,
Type::Reference(inner_type) => {
Expand All @@ -131,12 +131,8 @@ pub fn validate_combine_signer_and_txn_args(

let allowed_structs = get_allowed_structs(are_struct_constructors_enabled);
// Need to keep this here to ensure we return the historic correct error code for replay
for ty in func.parameters[signer_param_cnt..].iter() {
let valid = is_valid_txn_arg(
session,
&ty.subst(&func.type_arguments).unwrap(),
allowed_structs,
);
for ty in func.param_tys[signer_param_cnt..].iter() {
let valid = is_valid_txn_arg(session, &ty.subst(&func.ty_args).unwrap(), allowed_structs);
if !valid {
return Err(VMStatus::error(
StatusCode::INVALID_MAIN_FUNCTION_SIGNATURE,
Expand All @@ -145,7 +141,7 @@ pub fn validate_combine_signer_and_txn_args(
}
}

if (signer_param_cnt + args.len()) != func.parameters.len() {
if (signer_param_cnt + args.len()) != func.param_tys.len() {
return Err(VMStatus::error(
StatusCode::NUMBER_OF_ARGUMENTS_MISMATCH,
None,
Expand All @@ -168,9 +164,9 @@ pub fn validate_combine_signer_and_txn_args(
// FAILED_TO_DESERIALIZE_ARGUMENT error.
let args = construct_args(
session,
&func.parameters[signer_param_cnt..],
&func.param_tys[signer_param_cnt..],
args,
&func.type_arguments,
&func.ty_args,
allowed_structs,
false,
)?;
Expand Down Expand Up @@ -430,11 +426,11 @@ fn validate_and_construct(
expected_type,
)?;
let mut args = vec![];
for param_type in &instantiation.parameters {
for param_type in &instantiation.param_tys {
let mut arg = vec![];
recursively_construct_arg(
session,
&param_type.subst(&instantiation.type_arguments).unwrap(),
&param_type.subst(&instantiation.ty_args).unwrap(),
allowed_structs,
cursor,
initial_cursor_len,
Expand Down
6 changes: 3 additions & 3 deletions aptos-move/aptos-vm/src/verifier/view_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) fn validate_view_function(
}

// Must return values
if fun_inst.return_.is_empty() {
if fun_inst.return_tys.is_empty() {
return Err(
PartialVMError::new(StatusCode::INVALID_MAIN_FUNCTION_SIGNATURE)
.with_message("view function must return values".to_string()),
Expand All @@ -56,9 +56,9 @@ pub(crate) fn validate_view_function(
let allowed_structs = get_allowed_structs(struct_constructors_feature);
let args = transaction_arg_validation::construct_args(
session,
&fun_inst.parameters,
&fun_inst.param_tys,
args,
&fun_inst.type_arguments,
&fun_inst.ty_args,
allowed_structs,
true,
)
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/e2e-move-tests/src/aggregator_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl ElementType {
address: AccountAddress::ONE,
module: ident_str!("string").to_owned(),
name: ident_str!("String").to_owned(),
type_params: vec![],
type_args: vec![],
})),
}
}
Expand Down
4 changes: 2 additions & 2 deletions aptos-move/e2e-move-tests/src/tests/fungible_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ pub static FUNGIBLE_STORE_TAG: Lazy<StructTag> = Lazy::new(|| StructTag {
address: AccountAddress::from_hex_literal("0x1").unwrap(),
module: Identifier::new("fungible_asset").unwrap(),
name: Identifier::new("FungibleStore").unwrap(),
type_params: vec![],
type_args: vec![],
});

pub static OBJ_GROUP_TAG: Lazy<StructTag> = Lazy::new(|| StructTag {
address: AccountAddress::from_hex_literal("0x1").unwrap(),
module: Identifier::new("object").unwrap(),
name: Identifier::new("ObjectGroup").unwrap(),
type_params: vec![],
type_args: vec![],
});
#[test]
fn test_basic_fungible_token() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "3f0800000000000005000000000000006600000000000000340f0300000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "3f0800000000000005000000000000006600000000000000340f0300000000000000000000000000" },
],
gas_used: 2111,
status: Keep(
Expand Down Expand Up @@ -71,7 +71,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "7e0000000000000005000000000000007a0000000000000000000000000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "7e0000000000000005000000000000007a0000000000000000000000000000000000000000000000" },
],
gas_used: 126,
status: Keep(
Expand Down Expand Up @@ -108,7 +108,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "740000000000000005000000000000006f0000000000000000000000000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "740000000000000005000000000000006f0000000000000000000000000000000000000000000000" },
],
gas_used: 116,
status: Keep(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "798e01000000000007000000000000000200000000000000c0a39b00000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "798e01000000000007000000000000000200000000000000c0a39b00000000000000000000000000" },
],
gas_used: 102009,
status: Keep(
Expand Down Expand Up @@ -71,7 +71,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "b0ad01000000000006000000000000000200000000000000f064b900000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "b0ad01000000000006000000000000000200000000000000f064b900000000000000000000000000" },
],
gas_used: 110000,
status: Keep(
Expand Down Expand Up @@ -104,7 +104,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "b0ad0100000000000600000000000000020000000000000070f21401000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "b0ad0100000000000600000000000000020000000000000070f21401000000000000000000000000" },
],
gas_used: 110000,
status: Keep(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "7b8e0100000000000500000000000000a286010000000000340f0300000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "7b8e0100000000000500000000000000a286010000000000340f0300000000000000000000000000" },
],
gas_used: 102011,
status: Keep(
Expand Down Expand Up @@ -71,7 +71,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "b0ad0100000000000500000000000000acad01000000000000000000000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "b0ad0100000000000500000000000000acad01000000000000000000000000000000000000000000" },
],
gas_used: 110000,
status: Keep(
Expand Down Expand Up @@ -104,7 +104,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "b0ad0100000000000500000000000000acad01000000000000000000000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "b0ad0100000000000500000000000000acad01000000000000000000000000000000000000000000" },
],
gas_used: 110000,
status: Keep(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "798e01000000000007000000000000000200000000000000c0a39b00000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "798e01000000000007000000000000000200000000000000c0a39b00000000000000000000000000" },
],
gas_used: 102009,
status: Keep(
Expand Down Expand Up @@ -71,7 +71,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "a4da01000000000006000000000000000200000000000000f064b900000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "a4da01000000000006000000000000000200000000000000f064b900000000000000000000000000" },
],
gas_used: 121508,
status: Keep(
Expand Down Expand Up @@ -108,7 +108,7 @@ Ok(
),
),
events: [
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_params: [] }), event_data: "04c50200000000000600000000000000020000000000000070f21401000000000000000000000000" },
ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "04c50200000000000600000000000000020000000000000070f21401000000000000000000000000" },
],
gas_used: 181508,
status: Keep(
Expand Down
Loading

0 comments on commit 6cdd4c2

Please sign in to comment.