Skip to content

Commit

Permalink
Rename and rephrase Wolfgang's closure operations to match ongoing pa…
Browse files Browse the repository at this point in the history
…rser work:

- `LdFunction`, `LdFunctionGeneric` = generate a closure from a defined function
- `EarlyBind` = bind more arguments to any closure
- `Invoke` = call a closure with final arguments
Add some description/semantics to `file_format.rs` to better describe
the implementation which will be needed.

Get rid of complex Mask calculations in favor of simpler early bninding of
`k` initial arguments.

Hopefully keep all bytecode verifier operations working the same.
  • Loading branch information
brmataptos committed Nov 27, 2024
1 parent c7cd374 commit 8a6e7c5
Show file tree
Hide file tree
Showing 25 changed files with 689 additions and 339 deletions.
2 changes: 1 addition & 1 deletion api/types/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub trait Bytecode {
to: Box::new(self.new_move_type(t.borrow())),
},
SignatureToken::Function(..) => {
// TODO
// TODO(LAMBDA)
unimplemented!("signature token function to API MoveType")
},
}
Expand Down
3 changes: 2 additions & 1 deletion aptos-move/script-composer/src/decompiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ impl LocalState {
TypeTag::Vector(Box::new(Self::type_tag_from_sig_token(script, s)?))
},
SignatureToken::Function(..) => {
bail!("function types NYI for script composer")
// TODO(LAMBDA)
bail!("function types not yet implemented for script composer")
},
SignatureToken::Struct(s) => {
let module_handle = script.module_handle_at(script.struct_handle_at(*s).module);
Expand Down
11 changes: 6 additions & 5 deletions third_party/move/move-binary-format/src/check_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,12 @@ impl<'a> BoundsChecker<'a> {
)?;
}
},
Call(idx) | ClosPack(idx, _) => self.check_code_unit_bounds_impl(
Call(idx) | LdFunction(idx) => self.check_code_unit_bounds_impl(
self.view.function_handles(),
*idx,
bytecode_offset,
)?,
CallGeneric(idx) | ClosPackGeneric(idx, _) => {
CallGeneric(idx) | LdFunctionGeneric(idx) => {
self.check_code_unit_bounds_impl(
self.view.function_instantiations(),
*idx,
Expand Down Expand Up @@ -650,15 +650,16 @@ impl<'a> BoundsChecker<'a> {
},

// Instructions that refer to a signature
ClosEval(idx)
| VecPack(idx, _)
VecPack(idx, _)
| VecLen(idx)
| VecImmBorrow(idx)
| VecMutBorrow(idx)
| VecPushBack(idx)
| VecPopBack(idx)
| VecUnpack(idx, _)
| VecSwap(idx) => {
| VecSwap(idx)
| Invoke(idx)
| EarlyBind(idx, _) => {
self.check_code_unit_bounds_impl(
self.view.signatures(),
*idx,
Expand Down
11 changes: 6 additions & 5 deletions third_party/move/move-binary-format/src/check_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl<'a> BinaryComplexityMeter<'a> {

for instr in &code.code {
match instr {
CallGeneric(idx) | ClosPackGeneric(idx, ..) => {
CallGeneric(idx) | LdFunctionGeneric(idx, ..) => {
self.meter_function_instantiation(*idx)?;
},
PackGeneric(idx) | UnpackGeneric(idx) => {
Expand All @@ -284,15 +284,16 @@ impl<'a> BinaryComplexityMeter<'a> {
ImmBorrowVariantFieldGeneric(idx) | MutBorrowVariantFieldGeneric(idx) => {
self.meter_variant_field_instantiation(*idx)?;
},
ClosEval(idx)
| VecPack(idx, _)
VecPack(idx, _)
| VecLen(idx)
| VecImmBorrow(idx)
| VecMutBorrow(idx)
| VecPushBack(idx)
| VecPopBack(idx)
| VecUnpack(idx, _)
| VecSwap(idx) => {
| VecSwap(idx)
| Invoke(idx)
| EarlyBind(idx, _) => {
self.meter_signature(*idx)?;
},

Expand Down Expand Up @@ -324,7 +325,7 @@ impl<'a> BinaryComplexityMeter<'a> {
| PackVariant(_)
| UnpackVariant(_)
| TestVariant(_)
| ClosPack(..)
| LdFunction(_)
| ReadRef
| WriteRef
| FreezeRef
Expand Down
2 changes: 1 addition & 1 deletion third_party/move/move-binary-format/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn sig_to_ty(sig: &SignatureToken) -> Option<MoveTypeLayout> {
SignatureToken::U256 => Some(MoveTypeLayout::U256),
SignatureToken::Vector(v) => Some(MoveTypeLayout::Vector(Box::new(sig_to_ty(v.as_ref())?))),
SignatureToken::Function(..) => {
// TODO: do we need representation in MoveTypeLayout?
// TODO(LAMBDA): do we need representation in MoveTypeLayout?
None
},
SignatureToken::Reference(_)
Expand Down
15 changes: 15 additions & 0 deletions third_party/move/move-binary-format/src/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ impl Table {
}
}

fn read_u8_internal(cursor: &mut VersionedCursor) -> BinaryLoaderResult<u8> {
cursor.read_u8().map_err(|_| {
PartialVMError::new(StatusCode::MALFORMED).with_message("Unexpected EOF".to_string())
})
}

fn read_u16_internal(cursor: &mut VersionedCursor) -> BinaryLoaderResult<u16> {
let mut u16_bytes = [0; 2];
cursor
Expand Down Expand Up @@ -1814,6 +1820,15 @@ fn load_code(cursor: &mut VersionedCursor, code: &mut Vec<Bytecode>) -> BinaryLo
Opcodes::CAST_U16 => Bytecode::CastU16,
Opcodes::CAST_U32 => Bytecode::CastU32,
Opcodes::CAST_U256 => Bytecode::CastU256,

Opcodes::LD_FUNCTION => Bytecode::LdFunction(load_function_handle_index(cursor)?),
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)?)
},
};
code.push(bytecode);
}
Expand Down
Loading

0 comments on commit 8a6e7c5

Please sign in to comment.