Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnsafeCell::get_mut() is different from std #277

Open
kvark opened this issue Jun 6, 2022 · 5 comments
Open

UnsafeCell::get_mut() is different from std #277

kvark opened this issue Jun 6, 2022 · 5 comments

Comments

@kvark
Copy link
Contributor

kvark commented Jun 6, 2022

In std, it gets &mut self. In loom, it gets &self.
I think it's not a good idea to diverge in this way. I understand the return type may be different, but &self should be borrowed in the same way as it is in std.

@Darksonn
Copy link
Contributor

Darksonn commented Jun 6, 2022

Ah, well, the get_mut function in loom was never intended to be the loom version of the standard library function of the same name. It is intended to be the loom version of UnsafeCell::get in the cases where you want to modify the value. (And our get is the version of UnsafeCell::get for situations where you only read the value.)

@kvark
Copy link
Contributor Author

kvark commented Jun 7, 2022

Ok, if the intent was so different, let's have a different name to avoid confusion.
As far as I see, loom is generally used as a replacement for std, so having a difference in semantics like this is not desirable.

@hawkw
Copy link
Member

hawkw commented Jun 7, 2022

it's worth noting that the type was previously named CausalCell, but was renamed to UnsafeCell in #111. here's Carl's rationale at the time: #111 (comment)

@Darksonn
Copy link
Contributor

Darksonn commented Jun 7, 2022

I don't think this api is that bad. Since std::cell::UnsafeCell::get can be used to reimplement std::cell::UnsafeCell::get_mut, you can use our get_mut both as a get and get_mut.

@wyfo
Copy link

wyfo commented Jul 12, 2023

Should it be to add a method equivalent to std::cell::UnsafeCell::get_mut in loom::cell::UnsafeCell? std get_mut is normally safe to call (because of exclusive reference), but calling loom equivalent requires unsafe code, while it could be avoided.

I've just written this post about implementing AsMut for cell types; could loom::cell::UnsafeCell also implement AsMut?

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

No branches or pull requests

4 participants