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

Attempt to make FocusMut::pair compatible with stacked borrows #60

Closed
wants to merge 1 commit into from

Conversation

jplatte
Copy link
Contributor

@jplatte jplatte commented May 31, 2023

I wanted to take a stab at fixing #59 by making FocusMut::pair compatible with Stacked Borrows. I quickly ran into the limits of my understanding of this code though. Before I try harder, I wanted to ask if this is at all considered a useful change. We'd probably have to do the same thing for the triplet function right below pair for this to be useful.

@jneem
Copy link
Owner

jneem commented May 31, 2023

I think this is might get complicated, especially with triplet. The issue is that the other representation is basically a tree of chunks, and if I understood this comment correctly, the only way to do this under stacked borrows is to retrieve both pointers on the same tree traversal. So then you'll have to repeat the logic in Vector::get and Node::index multiple times...

I'm not sure I understood everything completely, but I wonder if this can be solved by just keeping the leaves stored behind a *mut [T] or something. That way you can access that chunk of memory without going through any &mut reference to it, which might stop the stacked borrows from invalidating it?

@jplatte
Copy link
Contributor Author

jplatte commented Jun 1, 2023

Yeah, that would be the other possibility (using NonNull though, to keep niche optimizations) but I think it would potentially push a lot of code into unsafe? Or maybe it's not actually that much..

Anyways, I'll close this since I think you're right that it requires a bunch of duplication.

@jplatte jplatte closed this Jun 1, 2023
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