Verify that function signature matches declared signature
Feature
Add a check that a function signature matches its declared signature. For example in the following code:
let mut main_sig = module.make_signature();
main_sig.returns = vec![AbiParam::new(types::I32)];
let main_id = module
.declare_function("main", cranelift_module::Linkage::Export, &main_sig)
.unwrap();
let mut main = Function::new();
main.signature = main_sig;
It is very easy to forget to add the ctx.func.signature = main_sig; line which can cause confusing verifier errors such as arguments of return must match function signature, which actively makes it harder to identify the error.
Benefit
This makes it easier to learn to use cranelift and easier to debug a class of errors.
Implementation
I think this would likely end up being put somewhere other than the verifier, as I believe the verifier likely doesn't have sufficient information to check this. Maybe in the module API somewhere?
Alternatives
It also seems viable to change the API somehow such that a signature is only required once per function. Perhaps something like this:
let mut main_sig = module.make_signature();
main_sig.returns = vec![AbiParam::new(types::I32)];
let (main_id, main) = module
.declare_function("main", cranelift_module::Linkage::Export, main_sig)
.unwrap();
Having .declare_function() construct and return a Function with the given signature.