Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Ability to construct const/non-mutable arrays of unknown size from mutable arrays #570

@mkustermann

Description

@mkustermann

It seems WasmGC currently can only create WasmGC arrays via the following instructions:

  • array.new
  • array.new_default
  • array.new_fixed
  • array.new_elem
  • array.new_data

If the array's field type is const then after creation the array can only be accessed in read-only mode (accessing length & elements).

It can be very beneficial for compilers & optimizers to know that an array is const, so two loads at same index will always yield the same value, etc. So we'd like to take advantage of that. If we know the length of the array it's very convenient to use array.new_fixed. Though if we don't know the length and have the array values in a mutable array (i.e. field type is var) it seems the only way to create a const array from that would be to load elements from the mutable array, store into element section and then use array.new_elem. This seems super cumbersome.

Is there any simple way to create a const array with contents from a var array where the length is unknown?

It would be nice to have an array.copy() (related #313) or array.new_copy() (related: #367) that atomically create a const array and initializes it from a source array (const or var) - or a sub-range of one.

/cc @jakobkummerow @tlively @rossberg

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions