-
Notifications
You must be signed in to change notification settings - Fork 548
Fill out the borrowck chapter a bit more #234
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
Conversation
cc #180 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great. Left a few nits. I'm happy to land with typos fixed and keep iterating.
src/borrow_check/region_inference.md
Outdated
|
||
## Universal regions | ||
|
||
*to be written* – explain the `UniversalRegions` type | ||
The [`UnversalRegions`] type represents a collection of _unversal_ regions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "Universal" is misspelled as "unversal" in few places here. I think I would explain this through an example. Basically say something about how it computes information about the various named lifetimes in scope and their relationships to one another e.g., for the following function:
fn foo<'a>(x: &'a u32) { .. }
we would create a "universal region" 'a
as well as 'static
. (I really want to rename this, but anyway.)
That's probably good enough to start. The various categories of lifetimes around closures are interesting but maybe not needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I didn't dig into this part of the code, so I'm not really sure how it computes that info. I did add the other things you mentioned, though, and a note to add more.
src/borrow_check/region_inference.md
Outdated
The value of a region can be thought of as a **set**; we call the | ||
domain of this set a `RegionElement`. In the code, the value for all | ||
regions is maintained in | ||
The value of a region can be thought of as a **set** of points in the MIR where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really complete. It's actually a set of points + a set of universal regions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But adding a universal region is adding a set, no?
Also, the universal regions are the end('foo)
elements, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wondered if you would call me on that. =)
Yes, it's best I think to think of universal regions as "unknown sets", but they are not sets of points in MIR -- or at least they include points from outside the fn being investigated (to me, MIR implies "the source of one function).
I think it's also valid to think of a region as a "set of elements" where an "element" is a "MIR point" or "universal regions". That's certainly how it's implemented.
I guess I'm not sure what's the best way to describe it. I'm trying to remember if there is some point where the distinction is important. I'm also more and more trying to move into the polonius mindset, which is sort of different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this sentence. Let me know what you think.
I'm trying to remember if there is some point where the distinction is important.
Perhaps something around placeholders?
I'm also more and more trying to move into the polonius mindset, which is sort of different.
Would it be better to stay in the "NLL" mindset here for consistency and add a new chapter on Polonius?
src/borrow_check/region_inference.md
Outdated
|
||
Here are some of the fields of the struct: | ||
|
||
- `constraints`: contains all the outlives constraints. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we link to the rustdoc here, or otherwise try to prevent bitrot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe not worth it, I have some thoughts on how to revisit this section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to rework this section a bit to factor out the details from the meat. I also added an example.
I am a bit fuzzy on this part, so please let me know if you spot any problems. In particular, the example is a bit hand-wavey in some places...
we are inside a closure, we just collect all the constraints we can't prove yet | ||
and return them. Later, when we are borrow check the MIR node that created the | ||
closure, we can also check that these constraints hold. At that time, if we | ||
can't prove they hold, we report an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine, but really needs some examples
- `closure_bounds_mapping`: used for propagating region constraints from | ||
closures back out to the creater of the closure. | ||
|
||
TODO: should we discuss any of the others fields? What about the SCCs? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like overall this discussion is a bit too focused on the "low-level details" and not much about the high-level process, but it seems like a good start.
Thanks Niko! I will take a look at your comments and update accordingly. It might be a little while though... |
Thanks @mark-i-m =) finally merged |
I'm planning to play around with the borrow checker a bit for a class project, so I've learning a bit more.
Please let me know if anything is inaccurate or incomplete.
r? @nikomatsakis @pnkfelix