Skip to content

Commit

Permalink
[language] Binary format changes
Browse files Browse the repository at this point in the history
This is the beginning of changes to the binary format.
The idea is to work on this branch until things are ready.
Possibly (and likely) multiple people will have to synch to this branch
and work will be comitted here. Eventually we squash and commit everything.
This PR just adds few tables and struct but does nothing with them.
They are essentially unused.
I'll start using them soon.
I may `push -f` until someone else starts working on this.
  • Loading branch information
Dario Russi committed Mar 3, 2020
1 parent 63e2d57 commit 56a1749
Show file tree
Hide file tree
Showing 100 changed files with 1,017 additions and 896 deletions.
Expand Up @@ -18,29 +18,29 @@ fn empty_module_no_errors() {
}

#[test]
fn invalid_type_param_in_fn_return_types() {
fn invalid_type_param_in_fn_return_() {
use SignatureToken::*;

let mut m = basic_test_module();
m.function_signatures[0].return_types = vec![TypeParameter(0)];
m.function_signatures[0].return_ = vec![TypeParameter(0)];
m.freeze().unwrap_err();
}

#[test]
fn invalid_type_param_in_fn_arg_types() {
fn invalid_type_param_in_fn_parameters() {
use SignatureToken::*;

let mut m = basic_test_module();
m.function_signatures[0].arg_types = vec![TypeParameter(0)];
m.function_signatures[0].parameters = vec![TypeParameter(0)];
m.freeze().unwrap_err();
}

#[test]
fn invalid_struct_in_fn_return_types() {
fn invalid_struct_in_fn_return_() {
use SignatureToken::*;

let mut m = basic_test_module();
m.function_signatures[0].return_types = vec![Struct(StructHandleIndex::new(1), vec![])];
m.function_signatures[0].return_ = vec![Struct(StructHandleIndex::new(1), vec![])];
m.freeze().unwrap_err();
}

Expand Down Expand Up @@ -76,10 +76,7 @@ fn invalid_locals_id_in_call() {
use Bytecode::*;

let mut m = basic_test_module();
m.function_defs[0].code.code = vec![Call(
FunctionHandleIndex::new(0),
LocalsSignatureIndex::new(1),
)];
m.function_defs[0].code.code = vec![Call(FunctionHandleIndex::new(0), SignatureIndex::new(1))];
m.freeze().unwrap_err();
}

Expand All @@ -89,12 +86,8 @@ fn invalid_type_param_in_call() {
use SignatureToken::*;

let mut m = basic_test_module();
m.locals_signatures
.push(LocalsSignature(vec![TypeParameter(0)]));
m.function_defs[0].code.code = vec![Call(
FunctionHandleIndex::new(0),
LocalsSignatureIndex::new(1),
)];
m.locals_signatures.push(Signature(vec![TypeParameter(0)]));
m.function_defs[0].code.code = vec![Call(FunctionHandleIndex::new(0), SignatureIndex::new(1))];
m.freeze().unwrap_err();
}

Expand All @@ -104,14 +97,9 @@ fn invalid_struct_as_type_actual_in_exists() {
use SignatureToken::*;

let mut m = basic_test_module();
m.locals_signatures.push(LocalsSignature(vec![Struct(
StructHandleIndex::new(3),
vec![],
)]));
m.function_defs[0].code.code = vec![Call(
FunctionHandleIndex::new(0),
LocalsSignatureIndex::new(1),
)];
m.locals_signatures
.push(Signature(vec![Struct(StructHandleIndex::new(3), vec![])]));
m.function_defs[0].code.code = vec![Call(FunctionHandleIndex::new(0), SignatureIndex::new(1))];
m.freeze().unwrap_err();
}

Expand Down
Expand Up @@ -17,7 +17,7 @@ use vm::file_format::{Bytecode::*, CompiledModule, SignatureToken::*, *};
#[test]
fn test_reference_of_reference() {
let mut m = basic_test_module();
m.locals_signatures[0] = LocalsSignature(vec![Reference(Box::new(Reference(Box::new(
m.locals_signatures[0] = Signature(vec![Reference(Box::new(Reference(Box::new(
SignatureToken::Bool,
))))]);
let errors = SignatureChecker::new(&m.freeze().unwrap()).verify();
Expand Down Expand Up @@ -115,20 +115,24 @@ fn no_verify_locals_good() {
signature: FunctionSignatureIndex(1),
},
],
field_handles: vec![],
struct_instantiations: vec![],
function_instantiations: vec![],
field_instantiations: vec![],
type_signatures: vec![],
function_signatures: vec![
FunctionSignature {
return_types: vec![],
arg_types: vec![Address],
type_formals: vec![],
return_: vec![],
parameters: vec![Address],
type_parameters: vec![],
},
FunctionSignature {
return_types: vec![],
arg_types: vec![U64],
type_formals: vec![],
return_: vec![],
parameters: vec![U64],
type_parameters: vec![],
},
],
locals_signatures: vec![LocalsSignature(vec![Address]), LocalsSignature(vec![U64])],
locals_signatures: vec![Signature(vec![Address]), Signature(vec![U64])],
identifiers: vec![
Identifier::new("Bad").unwrap(),
Identifier::new("blah").unwrap(),
Expand All @@ -145,7 +149,7 @@ fn no_verify_locals_good() {
acquires_global_resources: vec![],
code: CodeUnit {
max_stack_size: 0,
locals: LocalsSignatureIndex(0),
locals: SignatureIndex(0),
code: vec![Ret],
},
},
Expand All @@ -155,7 +159,7 @@ fn no_verify_locals_good() {
acquires_global_resources: vec![],
code: CodeUnit {
max_stack_size: 0,
locals: LocalsSignatureIndex(1),
locals: SignatureIndex(1),
code: vec![Ret],
},
},
Expand All @@ -181,13 +185,17 @@ fn no_verify_locals_bad1() {
name: IdentifierIndex(1),
signature: FunctionSignatureIndex(0),
}],
field_handles: vec![],
struct_instantiations: vec![],
function_instantiations: vec![],
field_instantiations: vec![],
type_signatures: vec![],
function_signatures: vec![FunctionSignature {
return_types: vec![],
arg_types: vec![Address],
type_formals: vec![],
return_: vec![],
parameters: vec![Address],
type_parameters: vec![],
}],
locals_signatures: vec![LocalsSignature(vec![U64])],
locals_signatures: vec![Signature(vec![U64])],
identifiers: vec![
Identifier::new("Bad").unwrap(),
Identifier::new("blah").unwrap(),
Expand All @@ -202,7 +210,7 @@ fn no_verify_locals_bad1() {
acquires_global_resources: vec![],
code: CodeUnit {
max_stack_size: 0,
locals: LocalsSignatureIndex(0),
locals: SignatureIndex(0),
code: vec![Ret],
},
}],
Expand All @@ -226,13 +234,17 @@ fn no_verify_locals_bad2() {
name: IdentifierIndex(1),
signature: FunctionSignatureIndex(0),
}],
field_handles: vec![],
struct_instantiations: vec![],
function_instantiations: vec![],
field_instantiations: vec![],
type_signatures: vec![],
function_signatures: vec![FunctionSignature {
return_types: vec![],
arg_types: vec![Address],
type_formals: vec![],
return_: vec![],
parameters: vec![Address],
type_parameters: vec![],
}],
locals_signatures: vec![LocalsSignature(vec![])],
locals_signatures: vec![Signature(vec![])],
identifiers: vec![
Identifier::new("Bad").unwrap(),
Identifier::new("blah").unwrap(),
Expand All @@ -247,7 +259,7 @@ fn no_verify_locals_bad2() {
acquires_global_resources: vec![],
code: CodeUnit {
max_stack_size: 0,
locals: LocalsSignatureIndex(0),
locals: SignatureIndex(0),
code: vec![Ret],
},
}],
Expand All @@ -272,13 +284,17 @@ fn no_verify_locals_bad3() {
name: IdentifierIndex(1),
signature: FunctionSignatureIndex(0),
}],
field_handles: vec![],
struct_instantiations: vec![],
function_instantiations: vec![],
field_instantiations: vec![],
type_signatures: vec![],
function_signatures: vec![FunctionSignature {
return_types: vec![],
arg_types: vec![Address],
type_formals: vec![],
return_: vec![],
parameters: vec![Address],
type_parameters: vec![],
}],
locals_signatures: vec![LocalsSignature(vec![U64, Address])],
locals_signatures: vec![Signature(vec![U64, Address])],
identifiers: vec![
Identifier::new("Bad").unwrap(),
Identifier::new("blah").unwrap(),
Expand All @@ -293,7 +309,7 @@ fn no_verify_locals_bad3() {
acquires_global_resources: vec![],
code: CodeUnit {
max_stack_size: 0,
locals: LocalsSignatureIndex(0),
locals: SignatureIndex(0),
code: vec![Ret],
},
}],
Expand All @@ -318,13 +334,17 @@ fn no_verify_locals_bad4() {
name: IdentifierIndex(1),
signature: FunctionSignatureIndex(0),
}],
field_handles: vec![],
struct_instantiations: vec![],
function_instantiations: vec![],
field_instantiations: vec![],
type_signatures: vec![],
function_signatures: vec![FunctionSignature {
return_types: vec![],
arg_types: vec![U64, Address],
type_formals: vec![],
return_: vec![],
parameters: vec![U64, Address],
type_parameters: vec![],
}],
locals_signatures: vec![LocalsSignature(vec![U64, U64, Address])],
locals_signatures: vec![Signature(vec![U64, U64, Address])],
identifiers: vec![
Identifier::new("Bad").unwrap(),
Identifier::new("blah").unwrap(),
Expand All @@ -339,7 +359,7 @@ fn no_verify_locals_bad4() {
acquires_global_resources: vec![],
code: CodeUnit {
max_stack_size: 0,
locals: LocalsSignatureIndex(0),
locals: SignatureIndex(0),
code: vec![Ret],
},
}],
Expand Down
Expand Up @@ -5,15 +5,15 @@ use bytecode_verifier::UnusedEntryChecker;
use libra_types::{identifier::Identifier, vm_error::StatusCode};
use proptest::prelude::*;
use vm::file_format::{
CompiledModule, FieldDefinition, IdentifierIndex, LocalsSignature, ModuleHandleIndex,
SignatureToken, StructHandle, StructHandleIndex, TypeSignature, TypeSignatureIndex,
CompiledModule, FieldDefinition, IdentifierIndex, ModuleHandleIndex, Signature, SignatureToken,
StructHandle, StructHandleIndex, TypeSignature, TypeSignatureIndex,
};

proptest! {
#[test]
fn unused_locals_signature(module in CompiledModule::valid_strategy(10)) {
let mut module = module.into_inner();
module.locals_signatures.push(LocalsSignature(vec![]));
module.locals_signatures.push(Signature(vec![]));
let module = module.freeze().unwrap();
let unused_entry_checker = UnusedEntryChecker::new(&module);
prop_assert!(!unused_entry_checker.verify().is_empty());
Expand Down Expand Up @@ -50,7 +50,7 @@ proptest! {
module: ModuleHandleIndex::new(0),
name: IdentifierIndex::new(struct_name_idx),
is_nominal_resource: false,
type_formals: vec![],
type_parameters: vec![],
});

module.field_defs.push(FieldDefinition{
Expand Down

0 comments on commit 56a1749

Please sign in to comment.