Frontend assumes names from Wasm's `name` section are unique
- Lingua principale
- Rust
- Stelle
- 115
- Fork
- 84
- Merge medio
- 1g 8h
- PR unite (30g)
- 15
Descrizione
However [according to the spec](https://webassembly.github.io/spec/core/appendix/custom.html#name-section)
> Names need not be unique.
So far names turned out to be unique in our examples and fixtures. When switching the default panic strategy from `immediate-abort` to `abort` (#1339), `Felt` related formatting code produces duplicate function names in the `name` section for multiple examples/fixtures.
### Reproduction
```sh
cargo make midenc # build bin/midenc
cd examples/counter-contract
RUSTFLAGS="-C panic=abort" ../../bin/midenc miden-project.toml
thread 'main' (185908) panicked at hir/src/ir/operation.rs:209:17:
Unable to insert builtin.function in symbol table of builtin.module: symbol _RNvXsq_NtCs9z35J0Io6i7_11miden_field10wasm_midenNtB5_16FeltFromIntErrorNtNtCs9YlYMtCqyny_4core3fmt5Debug3fmt is already registered to another operation _RNvXsq_NtCs9z35J0Io6i7_11miden_field10wasm_midenNtB5_16FeltFromIntErrorNtNtCs9YlYMtCqyny_4core3fmt5Debug3fmt.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
### Why this was hidden so far
It's formatting related code which until recently wasn't supported for the Miden target and got eliminated due to `panic=immediate-abort`. With `panic=abort` it stays around.
`Felt` is special but I think regardless we must not assume that names in the `name` section are unique.
### Proposed fix
Try to derive a unique HIR symbol, e.g. by combining the name with the unique function index.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
The issue is in the frontend's handling of the WebAssembly name section. Look at the symbol table insertion in `hir/src/ir/operation.rs` around line 209. The fix involves generating a unique HIR symbol, perhaps by combining the function name with its index. Start by building the compiler with `cargo make midenc`, then reproduce the error in `examples/counter-contract` with the given command. Check how function names are currently registered and where duplicates arise.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust, wasm
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Attiva
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 65/100