Skip to content

Materialize fixed-array values at initialization and construction boundaries #953

Closed

Description

@LunaStev

Problem

Initialized fixed arrays cannot be copied by an ordinary local initializer. The frontend accepts equal array types, but array-variable expressions lower to their storage address while the destination boundary expects an aggregate value. Several construction and method-call paths omit the load that ordinary assignment/call/return paths already perform.

Audited canonical master d59bdab376bdc04edacdc8029b256cb8d55b5adf on Linux amd64 with checkout-built Wave 0.0.1-alpha-dev, Rust 1.89.0 and LLVM 21.1.8.

Reproduction

fun main() -> i32 {
    var source: array<i32, 2> = [11, 22];
    var copy: array<i32, 2> = source;
    return copy[1];
}
target/debug/wavec check repro.wave
target/debug/wavec build repro.wave --emit=ir -O0 --out-dir /tmp/wave-array-copy-o0
target/debug/wavec build repro.wave --emit=ir -O2 --out-dir /tmp/wave-array-copy-o2

check succeeds. Both builds fail with E9001: Type mismatch: expected ... [2 x i32] ... got ... ptr, reported from llvm/src/statement/variable.rs:156.

The same address/value mismatch is reproduced at O0/O2 for:

// Struct literal field
struct Record { values: array<i32, 2>; }
// after declaring source above:
var record: Record = Record { values: source };

// Nested array elements
var nested: array<array<i32, 2>, 2> = [source, source];

Method-style array arguments and array receivers also fail (receiver.total(source) and source.total() when the corresponding ordinary function parameter is an array). Controls var copy: array<i32,2>; copy = source;, total(source), and storing a returned array into a local all build at O0/O2.

Scope

Materialize address-backed fixed arrays at the existing by-value boundaries for local initialization, aggregate construction and method-style calls. Group these failures because they have the same missing storage-to-value transition. Keep ordinary array address/index behavior and the existing ABI; do not make array copies aliases or infer new types in the backend.

Starting points: array variable expressions, ordinary local initializer, nested literal elements, struct fields, and method arguments.

Related #914 completed the separate return boundary fix and explicitly preserved address-based ordinary array expressions. #501 concerned pointer-indexed struct values, rather than fixed-array materialization. #409 remains the general backend error-channel tracker; fixing these valid values does not require that broad refactor. Whale array support #880 is separate.

Difficulty: medium; help wanted. Not marked good first issue because several value boundaries and copy/evaluation semantics need coordinated regression coverage.

Completion criteria

  • Equal-type local array copies, nested array values, struct array fields and method-style array arguments build and execute correctly at O0/O2.
  • Mutating the copy leaves the source unchanged, including nested and zero-length arrays.
  • Existing direct calls, assignments, returns and address-of/index behavior retain their semantics.
  • Literal/variable/grouped sources and side-effecting value producers are covered without duplicate evaluation.

Activity

  1. added
    bug
    help wanted
    on Oct 18, 2026
  2. added a commit that references this issue on Nov 13, 2026
    be6a7a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions