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

Clarify when protectors are added in tree borrows #11

Open
Imberflur opened this issue Jan 13, 2024 · 1 comment
Open

Clarify when protectors are added in tree borrows #11

Imberflur opened this issue Jan 13, 2024 · 1 comment

Comments

@Imberflur
Copy link

Imberflur commented Jan 13, 2024

Hi! https://perso.crans.org/vanille/treebor has been really useful for my understanding of the Tree Borrows model and for quickly referencing certain aspects. Thank you for this!

When reading the section on interior mutability and the summmary, I could not find anything indicating that shared references with interior mutability don't have protectors added (although I may have missed a detail). In fact, the summary section specifically includes that when entering a function "add a protector to all reference arguments".

However, after further investigation I found that any reference that would keep the tag of its parent pointer does not have a protector added. At least AFAICT from this:
https://github.com/rust-lang/miri/blob/13c915bb42aab8ee4075632e2aff42e95d570b56/src/borrow_tracker/tree_borrows/mod.rs#L157

It seems like there is potential for clarification here?

@Vanille-N
Copy link
Owner

Thanks for reporting this, I suppose there is indeed some clarification to be made.

Protectors are bound to tags and are created at the same time as the tag and at no other moment.
So if a reference inherits the tag of its parent it also inherits the protector (or lack thereof) of the parent.
This leads to two symmetrical behaviors not quite captured in "all reference arguments get a protector":

  • interior mutable shared references get the parent tag and thus have a protector only if the parent does
  • raw pointers duplicated from references may have a protector if the "parent" pointer (which actually has an identical tag) is protected

I hope this clears the confusion for you right now, I will also think of a way to change the wording of that section to make sure this gets across on the first reading.

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

2 participants