Skip to content

Vec.remove(0) returns the wrong element for 64-byte elements (POD too); into_iter inherits it #1689

Closed

Description

@ehartford

Narrowed from the original into_iter report: the defect is in Vec.remove(0) itself, for large elements, independent of str fields.

Repro (installed compiler 7456c37b…, main 1e839443):

type H { a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32, i: i32, j: i32, k: i32, l: i32, m: i32, n: i32, o: i32, p: i32 }
fn main:
    var v: Vec[H] = Vec.new()
    v.push(H { a: 1, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, i: 0, j: 0, k: 0, l: 0, m: 0, n: 0, o: 0, p: 0 })
    v.push(H { a: 2, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, i: 0, j: 0, k: 0, l: 0, m: 0, n: 0, o: 0, p: 0 })
    let first = v.remove(0)
    print(f"{first.a} then {v.remove(0).a}")

Expected 1 then 2, actual 2 then 2. A 64-byte POD record; the same with a 24-byte record ({ n: i32, s: str }) prints correctly, and a six-field record with three strs (also 64 bytes) shows the same wrong result (remove(0) yields element 1, then element 1 again — the removed value is read after the shift, or the shift copies the wrong range). into_iter (VecIntoIter.next = remove(0)) inherits it, which is how it was first seen.

Likely class: the aggregate-copy / memmove lowering for element sizes above the store-merging threshold (#1129); route: --dump-mir of Vec.remove specialized for H, then the emitted IR of the shift and the returned copy.

Activity

  1. changed the title [-]into_iter over a returned Vec of a record with three str fields yields the last element at every position[/-] [+]Vec.remove(0) returns the wrong element for 64-byte elements (POD too); into_iter inherits it[/+] on Sep 25, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions