bytecodealliance / bytecodealliance/wasm-tools

`wasm-mutate`: List of mutations we should support

Open
#415 9 comments 0 reactions 0 assignees View on GitHub
good first issue help wanted wasm-mutate
Dominant language
Rust
Stars
1.8k
Forks
351
Avg merge
1d 6h
Merged PRs (30d)
46

Description

We should have an add, edit, reorder, and remove mutator for each Wasm section (where it makes sense). This is a tracking issue for each of these things.

In general, removing an entity should be something done optimistically, but which can fail if the entity is referenced in other sections (e.g. if we are trying to remove a global, but a function uses it via `global.get` or `global.set`).

### Custom Sections

* [x] Add new custom section
* [x] Edit existing custom section
* [x] add bytes
* [x] remove bytes
* [x] edit bytes
* [x] Remove custom section
* [x] Move existing custom section

### Type Section

* [x] Add new type
* [ ] Edit type (if it isn't used)
* [x] Remove type
* [ ] Reorder types

### Import Section

* [ ] Add new import
* [ ] Edit import name/module
* [ ] Edit import kind (if it isn't used)
* [x] Remove import
* [ ] Reorder imports

### Function Section

* [x] Add new function
* [ ] Add a parameter (and update the code section as necessary)
* [ ] Remove a parameter (and update the code section as necessary)
* [ ] Turn a parameter into a local (and update calls and type section as necessary)
* [x] Remove function
* [ ] Reorder functions

### Table Section

* [ ] Add a new table (if there aren't any tables or bulk memory is enabled)
* [ ] Edit an existing table
* [x] Remove a table
* [ ] Reorder tables

### Memory Section

* [ ] Add a new memory (if there aren't any memories or multi-memory is enabled)
* [ ] Edit an existing memory
* [x] Remove a memory
* [ ] Reorder memories

### Global Section

* [ ] Add a new global
* [ ] Edit an existing global
* [x] Remove a global
* [ ] Reorder globals

### Export Section

* [ ] Add a new export
* [X] Rename an existing export
* [ ] Edit an existing export to export a different entity
* [X] Remove an export

### Start Section

* [ ] Add a start section (if there isn't one, and there is a function of the right type)
* [ ] Change which function is the start function in an existing start section (if there is another of the right type)
* [x] Remove the start section

### Element Section

* [ ] Add a new element segment
* [ ] Edit an existing element segment
* [ ] Reorder functions in the segment
* [ ] Add a new function to the segment
* [ ] Remove a function from the segment (needs to be careful of `ref.func`s referencing this function)
* [x] Remove an element segment
* [ ] Reorder element segments

### Code Section

* [ ] Remove unused locals
* [ ] Outline an expression into a new function
* [ ] Inline a function call
* [ ] Swap two expressions that don't have any ordering between each other

#### Peephole Mutations

* [ ] Allow writing rules with wildcard immediates (e.g. `(elem.drop.*) => (container)` instead of `(elem.drop.0) => (container)` and `(elem.drop.1) => (container)`, etc...)
* [ ] Replace an `f64` or `f32` value with NaN (when not preserving semantics)
* [ ] Replace a value with a use of an existing local of the same type (when not preserving semantics)
* [ ] Replace a value with a use of an existing global of the same type (when not preserving semantics)
* [ ] Swap operands of the same arity, e.g. turn `(i32.add ?x ?y)` into `(i32.mul ?x ?y)`, etc... (when not preserving semantics)
* [ ] Completely remove expressions that don't produce any result values, e.g. stores and void calls (when not preserving semantics)
* [ ] Insert expressions that don't produce any result in arbitrary places, e.g. stores and void calls (when not preserving semantics)

#### Code Motion Mutations

* [ ] Replace the body of an `if`/`else`/`loop`/`block` with `unreachable` (if not preserving semantics)
* [ ] Replace `if .. else .. end` with just the consequent or just the alternative as a `block` (if not preserving semantics)
* [ ] Replace `loop` with `block` and vice versa (if not preserving semantics)
* [ ] Delete a whole `if`/`else`, `block`, or `loop`, dropping parameters and producing dummy value results as necessary (if not preserving semantics)
* [ ] Inline a `block .. end` as just the `..` part (will require checking that there are no `br` instructions targeting the block, as well as renumbering nested `br`s that jump to some label outside this block)

### Data Section

* [ ] Add a new data segment
* [x] Edit an existing data segment
* [x] Reorder bytes within the segment
* [x] Add bytes to the segment
* [x] Remove bytes from the segment
* [x] Remove a data segment
* [ ] Reorder data segments

### Data Count Section

Not really applicable. More of something we just have to keep up to date based on mutations of the data section.

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.