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

Cell type that uses address of cell owner as key #14

Closed
uazu opened this issue Aug 17, 2021 · 4 comments
Closed

Cell type that uses address of cell owner as key #14

uazu opened this issue Aug 17, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@uazu
Copy link
Owner

uazu commented Aug 17, 2021

Since Rust guarantees no dangling references or use-after-free in safe code, it should be possible to use the address of the cell-owner as the key to access the cells, storing the address as the key in the cell.

If the owner is moved, then it loses access to the cells (which would typically be a bug in the user's code). Also if the owner is dropped and another owner created in the same memory, it will gain access to all the cells previously owned by the old owner. But this doesn't cause soundness problems, because there is still just one owner at any one time. Also access to a cell requires both a pointer to the cell and also the owner's key. So it really doesn't cause any issues that some other code might get logical ownership as it can't get access unless it also has pointers to the cells.

@uazu uazu added the enhancement New feature or request label Aug 17, 2021
@SoniEx2
Copy link
Contributor

SoniEx2 commented Aug 19, 2021

You can get dangling references: Box::new(()). But a PCellOwner could just be assert-non-zero-size. Pin might also be relevant here.

@uazu
Copy link
Owner Author

uazu commented Aug 19, 2021

Yes, ZSTs were in the back of my mind -- that's a good point. In any case I was thinking of making the owner contain a usize which was the owner's address when the first cell was created from it. The ownership would still be determined purely by the owner's current address, but the stored usize would be used to give a better diagnostic in the panic, e.g. "you moved the owner" or whatever. I think pinning can be left to the user. If they want to pin the structure which surrounds the owner to get that guarantee, and are willing to pay for the complexity, then that's up to them.

@SoniEx2
Copy link
Contributor

SoniEx2 commented Jan 25, 2022

Is this still relevant? Looks like we have #25 now.

@uazu
Copy link
Owner Author

uazu commented Jan 26, 2022

Yes, you're right. Thanks! I will close this as it is already implemented

@uazu uazu closed this as completed Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants