bjorn3 commented on issue #5229:
Would it make sense to have a method that returns
&UnsafeCell<[T]>or&Cell<[T]>?
github-actions[bot] commented on issue #5229:
Subscribe to Label Action
cc @kubkon
<details>
This issue or pull request has been labeled: "wasi"Thus the following users have been cc'd because of the following labels:
- kubkon: wasi
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
abrown commented on issue #5229:
Would it make sense to have a method that returns
&UnsafeCell<[T]>or&Cell<[T]>?I'm open to it; not sure if all of the functions exposed are necessary, though. Let's see what @alexcrichton and @pchickey think?
abrown commented on issue #5229:
Otherwise I think it should be able to implement:
rust impl<T> Deref for UnsafeGuestSlice<'_, T> { type Target = [UnsafeCell<T>]; // ... }which could actually be relatively convenient to work with.
Thinking about this more, I don't think accessing
Tthrough anUnsafeCellis right:UnsafeCell::get_mutwould give us a&mut Tand the documentation of that method claims that "this call borrows theUnsafeCellmutably (at compile-time) which guarantees that we possess the only reference," which is incorrect. It's incorrect becauseUnsafeGuestSliceis pointing to shared memory which could be modified at any time by any WASI thread, outside of the Rust borrowing world. @alexcrichton, what do you think?
alexcrichton commented on issue #5229:
The
get_mutmethod requires&mut selfso we won't have to worry about that here since we'll never hand out&mut UnsafeCell<T>. By more-or-less handing out&[UnsafeCell<T>]we're basically saying "here's a 100% valid region of memory in terms of in-bounds, you have access to it, and it's all aligned correctly and whatnot -- but the contents of memory are ruled by other mechanisms"The only way to interact with the contents of
&UnsafeCell<T>is to haveunsafe, which is the goal here, so I think it'll work out well. For unshared cases the wrapper methods to go to safe slices will work, and for shared cases it's clear that atomics/raw intrinsics/etc need to get used (and is something we'll document).
abrown commented on issue #5229:
The
get_mutmethod requires&mut selfAh, yeah, I see what you mean; this makes more sense. I'm not sure how/when this would be used, though; I guess this would be yet another way to modify a slice besides the
unsafeUnsafeGuestSlice::get_mut? (I guess we could also expose anunsafe`UnsafeGuestSlice::getwhich would return a&[T]). If this isn't going to be used just yet, should we implement this in this PR or wait until it is needed?
abrown edited a comment on issue #5229:
The
get_mutmethod requires&mut selfAh, yeah, I see what you mean; this makes more sense. I'm not sure how/when this would be used, though; I guess this would be yet another way to modify a slice besides the
unsafeUnsafeGuestSlice::get_mut? (I guess we could also expose anunsafeUnsafeGuestSlice::getwhich would return a&[T]). If this isn't going to be used just yet, should we implement this in this PR or wait until it is needed?
abrown edited a comment on issue #5229:
The
get_mutmethod requires&mut selfAh, yeah, I see what you mean; this makes more sense. I'm not sure how/when this would be used, though; I guess this would be yet another way to modify a slice besides the
unsafeUnsafeGuestSlice::get_mut? (I guess for completeness we could also expose anunsafeUnsafeGuestSlice::getwhich would return a&[T]). If this isn't going to be used just yet, should we implement this in this PR or wait until it is needed?
alexcrichton commented on issue #5229:
Oh I don't think the
Derefimpl is really all that important to have, it's just a "might as well" sort of thing. I think though having an interimUnsafeGuestSliceget constructed on the way to aGuestSlice{,Mut}will exercise it and make it useful. Only for niche cases willUnsafeGuestSlicebe useful. Note though we could haveUnsafeGuestSlice::copy_from_sliceas a safe method which only fails due to active borrows.
Last updated: Dec 13 2025 at 19:03 UTC