Skip to content

wasm-mutate: List of mutations we should support #415

Open
@fitzgen

Description

@fitzgen

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

  • Add new custom section
  • Edit existing custom section
    • add bytes
    • remove bytes
    • edit bytes
  • Remove custom section
  • Move existing custom section

Type Section

  • Add new type
  • Edit type (if it isn't used)
  • Remove type
  • Reorder types

Import Section

  • Add new import
  • Edit import name/module
  • Edit import kind (if it isn't used)
  • Remove import
  • Reorder imports

Function Section

  • 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)
  • 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
  • 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
  • Remove a memory
  • Reorder memories

Global Section

  • Add a new global
  • Edit an existing global
  • Remove a global
  • Reorder globals

Export Section

  • Add a new export
  • Rename an existing export
  • Edit an existing export to export a different entity
  • 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)
  • 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.funcs referencing this function)
  • 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 brs that jump to some label outside this block)

Data Section

  • Add a new data segment
  • Edit an existing data segment
    • Reorder bytes within the segment
    • Add bytes to the segment
    • Remove bytes from the segment
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomershelp wantedExtra attention is neededwasm-mutateIssues related to the `wasm-mutate` crate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions