Skip to content

Commit

Permalink
rename EarlyBind and Invoke operations to EarlyBindFunction and Invok…
Browse files Browse the repository at this point in the history
…eFunction based on George's suggestion
  • Loading branch information
brmataptos committed Nov 27, 2024
1 parent 8a6e7c5 commit f49f228
Show file tree
Hide file tree
Showing 31 changed files with 128 additions and 110 deletions.
4 changes: 2 additions & 2 deletions third_party/move/move-binary-format/src/check_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,8 @@ impl<'a> BoundsChecker<'a> {
| VecPopBack(idx)
| VecUnpack(idx, _)
| VecSwap(idx)
| Invoke(idx)
| EarlyBind(idx, _) => {
| InvokeFunction(idx)
| EarlyBindFunction(idx, _) => {
self.check_code_unit_bounds_impl(
self.view.signatures(),
*idx,
Expand Down
4 changes: 2 additions & 2 deletions third_party/move/move-binary-format/src/check_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ impl<'a> BinaryComplexityMeter<'a> {
| VecPopBack(idx)
| VecUnpack(idx, _)
| VecSwap(idx)
| Invoke(idx)
| EarlyBind(idx, _) => {
| InvokeFunction(idx)
| EarlyBindFunction(idx, _) => {
self.meter_signature(*idx)?;
},

Expand Down
9 changes: 5 additions & 4 deletions third_party/move/move-binary-format/src/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1825,10 +1825,11 @@ fn load_code(cursor: &mut VersionedCursor, code: &mut Vec<Bytecode>) -> BinaryLo
Opcodes::LD_FUNCTION_GENERIC => {
Bytecode::LdFunctionGeneric(load_function_inst_index(cursor)?)
},
Opcodes::INVOKE => Bytecode::Invoke(load_signature_index(cursor)?),
Opcodes::EARLY_BIND => {
Bytecode::EarlyBind(load_signature_index(cursor)?, read_u8_internal(cursor)?)
},
Opcodes::INVOKE_FUNCTION => Bytecode::InvokeFunction(load_signature_index(cursor)?),
Opcodes::EARLY_BIND_FUNCTION => Bytecode::EarlyBindFunction(
load_signature_index(cursor)?,
read_u8_internal(cursor)?,
),
};
code.push(bytecode);
}
Expand Down
14 changes: 8 additions & 6 deletions third_party/move/move-binary-format/src/file_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2988,7 +2988,7 @@ pub enum Bytecode {

#[group = "closure"]
#[description = r#"
`EarlyBind(|t1..tn|r with a, count)` creates new function value based
`EarlyBindFunction(|t1..tn|r with a, count)` creates new function value based
on the function value at top of stack by adding `count` arguments
popped from the stack to the closure found on top of stack.
Expand Down Expand Up @@ -3024,11 +3024,11 @@ pub enum Bytecode {
func param types match provided parameter types
"#]
#[gas_type_creation_tier_0 = "closure_ty"]
EarlyBind(SignatureIndex, u8),
EarlyBindFunction(SignatureIndex, u8),

#[group = "closure"]
#[description = r#"
`Invoke(|t1..tn|r with a)` calls a function value of the specified type,
`InvokeFunction(|t1..tn|r with a)` calls a function value of the specified type,
with `n` argument values from the stack.
On top of the stack is the closure being evaluated, underneath the arguments:
Expand Down Expand Up @@ -3095,7 +3095,7 @@ pub enum Bytecode {
assert ty == locals[#args - i - 1]
"#]
#[gas_type_creation_tier_1 = "closure_ty"]
Invoke(SignatureIndex),
InvokeFunction(SignatureIndex),

#[group = "stack_and_local"]
#[description = "Push a u16 constant onto the stack."]
Expand Down Expand Up @@ -3209,8 +3209,10 @@ impl ::std::fmt::Debug for Bytecode {
Bytecode::UnpackVariantGeneric(a) => write!(f, "UnpackVariantGeneric({})", a),
Bytecode::LdFunction(a) => write!(f, "LdFunction({})", a),
Bytecode::LdFunctionGeneric(a) => write!(f, "LdFunctionGeneric({})", a),
Bytecode::EarlyBind(sig_idx, a) => write!(f, "EarlyBind({}, {})", sig_idx, a),
Bytecode::Invoke(sig_idx) => write!(f, "Invoke({})", sig_idx),
Bytecode::EarlyBindFunction(sig_idx, a) => {
write!(f, "EarlyBindFunction({}, {})", sig_idx, a)
},
Bytecode::InvokeFunction(sig_idx) => write!(f, "InvokeFunction({})", sig_idx),
Bytecode::ReadRef => write!(f, "ReadRef"),
Bytecode::WriteRef => write!(f, "WriteRef"),
Bytecode::FreezeRef => write!(f, "FreezeRef"),
Expand Down
8 changes: 4 additions & 4 deletions third_party/move/move-binary-format/src/file_format_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ pub enum Opcodes {
// Closures
LD_FUNCTION = 0x58,
LD_FUNCTION_GENERIC = 0x59,
INVOKE = 0x5A,
EARLY_BIND = 0x5B,
INVOKE_FUNCTION = 0x5A,
EARLY_BIND_FUNCTION = 0x5B,
}

/// Upper limit on the binary size
Expand Down Expand Up @@ -797,8 +797,8 @@ pub fn instruction_key(instruction: &Bytecode) -> u8 {
// Since bytecode version 8
LdFunction(_) => Opcodes::LD_FUNCTION,
LdFunctionGeneric(_) => Opcodes::LD_FUNCTION_GENERIC,
Invoke(_) => Opcodes::INVOKE,
EarlyBind(..) => Opcodes::EARLY_BIND,
InvokeFunction(_) => Opcodes::INVOKE_FUNCTION,
EarlyBindFunction(..) => Opcodes::EARLY_BIND_FUNCTION,
};
opcode as u8
}
8 changes: 4 additions & 4 deletions third_party/move/move-binary-format/src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,12 +1104,12 @@ fn serialize_instruction_inner(
binary.push(Opcodes::LD_FUNCTION_GENERIC as u8)?;
serialize_function_inst_index(binary, method_idx)
},
Bytecode::Invoke(sig_idx) => {
binary.push(Opcodes::INVOKE as u8)?;
Bytecode::InvokeFunction(sig_idx) => {
binary.push(Opcodes::INVOKE_FUNCTION as u8)?;
serialize_signature_index(binary, sig_idx)
},
Bytecode::EarlyBind(sig_idx, value) => {
binary.push(Opcodes::EARLY_BIND as u8)?;
Bytecode::EarlyBindFunction(sig_idx, value) => {
binary.push(Opcodes::EARLY_BIND_FUNCTION as u8)?;
serialize_signature_index(binary, sig_idx)?;
binary.push(*value)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ impl<'a> ApplyCodeUnitBoundsContext<'a> {
FunctionInstantiationIndex,
LdFunctionGeneric
),
Invoke(..) | EarlyBind(..) => {
InvokeFunction(..) | EarlyBindFunction(..) => {
panic!("Closure bytecode NYI: {:?}", code[bytecode_idx])
},
};
Expand Down Expand Up @@ -576,7 +576,7 @@ fn is_interesting(bytecode: &Bytecode) -> bool {
| LdFalse | ReadRef | WriteRef | Add | Sub | Mul | Mod | Div | BitOr | BitAnd | Xor
| Shl | Shr | Or | And | Not | Eq | Neq | Lt | Gt | Le | Ge | Abort | Nop => false,

LdFunction(_) | LdFunctionGeneric(_) | Invoke(_) | EarlyBind(..) => {
LdFunction(_) | LdFunctionGeneric(_) | InvokeFunction(_) | EarlyBindFunction(..) => {
// TODO(LAMBDA): implement
false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl<'a> AcquiresVerifier<'a> {
let fi = self.module.function_instantiation_at(*idx);
self.ld_function_acquire(fi.handle, offset)
},
Bytecode::EarlyBind(_sig_idx, _count) => Ok(()),
Bytecode::Invoke(_sig_idx) => self.invoke_acquire(offset),
Bytecode::EarlyBindFunction(_sig_idx, _count) => Ok(()),
Bytecode::InvokeFunction(_sig_idx) => self.invoke_acquire(offset),

Bytecode::Pop
| Bytecode::BrTrue(_)
Expand Down Expand Up @@ -216,7 +216,7 @@ impl<'a> AcquiresVerifier<'a> {
offset: CodeOffset,
) -> PartialVMResult<()> {
// Currenty we are disallowing acquires for any function value which
// is created, so Invoke does nothing with acquires.
// is created, so InvokeFunction does nothing with acquires.
// TODO(LAMBDA) In the future this may change.
let function_handle = self.module.function_handle_at(fh_idx);
let function_acquired_resources = self.function_acquired_resources(function_handle, fh_idx);
Expand All @@ -228,7 +228,7 @@ impl<'a> AcquiresVerifier<'a> {

fn invoke_acquire(&mut self, _offset: CodeOffset) -> PartialVMResult<()> {
// Currenty we are disallowing acquires for any function value which
// is created, so Invoke does nothing with acquires.
// is created, so InvokeFunction does nothing with acquires.
// TODO(LAMBDA) In the future this may change.
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ impl<'a> InstructionConsistency<'a> {
let func_inst = self.resolver.function_instantiation_at(*idx);
self.check_ld_function_op(offset, func_inst.handle, /* generic */ true)?;
},
Invoke(sig_idx) => {
InvokeFunction(sig_idx) => {
// reuse code to check for signature issues.
self.check_bind_count(offset, *sig_idx, 0)?;
},
EarlyBind(sig_idx, count) => {
EarlyBindFunction(sig_idx, count) => {
self.check_bind_count(offset, *sig_idx, *count)?;
},
Pack(idx) | Unpack(idx) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ fn execute_inner(
| Bytecode::TestVariantGeneric(_)
| Bytecode::LdFunction(_)
| Bytecode::LdFunctionGeneric(_)
| Bytecode::Invoke(_)
| Bytecode::EarlyBind(..)
| Bytecode::InvokeFunction(_)
| Bytecode::EarlyBindFunction(..)
| Bytecode::ReadRef
| Bytecode::WriteRef
| Bytecode::CastU8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,14 @@ impl AbstractState {
) -> PartialVMResult<AbstractValue> {
if !acquired_resources.is_empty() {
// TODO(LAMBDA): Currently acquires must be empty unless we disallow
// Invoke to call to functions defined in the same module.
// InvokeFunction to call to functions defined in the same module.
return Err(self.error(StatusCode::INVALID_ACQUIRES_ANNOTATION, offset));
}
// TODO(LAMBDA): Double-check that we don't need meter adjustments here.
Ok(AbstractValue::NonReference)
}

pub fn invoke(
pub fn invoke_function(
&mut self,
offset: CodeOffset,
arguments: Vec<AbstractValue>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn ld_function(
Ok(())
}

fn early_bind(
fn early_bind_function(
verifier: &mut ReferenceSafetyAnalysis,
_arg_tys: Vec<SignatureToken>,
k: u8,
Expand All @@ -140,7 +140,7 @@ fn early_bind(
Ok(())
}

fn invoke(
fn invoke_function(
verifier: &mut ReferenceSafetyAnalysis,
state: &mut AbstractState,
offset: CodeOffset,
Expand All @@ -153,7 +153,7 @@ fn invoke(
.map(|_| verifier.stack.pop().unwrap())
.rev()
.collect();
let values = state.invoke(offset, arguments, &result_tys, meter)?;
let values = state.invoke_function(offset, arguments, &result_tys, meter)?;
for value in values {
verifier.stack.push(value)
}
Expand Down Expand Up @@ -578,13 +578,13 @@ fn execute_inner(
let function_handle = verifier.resolver.function_handle_at(func_inst.handle);
ld_function(verifier, state, offset, function_handle, meter)?
},
Bytecode::EarlyBind(sig_idx, k) => {
Bytecode::EarlyBindFunction(sig_idx, k) => {
let (arg_tys, _result_tys) = fun_type(verifier, *sig_idx)?;
early_bind(verifier, arg_tys, *k)?
early_bind_function(verifier, arg_tys, *k)?
},
Bytecode::Invoke(sig_idx) => {
Bytecode::InvokeFunction(sig_idx) => {
let (arg_tys, result_tys) = fun_type(verifier, *sig_idx)?;
invoke(verifier, state, offset, arg_tys, result_tys, meter)?
invoke_function(verifier, state, offset, arg_tys, result_tys, meter)?
},

Bytecode::VecPack(idx, num) => {
Expand Down
5 changes: 4 additions & 1 deletion third_party/move/move-bytecode-verifier/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ impl<'a> SignatureChecker<'a> {
},

// Closure operations not supported by legacy signature checker
LdFunction(..) | LdFunctionGeneric(..) | Invoke(_) | EarlyBind(..) => {
LdFunction(..)
| LdFunctionGeneric(..)
| InvokeFunction(_)
| EarlyBindFunction(..) => {
return Err(PartialVMError::new(StatusCode::UNEXPECTED_VERIFIER_ERROR)
.with_message("closure operations not supported".to_owned()))
},
Expand Down
8 changes: 4 additions & 4 deletions third_party/move/move-bytecode-verifier/src/signature_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,12 @@ impl<'a, const N: usize> SignatureChecker<'a, N> {
entry.insert(());
}
},
Invoke(idx) => map_err(self.verify_fun_sig_idx(
InvokeFunction(idx) => map_err(self.verify_fun_sig_idx(
*idx,
&mut checked_fun_insts,
&ability_context,
))?,
EarlyBind(idx, count) => {
EarlyBindFunction(idx, count) => {
map_err(self.verify_fun_sig_idx(
*idx,
&mut checked_fun_insts,
Expand All @@ -922,7 +922,7 @@ impl<'a, const N: usize> SignatureChecker<'a, N> {
return map_err(Err(PartialVMError::new(
StatusCode::NUMBER_OF_ARGUMENTS_MISMATCH,
)
.with_message("in EarlyBind".to_string())));
.with_message("in EarlyBindFunction".to_string())));
};
};
entry.insert(());
Expand Down Expand Up @@ -1142,7 +1142,7 @@ impl<'a, const N: usize> SignatureChecker<'a, N> {
Ok(())
}

// Checks that a `sig_idx` parameter to `Invoke` or `EarlyBind` is well-formed.
// Checks that a `sig_idx` parameter to `InvokeFunction` or `EarlyBindFunction` is well-formed.
fn verify_fun_sig_idx(
&self,
idx: SignatureIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ impl<'a> StackUsageVerifier<'a> {
(0, 1)
},

// Invoke pops a function and the number of arguments and pushes the results of the
// InvokeFunction pops a function and the number of arguments and pushes the results of the
// given function type
Bytecode::Invoke(idx) => {
Bytecode::InvokeFunction(idx) => {
if let Some(SignatureToken::Function(args, results, _)) =
self.resolver.signature_at(*idx).0.first()
{
Expand All @@ -253,8 +253,8 @@ impl<'a> StackUsageVerifier<'a> {
}
},

// EarlyBind pops a function value and the captured arguments and returns 1 value
Bytecode::EarlyBind(idx, arg_count) => {
// EarlyBindFunction pops a function value and the captured arguments and returns 1 value
Bytecode::EarlyBindFunction(idx, arg_count) => {
if let Some(SignatureToken::Function(args, _results, _)) =
self.resolver.signature_at(*idx).0.first()
{
Expand Down
12 changes: 6 additions & 6 deletions third_party/move/move-bytecode-verifier/src/type_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ fn call(
Ok(())
}

fn invoke(
fn invoke_function(
verifier: &mut TypeSafetyChecker,
meter: &mut impl Meter,
offset: CodeOffset,
Expand Down Expand Up @@ -391,7 +391,7 @@ fn ld_function(
)
}

fn early_bind(
fn early_bind_function(
verifier: &mut TypeSafetyChecker,
meter: &mut impl Meter,
offset: CodeOffset,
Expand Down Expand Up @@ -881,16 +881,16 @@ fn verify_instr(
ld_function(verifier, meter, offset, &func_inst.handle, type_args)?
},

Bytecode::EarlyBind(idx, count) => {
Bytecode::EarlyBindFunction(idx, count) => {
// The signature checker has verified this is a function type.
let expected_ty = safe_unwrap!(verifier.resolver.signature_at(*idx).0.first());
early_bind(verifier, meter, offset, expected_ty, *count)?
early_bind_function(verifier, meter, offset, expected_ty, *count)?
},

Bytecode::Invoke(idx) => {
Bytecode::InvokeFunction(idx) => {
// The signature checker has verified this is a function type.
let expected_ty = safe_unwrap!(verifier.resolver.signature_at(*idx).0.first());
invoke(verifier, meter, offset, expected_ty)?
invoke_function(verifier, meter, offset, expected_ty)?
},

Bytecode::Pack(idx) => {
Expand Down
4 changes: 2 additions & 2 deletions third_party/move/move-compiler-v2/src/bytecode_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ impl<'env> Generator<'env> {
}
),
// TODO(LAMBDA)
ExpData::Invoke(id, _exp, _) => self.error(
ExpData::InvokeFunction(id, _exp, _) => self.error(
*id,
if self.check_if_lambdas_enabled() {
"Calls to function values other than inline function parameters not yet implemented"
Expand Down Expand Up @@ -816,7 +816,7 @@ impl<'env> Generator<'env> {
self.gen_function_call(targets, id, m.qualified(*f), args)
},
// TODO(LAMBDA)
Operation::EarlyBind => self.error(
Operation::EarlyBindFunction => self.error(
id,
if self.check_if_lambdas_enabled() {
"Function-typed values not yet implemented except as parameters to calls to inline functions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ fn find_possibly_modified_vars(
},
};
},
Invoke(..) | Return(..) | Quant(..) | Loop(..) | Mutate(..) | SpecBlock(..) => {
InvokeFunction(..) | Return(..) | Quant(..) | Loop(..) | Mutate(..) | SpecBlock(..) => {
// We don't modify top-level variables here.
match pos {
VisitorPosition::Pre => {
Expand Down
Loading

0 comments on commit f49f228

Please sign in to comment.