Skip to content

Atomic intrinsics pass an element view's address as the value (D27 materialization skipped) #1287

Closed

Description

@ehartford

Found rewriting `examples/ephemerality-and-lowering` under #1150 ruling 4.

`Atomic[i32].store(v, order)` / `fetch_add` are lowered as intrinsics (`src/MirLower.w:10359`, `ATOMIC_STORE`). When the argument is a positional element view (`xs[i]` or `xs.get(i)`, exact type `&i32` per D27 / §3.8), the intrinsic path does not materialize the `Copy` pointee under the owned demand of the `T` parameter: on a global `Atomic` the stored value is the element's address (consecutive elements differ by 4), and on a local `Atomic` the store is a no-op. A plain or generic function parameter (`fn take(v: i32)`, `fn take_gen[T](v: T)`) receives the value correctly, so the defect is in the intrinsic argument lowering, not in the view itself.

Repro (installed `with v0.15.2.1-g478b26481`):

```
use std.sync
var a: Atomic[i32] = Atomic.new(0)
fn main:
var order = Vec.new()
order.push(1)
order.push(2)
order.push(3)
a.store(order[2], .SeqCst)
print(f"a={a.load(.SeqCst)}") // expected 3; prints e.g. 39534616
a.store(order.get(1), .SeqCst)
print(f"a={a.load(.SeqCst)}") // expected 2; prints 39534612
let b: Atomic[i32] = Atomic.new(0)
b.store(order[2], .SeqCst)
print(f"b={b.load(.SeqCst)}") // expected 3; prints 0
```

Expected: both print the element value. Spec: §3.8 / D27 (an owned demand materializes a `Copy` pointee), §14.17.1.

Workaround in the example: `let v: i32 = order[2]` then `store(v, ...)` (remove when fixed).

Activity

  1. added a commit that references this issue on Sep 22, 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