From `cargo clippy -- -D warnings`:
```
error: all if blocks contain the same code at the start
--> compiler/gen_wasm/src/wasm_module/sections.rs:478:9
|
478 | / if bytes[*cursor] == 0 {
479 | | u8::skip_bytes(bytes, cursor);
480 | | u32::skip_bytes(bytes, cursor);
| |___________________________________________^
|
= note: `-D clippy::branches-sharing-code` implied by `-D warnings`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code
help: consider moving the start statements out like this
|
478 ~ u8::skip_bytes(bytes, cursor);
479 + u32::skip_bytes(bytes, cursor);
480 + if bytes[*cursor] == 0 {
|
error: could not compile `roc_gen_wasm` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed
```
https://webassembly.github.io/spec/core/binary/modules.html#binary-datacountsec
Tools like wasm2wat and wasm-validate reject the module when this section is included!
Its purpose is to enable single-pass validation for two specific instructions that were
not in the original Wasm MVP: memory.init and data.drop.
We don't use them in our Roc backend. It seems to make sense just to drop the section.
Linked external functions must be declared in the Import section,
and they must come first in the function index space.
In other words, internal function numbers start at the number of imports.
However we don't know in advance how many builtins the code may call,
and we don't want to add more passes over the full IR. Instead we re-index
function references at the end of code generation.
For references to addresses of constant strings, we make an entry in
reloc.CODE and configure the relocation type to say it points at a
memory address. (At least I think this is right, I can't test it yet!)
The same info can also be used for de-duplication.
It turns out we don't need reloc.DATA. I had misunderstood it.
The use case for that would be constant nested data structures,
where constant data would contain pointers to other constant data.
I don't think we're doing this in Roc at all, but not sure.