bytecodealliance / bytecodealliance/wasmtime

Verify that function signature matches declared signature

Open
#7,684 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

#### Feature

Add a check that a function signature matches its declared signature. For example in the following code:
```rust
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:
```rust
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.