Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda support in VM: Wolfgang's PR plus some simplifications (removing mask, clarifying ops) #15387

Open
wants to merge 3 commits into
base: 11-21-lambda-compiler-completion
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/types/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ pub trait Bytecode {
mutable: true,
to: Box::new(self.new_move_type(t.borrow())),
},
SignatureToken::Function(..) => {
// TODO(LAMBDA)
unimplemented!("signature token function to API MoveType")
},
}
}

Expand Down
4 changes: 4 additions & 0 deletions aptos-move/script-composer/src/decompiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ impl LocalState {
SignatureToken::Vector(s) => {
TypeTag::Vector(Box::new(Self::type_tag_from_sig_token(script, s)?))
},
SignatureToken::Function(..) => {
// 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);
TypeTag::Struct(Box::new(StructTag {
Expand Down
1 change: 1 addition & 0 deletions third_party/move/move-binary-format/src/binary_views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ impl<'a> BinaryIndexedView<'a> {
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)
Expand Down
16 changes: 12 additions & 4 deletions third_party/move/move-binary-format/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ impl CompiledScriptBuilder {
sig: &SignatureToken,
) -> PartialVMResult<SignatureToken> {
use SignatureToken::*;
let import_vec =
|s: &mut Self, v: &[SignatureToken]| -> PartialVMResult<Vec<SignatureToken>> {
v.iter()
.map(|sig| s.import_signature_token(module, sig))
.collect::<PartialVMResult<Vec<_>>>()
};
Ok(match sig {
U8 => U8,
U16 => U16,
Expand All @@ -229,13 +235,15 @@ impl CompiledScriptBuilder {
MutableReference(Box::new(self.import_signature_token(module, ty)?))
},
Vector(ty) => Vector(Box::new(self.import_signature_token(module, ty)?)),
Function(args, result, abilities) => Function(
import_vec(self, args)?,
import_vec(self, result)?,
*abilities,
),
Struct(idx) => Struct(self.import_struct(module, *idx)?),
StructInstantiation(idx, inst_tys) => StructInstantiation(
self.import_struct(module, *idx)?,
inst_tys
.iter()
.map(|sig| self.import_signature_token(module, sig))
.collect::<PartialVMResult<Vec<_>>>()?,
import_vec(self, inst_tys)?,
),
})
}
Expand Down
10 changes: 6 additions & 4 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) => 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) => {
CallGeneric(idx) | LdFunctionGeneric(idx) => {
self.check_code_unit_bounds_impl(
self.view.function_instantiations(),
*idx,
Expand Down Expand Up @@ -657,7 +657,9 @@ impl<'a> BoundsChecker<'a> {
| VecPushBack(idx)
| VecPopBack(idx)
| VecUnpack(idx, _)
| VecSwap(idx) => {
| VecSwap(idx)
| InvokeFunction(idx)
| EarlyBindFunction(idx, _) => {
self.check_code_unit_bounds_impl(
self.view.signatures(),
*idx,
Expand All @@ -684,7 +686,7 @@ impl<'a> BoundsChecker<'a> {
for ty in ty.preorder_traversal() {
match ty {
Bool | U8 | U16 | U32 | U64 | U128 | U256 | Address | Signer | TypeParameter(_)
| Reference(_) | MutableReference(_) | Vector(_) => (),
| Reference(_) | MutableReference(_) | Vector(_) | Function(..) => (),
Struct(idx) => {
check_bounds_impl(self.view.struct_handles(), *idx)?;
if let Some(sh) = self.view.struct_handles().get(idx.into_index()) {
Expand Down
9 changes: 6 additions & 3 deletions third_party/move/move-binary-format/src/check_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> BinaryComplexityMeter<'a> {
cost = cost.saturating_add(moduel_name.len() as u64 * COST_PER_IDENT_BYTE);
},
U8 | U16 | U32 | U64 | U128 | U256 | Signer | Address | Bool | Vector(_)
| TypeParameter(_) | Reference(_) | MutableReference(_) => (),
| Function(..) | TypeParameter(_) | Reference(_) | MutableReference(_) => (),
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ impl<'a> BinaryComplexityMeter<'a> {

for instr in &code.code {
match instr {
CallGeneric(idx) => {
CallGeneric(idx) | LdFunctionGeneric(idx, ..) => {
self.meter_function_instantiation(*idx)?;
},
PackGeneric(idx) | UnpackGeneric(idx) => {
Expand Down Expand Up @@ -291,7 +291,9 @@ impl<'a> BinaryComplexityMeter<'a> {
| VecPushBack(idx)
| VecPopBack(idx)
| VecUnpack(idx, _)
| VecSwap(idx) => {
| VecSwap(idx)
| InvokeFunction(idx)
| EarlyBindFunction(idx, _) => {
self.meter_signature(*idx)?;
},

Expand Down Expand Up @@ -323,6 +325,7 @@ impl<'a> BinaryComplexityMeter<'a> {
| PackVariant(_)
| UnpackVariant(_)
| TestVariant(_)
| LdFunction(_)
| ReadRef
| WriteRef
| FreezeRef
Expand Down
4 changes: 4 additions & 0 deletions third_party/move/move-binary-format/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ fn sig_to_ty(sig: &SignatureToken) -> Option<MoveTypeLayout> {
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(..) => {
// TODO(LAMBDA): do we need representation in MoveTypeLayout?
None
},
SignatureToken::Reference(_)
| SignatureToken::MutableReference(_)
| SignatureToken::Struct(_)
Expand Down
16 changes: 16 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,16 @@ 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_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
Loading
Loading