Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.

Commit 571e493

Browse files
committed
Add interface example
1 parent b5b567a commit 571e493

File tree

22 files changed

+368
-19
lines changed

22 files changed

+368
-19
lines changed

language/move-binary-format/src/deserializer.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,11 +1026,18 @@ fn load_signature_token(cursor: &mut VersionedCursor) -> BinaryLoaderResult<Sign
10261026
} => {
10271027
if parameters.len() < params_len {
10281028
parameters.push(tok);
1029-
T::Function {
1030-
params_len,
1031-
parameters,
1032-
return_len,
1033-
return_,
1029+
if parameters.len() == params_len && return_len == 0 {
1030+
T::Saturated(SignatureToken::Function(Box::new(FunctionType {
1031+
parameters,
1032+
return_,
1033+
})))
1034+
} else {
1035+
T::Function {
1036+
params_len,
1037+
parameters,
1038+
return_len,
1039+
return_,
1040+
}
10341041
}
10351042
} else if return_.len() < return_len {
10361043
return_.push(tok);

language/move-bytecode-verifier/src/signature.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'a> SignatureChecker<'a> {
347347
use SignatureToken::*;
348348
match ty {
349349
U8 | U16 | U32 | U64 | U128 | U256 | Bool | Address | Signer | Struct(_)
350-
| TypeParameter(_) => Ok(()),
350+
| TypeParameter(_) | Function(_) => Ok(()),
351351
Reference(_) | MutableReference(_) => {
352352
// TODO: Prop tests expect us to NOT check the inner types.
353353
// Revisit this once we rework prop tests.
@@ -356,10 +356,6 @@ impl<'a> SignatureChecker<'a> {
356356
}
357357
Vector(ty) => self.check_signature_token(ty),
358358
StructInstantiation(_, type_arguments) => self.check_signature_tokens(type_arguments),
359-
Function(func_ty) => {
360-
func_ty.parameters.iter().map(|ty| self.check_signature_token(ty)).collect::<PartialVMResult<()>>()?;
361-
func_ty.return_.iter().map(|ty| self.check_signature_token(ty)).collect::<PartialVMResult<()>>()
362-
}
363359
}
364360
}
365361

language/move-bytecode-verifier/src/struct_defs.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,8 @@ impl<'a> StructDefGraphBuilder<'a> {
132132
.insert(*struct_def_idx);
133133
}
134134
}
135-
T::Function(func_ty) => {
136-
for t in &func_ty.parameters {
137-
self.add_signature_token(neighbors, cur_idx, t)?
138-
}
139-
for t in &func_ty.return_ {
140-
self.add_signature_token(neighbors, cur_idx, t)?
141-
}
142-
}
135+
// TODO: Is this safe?
136+
T::Function(_func_ty) => (),
143137
T::StructInstantiation(sh_idx, inners) => {
144138
if let Some(struct_def_idx) = self.handle_to_def.get(sh_idx) {
145139
neighbors

language/move-compiler/src/interface_generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn write_signature_token(ctx: &mut Context, t: &SignatureToken) -> String {
369369
format!("&mut {}", write_signature_token(ctx, inner))
370370
}
371371
SignatureToken::TypeParameter(idx) => write_type_parameter(*idx),
372-
SignatureToken::Function(_) => unimplemented!(),
372+
SignatureToken::Function(_) => "function_ptr".to_string(),
373373
}
374374
}
375375

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//# publish
2+
module 0x42.M {
3+
public sum(a: u64, b: u64): u64 {
4+
let c: u64;
5+
label b0:
6+
c = copy(a) + copy(b);
7+
return copy(c);
8+
}
9+
}
10+
11+
//# run
12+
import 0x42.M;
13+
14+
main() {
15+
let func: |u64, u64| (u64);
16+
let a: u64;
17+
label b0:
18+
func = get_function_pointer(M.sum);
19+
return;
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
processed 2 tasks
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//# publish
2+
module 0x42.M {
3+
public sum(a: u64, b: u64): u64 {
4+
let c: u64;
5+
label b0:
6+
c = copy(a) + copy(b);
7+
return copy(c);
8+
}
9+
}
10+
11+
//# run
12+
import 0x42.M;
13+
14+
15+
main() {
16+
let func: |u64, u64| (u64);
17+
let a: u64;
18+
label b0:
19+
func = get_function_pointer(M.sum);
20+
a = call_function_pointer<|u64, u64| (u64)>(0, 1, copy(func));
21+
assert(move(a) == 1, 0);
22+
return;
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
processed 2 tasks
2+
3+
task 1 'publish'. lines 11-16:
4+
Error: Unable to publish module '00000000000000000000000000000042::F'. Got VMError: {
5+
major_status: FIELD_MISSING_TYPE_ABILITY,
6+
sub_status: None,
7+
location: 0x42::F,
8+
indices: [(StructDefinition, 0)],
9+
offsets: [],
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//# publish
2+
module 0x42.M {
3+
public sum(a: u64, b: u64): u64 {
4+
let c: u64;
5+
label b0:
6+
c = copy(a) + copy(b);
7+
return copy(c);
8+
}
9+
}
10+
11+
//# publish
12+
module 0x42.F {
13+
struct T has store {
14+
f: |u64, u64| (u64),
15+
}
16+
}

0 commit comments

Comments
 (0)