Skip to content

Conversation

@nnethercote
Copy link
Collaborator

It's wildly unsound, as far as I can tell.

  • The use of UnsafeCell/unsafe impl Send/unsafe impl Sync is very dodgy.
  • The use of MaybeUninit<[T; N]> is completely wrong. It should be [<MaybeUninit<T>; N>], which allows for partial initialization.
  • The examples don't use write/assume_init with MaybeUninit, which is UB.

The alternative is to use #[address_space(shared) static mut [MaybeUninit<T>; N] directly instead. That avoids all the unsoundness, and is more ergonomic because you don't have to work with a raw pointer, and is clearer because details aren't hidden within the macro.

I moved (with some modifications) the comments on shared_array to the address_space proc macro because there were some useful details in there.

@nnethercote
Copy link
Collaborator Author

While I was fixing #317 I found this macro and concluded it was both irredeemable and unnecessary. Using address_space(shared) directly is much better.

@nnethercote nnethercote force-pushed the rm-shared_array branch 2 times, most recently from a3a1ef6 to 709e14b Compare November 25, 2025 02:34
It's wildly unsound, as far as I can tell.
- The use of `UnsafeCell`/`unsafe impl Send`/`unsafe impl Sync` is very
  dodgy.
- The use of `MaybeUninit<[T; N]>` is completely wrong. It should be
  `[<MaybeUninit<T>; N>]`, which allows for partial initialization.
- The examples don't use `write`/`assume_init` with `MaybeUninit`, which
  is UB.

The alternative is to use `#[address_space(shared) static mut
[MaybeUninit<T>; N]` directly instead. That avoids all the unsoundness,
and is more ergonomic because you don't have to work with a raw pointer,
and is clearer because details aren't hidden within the macro.

I moved (with some modifications) the comments on `shared_array` to the
`address_space` proc macro because there were some useful details in
there.
This was non-obvious to me, and took a minute to work out.
@LegNeato LegNeato merged commit 7fa76f3 into Rust-GPU:main Nov 26, 2025
11 checks passed
@nnethercote nnethercote deleted the rm-shared_array branch November 26, 2025 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants