bytecodealliance / bytecodealliance/wasmtime
Cranelift: Turn sret into a return type annotation
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 126
Description
#### Feature
Currently, struct return is enabled in cranelift via the `sret` parameter annotation. This annotation marks the parameter as a required input, and also signals to the abi that this value will be returned and may need special handling. As the value is not explicitly returned, the lowering module is responsible for tracking and returning that parameter in an abi-defined location. Cranelift itself doesn't write data to the memory pointed to by the `sret` param, and instead relies on the clif producer to write data out.
Since cranelift itself doesn't need to know that an input will ultimately be used as an `sret` location, I'd like to propose that we turn `sret` into an annotation on a return type instead. For example, consider this existing function:
```
function %f0(i64 sret) {
block0(v0: i64):
v1 = iconst.i64 42
store v1, v0
return
}
```
As the consumer is already responsible for writing to `v0`, and cranelift has no other need to know that the parameter will ultimately be a struct return, we could instead implement it as the following:
```
function %f0(i64) -> i64 sret {
block0(v0: i64):
v1 = iconst.i64 42
store v1, v0
return v0
}
```
#### Benefit
This change would simplify the lowering code a bit, and make it more clear that struct returns are for the most part coordinated by the clif producer; cranelift only needs to know about a struct return to satisfy the requirements of the abi it's targeting.
#### Implementation
This should be a fairly straight forward refactoring.
#### Alternatives
We can certainly leave struct return the way it is, keeping the connection between the parameter and return value.
Contributor guide
Assessment
This issue has not been assessed yet.